14/06/2008, 13:22
|
| | Fecha de Ingreso: junio-2008
Mensajes: 5
Antigüedad: 16 años, 7 meses Puntos: 0 | |
Respuesta: Dispositivo de audio Hola tengo un problema similar, probé con lo del pragma pero me sigue dando el mismo error: undefined reference to '_waveInOpen@24' y similares
Este es el código
//#pragma comment (lib,"winmm.lib")
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
int main()
{
const int NUMPTS = 44100 * 10; // 10 seconds
int sampleRate = 44100;
short int waveIn[NUMPTS]; // 'short int' is a 16-bit type; I request 16-bit samples below
// for 8-bit capture, you'd use 'unsigned char' or 'BYTE' 8-bit types
HWAVEIN hWaveIn;
WAVEHDR WaveInHdr;
MMRESULT result;
// Specify recording parameters
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;
result = waveInOpen(&hWaveIn, WAVE_MAPPER,&pFormat,
0L, 0L, WAVE_FORMAT_DIRECT);
if (result)
{
char fault[256];
waveInGetErrorText(result, fault, 256);
cout<<"Failed to open waveform input device."<<endl;
// Application->MessageBox(fault, "Failed to open waveform input device.",
// MB_OK | MB_ICONEXCLAMATION);
return 0;
}
// Set up and prepare header for input
WaveInHdr.lpData = (LPSTR)waveIn;
WaveInHdr.dwBufferLength = NUMPTS*2;
WaveInHdr.dwBytesRecorded=0;
WaveInHdr.dwUser = 0L;
WaveInHdr.dwFlags = 0L;
WaveInHdr.dwLoops = 0L;
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// Insert a wave input buffer
result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
if (result)
{
cout<<"Failed to read block from device"<<endl;
//MessageBox(Application->Handle, "Failed to read block from device",
// NULL, MB_OK | MB_ICONEXCLAMATION);
return 1;
}
// Commence sampling input
result = waveInStart(hWaveIn);
if (result)
{
cout<<"Failed to start recording"<<endl;
//MessageBox(Application->Handle, "Failed to start recording",
// NULL, MB_OK | MB_ICONEXCLAMATION);
return 1;
}
// Wait until finished recording
do {} while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR))==WAVERR_STILLPLAYING);
waveInClose(hWaveIn);
cout << "Hello world!" << endl;
return 0;
}
lo que quiero es tomar el audio desde C++ a bajo nivel, y si es posible un código compatible para Linux.
1) mmsystem.h ¿anda en linux? ¿Que otra librería me recomiendan?
Muchas Gracias |