看板 C_and_CPP 關於我們 聯絡資訊
最近在播放wav檔時有了一些問題, 播出來的聲音只有"逼"一聲,跟檔案的聲音不一樣。 先讀出前面檔頭後,得到: Channel: 1 //值存在 m_wChannels; Sample rate: 11025 //值存在 m_dwSampleRate; Bit rate: 8 //值存在 m_wBitRate; Block Align: 1 //值存在 m_wBlockAlign; Size of Data: 7057 //值存在 m_dwBufferSize; 用BYTE pointer讀取檔頭後面的data sample: BYTE* m_pRawDataBuf = new BYTE [m_dwBufferSize]; DWORD cbRead = 0; BOOL bOK = ReadFile(m_hFile, m_pRawDataBuf, sizeof(m_dwBufferSize), &cbRead, NULL); Q1. 請問用BYTE儲存後面的sample value對嗎?還是要用char? Q2. Sample value的range是 0~255 還是 -127~128? 然後用waveOutXXX系列的函數輸出聲音,依序調用waveOutOpen, waveOutPrepareHeader, waveOutWrite, waveOutUnprepareHeader HWAVEOUT m_hWaveOut = NULL; WAVEFORMATEX wavFormat = {0}; memcpy_s(&wavFormat, sizeof(WAVEFORMATEX), &m_pcmHeader, sizeof(PCMWAVEFORMAT)); UINT uResult = 0; uResult = waveOutOpen(&m_hWaveOut, WAVE_MAPPER, (LPWAVEFORMATEX)&wavFormat, NULL, 0, CALLBACK_NULL); if(uResult != MMSYSERR_NOERROR) return WAVEHDR wavHeader = {0}; wavHeader.dwBufferLength = m_dwBufferSize; wavHeader.lpData = (char*)m_pRawDataBuf; uResult = waveOutPrepareHeader(m_hWaveOut, &wavHeader, sizeof(WAVEHDR)); if(uResult != MMSYSERR_NOERROR) return; uResult = waveOutWrite(m_hWaveOut, &wavHeader, sizeof(WAVEHDR)); if(uResult != MMSYSERR_NOERROR) return; Sleep(3000); while(waveOutUnprepareHeader(m_hWaveOut, &wavHeader, sizeof(WAVEHDR)) == WAVERR_STILLPLAYING) Sleep(100); 每個API調用結果uResult都是0,表示正確,但最後輸出的聲音卻只有"逼"一聲 Q3. 請問是哪裡有出錯嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.240.215.117
pico2k:改用PlaySoundA/PlaySoundW 吧 07/26 23:35
firejox:sizeof(m_dwBufferSize)... 07/28 16:57