snd_buffer(SOUND* snd, void** pDesc, void*** ppSample)
Reads, modifies, or replaces a sound buffer at runtime. Can be used to play own sound samples through the engine's sound player.
A7.80 LC
Parameters:
pDesc - Pointer that is set to the sound's DSBUFFERDESC pointer. Can be used to read and modify the DSBUFFERDESC struct.
ppSample - Pointer that is set to the address of the sound's sample buffer pointer. Can be used to read, modify, or free and replace the sample buffer.
Speed:
Fast
Remarks:
- The DSBUFFERDESC struct is defined in include\d3d9.h,
and can be used to retrieve the sound length and sample frequency.
A7.81
- For freeing the old and allocating a new sample buffer, the sys_free and sys_malloc functions must be used.
- Sample buffers can only be changed or copied into before the sound is played the first time. Afterwards it can't be modified anymore
by directly accessing the buffer. For changing a sound while it's playing, use snd_add.
Example (C++ or lite-C):
DSBUFFERDESC *dsBufferDesc; // from DirectSound 8
byte** pSampleBuffer;
SOUND* oldsound = snd_create("#20"); // create a 20 seconds dummy sound
snd_buffer(oldsound,&dsBufferDesc,&pSampleBuffer);
// remove original sample
if (pSampleBuffer && *pSampleBuffer) sys_free(*pSampleBuffer);
// create and copy a new sample
byte* myNewSampleBuffer = (byte*)sys_malloc(myNewBufferLength);
memcpy(myNewSampleBuffer,mySoundData,myNewBufferLength);
// replace with new sample
*pSampleBuffer = myNewSampleBuffer;
dsBufferDesc->dwBufferBytes = myNewBufferLength;
memcpy(dsBufferDesc->lpwfxFormat,myNewWaveFormat,sizeof(WAVEFORMATEX));
See also:
SOUND, snd_create,
snd_add
► latest
version online