/* extract pitch contour of the input sound file */ int SPitchContourExtraction(char* filename,float*& fPitchData,int &nFrm){ SWaveDataStru mySWaveDataStru; if(WaveRead(filename,mySWaveDataStru)!=0){ printf("Error on WaveRead\n"); return -1; } mySWaveDataStru.fs=8000; SPitchExtraction(mySWaveDataStru, 0.0015f, MIN_PITCH_VALUE, MAX_PITCH_VALUE, 50, 500,fPitchData,nFrm); delete[] mySWaveDataStru.fDataBuf; return 0; }
/* ------------------------------------------------------------------------------------ */ int StreamingAudio::PumpWave(int nSize) { HRESULT hr; void *lpbuf1 = NULL, *lpbuf2 = NULL; DWORD dwsize1 = 0, dwsize2 = 0; UINT nBytesRead = 0; // Ok, we need to set up our "silence" value and adjust it for // ..8bit samples if needed. int nSilence = 0x0; if(m_pWaveFormat->wBitsPerSample == 8) nSilence = 0x80; // In case wave is 8-bit // Ok, try to lock <n>K of the buffer. If it fails, just bail this // ..function. hr = m_pStream->Lock(m_nOffset, nSize, &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0); if(hr != DS_OK) { CCD->ReportError("[WARNING] StreamingAudio::PumpWave: Failed to lock", false); return RGF_SUCCESS; // Fake it, bail out } if(lpbuf1 != NULL) memset(lpbuf1, nSilence, dwsize1); // Clear to silence if(lpbuf2 != NULL) memset(lpbuf2, nSilence, dwsize2); // Here, also m_nOffset = (m_nOffset + dwsize1 + dwsize2) % kBufferSize; if(m_fEOF == true) { m_pStream->Unlock(lpbuf1, dwsize1, lpbuf2, dwsize2); return RGF_SUCCESS; // End of file, pump silence } if(m_fActive == false) { m_pStream->Unlock(lpbuf1, dwsize1, lpbuf2, dwsize2); return RGF_SUCCESS; // Inactive, pump silence } // Fine, read data into the circular buffer directly from the // ..wave file if there's anything there. // Fill block #1 hr = WaveRead(m_hWaveFile, dwsize1, (BYTE*)lpbuf1, &m_rRiffData, &nBytesRead); if(nBytesRead != dwsize1) // End of wave file { m_fEOF = true; // m_pStream->Unlock(lpbuf1, dwsize1, lpbuf2, dwsize2); // return RGF_SUCCESS; } if((lpbuf2 != NULL) && (!m_fEOF)) { // Fill block #2 hr = WaveRead(m_hWaveFile, dwsize2, (BYTE*)lpbuf2, &m_rRiffData, &nBytesRead); if(nBytesRead != dwsize2) // End of wave file m_fEOF = true; } // Unlock buffer, we're done with it for now. m_pStream->Unlock(lpbuf1, dwsize1, lpbuf2, dwsize2); // Ok, if we're at the end of file AND we're flagged to loop, rewind // ..to the beginning of the buffer so we start from the top next // ..time through. if(m_fEOF && m_bLoops) Rewind(); // Hope the sound designer looped the WAVE right! return RGF_SUCCESS; }