Hola,
Soy nuevo en OpenAL y estoy intentando hacer un protopipo que simplemente capture audio del micrófono y lo guarde en un archivo .raw. He seguido varios tutoriales y conseguí hacer esto:
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <al.h>
#include <alc.h>
#include <alut.h>
#include <fcntl.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define SRATE 8000
#define SSIZE 1024
#define FILENAME "telo.raw"
int main (void){
ALbyte buffer[22050];
ALint sample;
FILE *pFileRAW;
const ALCchar *szDefaultCaptureDevice;
// Get list of available Capture Devices
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
if (pDeviceList)
{
cout<<"Dispositivos de captura disponibles:"<<endl;
while (*pDeviceList)
{
cout<<" *"<<pDeviceList<<endl;
pDeviceList += strlen(pDeviceList) + 1;
}
}
// Get the name of the 'default' capture device
szDefaultCaptureDevice = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
//ALCdevice* audioDevice = alcOpenDevice(szDefaultCaptureDevice);
//ALCcontext* audioContext = alcCreateContext(audioDevice,NULL);
//alcMakeContextCurrent(audioContext);
fopen_s(&pFileRAW,FILENAME, "wb");
ALCdevice *device = alcCaptureOpenDevice(szDefaultCaptureDevice, SRATE, AL_FORMAT_STEREO16, SSIZE);
//ALCdevice *device = alcCaptureOpenDevice(szDefaultCaptureDevice, SRATE, AL_FORMAT_MONO16, SSIZE);
/*if (alGetError() != AL_NO_ERROR) {
return 0;
}*/
cout<<endl;
cout<<"Pulse la tecla 's' para iniciar la captura"<<endl;
cout<<endl;
cout<<"Pulse cualquier tecla para parar la grabacion"<<endl;
char tecla;
cin>>tecla;
if(tecla=='s'){
alcCaptureStart(device);
cout<<"Grabando"<<endl;
while (!_kbhit()) {
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
//cout<<"samples capturadas: "<<sample<<endl;
alcCaptureSamples(device, (ALCvoid *)buffer, sample);
fwrite(buffer,sample, 1, pFileRAW);
}
fclose( pFileRAW );
alcCaptureStop(device);
alcCaptureCloseDevice(device);
}
return 0;
}
Mi duda es, cuando voy a reproducir el archivo con audacity o otro programa, la duración de este es mucho menor que la del tiempo empleado en la grabación. ¿por que pasa eso? Por ejemplo hice el mismo prototipo en Android y el archivo tiene la duración correcta.
Muchas gracias
Soy nuevo en OpenAL y estoy intentando hacer un protopipo que simplemente capture audio del micrófono y lo guarde en un archivo .raw. He seguido varios tutoriales y conseguí hacer esto:
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <al.h>
#include <alc.h>
#include <alut.h>
#include <fcntl.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define SRATE 8000
#define SSIZE 1024
#define FILENAME "telo.raw"
int main (void){
ALbyte buffer[22050];
ALint sample;
FILE *pFileRAW;
const ALCchar *szDefaultCaptureDevice;
// Get list of available Capture Devices
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
if (pDeviceList)
{
cout<<"Dispositivos de captura disponibles:"<<endl;
while (*pDeviceList)
{
cout<<" *"<<pDeviceList<<endl;
pDeviceList += strlen(pDeviceList) + 1;
}
}
// Get the name of the 'default' capture device
szDefaultCaptureDevice = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
//ALCdevice* audioDevice = alcOpenDevice(szDefaultCaptureDevice);
//ALCcontext* audioContext = alcCreateContext(audioDevice,NULL);
//alcMakeContextCurrent(audioContext);
fopen_s(&pFileRAW,FILENAME, "wb");
ALCdevice *device = alcCaptureOpenDevice(szDefaultCaptureDevice, SRATE, AL_FORMAT_STEREO16, SSIZE);
//ALCdevice *device = alcCaptureOpenDevice(szDefaultCaptureDevice, SRATE, AL_FORMAT_MONO16, SSIZE);
/*if (alGetError() != AL_NO_ERROR) {
return 0;
}*/
cout<<endl;
cout<<"Pulse la tecla 's' para iniciar la captura"<<endl;
cout<<endl;
cout<<"Pulse cualquier tecla para parar la grabacion"<<endl;
char tecla;
cin>>tecla;
if(tecla=='s'){
alcCaptureStart(device);
cout<<"Grabando"<<endl;
while (!_kbhit()) {
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
//cout<<"samples capturadas: "<<sample<<endl;
alcCaptureSamples(device, (ALCvoid *)buffer, sample);
fwrite(buffer,sample, 1, pFileRAW);
}
fclose( pFileRAW );
alcCaptureStop(device);
alcCaptureCloseDevice(device);
}
return 0;
}
Mi duda es, cuando voy a reproducir el archivo con audacity o otro programa, la duración de este es mucho menor que la del tiempo empleado en la grabación. ¿por que pasa eso? Por ejemplo hice el mismo prototipo en Android y el archivo tiene la duración correcta.
Muchas gracias