Skip to content

Waxo/ALSA_encapsulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ALSA_encapsulation

Encapsulation of the standard ALSA library This library is multi-threaded.

Example Usage

Allocation or instantiation
AlsaControl *ac = new AlsaControl(16000, 2048, 16, MONO); //rate : 16000, frames: 2048, bits: 16
/* do something */
delete ac;
Recording in a file for a specific time (in micro-seconds)
ac->RecordToFile("filename", 10000000); //recording to filename.wav for 10 seconds
Listening and recording to a file
ac->Listen("filename");
/* do something */
ac->Stop();
Listening and using it inside an other class
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)

Methods

Listen

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

Listen with callback

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 (listening)

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)

Record to file

RecordToFile(std::string filename, int const &duration_in_us)
Start recording the audio input to the file.

ALSA parameters

ShowALSAParameters()
Show all the parameters of the current sound card

Force period size

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

About

Encapsulation of the standard ALSA library This library is multi-threaded.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published