本文介绍了为什么要播放单声道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么要单声道播放?
Why play it mono?
#pragma comment (lib, "winmm.lib")
#include <windows.h>
#include <mmsystem.h>
#include <stdlib.h>
void CALLBACK waveInProc(HWAVEIN hwi,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2);
bool addbuffer(WAVEHDR *pWaveHdr);
#define system_buf_len 4410
const int num_buff = 3;
HWAVEOUT hvo;
HWAVEIN hvi;
WAVEFORMATEX waveFormat;
WAVEHDR *whdrO;
WAVEHDR buffer[num_buff];
int main()
{
whdrO=(WAVEHDR*)malloc(sizeof(WAVEHDR));
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.wBitsPerSample = 16;
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 44100;
waveFormat.nBlockAlign = (waveFormat.nChannels * waveFormat.wBitsPerSample) / 8;
waveFormat.nAvgBytesPerSec = (waveFormat.nSamplesPerSec * waveFormat.nBlockAlign);
waveFormat.cbSize = 0;
UINT uDevice = 0;
MMRESULT mmres;
mmres = waveInOpen(&hvi,uDevice,&waveFormat,(DWORD)waveInProc,0,CALLBACK_FUNCTION);
mmres = waveOutOpen(&hvo,WAVE_MAPPER,&waveFormat,0,0,CALLBACK_NULL);
for (int i=0; i<num_buff; i++)
{
buffer[i].lpData = (char*)malloc(system_buf_len);
buffer[i].dwBufferLength = system_buf_len;
buffer[i].dwBytesRecorded = 0;
buffer[i].dwUser = 0;
buffer[i].dwFlags = 0;
buffer[i].dwLoops = 0;
waveInPrepareHeader(hvi, &buffer[i], sizeof(WAVEHDR));
waveInAddBuffer(hvi, &buffer[i], sizeof(WAVEHDR));
}
waveInStart(hvi);
system("pause");
waveInClose(hvi);
waveOutClose(hvo);
return 0;
}
void CALLBACK waveInProc(HWAVEIN hwi,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2)
{
WAVEHDR* pWaveHdr;
switch(uMsg)
{
case MM_WIM_DATA:
pWaveHdr = ((WAVEHDR*)dwParam1);
if (pWaveHdr && hwi)
if (pWaveHdr->dwFlags && WHDR_DONE == WHDR_DONE)
{
addbuffer(pWaveHdr);
waveInAddBuffer(hwi, pWaveHdr, sizeof(WAVEHDR));
}
break;
}
}
bool addbuffer(WAVEHDR *waveHdr)
{
memcpy(whdrO,waveHdr,sizeof(WAVEHDR));
waveInUnprepareHeader(hvi,waveHdr,sizeof(WAVEHDR));
waveOutPrepareHeader(hvo,waveHdr,sizeof(WAVEHDR));
waveOutWrite(hvo,whdrO, sizeof(WAVEHDR));
return true;
}
推荐答案
这篇关于为什么要播放单声道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!