diff --git a/tests/am-tests/Makefile b/tests/am-tests/Makefile index 907ff4f..de6da42 100644 --- a/tests/am-tests/Makefile +++ b/tests/am-tests/Makefile @@ -1,3 +1,3 @@ NAME = amtest -SRCS = $(shell find src/ -name "*.c") +SRCS = $(shell find src/ -name "*.[cS]") include $(AM_HOME)/Makefile diff --git a/tests/am-tests/src/main.c b/tests/am-tests/src/main.c index 0c7b300..cae9cd3 100644 --- a/tests/am-tests/src/main.c +++ b/tests/am-tests/src/main.c @@ -11,6 +11,7 @@ static const char *tests[256] = { ['t'] = "real-time clock test", ['k'] = "readkey test", ['v'] = "display test", + ['a'] = "audio test", ['p'] = "x86 virtual memory test", }; @@ -23,6 +24,7 @@ int main(const char *args) { CASE('t', rtc_test, IOE); CASE('k', keyboard_test, IOE); CASE('v', video_test, IOE); + CASE('a', audio_test, IOE); CASE('p', vm_test, CTE(vm_handler), VME(simple_pgalloc, simple_pgfree)); case 'H': default: diff --git a/tests/am-tests/src/tests/audio.c b/tests/am-tests/src/tests/audio.c new file mode 100644 index 0000000..5ad030a --- /dev/null +++ b/tests/am-tests/src/tests/audio.c @@ -0,0 +1,27 @@ +#include + +void audio_test() { + if (!io_read(AM_AUDIO_CONFIG).present) { + printf("WARNING: %s does not support audio\n", TOSTRING(__ARCH__)); + return; + } + + io_write(AM_AUDIO_CTRL, 8000, 1, 1024, 8192); + + extern uint8_t audio_payload, audio_payload_end; + uint32_t audio_len = &audio_payload_end - &audio_payload; + int nplay = 0; + Area sbuf; + sbuf.start = &audio_payload; + while (nplay < audio_len) { + int len = (audio_len - nplay > 4096 ? 4096 : audio_len - nplay); + sbuf.end = sbuf.start + len; + io_write(AM_AUDIO_PLAY, sbuf); + sbuf.start += len; + nplay += len; + printf("Already play %d/%d bytes of data\n", nplay, audio_len); + } + + // wait until the audio finishes + while (io_read(AM_AUDIO_STATUS).count > 0); +} diff --git a/tests/am-tests/src/tests/audio/audio-data.S b/tests/am-tests/src/tests/audio/audio-data.S new file mode 100644 index 0000000..f1fc11b --- /dev/null +++ b/tests/am-tests/src/tests/audio/audio-data.S @@ -0,0 +1,6 @@ +.section .data +.global audio_payload, audio_payload_end +.p2align 3 +audio_payload: +.incbin "src/tests/audio/little-star.pcm" +audio_payload_end: diff --git a/tests/am-tests/src/tests/audio/little-star.pcm b/tests/am-tests/src/tests/audio/little-star.pcm new file mode 100644 index 0000000..afb8880 Binary files /dev/null and b/tests/am-tests/src/tests/audio/little-star.pcm differ