Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Playing only part of a .wav file with directSound

Posted on 2005-05-12
2
Medium Priority
?
826 Views
Last Modified: 2013-12-08
Hi there,

I need to be be able to take a .wav file and play only part of it eg from 200to 800 ms through the file. I have code that will do it using DirectShow, but I'd like to do it in directSound.  Also, I can play the whole file using DirectSound, based on the examples in the SDK, but I don't know how to just play part of it.  Is it possible?  If the answer is "yes", and I get an explanation of how to make it work, I'll up the points to 250.

I'm using Visual C++ .NET 2003 IDE to write native C++ code, if it makes a difference.

Thank you.
0
Comment
Question by:wilsonian
2 Comments
 
LVL 17

Accepted Solution

by:
davebytes earned 1000 total points
ID: 14057697
I don't offhand know of a way to do it without copying the data that would get it EXACT -- i.e., you could use a position notification callback to try to stop it really close to where you want it to end, and set the starting position to the desired offset... but no guarantee you'll stop it 'on a dime' where desired...

Copying the data is pretty trivial -- it's JUST basic PCM audio data we're talking about here.  So clipping out a particular 600ms 'chunk' is simply calculating the byte offset for the start, and the byte length of that many ms, based on the format of the audio (mono vs stereo, samples per second/frequency, etc.).  Just create a DirectSoundBuffer object with the buffer size equal to the 'chunk', Lock the buffer, do a memcpy from the source data ptr + byte offset, to the locked buffer ptr, of the determined byte length.  Unlock, and Play.

-d
0
 

Author Comment

by:wilsonian
ID: 14065221
My boss has decided there are other things it's more important for me to be doing at the moment so I haven't had a chance to try this out but your solution seems sensible so I'll give you the points to save this dragging out.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question