![]() |
SmartCradle v1
Baby smart cradle
|
Microphone module implementation. More...

Go to the source code of this file.
Macros | |
| #define | THRESHOLD -35 |
| #define | LIMIT 3 |
Functions | |
| int | startRecording () |
| Records a 2 second .wav audio from microphone. More... | |
| double | calculateLoudness () |
| Calculates loudness of the .wav file. More... | |
| int | processAudio (double *loudness) |
| Processes the audio to check whether the baby is crying. More... | |
Microphone module implementation.
Definition in file microphone.c.
| #define LIMIT 3 |
Definition at line 16 of file microphone.c.
| #define THRESHOLD -35 |
Definition at line 15 of file microphone.c.
| double calculateLoudness | ( | ) |
Calculates loudness of the .wav file.
The value returned is expressed in the decibel (dB) scale being -1 the maximum value.
Definition at line 41 of file microphone.c.
| int processAudio | ( | double * | loudness | ) |
Processes the audio to check whether the baby is crying.
The loudness of the audio samples is calculated and, if the predefined threshold is passed, a counter is incremented. At 3 consecutive samples that have breached the threshold, it is considered that the baby is crying.
Definition at line 73 of file microphone.c.
| int startRecording | ( | ) |
Records a 2 second .wav audio from microphone.
Recording is possible by using FFmpeg. The parameters used are: -f alsa : force audio input device to be of ALSA -ac 1 : set audio channel to 1 -ar 44100 : set audio sampling rate to 44100 Hz -i plughw:0,0 : select the audio card referencing the microphone -c:a copy : set audio codec to copy (copies the frames directly instead of decoding/filtering/encoding) -t 2 : recording duration -y : overwrite output files audiorecord.wav output file
Definition at line 18 of file microphone.c.