How to create create 20 secondary buffers using direct sound


#1

HI everybody,
In my project i have to play 20 multiple sounds parallelly.
for that i created 20 secondary buffers. By using these 20 buffers i played the sound also.
but i am unable to stop perticular sound .

Can any body help me in this problem.plz.


#2

Sorry - I think you’re going to have to explain that a bit better!


#3

HI,

Thanks for your reply.

In our project we have to play 20 sounds parallely.

for that we are following the below code.

by using LPDIRECTSOUNDBUFFER buf1,buf2, we are creating 2 buffers.
LPDIRECTSOUNDBUFFER buf1,buf2;

in main function we are play function to generate sound.we are calling this functtion twice.to generate 2 sounds.

play(&buf1);
play(&buf2);

void play( LPDIRECTSOUNDBUFFER *lpDSBuf)
{
HRESULT hr1;

m_pDataWPlay1 = NULL;
m_pDataWPlay2 = NULL;

memset(&m_PCMWf, 0, sizeof(PCMWAVEFORMAT));
m_PCMWf.wf.wFormatTag = WAVE_FORMAT_PCM;
m_PCMWf.wf.nChannels = 2;
m_PCMWf.wf.nSamplesPerSec = 22050;
m_PCMWf.wf.nBlockAlign = 4;
m_PCMWf.wf.nAvgBytesPerSec = 88200;
m_PCMWf.wBitsPerSample = 16;

memset(&m_DSBufDesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.

m_DSBufDesc.dwSize = sizeof(DSBUFFERDESC);
m_DSBufDesc.dwFlags = DSBCAPS_STATIC|DSBCAPS_CTRLFREQUENCY|DSBCAPS_GLOBALFOCUS|DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLVOLUME;
m_DSBufDesc.dwBufferBytes =l_bufsize;
m_DSBufDesc.lpwfxFormat = (LPWAVEFORMATEX)&m_PCMWf;
if(hr1==(lpDSO)->CreateSoundBuffer(lpDSO,&m_DSBufDesc,lpDSBuf,NULL))
{
printf(“created”);
}

if(hr1==(*lpDSBuf)->Lock( 0, m_DSBufDesc.dwBufferBytes, &m_pDataWPlay1, &m_dwLengthWPlay1,
&m_pDataWPlay2, &m_dwLengthWPlay2, 0L ))
{
printf(“locked”);

}

memcpy(m_pDataWPlay1 , temp, l_bufsize );

(*lpDSBuf)->Unlock( m_pDataWPlay1, m_DSBufDesc.dwBufferBytes, NULL, 0 );

if((hr=(*lpDSBuf)->Play(0,0,0))==0)
{
printf(“played”);
}

m_pDataWPlay1 = NULL;
}

here we are creating the direct sound object by using following code.

hr = DirectSoundCreate(NULL,&lpDSO,NULL);
if (hr == DS_OK)
{
printf(“object created”);
hr1 = (lpDSO)->lpVtbl->SetCooperativeLevel(lpDSO, hMainWnd ,DSSCL_PRIORITY);
if (hr1 == DS_OK) //see if Coop worked
{
printf(“set cooperative level”); //we initialized successfully, return true

}
}

can u please see whether we are following right approach


#4

erm… have you wandered onto the wrong website by mistake?? How does this relate to Juce, exactly?..