diff --git a/nanos-lite/include/device.h b/nanos-lite/include/device.h index 9e73f65..f3203db 100644 --- a/nanos-lite/include/device.h +++ b/nanos-lite/include/device.h @@ -8,6 +8,13 @@ size_t events_read(void *buf, size_t offset, size_t len); size_t dispinfo_read(void *buf, size_t offset, size_t len); size_t fb_write(const void *buf, size_t offset, size_t len); + +size_t sb_write(const void *buf, size_t offset, size_t len); +// freq, channels, samples +size_t sbctl_write(const void *buf, size_t offset, size_t len); +// the number of sound buffer unused length +size_t sbctl_read(void *buf, size_t offset, size_t len); + int _fb_size(); #endif \ No newline at end of file diff --git a/nanos-lite/src/device.c b/nanos-lite/src/device.c index 577e0fe..ff3f957 100644 --- a/nanos-lite/src/device.c +++ b/nanos-lite/src/device.c @@ -49,6 +49,26 @@ size_t fb_write(const void *buf, size_t offset, size_t len) { return len; } +size_t sb_write(const void *buf, size_t offset, size_t len) { + Area sbuf = { + .start = (char*)buf, + .end = (char*)buf + len + }; + io_write(AM_AUDIO_PLAY, sbuf); + return len; +} + +size_t sbctl_write(const void *buf, size_t offset, size_t len) { + io_write(AM_AUDIO_CTRL, ((int32_t*)buf)[0], ((int32_t*)buf)[1], ((int32_t*)buf)[2]); + return 12; +} + +size_t sbctl_read(void *buf, size_t offset, size_t len) { + int szbuf = io_read(AM_AUDIO_CONFIG).bufsize; + *(int32_t*)buf = szbuf - io_read(AM_AUDIO_STATUS).count; + return 4; +} + int _fb_size() { AM_GPU_CONFIG_T gconf = io_read(AM_GPU_CONFIG); return gconf.vmemsz; diff --git a/nanos-lite/src/fs.c b/nanos-lite/src/fs.c index 0d89504..9c2bfaa 100644 --- a/nanos-lite/src/fs.c +++ b/nanos-lite/src/fs.c @@ -15,7 +15,7 @@ typedef struct { } Finfo; enum {FD_STDIN, FD_STDOUT, FD_STDERR, - FD_DEV_EVENTS, FD_DEV_FB, + FD_DEV_EVENTS, FD_DEV_FB, FD_DEV_SB, FD_DEV_SBCTL, FD_PROC_DISPINFO}; size_t invalid_read(void *buf, size_t offset, size_t len) { @@ -36,6 +36,8 @@ static Finfo file_table[] __attribute__((used)) = { [FD_DEV_EVENTS] = {"/dev/events", 0, 0, events_read, invalid_write}, [FD_DEV_FB] = {"/dev/fb", 0, 0, invalid_read, fb_write}, [FD_PROC_DISPINFO] = {"/proc/dispinfo", 0, 0, dispinfo_read, invalid_write}, + [FD_DEV_SB] = {"/dev/sb", 0, 0, invalid_read, sb_write}, + [FD_DEV_SBCTL] = {"/dev/sbctl", 0, 0, sbctl_read, sbctl_write}, #include "files.h" }; diff --git a/navy-apps/libs/libminiSDL/src/audio.c b/navy-apps/libs/libminiSDL/src/audio.c index 547087b..053419d 100644 --- a/navy-apps/libs/libminiSDL/src/audio.c +++ b/navy-apps/libs/libminiSDL/src/audio.c @@ -2,10 +2,13 @@ #include int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) { + NDL_OpenAudio(desired->freq, desired->channels, desired->samples); + // desired->callback() return 0; } void SDL_CloseAudio() { + NDL_CloseAudio(); } void SDL_PauseAudio(int pause_on) { diff --git a/navy-apps/libs/libndl/NDL.c b/navy-apps/libs/libndl/NDL.c index b40442d..03e71fd 100644 --- a/navy-apps/libs/libndl/NDL.c +++ b/navy-apps/libs/libndl/NDL.c @@ -103,17 +103,43 @@ void NDL_DrawRect(uint32_t *pixels, int x, int y, int w, int h) { } void NDL_OpenAudio(int freq, int channels, int samples) { + FILE* fp = fopen("/dev/sbctl", "w"); + if (fp == NULL) { + printf("cannot open /dev/fb"); + exit(-1); + } + int arr[] = { + freq, channels, samples + }; + fwrite(arr, sizeof(int), 3, fp); + fclose(fp); } void NDL_CloseAudio() { + } int NDL_PlayAudio(void *buf, int len) { - return 0; + FILE* fp = fopen("/dev/sb", "w"); + if (fp == NULL) { + printf("cannot open /dev/fb"); + exit(-1); + } + fwrite(buf, 1, len, fp); + fclose(fp); + return len; } int NDL_QueryAudio() { - return 0; + FILE* fp = fopen("/dev/sbctl", "r"); + if (fp == NULL) { + printf("cannot open /dev/fb"); + exit(-1); + } + int ret; + fread(&ret, sizeof(int), 1, fp); + fclose(fp); + return ret; } int NDL_Init(uint32_t flags) {