Go to the documentation of this file.
17 #include "pv_recorder.h"
27 fprintf(stderr,
"usage: %s --show_audio_devices\n"
28 " %s audio_device_index path_to_raw_file\n", program, program);
33 if ((argc != 2) && (argc != 3)) {
40 if (strcmp(
argv[1],
"--show_audio_devices") == 0) {
41 char **devices =
NULL;
51 fprintf(stdout,
"Printing devices...\n");
52 for (int32_t i = 0; i <
count; i++) {
53 fprintf(stdout,
"index: %d, name: %s\n", i, devices[i]);
60 const int32_t device_index = (int32_t) strtol(
argv[1],
NULL, 10);
61 const char *path_to_raw_file =
NULL;
64 path_to_raw_file =
argv[2];
68 fprintf(stdout,
"Initializing pv_recorder...\n");
70 const int32_t frame_length = 512;
79 fprintf(stdout,
"Selected device: %s.\n", selected_device);
81 fprintf(stdout,
"Start recording...\n");
88 int16_t *pcm = malloc(frame_length *
sizeof(int16_t));
90 fprintf(stderr,
"Failed to allocate pcm memory.\n");
95 if (path_to_raw_file) {
96 file = fopen(path_to_raw_file,
"wb");
98 fprintf(stderr,
"Failed to open file.\n");
110 const size_t length = fwrite(pcm,
sizeof(int16_t), frame_length, file);
111 if (length != frame_length) {
112 fprintf(stderr,
"Failed to write raw bytes to file.\n");
122 fprintf(stdout,
"Stop recording...\n");
129 fprintf(stdout,
"Deleting pv_recorder...\n");
PV_API void pv_recorder_delete(pv_recorder_t *object)
static volatile bool is_interrupted
PV_API pv_recorder_status_t pv_recorder_init(int32_t device_index, int32_t frame_length, int32_t buffer_size_msec, bool log_overflow, pv_recorder_t **object)
PV_API void pv_recorder_free_device_list(int32_t count, char **devices)
PV_API pv_recorder_status_t pv_recorder_read(pv_recorder_t *object, int16_t *pcm)
PV_API pv_recorder_status_t pv_recorder_stop(pv_recorder_t *object)
void interrupt_handler(int _)
const PV_API char * pv_recorder_get_selected_device(pv_recorder_t *object)
const PV_API char * pv_recorder_version(void)
static void print_usage(const char *program)
int main(int argc, char *argv[])
const PV_API char * pv_recorder_status_to_string(pv_recorder_status_t status)
PV_API pv_recorder_status_t pv_recorder_start(pv_recorder_t *object)
@ PV_RECORDER_STATUS_SUCCESS
PV_API pv_recorder_status_t pv_recorder_get_audio_devices(int32_t *count, char ***devices)