playing multiple wave files simultaneously with different volumes

5620a3b35c559ddea152e794a7e06382
0
k_sivarasah 101 Oct 15, 2010 at 08:35

Hi,

i’d like to play 2 audio files at the same time, but want them to have different volumes. i found a way to play them with wavOutOpen, Prepare Header…

but if i try to adjust the volume, the master wave-volume of both files are changed. that means both audio files have the same volume.

is there a way to set volume for those waves individually?

thx for any help
K.S.

6 Replies

Please log in or register to post a reply.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Oct 15, 2010 at 12:46

sure, you should just use a software implementation for audio, cause its not very computationally intense.

if you get access to the primary sound buffer manually, you can mix the sounds yourself and get anything you want out of them, even changing frequency or maybe adding a few small effects.

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 Oct 15, 2010 at 13:09

Alternatively, grab some audio library like bass or fmod and let it do the mixing for you.

5620a3b35c559ddea152e794a7e06382
0
k_sivarasah 101 Oct 19, 2010 at 11:53

thanks a lot for ur replies. my internet was not working, so i couldnt check for replies.

do u know any tutorial-sites for audio library like bass or fmod, or software implementation of audio u mentioned? otherwise I’ll google, try it out and post again if i have questions :)

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 104 Oct 19, 2010 at 14:27

If you want to go the software method (its as easy as adding samples together then digitally limiting if you really need it, but + by itself works.) direct sound is fine, thats how I did all my software DSP work! Just get any old direct x sdk and itll work, direct sound hasnt been updated since 10 years ago or something chronic like that. Dont worry it comes with full documentation.

5620a3b35c559ddea152e794a7e06382
0
k_sivarasah 101 Oct 21, 2010 at 13:58

hi

i read a lot and tried to write a code to simply playback an audio file with direct sound. but i just dont know how to load a file into the buffer. here is my code:

#include .....
#include <dsound.h>

using namespace std;

WAVEFORMATEX wfx;
DSBUFFERDESC dsBufferDesc;
LPDIRECTSOUND lpdSound = 0;
LPDIRECTSOUNDBUFFER lpdsBuffer = NULL;
HRESULT result;
HWND hWnd;
FILE* filePtr;    // file pointer for wave-file

int _tmain(int argc, _TCHAR* argv[])
{
    // waveformat settings
    memset(&wfx, 0, sizeof(WAVEFORMATEX));
    wfx.nSamplesPerSec = 44100; /* sample rate */
    wfx.wBitsPerSample = 16;   /* sample size */
    wfx.nChannels   = 2;   /* channels  */
    wfx.wFormatTag   = WAVE_FORMAT_PCM;
    wfx.nBlockAlign = 4;

    // DSBUFFERDESC structure settings
    memset(&dsBufferDesc, 0, sizeof(DSBUFFERDESC)); 
    dsBufferDesc.dwSize = sizeof(DSBUFFERDESC); 
    dsBufferDesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; 
    dsBufferDesc.dwBufferBytes = 0; 
    dsBufferDesc.lpwfxFormat = &wfx;

    DirectSoundCreate(NULL, &lpdSound, NULL);
    lpdSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
    lpdSound->CreateSoundBuffer(&dsBufferDesc, &lpdsBuffer, 0);
    return 0;
}

thanks for any help.

5620a3b35c559ddea152e794a7e06382
0
k_sivarasah 101 Oct 21, 2010 at 14:18

is LPDIRECTSOUNDBUFFER lpdsBuffer = NULL; just my primary buffer and i also need a secondarybuffer (LPDIRECTSOUNDBUFFER8) for playback?