SmartCradle v1
Baby smart cradle
microphone.c File Reference

Microphone module implementation. More...

#include <sndfile.h>
#include <sys/syslog.h>
#include <sys/wait.h>
#include "../inc/microphone.h"
Include dependency graph for microphone.c:

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...
 

Detailed Description

Microphone module implementation.

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

Definition in file microphone.c.

Macro Definition Documentation

◆ LIMIT

#define LIMIT   3

Definition at line 16 of file microphone.c.

◆ THRESHOLD

#define THRESHOLD   -35

Definition at line 15 of file microphone.c.

Function Documentation

◆ calculateLoudness()

double calculateLoudness ( )

Calculates loudness of the .wav file.

The value returned is expressed in the decibel (dB) scale being -1 the maximum value.

Returns
double (dB)

Definition at line 41 of file microphone.c.

◆ 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.