2017-04-29 22:37:15 +02:00
|
|
|
#include "coding.h"
|
|
|
|
#include "../util.h"
|
2008-06-15 06:01:03 +02:00
|
|
|
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
#include <vorbis/vorbisfile.h>
|
|
|
|
|
|
|
|
void decode_ogg_vorbis(ogg_vorbis_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels) {
|
|
|
|
int samples_done = 0;
|
|
|
|
OggVorbis_File *ogg_vorbis_file = &data->ogg_vorbis_file;
|
|
|
|
|
|
|
|
do {
|
|
|
|
long rc = ov_read(ogg_vorbis_file, (char *)(outbuf + samples_done*channels),
|
|
|
|
(samples_to_do - samples_done)*sizeof(sample)*channels, 0,
|
|
|
|
sizeof(sample), 1, &data->bitstream);
|
|
|
|
|
|
|
|
if (rc > 0) samples_done += rc/sizeof(sample)/channels;
|
|
|
|
else return;
|
|
|
|
} while (samples_done < samples_to_do);
|
2015-05-13 20:11:24 +02:00
|
|
|
|
|
|
|
swap_samples_le(outbuf, samples_to_do*channels);
|
2008-06-15 06:01:03 +02:00
|
|
|
}
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
void reset_ogg_vorbis(VGMSTREAM *vgmstream) {
|
2018-03-10 16:59:00 +01:00
|
|
|
OggVorbis_File *ogg_vorbis_file;
|
2017-04-29 22:37:15 +02:00
|
|
|
ogg_vorbis_codec_data *data = vgmstream->codec_data;
|
2018-03-10 16:59:00 +01:00
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
ogg_vorbis_file = &(data->ogg_vorbis_file);
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
ov_pcm_seek(ogg_vorbis_file, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void seek_ogg_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
|
2018-03-10 16:59:00 +01:00
|
|
|
OggVorbis_File *ogg_vorbis_file;
|
2017-04-29 22:37:15 +02:00
|
|
|
ogg_vorbis_codec_data *data = (ogg_vorbis_codec_data *)(vgmstream->codec_data);
|
2018-03-10 16:59:00 +01:00
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
ogg_vorbis_file = &(data->ogg_vorbis_file);
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
ov_pcm_seek_lap(ogg_vorbis_file, num_sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_ogg_vorbis(ogg_vorbis_codec_data *data) {
|
2017-09-17 03:35:24 +02:00
|
|
|
if (data) {
|
2017-04-29 22:37:15 +02:00
|
|
|
OggVorbis_File *ogg_vorbis_file = &(data->ogg_vorbis_file);
|
|
|
|
|
|
|
|
ov_clear(ogg_vorbis_file);
|
|
|
|
|
|
|
|
close_streamfile(data->ov_streamfile.streamfile);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-15 06:01:03 +02:00
|
|
|
#endif
|