Encapsulation of the standard ALSA library This library is multi-threaded.
AlsaControl *ac = new AlsaControl(16000, 2048, 16, MONO); //rate : 16000, frames: 2048, bits: 16
/* do something */
delete ac;
ac->RecordToFile("filename", 10000000); //recording to filename.wav for 10 seconds
ac->Listen("filename");
/* do something */
ac->Stop();
ac->ListenWithCallback(std::bind(&LambdaClass::LambdaCallback, class_to_call, std::placeholders::_1, std::placeholders::_2), "filename");
sleep(8);
ac->Stop();
The LambdaCallback
must have the signature void LambdaCallback(char* buffer, int rc)
Listen()
and Listen(std::string filename)
Start listening the audio input. If a filename is sent record the output in a file.
You must call Stop() before deleting the object
Listen()
is not really usefull
ListenWithCallback(std::function<void(char *, int)> func)
and ListenWithCallback(std::function<void(char *, int)> func, std::string filename)
Start listening the audio input and send it to a callback. If a filename is sent record the output in a file.
char*
is the buffer with the part of the recording
You must call Stop() before deleting the object
Stop()
Stop listening. Must be called after each listen* function
Listen()
Listen(std::string filename)
ListenWithCallback(std::function<void(char *, int)> func)
ListenWithCallback(std::function<void(char *, int)> func, std::string filename)
RecordToFile(std::string filename, int const &duration_in_us)
Start recording the audio input to the file.
ShowALSAParameters()
Show all the parameters of the current sound card
ForcePeriodSize(int const &value)
Sometimes the period size gets wrong value (from snd_pcm_hw_params_get_period_size
), this method force the period size to the value passed