test,am-tests: add audio test

This commit is contained in:
Zihao Yu 2020-09-03 00:42:55 +08:00
parent 9e59fd2cba
commit 07c99a1e2a
5 changed files with 36 additions and 1 deletions

View file

@ -1,3 +1,3 @@
NAME = amtest
SRCS = $(shell find src/ -name "*.c")
SRCS = $(shell find src/ -name "*.[cS]")
include $(AM_HOME)/Makefile

View file

@ -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:

View file

@ -0,0 +1,27 @@
#include <amtest.h>
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);
}

View file

@ -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:

Binary file not shown.