Click here to Skip to main content
15,912,977 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Proper usage of #pragma once Pin
cmk29-Jun-04 9:56
cmk29-Jun-04 9:56 
GeneralRe: Proper usage of #pragma once Pin
Jeremy Falcon29-Jun-04 10:49
professionalJeremy Falcon29-Jun-04 10:49 
GeneralRe: Proper usage of #pragma once Pin
PJ Arends29-Jun-04 11:07
professionalPJ Arends29-Jun-04 11:07 
GeneralRe: Proper usage of #pragma once Pin
Maximilien30-Jun-04 3:25
Maximilien30-Jun-04 3:25 
GeneralRe: Proper usage of #pragma once Pin
Michael Dunn29-Jun-04 12:09
sitebuilderMichael Dunn29-Jun-04 12:09 
QuestionHow do I keep Menu from covering Property page tabs Pin
Bob_The_Programmer29-Jun-04 8:58
Bob_The_Programmer29-Jun-04 8:58 
Questionhow to loop portions of a WAV using DirectSound? Pin
seanmc.cs29-Jun-04 8:26
seanmc.cs29-Jun-04 8:26 
AnswerRe: how to loop portions of a WAV using DirectSound? Pin
Antti Keskinen29-Jun-04 11:57
Antti Keskinen29-Jun-04 11:57 
Use three buffers.

The primary buffer is used by DirectSound to playback the wave. You shovel data into this buffer, DirectSound then plays the data and then the data is discarded. You then have one secondary buffer that contains actual data from the file you wish to play. The easiest way is to use small wave files and load the entire file into this buffer. Finally, you have a tertiary buffer that contains only the data you wish to loop. If your sound files are large (over 1 Mb), the secondary buffer must be a streaming one or you'll quickly run out of memory.

While normal playback is up, shovel data from the secondary buffer into the primary buffer. When a looping section occurs, shovel data into the primary buffer from the tertiary one. When the looping should end

The most efficient way to do this is to create two wave files. One which has the entire wave you wish the play, and one with just the looping section. You can then use a full-feature wave editor program to accurately pinpoint the samples and timings on where you can start the loop, and where you can end it and continue with the original file.

It is wise to use a buffer. The alternative is that you shovel data directly from the file stream into the primary buffer. The disadvantage is that if a disk-excessive application happens to start or the OS needs access to the drive, your sound may glitch badly. Loading the data into a buffer beforehand is more efficient. Naturally, best results are achieved by using small buffers and always keeping a few seconds of audio data in reserve.

For an example on how to use a secondary buffer with DirectSound, you should consult the DirectSound C++ SDK and it's manual. The necessary functions (Lock, Unlock, Play) can be found from the IDirectSoundBuffer -interface.

I suggest you first design the buffer-usage with a paper and a pen, taking note of buffer positions, chunk sizes and all that. Remember that you can specify the size of the secondary buffer, but not for the primary one.

If this does not help you out, I might consider writing a small sample application, as the technique interests me as well.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: how to loop portions of a WAV using DirectSound? Pin
seanmc.cs30-Jun-04 15:53
seanmc.cs30-Jun-04 15:53 
GeneralRe: how to loop portions of a WAV using DirectSound? Pin
seanmc.cs30-Jun-04 17:22
seanmc.cs30-Jun-04 17:22 
GeneralRe: how to loop portions of a WAV using DirectSound? Pin
Antti Keskinen1-Jul-04 7:33
Antti Keskinen1-Jul-04 7:33 
AnswerBlips are natural! Pin
normanS1-Jul-04 3:23
normanS1-Jul-04 3:23 
Generalwinsock2 for MS Visual C++ Toolkit 2003 Pin
george kermeen29-Jun-04 8:21
george kermeen29-Jun-04 8:21 
GeneralRe: winsock2 for MS Visual C++ Toolkit 2003 Pin
palbano29-Jun-04 13:39
palbano29-Jun-04 13:39 
GeneralRe: winsock2 for MS Visual C++ Toolkit 2003 Pin
george kermeen30-Jun-04 4:18
george kermeen30-Jun-04 4:18 
Generalwin32 dll Pin
ns29-Jun-04 7:42
ns29-Jun-04 7:42 
GeneralRe: win32 dll Pin
Jeremy Falcon29-Jun-04 8:53
professionalJeremy Falcon29-Jun-04 8:53 
GeneralStart Full or Min Pin
Zenix229-Jun-04 7:35
Zenix229-Jun-04 7:35 
GeneralRe: Start Full or Min Pin
David Crow29-Jun-04 8:31
David Crow29-Jun-04 8:31 
GeneralRe: Start Full or Min Pin
Zenix229-Jun-04 9:43
Zenix229-Jun-04 9:43 
GeneralRe: Start Full or Min Pin
vcplusplus29-Jun-04 13:58
vcplusplus29-Jun-04 13:58 
GeneralRe: Start Full or Min Pin
David Crow30-Jun-04 2:39
David Crow30-Jun-04 2:39 
GeneralRe: Start Full or Min Pin
Zenix21-Jul-04 4:55
Zenix21-Jul-04 4:55 
GeneralRe: Start Full or Min Pin
David Crow1-Jul-04 5:09
David Crow1-Jul-04 5:09 
GeneralRe: Start Full or Min Pin
Zenix21-Jul-04 5:23
Zenix21-Jul-04 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.