Add support for zip BGM preview
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
#include "loading.h"
|
||||||
|
|
||||||
#include <tremor/ivorbisfile.h>
|
#include <tremor/ivorbisfile.h>
|
||||||
#include <tremor/ivorbiscodec.h>
|
#include <tremor/ivorbiscodec.h>
|
||||||
@@ -37,16 +38,17 @@
|
|||||||
#define BUF_TO_READ 40960 // How much data should be buffered at a time
|
#define BUF_TO_READ 40960 // How much data should be buffered at a time
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *filename;
|
|
||||||
OggVorbis_File vf;
|
OggVorbis_File vf;
|
||||||
ndspWaveBuf wave_buf[2];
|
ndspWaveBuf wave_buf[2];
|
||||||
float mix[12];
|
float mix[12];
|
||||||
u8 buf_pos;
|
u8 buf_pos;
|
||||||
long data_read;
|
long data_read;
|
||||||
volatile bool stop;
|
volatile bool stop;
|
||||||
|
char *filebuf;
|
||||||
|
u32 filesize;
|
||||||
} audio_s;
|
} audio_s;
|
||||||
|
|
||||||
Result load_audio(u16 *, audio_s *);
|
Result load_audio(Entry_s, audio_s *);
|
||||||
Result play_audio(audio_s *);
|
Result play_audio(audio_s *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -436,7 +436,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
preview_mode = load_preview(*current_list, &preview_offset);
|
preview_mode = load_preview(*current_list, &preview_offset);
|
||||||
audio = calloc(sizeof(audio_s), 1);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Result play_audio(audio_s *audio)
|
|||||||
ov_clear(&audio->vf);
|
ov_clear(&audio->vf);
|
||||||
if (read == 0) // EoF
|
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 :(
|
} else // Error :(
|
||||||
{
|
{
|
||||||
char error[100] = {0};
|
char error[100] = {0};
|
||||||
@@ -66,24 +66,17 @@ Result play_audio(audio_s *audio)
|
|||||||
|
|
||||||
void thread_audio(void* data) {
|
void thread_audio(void* data) {
|
||||||
audio_s *audio = (audio_s*)data;
|
audio_s *audio = (audio_s*)data;
|
||||||
DEBUG(audio->filename);
|
|
||||||
while(!audio->stop) {
|
while(!audio->stop) {
|
||||||
play_audio(audio);
|
play_audio(audio);
|
||||||
}
|
}
|
||||||
|
free(audio->filebuf);
|
||||||
free(audio);
|
free(audio);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the audio struct
|
// 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};
|
audio->filesize = load_data("/bgm.ogg", entry, &audio->filebuf);
|
||||||
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->mix[0] = audio->mix[1] = 1.0f; // Determines volume for the 12 (?) different outputs. See http://smealum.github.io/ctrulib/channel_8h.html#a30eb26f1972cc3ec28370263796c0444
|
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
|
ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); // Tremor outputs ogg files in 16 bit PCM stereo
|
||||||
ndspChnSetMix(0, audio->mix); // See mix comment above
|
ndspChnSetMix(0, audio->mix); // See mix comment above
|
||||||
|
|
||||||
FILE *file = fopen(cpath, "rb");
|
FILE *file = fmemopen(audio->filebuf, audio->filesize, "rb");
|
||||||
if(file != NULL)
|
if(file != NULL)
|
||||||
{
|
{
|
||||||
int e = ov_open(file, &audio->vf, NULL, 0);
|
int e = ov_open(file, &audio->vf, NULL, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user