|
tico 0.1
Mechanical Watch Terminal Timegrapher
|
#include "mysound.h"#include "config.h"#include "myarr.h"#include "mydefs.h"#include "myfft.h"#include "mysync.h"#include "parseargs.h"#include "printing.h"#include <alsa/asoundlib.h>#include <ctype.h>#include <errno.h>#include <fftw3.h>#include <limits.h>#include <math.h>#include <poll.h>#include <pthread.h>#include <stddef.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <sys/timerfd.h>#include <time.h>#include <unistd.h>
Functions | |
| void | open_capture_elem (CaptureCtx *ctx, const CapConfig *cfg) |
| Open the ALSA mixer and find the 'Capture' element for microphone control. More... | |
| snd_pcm_t * | initAudio (snd_pcm_format_t format, char *device, unsigned int *rate) |
| Initializes the ALSA audio capture device with the specified format, device name, and sample rate. More... | |
| int | initAudioSource (CapConfig *cfg, unsigned int *actualRate) |
| Initializes the audio source for capture based on the provided configuration. This function sets up the ALSA capture device and retrieves the actual sample rate being used. More... | |
| int | readBufferOrFile (int *derivative, size_t ArrayLength, FILE *fpInput, CaptureCtx *ctx, int16_t *buffer16) |
| Reads audio data from the capture device or a file into a buffer. More... | |
| int | getData (FILE *fpInput, struct myarr *derivative, CaptureCtx *ctx, int16_t *out) |
| Retrieves audio data from the capture context or input file and processes it into a derivative array. More... | |
| int | captureSetup (CaptureCtx *ctx, CapConfig *cfg, unsigned int rate) |
| captureSetup More... | |
| void | captureTeardown (CaptureCtx *ctx) |
| Cleans up and releases resources associated with the audio capture context. More... | |
| int | readSamples (snd_pcm_t *cap, size_t ArrayLength, int16_t *out) |
| Reads audio samples from the ALSA capture device into a buffer. More... | |
| const char * | get_default_device (void) |
| Retrieves the default ALSA audio capture device, preferring sysdefault devices with 'usb' in their description. More... | |
| int | get_mic_amplification (const CaptureCtx *ctx, long *value) |
| Get the current microphone amplification (capture volume) from ALSA mixer. More... | |
| int | set_mic_amplification (const CaptureCtx *ctx, long value) |
| Set the microphone amplification (capture volume) using ALSA mixer. More... | |
| int captureSetup | ( | CaptureCtx * | ctx, |
| CapConfig * | cfg, | ||
| unsigned int | rate | ||
| ) |
captureSetup
Sets up the ALSA audio capture device based on the provided context and configuration.
| void captureTeardown | ( | CaptureCtx * | ctx | ) |
Cleans up and releases resources associated with the audio capture context.
| ctx | A pointer to the CaptureCtx structure to be cleaned up. |
| const char * get_default_device | ( | void | ) |
Retrieves the default ALSA audio capture device, preferring sysdefault devices with 'usb' in their description.
This function executes the 'arecord -L' command to list available ALSA devices and parses the output to find a suitable default device. It first looks for devices with 'sysdefault:' in their name and 'usb' in their description. If such a device is found, it is returned as the default. If no USB sysdefault device is found, it falls back to any sysdefault device. If no sysdefault devices are found, it returns 'default'.
| int get_mic_amplification | ( | const CaptureCtx * | ctx, |
| long * | value | ||
| ) |
Get the current microphone amplification (capture volume) from ALSA mixer.
This function queries the ALSA mixer for the current capture volume (microphone gain) for the specified capture context.
| ctx | Pointer to the CaptureCtx containing the mixer handle and element. |
| value | Output pointer for the amplification value. |
| int getData | ( | FILE * | fpInput, |
| struct myarr * | derivative, | ||
| CaptureCtx * | ctx, | ||
| int16_t * | out | ||
| ) |
Retrieves audio data from the capture context or input file and processes it into a derivative array.
| fpInput | A pointer to a FILE object representing the input file to read from. If NULL, audio will be read from the capture device. |
| derivative | A pointer to a myarr structure where the computed derivative values will be stored. |
| ctx | A pointer to the CaptureCtx structure containing the capture context and configuration. |
| out | A pointer to an int16_t array where the raw audio samples will be stored before being processed into the derivative array. |
| snd_pcm_t * initAudio | ( | snd_pcm_format_t | format, |
| char * | device, | ||
| unsigned int * | rate | ||
| ) |
Initializes the ALSA audio capture device with the specified format, device name, and sample rate.
| format | The audio format to use (e.g., SND_PCM_FORMAT_S16_LE). |
| device | The name of the ALSA device to open (e.g., "default"). |
| rate | A pointer to an unsigned int where the actual sample rate will be stored. This may be modified if the requested rate is not supported. |
| int initAudioSource | ( | CapConfig * | cfg, |
| unsigned int * | actualRate | ||
| ) |
Initializes the audio source for capture based on the provided configuration. This function sets up the ALSA capture device and retrieves the actual sample rate being used.
| cfg | A pointer to the CapConfig structure containing the desired configuration for audio capture. |
| actualRate | A pointer to an unsigned int where the actual sample rate will be stored after initialization. |
| void open_capture_elem | ( | CaptureCtx * | ctx, |
| const CapConfig * | cfg | ||
| ) |
Open the ALSA mixer and find the 'Capture' element for microphone control.
This function checks if the mixer handle and element are already stored in the configuration. If not, it opens the mixer, attaches to the specified device, registers simple elements, loads the mixer, and finds the 'Capture' element. The found element is stored in the configuration for future use.
| ctx | Capture context to store the mixer handle and element. |
| cfg | Configuration containing device information and mixer state. |
| int readBufferOrFile | ( | int * | derivative, |
| size_t | ArrayLength, | ||
| FILE * | fpInput, | ||
| CaptureCtx * | ctx, | ||
| int16_t * | buffer16 | ||
| ) |
Reads audio data from the capture device or a file into a buffer.
| derivative | A pointer to an integer array where the read audio samples will be stored. |
| ArrayLength | The number of audio samples to read into the buffer. |
| fpInput | A pointer to a FILE object representing the input file to read from. If NULL, audio will be read from the capture device. |
| ctx | A pointer to the CaptureCtx structure containing the capture context and configuration. |
| buffer16 | A pointer to an int16_t array where the raw audio samples will be stored before being processed into the derivative array. |
| int readSamples | ( | snd_pcm_t * | cap, |
| size_t | ArrayLength, | ||
| int16_t * | out | ||
| ) |
Reads audio samples from the ALSA capture device into a buffer.
| cap | A pointer to the snd_pcm_t capture handle representing the ALSA capture device. |
| ArrayLength | The number of audio samples to read into the output buffer. |
| out | A pointer to an int16_t array where the read audio samples will be stored. |
| int set_mic_amplification | ( | const CaptureCtx * | ctx, |
| long | value | ||
| ) |
Set the microphone amplification (capture volume) using ALSA mixer.
This function sets the ALSA mixer capture volume (microphone gain) to the specified value for the given capture context. The value should be within the hardware limits stored in the context's AmpResult struct.
| ctx | Pointer to the CaptureCtx containing the mixer handle and element. |
| value | The amplification value to set. |