HRESULT CDelay::InternalAllocateStreamingResources() { AtlTrace("InternalAllocateStreamingResources()\n"); _ASSERTE(InputType(0)->formattype == FORMAT_WaveFormatEx); _ASSERTE(m_dwDelay > 0); m_pWave = (WAVEFORMATEX*)InputType(0)->pbFormat; // Allocate the buffer that holds the delayed samples m_cbDelayBuffer = (m_dwDelay * m_pWave->nSamplesPerSec * m_pWave->nBlockAlign) / 1000; m_pbDelayBuffer = (BYTE*)CoTaskMemAlloc(m_cbDelayBuffer); if (m_pbDelayBuffer == NULL) { return E_OUTOFMEMORY; } FillBufferWithSilence(); m_pbDelayPtr = m_pbDelayBuffer; AtlTrace("\tAllocated %d byte buffer.\n", m_cbDelayBuffer); DumpWaveformat(m_pWave); return S_OK; }
HRESULT CDelay::InternalFlush() { AtlTrace("InternalFlush()\n"); m_pBuffer = NULL; if (m_pbDelayBuffer) { FillBufferWithSilence(); } return S_OK; }
void SetupDSoundBuffers(void) { LPDIRECTSOUNDBUFFER lpdsb; DSBUFFERDESC dsPrimaryBuff, dsbdesc; WAVEFORMATEX wfm; HRESULT hr; int count; if (lpdsbuf) { CloseDLL(); InitiateAudio(AudioInfo);} if ( FAILED( hr = DirectSoundCreate( NULL, &lpds, NULL ) ) ) { return FALSE; } if ( FAILED( hr = IDirectSound8_SetCooperativeLevel(lpds, AudioInfo.hwnd, DSSCL_PRIORITY ))) { return FALSE; } for ( count = 0; count < NUMCAPTUREEVENTS; count++ ) { rghEvent[count] = CreateEvent( NULL, FALSE, FALSE, NULL ); if (rghEvent[count] == NULL ) { return FALSE; } } memset( &dsPrimaryBuff, 0, sizeof( DSBUFFERDESC ) ); dsPrimaryBuff.dwSize = sizeof( DSBUFFERDESC ); dsPrimaryBuff.dwFlags = DSBCAPS_PRIMARYBUFFER; dsPrimaryBuff.dwBufferBytes = 0; dsPrimaryBuff.lpwfxFormat = NULL; memset( &wfm, 0, sizeof( WAVEFORMATEX ) ); wfm.wFormatTag = WAVE_FORMAT_PCM; wfm.nChannels = 2; wfm.nSamplesPerSec = 44100; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; hr = IDirectSound8_CreateSoundBuffer(lpds,&dsPrimaryBuff, &lpdsb, NULL); if (SUCCEEDED ( hr ) ) { IDirectSoundBuffer8_SetFormat(lpdsb, &wfm ); IDirectSoundBuffer8_Play(lpdsb, 0, 0, DSBPLAY_LOOPING ); } wfm.nSamplesPerSec = Frequency; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; memset( &dsbdesc, 0, sizeof( DSBUFFERDESC ) ); dsbdesc.dwSize = sizeof( DSBUFFERDESC ); dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; dsbdesc.dwBufferBytes = BufferSize * 3; dsbdesc.lpwfxFormat = &wfm; if ( FAILED( hr = IDirectSound8_CreateSoundBuffer(lpds, &dsbdesc, &lpdsbuf, NULL ) ) ) { DisplayError("Failed in creation of Play buffer 1"); } FillBufferWithSilence( lpdsbuf ); rgdscbpn[0].dwOffset = ( BufferSize ) - 1; rgdscbpn[0].hEventNotify = rghEvent[0]; rgdscbpn[1].dwOffset = ( BufferSize * 2) - 1; rgdscbpn[1].hEventNotify = rghEvent[1]; rgdscbpn[2].dwOffset = ( BufferSize * 3) - 1; rgdscbpn[2].hEventNotify = rghEvent[2]; rgdscbpn[3].dwOffset = DSBPN_OFFSETSTOP; rgdscbpn[3].hEventNotify = rghEvent[3]; if ( FAILED( hr = IDirectSound8_QueryInterface(lpdsbuf, &IID_IDirectSoundNotify, ( VOID ** )&lpdsNotify ) ) ) { DisplayError("IDirectSound8_QueryInterface: Failed\n"); return; } // Set capture buffer notifications. if ( FAILED( hr = IDirectSoundNotify_SetNotificationPositions(lpdsNotify, NUMCAPTUREEVENTS, rgdscbpn ) ) ) { DisplayError("IDirectSoundNotify_SetNotificationPositions: Failed"); return; } //AddEffect(); }