Tag: 录音

尝试编写通过WinAPI录制和播放声音的函数

我正在尝试在C中创建2个函数: 一个录制麦克风X秒 获得录音并播放给用户的录音 这就是我写的: #include #include using namespace std; #pragma comment(lib, “winmm.lib”) WAVEHDR StartRecord(int seconds) { const int NUMPTS = 44100 * seconds; int sampleRate = 44100; short int *waveIn = new short int[NUMPTS]; HWAVEIN hWaveIn; WAVEHDR WaveInHdr; MMRESULT result; WAVEFORMATEX pFormat; pFormat.wFormatTag = WAVE_FORMAT_PCM; pFormat.nChannels = 1; pFormat.nSamplesPerSec = sampleRate; pFormat.nAvgBytesPerSec = 2 * […]

压缩PCM数据

我正在使用WinAPI – Wavefunction来创建一个记录麦克风X秒的录制程序。 我在网上搜索了一下,发现PCM数据太大了,通过套接字发送它会有问题…… 如何将其压缩到更小的尺寸? 任何简单/“便宜”的方式? 我也注意到,当我使用Wave API函数声明格式时,我正在使用此代码: WAVEFORMATEX pFormat; pFormat.wFormatTag= WAVE_FORMAT_PCM; // simple, uncompressed format pFormat.nChannels=1; // 1=mono, 2=stereo pFormat.nSamplesPerSec=sampleRate; // 44100 pFormat.nAvgBytesPerSec=sampleRate*2; // = nSamplesPerSec * n.Channels * wBitsPerSample/8 pFormat.nBlockAlign=2; // = n.Channels * wBitsPerSample/8 pFormat.wBitsPerSample=16; // 16 for high quality, 8 for telephone-grade pFormat.cbSize=0; 如您所见, pFormat.wFormatTag= WAVE_FORMAT_PCM; 也许我可以插入而不是WAVE_FORMAT_PCM其他东西,所以它会被立即压缩? 我已经检查了MSDN的其他值,虽然它们在我的Visual Studio中都不适合我… 那我该怎么办? 谢谢!