# playing multiple wave files simultaneously with different volumes

6 replies to this topic

### #1k.sivarasah

New Member

• Members
• 4 posts

Posted 15 October 2010 - 08:35 AM

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.

### #2rouncer

Senior Member

• Members
• 2725 posts

Posted 15 October 2010 - 12:46 PM

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.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #3Sol_HSA

Senior Member

• Members
• 510 posts
• LocationNowhere whenever

Posted 15 October 2010 - 01:09 PM

Alternatively, grab some audio library like bass or fmod and let it do the mixing for you.
http://iki.fi/sol - my schtuphh

### #4k.sivarasah

New Member

• Members
• 4 posts

Posted 19 October 2010 - 11:53 AM

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 :)

### #5rouncer

Senior Member

• Members
• 2725 posts

Posted 19 October 2010 - 02:27 PM

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.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

### #6k.sivarasah

New Member

• Members
• 4 posts

Posted 21 October 2010 - 01:58 PM

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.

### #7k.sivarasah

New Member

• Members
• 4 posts

Posted 21 October 2010 - 02:18 PM

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

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users