Don't try and play mono ogg files
This commit is contained in:
@@ -477,33 +477,44 @@ Result load_audio(Entry_s entry, audio_s *audio)
|
||||
svcCreateEvent(&audio->finished, RESET_STICKY);
|
||||
|
||||
ndspChnSetInterp(0, NDSP_INTERP_LINEAR);
|
||||
ndspChnSetRate(0, 44100);
|
||||
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 = fmemopen(audio->filebuf, audio->filesize, "rb");
|
||||
DEBUG("Filesize: %lld\n", audio->filesize);
|
||||
if(file != NULL)
|
||||
{
|
||||
int e = ov_open(file, &audio->vf, NULL, 0);
|
||||
if (e < 0)
|
||||
{
|
||||
DEBUG("Vorbis: %d\n", e);
|
||||
free(audio->filebuf);
|
||||
free(audio);
|
||||
fclose(file);
|
||||
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||
}
|
||||
|
||||
vorbis_info *vi = ov_info(&audio->vf, -1);
|
||||
ndspChnSetRate(0, vi->rate);// Set sample rate to what's read from the ogg file
|
||||
if (vi->channels == 2) {
|
||||
DEBUG("Using stereo\n");
|
||||
ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); // 2 channels == Stereo
|
||||
} else {
|
||||
DEBUG("Invalid number of channels\n");
|
||||
free(audio->filebuf);
|
||||
free(audio);
|
||||
fclose(file);
|
||||
return MAKERESULT(RL_FATAL, RS_INVALIDARG, RM_APPLICATION, RD_NO_DATA);
|
||||
}
|
||||
|
||||
audio->wave_buf[0].nsamples = audio->wave_buf[1].nsamples = vi->rate / 4; // 4 bytes per sample, samples = rate (bytes) / 4
|
||||
audio->wave_buf[0].status = audio->wave_buf[1].status = NDSP_WBUF_DONE; // Used in play to stop from writing to current buffer
|
||||
audio->wave_buf[0].data_vaddr = linearAlloc(BUF_TO_READ); // Most vorbis packets should only be 4 KB at most (?) Possibly dangerous assumption
|
||||
audio->wave_buf[1].data_vaddr = linearAlloc(BUF_TO_READ);
|
||||
DEBUG("Success!");
|
||||
DEBUG("Success!\n");
|
||||
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_APPLICATION, RD_SUCCESS);
|
||||
} else {
|
||||
free(audio->filebuf);
|
||||
free(audio);
|
||||
fclose(file);
|
||||
DEBUG("fmemopen failed!\n");
|
||||
return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -460,6 +460,7 @@ int main(void)
|
||||
audio = calloc(1, sizeof(audio_s));
|
||||
Result r = load_audio(current_list->entries[current_list->selected_entry], audio);
|
||||
if (R_SUCCEEDED(r)) play_audio(audio);
|
||||
else audio = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -30,11 +30,14 @@
|
||||
// Play a given audio struct
|
||||
Result update_audio(audio_s *audio)
|
||||
{
|
||||
long size = audio->wave_buf[audio->buf_pos].nsamples * 4 - audio->data_read;
|
||||
long size = BUF_TO_READ - audio->data_read;
|
||||
DEBUG("Audio Size: %ld\n", size);
|
||||
if (audio->wave_buf[audio->buf_pos].status == NDSP_WBUF_DONE) // only run if the current selected buffer has already finished playing
|
||||
{
|
||||
size_t read = ov_read(&audio->vf, (char*)audio->wave_buf[audio->buf_pos].data_vaddr + audio->data_read, size, NULL); // read 1 vorbis packet into wave buffer
|
||||
DEBUG("Attempting ov_read\n");
|
||||
int bitstream;
|
||||
size_t read = ov_read(&audio->vf, (char*)audio->wave_buf[audio->buf_pos].data_vaddr + audio->data_read, size, &bitstream); // read 1 vorbis packet into wave buffer
|
||||
DEBUG("ov_read successful\n");
|
||||
|
||||
if (read <= 0) // EoF or error
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user