diff --git a/include/music.h b/include/music.h index 077bbf7..c59d49b 100644 --- a/include/music.h +++ b/include/music.h @@ -30,6 +30,7 @@ #include "common.h" #include "fs.h" #include "unicode.h" +#include "loading.h" #include #include @@ -37,16 +38,17 @@ #define BUF_TO_READ 40960 // How much data should be buffered at a time typedef struct { - char *filename; OggVorbis_File vf; ndspWaveBuf wave_buf[2]; float mix[12]; u8 buf_pos; long data_read; volatile bool stop; + char *filebuf; + u32 filesize; } audio_s; -Result load_audio(u16 *, audio_s *); +Result load_audio(Entry_s, audio_s *); Result play_audio(audio_s *); #endif \ No newline at end of file diff --git a/source/main.c b/source/main.c index 3bc3327..b23e8ea 100644 --- a/source/main.c +++ b/source/main.c @@ -436,7 +436,7 @@ int main(void) { preview_mode = load_preview(*current_list, &preview_offset); audio = calloc(sizeof(audio_s), 1); - load_audio(current_list->entries[current_list->selected_entry].path, audio); + load_audio(current_list->entries[current_list->selected_entry], audio); } else { diff --git a/source/music.c b/source/music.c index 2c92e1a..23df306 100644 --- a/source/music.c +++ b/source/music.c @@ -42,7 +42,7 @@ Result play_audio(audio_s *audio) ov_clear(&audio->vf); if (read == 0) // EoF { - ov_open(fopen(audio->filename, "rb"), &audio->vf, NULL, 0); // Reopen file. Don't need to reinit channel stuff since it's all the same as before + ov_open(fmemopen(audio->filebuf, audio->filesize, "rb"), &audio->vf, NULL, 0); // Reopen file. Don't need to reinit channel stuff since it's all the same as before } else // Error :( { char error[100] = {0}; @@ -66,24 +66,17 @@ Result play_audio(audio_s *audio) void thread_audio(void* data) { audio_s *audio = (audio_s*)data; - DEBUG(audio->filename); while(!audio->stop) { play_audio(audio); } + free(audio->filebuf); free(audio); } // Initialize the audio struct -Result load_audio(u16 *entry_path, audio_s *audio) +Result load_audio(Entry_s entry, audio_s *audio) { - u16 path[0x106] = {0}; - strucat(path, entry_path); - struacat(path, "/bgm.ogg"); - - ssize_t len = strulen(path, 0x106); - char *cpath = calloc(sizeof(char), len*sizeof(u16)); - utf16_to_utf8((u8*)cpath, path, len*sizeof(u16)); - audio->filename = cpath; + audio->filesize = load_data("/bgm.ogg", entry, &audio->filebuf); audio->mix[0] = audio->mix[1] = 1.0f; // Determines volume for the 12 (?) different outputs. See http://smealum.github.io/ctrulib/channel_8h.html#a30eb26f1972cc3ec28370263796c0444 @@ -92,7 +85,7 @@ Result load_audio(u16 *entry_path, audio_s *audio) ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); // Tremor outputs ogg files in 16 bit PCM stereo ndspChnSetMix(0, audio->mix); // See mix comment above - FILE *file = fopen(cpath, "rb"); + FILE *file = fmemopen(audio->filebuf, audio->filesize, "rb"); if(file != NULL) { int e = ov_open(file, &audio->vf, NULL, 0);