2
converts ogg frames into audioFrames
3
Copyright (C) 2001 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
14
#include "vorbisDecoder.h"
18
#define _VORBIS_NEED_SYNTHHEADER_1 1
19
#define _VORBIS_NEED_SYNTHHEADER_2 2
20
#define _VORBIS_NEED_SYNTHHEADER_3 3
22
#define _VORBIS_DECODE_SETUP 4
23
#define _VORBIS_DECODE_LOOP 5
27
VorbisDecoder::VorbisDecoder() {
28
vorbis_info_init(&vi);
29
vorbis_comment_init(&vc);
34
VorbisDecoder::~VorbisDecoder() {
37
int VorbisDecoder::hasHeader() {
38
return (initState>=_VORBIS_DECODE_LOOP);
41
int VorbisDecoder::decode(RawFrame* rawFrame,AudioFrame* dest) {
43
if ((rawFrame == NULL) || (dest == NULL)) {
44
cout << "VorbisDecoder::decode NULL pointer!"<<endl;
47
if (rawFrame->getFrameType() != _FRAME_RAW_OGG) {
48
cout << "VorbisDecoder::decode not _FRAME_RAW_OGG"<<endl;
52
ogg_packet* op=(ogg_packet*) rawFrame->getData();
54
case _VORBIS_NEED_SYNTHHEADER_1:
55
case _VORBIS_NEED_SYNTHHEADER_2:
56
case _VORBIS_NEED_SYNTHHEADER_3:
57
cout << "_VORBIS_NEED_SYNTHHEADER:"<<initState<<endl;
58
if(vorbis_synthesis_headerin(&vi,&vc,op)<0){
59
/* error case; not a vorbis header */
60
fprintf(stderr,"This Ogg bitstream does not contain Vorbis "
66
case _VORBIS_DECODE_SETUP:
67
cout << "_VORBIS_DECODE_SETUP"<<endl;
68
vorbis_synthesis_init(&vd,&vi); /* central decode state */
69
vorbis_block_init(&vd,&vb); /* local state for most of the decode
70
so multiple block decodes can
71
proceed in parallel. We could init
72
multiple vorbis_block structures
74
initState=_VORBIS_DECODE_LOOP;
75
// yes right, we must decode the packet!
76
// so there is no break here.
77
case _VORBIS_DECODE_LOOP: {
78
if(vorbis_synthesis(&vb,op)==0) {/* test for success! */
79
vorbis_synthesis_blockin(&vd,&vb);
81
cout << "vorbis_synthesis error"<<endl;
87
**pcm is a multichannel float vector. In stereo, for
88
example, pcm[0] is left, and pcm[1] is right. samples is
89
the size of each channel. Convert the float values
90
(-1.<=range<=1.) to whatever PCM format and write it out
93
int samples=vorbis_synthesis_pcmout(&vd,&pcm);
95
int maxSamples=dest->getSize();
96
if (samples > maxSamples) {
97
cout << "more samples in vorbis than we can store"<<endl;
100
dest->clearrawdata();
101
dest->setFrameFormat(vi.channels-1,vi.rate);
103
if (vi.channels == 2) {
104
dest->putFloatData(pcm[0],pcm[1],samples);
106
dest->putFloatData(pcm[0],NULL,samples);
109
vorbis_synthesis_read(&vd,samples); /* tell libvorbis how
118
cout << "unknown state in vorbis decoder"<<endl;
124
void VorbisDecoder::reset() {
125
initState=_VORBIS_NEED_SYNTHHEADER_1;
128
void VorbisDecoder::config(const char* ,const char* ,void* ) {