Como quito ese ruido?
como verán quiero hacer esto con doble buffer
Código C++:
Ver original
#include <windows.h> #include <stdio.h> #include <mmsystem.h> #include <math.h> WAVEFORMATEX WaveFormat; HWAVEOUT HWaveOut; DWORD WaveBufSize; WAVEHDR WaveHeader[2]; unsigned char onda[1024]; void CALLBACK WaveOutProc(HWAVEOUT waveOut, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { if(uMsg==MM_WOM_DONE) waveOutWrite(HWaveOut, (WAVEHDR *)dwParam1, sizeof(WAVEHDR)); } int main(int argc, char **argv) { //Creo la onda float PI=3.14159265358979323846; //Establesco los parametros de sonido WaveFormat.nSamplesPerSec = 26000; WaveFormat.wBitsPerSample = 8; WaveFormat.nChannels = 1; WaveFormat.cbSize = 0; WaveFormat.wFormatTag = WAVE_FORMAT_PCM; WaveFormat.nBlockAlign = (WaveFormat.wBitsPerSample /8) * WaveFormat.nChannels; WaveFormat.nAvgBytesPerSec = WaveFormat.nBlockAlign * WaveFormat.nSamplesPerSec; //Pongo el driver a sonar waveOutOpen(&HWaveOut, WAVE_MAPPER, &WaveFormat, (DWORD)WaveOutProc, 0, CALLBACK_FUNCTION); WaveBufSize=1024; WaveHeader[0].lpData=(char *)onda; WaveHeader[1].lpData=(char *)onda; WaveHeader[0].dwBufferLength=WaveBufSize; WaveHeader[1].dwBufferLength=WaveBufSize; waveOutPrepareHeader(HWaveOut, &WaveHeader[0], sizeof(WAVEHDR)); waveOutPrepareHeader(HWaveOut, &WaveHeader[1], sizeof(WAVEHDR)); waveOutWrite(HWaveOut, &WaveHeader[0], sizeof(WAVEHDR)); waveOutWrite(HWaveOut, &WaveHeader[1], sizeof(WAVEHDR)); //Finalizo waveOutReset(HWaveOut); waveOutUnprepareHeader(HWaveOut, &WaveHeader[1], sizeof(WAVEHDR)); waveOutUnprepareHeader(HWaveOut, &WaveHeader[0], sizeof(WAVEHDR)); waveOutClose(HWaveOut); }