SmartCradle v1
Baby smart cradle
microphone.h File Reference

Microphone module header. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ERR_OPEN   12
 
#define ERR_READ   15
 

Functions

int startRecording ()
 Records a 2 second .wav audio from microphone. More...
 
int processAudio (double *loudness)
 Processes the audio to check whether the baby is crying. More...
 

Detailed Description

Microphone module header.

Author
José Carvalho, João Carneiro
Date
2022-01-13

Definition in file microphone.h.

Macro Definition Documentation

◆ ERR_OPEN

#define ERR_OPEN   12

Error when opening audio file

Definition at line 13 of file microphone.h.

◆ ERR_READ

#define ERR_READ   15

Error when reading audio file

Definition at line 14 of file microphone.h.

Function Documentation

◆ processAudio()

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.

Returns
int

Definition at line 73 of file microphone.c.

◆ startRecording()

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

Returns
int

Definition at line 18 of file microphone.c.