diff --git a/Makefile b/Makefile index a547121..155dad4 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ diff --git a/test_audio.c b/test_audio.c new file mode 100644 index 0000000..8e99573 --- /dev/null +++ b/test_audio.c @@ -0,0 +1,36 @@ +#include "src/audio.h" +#include + +#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; +} \ No newline at end of file