1
0

A test util to play with audio.

This commit is contained in:
Alexander Andreev 2024-11-24 04:16:13 +04:00
parent 53081df814
commit 18b3a359e7
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 42 additions and 0 deletions

View File

@ -18,6 +18,12 @@ LDFLAGS += -lportaudio -lopus -lsodium
$(TARGET): $(OBJs)
$(CC) $(LDFLAGS) $^ -o $@
test_audio: test_audio.o $(OBJ_DIR)/audio.o
$(CC) $(LDFLAGS) $^ -o $@
test_audio.o: test_audio.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@

36
test_audio.c Normal file
View File

@ -0,0 +1,36 @@
#include "src/audio.h"
#include <stdlib.h>
#define CHANNELS 1
#define SAMPLE_RATE 48000
#define FRAMES_PER_BUFFFER 960
#define AUDIO_BUF_SIZE (FRAMES_PER_BUFFFER)
#define LEN_SEC 5
int main(int argc, char **argv) {
(void)argc;
(void)argv;
audio_init_soundsystem();
audio_t a;
audio_sample_t aud_buf[FRAMES_PER_BUFFFER] = {0};
audio_init_default(&a, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER);
audio_stream_input_toggle(&a); audio_stream_output_toggle(&a);
const size_t ii = (LEN_SEC * SAMPLE_RATE)/FRAMES_PER_BUFFFER;
for (size_t i = 0; i < ii; ++i) {
audio_read(&a, aud_buf, FRAMES_PER_BUFFFER);
audio_write(&a, aud_buf, FRAMES_PER_BUFFFER);
}
audio_stream_input_toggle(&a); audio_stream_output_toggle(&a);
audio_terminate_soundsystem();
return 0;
}