Mercurial > mplayer.hg
annotate libmpcodecs/ad_libvorbis.c @ 10636:7938ee85f355
shorter, sweeter, more portable, better calling syntax
author | diego |
---|---|
date | Sun, 17 Aug 2003 01:20:48 +0000 |
parents | f49a2bf04229 |
children | e94036364011 |
rev | line source |
---|---|
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
1 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
2 #include <stdio.h> |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
3 #include <stdlib.h> |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
4 #include <unistd.h> |
8220 | 5 #include <stdarg.h> |
6 #include <math.h> | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
7 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
8 #include "config.h" |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
9 #include "ad_internal.h" |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
10 |
8220 | 11 #ifdef USE_SETLOCALE |
12 #include <locale.h> | |
13 #endif | |
14 | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
15 #ifdef HAVE_OGGVORBIS |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
16 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
17 static ad_info_t info = |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
18 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
19 "Ogg/Vorbis audio decoder", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
20 "libvorbis", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
21 "Felix Buenemann, A'rpi", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
22 "libvorbis", |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
23 "" |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
24 }; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
25 |
7174 | 26 LIBAD_EXTERN(libvorbis) |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
27 |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
28 #ifdef TREMOR |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
29 #include <tremor/ivorbiscodec.h> |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
30 #else |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
31 #include <vorbis/codec.h> |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
32 #endif |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
33 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
34 // This struct is also defined in demux_ogg.c => common header ? |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
35 typedef struct ov_struct_st { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
36 vorbis_info vi; /* struct that stores all the static vorbis bitstream |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
37 settings */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
38 vorbis_comment vc; /* struct that stores all the bitstream user comments */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
39 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
40 vorbis_block vb; /* local working space for packet->PCM decode */ |
8220 | 41 float rg_scale; /* replaygain scale */ |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
42 #ifdef TREMOR |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
43 int rg_scale_int; |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
44 #endif |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
45 } ov_struct_t; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
46 |
8220 | 47 static int read_vorbis_comment( char* ptr, char* comment, char* format, ... ) { |
48 va_list va; | |
49 int clen, ret; | |
50 | |
51 va_start( va, format ); | |
52 clen = strlen( comment ); | |
53 #ifdef USE_SETLOCALE | |
54 setlocale( LC_NUMERIC, "C" ); | |
55 #endif | |
56 ret = strncasecmp( ptr, comment, clen) == 0 ? vsscanf( ptr+clen, format, va ) : 0; | |
57 #ifdef USE_SETLOCALE | |
58 setlocale( LC_NUMERIC, "" ); | |
59 #endif | |
60 va_end( va ); | |
61 | |
62 return ret; | |
63 } | |
64 | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
65 static int preinit(sh_audio_t *sh) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
66 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
67 sh->audio_out_minsize=1024*4; // 1024 samples/frame |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
68 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
69 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
70 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
71 static int init(sh_audio_t *sh) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
72 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
73 ogg_packet op; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
74 vorbis_comment vc; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
75 struct ov_struct_st *ov; |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
76 #define ERROR() { \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
77 vorbis_comment_clear(&vc); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
78 vorbis_info_clear(&ov->vi); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
79 free(ov); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
80 return 0; \ |
5775 | 81 } |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
82 /// Init the decoder with the 3 header packets |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
83 ov = (struct ov_struct_st*)malloc(sizeof(struct ov_struct_st)); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
84 vorbis_info_init(&ov->vi); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
85 vorbis_comment_init(&vc); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
86 op.bytes = ds_get_packet(sh->ds,&op.packet); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
87 op.b_o_s = 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
88 /// Header |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
89 if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
90 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: initial (identification) header broken!\n"); |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
91 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
92 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
93 op.bytes = ds_get_packet(sh->ds,&op.packet); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
94 op.b_o_s = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
95 /// Comments |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
96 if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
97 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: comment header broken!\n"); |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
98 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
99 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
100 op.bytes = ds_get_packet(sh->ds,&op.packet); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
101 //// Codebook |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
102 if(vorbis_synthesis_headerin(&ov->vi,&vc,&op)<0) { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
103 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n"); |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
104 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
105 } else { /// Print the infos |
8220 | 106 float rg_gain=0.f, rg_peak=0.f; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
107 char **ptr=vc.user_comments; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
108 while(*ptr){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
109 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr); |
8220 | 110 /* replaygain */ |
111 read_vorbis_comment( *ptr, "replaygain_album_gain=", "%f", &rg_gain ); | |
112 read_vorbis_comment( *ptr, "rg_audiophile=", "%f", &rg_gain ); | |
113 if( !rg_gain ) { | |
114 read_vorbis_comment( *ptr, "replaygain_track_gain=", "%f", &rg_gain ); | |
115 read_vorbis_comment( *ptr, "rg_radio=", "%f", &rg_gain ); | |
116 } | |
117 read_vorbis_comment( *ptr, "replaygain_album_peak=", "%f", &rg_peak ); | |
118 if( !rg_peak ) { | |
119 read_vorbis_comment( *ptr, "replaygain_track_peak=", "%f", &rg_peak ); | |
120 read_vorbis_comment( *ptr, "rg_peak=", "%f", &rg_peak ); | |
121 } | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
122 ++ptr; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
123 } |
8220 | 124 /* replaygain: scale */ |
125 if(!rg_gain) | |
126 ov->rg_scale = 1.f; /* just in case pow() isn't standard-conformant */ | |
127 else | |
128 ov->rg_scale = pow(10.f, rg_gain/20); | |
129 /* replaygain: anticlip */ | |
130 if(ov->rg_scale * rg_peak > 1.f) | |
131 ov->rg_scale = 1.f / rg_peak; | |
132 /* replaygain: security */ | |
133 if(ov->rg_scale > 15.) | |
134 ov->rg_scale = 15.; | |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
135 #ifdef TREMOR |
8946
9821db5b213f
1000l, this clips!! IMO rg_scale nonsense should be removed with
rfelker
parents:
8343
diff
changeset
|
136 ov->rg_scale_int = (int)(ov->rg_scale*64.f); |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
137 #endif |
8220 | 138 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel%s, %dHz, %dbit/s %cBR\n",(int)ov->vi.channels,ov->vi.channels>1?"s":"",(int)ov->vi.rate,(int)ov->vi.bitrate_nominal, |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
139 (ov->vi.bitrate_lower!=ov->vi.bitrate_nominal)||(ov->vi.bitrate_upper!=ov->vi.bitrate_nominal)?'V':'C'); |
8220 | 140 if(rg_gain || rg_peak) |
141 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Gain = %+.2f dB, Peak = %.4f, Scale = %.2f\n", rg_gain, rg_peak, ov->rg_scale); | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
142 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",vc.vendor); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
143 } |
5775 | 144 vorbis_comment_clear(&vc); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
145 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
146 // printf("lower=%d upper=%d \n",(int)ov->vi.bitrate_lower,(int)ov->vi.bitrate_upper); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
147 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
148 // Setup the decoder |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
149 sh->channels=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
150 sh->samplerate=ov->vi.rate; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
151 // assume 128kbit if bitrate not specified in the header |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
152 sh->i_bps=((ov->vi.bitrate_nominal>0) ? ov->vi.bitrate_nominal : 128000)/8; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
153 sh->context = ov; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
154 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
155 /// Finish the decoder init |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
156 vorbis_synthesis_init(&ov->vd,&ov->vi); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
157 vorbis_block_init(&ov->vd,&ov->vb); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
158 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n"); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
159 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
160 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
161 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
162 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
163 static void uninit(sh_audio_t *sh) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
164 { |
5775 | 165 struct ov_struct_st *ov = sh->context; |
166 vorbis_block_clear(&ov->vb); | |
167 vorbis_info_clear(&ov->vi); | |
168 free(ov); | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
169 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
170 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
171 static int control(sh_audio_t *sh,int cmd,void* arg, ...) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
172 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
173 switch(cmd) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
174 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
175 #if 0 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
176 case ADCTRL_RESYNC_STREAM: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
177 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
178 case ADCTRL_SKIP_FRAME: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
179 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
180 #endif |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
181 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
182 return CONTROL_UNKNOWN; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
183 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
184 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
185 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
186 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
187 int len = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
188 int samples; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
189 float **pcm; |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
190 float scale; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
191 struct ov_struct_st *ov = sh->context; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
192 while(len < minlen) { |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
193 while((samples=vorbis_synthesis_pcmout(&ov->vd,&pcm))<=0){ |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
194 ogg_packet op; |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
195 memset(&op,0,sizeof(op)); //op.b_o_s = op.e_o_s = 0; |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
196 op.bytes = ds_get_packet(sh->ds,&op.packet); |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
197 if(op.bytes<=0) break; |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
198 if(vorbis_synthesis(&ov->vb,&op)==0) /* test for success! */ |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
199 vorbis_synthesis_blockin(&ov->vd,&ov->vb); |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
200 } |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
201 if(samples<=0) break; // error/EOF |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
202 while(samples>0){ |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
203 int i,j; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
204 int clipflag=0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
205 int convsize=(maxlen-len)/(2*ov->vi.channels); // max size! |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
206 int bout=((samples<convsize)?samples:convsize); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
207 |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
208 if(bout<=0) break; // no buffer space |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
209 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
210 /* convert floats to 16 bit signed ints (host order) and |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
211 interleave */ |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
212 #ifdef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
213 if (ov->rg_scale_int == 64) { |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
214 for(i=0;i<ov->vi.channels;i++){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
215 ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
216 ogg_int16_t *ptr=convbuffer+i; |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
217 ogg_int32_t *mono=pcm[i]; |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
218 for(j=0;j<bout;j++){ |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
219 int val=mono[j]>>9; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
220 /* might as well guard against clipping */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
221 if(val>32767){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
222 val=32767; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
223 clipflag=1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
224 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
225 if(val<-32768){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
226 val=-32768; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
227 clipflag=1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
228 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
229 *ptr=val; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
230 ptr+=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
231 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
232 } |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
233 } else |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
234 #endif /* TREMOR */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
235 { |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
236 #ifndef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
237 scale = 32767.f * ov->rg_scale; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
238 #endif |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
239 for(i=0;i<ov->vi.channels;i++){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
240 ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]); |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
241 ogg_int16_t *ptr=convbuffer+i; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
242 #ifdef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
243 ogg_int32_t *mono=pcm[i]; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
244 for(j=0;j<bout;j++){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
245 int val=(mono[j]*ov->rg_scale_int)>>(9+6); |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
246 #else |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
247 float *mono=pcm[i]; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
248 for(j=0;j<bout;j++){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
249 int val=mono[j]*scale; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
250 /* might as well guard against clipping */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
251 if(val>32767){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
252 val=32767; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
253 clipflag=1; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
254 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
255 if(val<-32768){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
256 val=-32768; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
257 clipflag=1; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
258 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
259 #endif /* TREMOR */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
260 *ptr=val; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
261 ptr+=ov->vi.channels; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
262 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
263 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
264 } |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
265 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
266 if(clipflag) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
267 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(ov->vd.sequence)); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
268 len+=2*ov->vi.channels*bout; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
269 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples); |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
270 samples-=bout; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
271 vorbis_synthesis_read(&ov->vd,bout); /* tell libvorbis how |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
272 many samples we |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
273 actually consumed */ |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
274 } //while(samples>0) |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
275 // if (!samples) break; // why? how? |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
276 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
277 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
278 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
279 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
280 return len; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
281 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
282 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
283 #endif /* !HAVE_OGGVORBIS */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
284 |