Mercurial > mplayer.hg
annotate libmpcodecs/ad_libvorbis.c @ 15289:e985d786c5f1
macosx core video module
author | nplourde |
---|---|
date | Fri, 29 Apr 2005 11:05:16 +0000 |
parents | 4a6b79a1ad52 |
children | f3cf481bbcda |
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 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
11 #ifdef HAVE_OGGVORBIS |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
12 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
13 static ad_info_t info = |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
14 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
15 "Ogg/Vorbis audio decoder", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
16 "libvorbis", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
17 "Felix Buenemann, A'rpi", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
18 "libvorbis", |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
19 "" |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
20 }; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
21 |
7174 | 22 LIBAD_EXTERN(libvorbis) |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
23 |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
24 #ifdef TREMOR |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
25 #include <tremor/ivorbiscodec.h> |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
26 #else |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
27 #include <vorbis/codec.h> |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
28 #endif |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
29 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
30 // 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
|
31 typedef struct ov_struct_st { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
32 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
|
33 settings */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
34 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
|
35 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
|
36 vorbis_block vb; /* local working space for packet->PCM decode */ |
8220 | 37 float rg_scale; /* replaygain scale */ |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
38 #ifdef TREMOR |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
39 int rg_scale_int; |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
40 #endif |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
41 } ov_struct_t; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
42 |
8220 | 43 static int read_vorbis_comment( char* ptr, char* comment, char* format, ... ) { |
44 va_list va; | |
45 int clen, ret; | |
46 | |
47 va_start( va, format ); | |
48 clen = strlen( comment ); | |
49 ret = strncasecmp( ptr, comment, clen) == 0 ? vsscanf( ptr+clen, format, va ) : 0; | |
50 va_end( va ); | |
51 | |
52 return ret; | |
53 } | |
54 | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
55 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
|
56 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
57 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
|
58 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
59 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
60 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
61 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
|
62 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
63 ogg_packet op; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
64 vorbis_comment vc; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
65 struct ov_struct_st *ov; |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
66 #define ERROR() { \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
67 vorbis_comment_clear(&vc); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
68 vorbis_info_clear(&ov->vi); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
69 free(ov); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
70 return 0; \ |
5775 | 71 } |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
72 /// 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
|
73 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
|
74 vorbis_info_init(&ov->vi); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
75 vorbis_comment_init(&vc); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
76 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
|
77 op.b_o_s = 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
78 /// Header |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
79 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
|
80 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
|
81 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
82 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
83 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
|
84 op.b_o_s = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
85 /// Comments |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
86 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
|
87 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
|
88 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
89 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
90 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
|
91 //// Codebook |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
92 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
|
93 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
|
94 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
95 } else { /// Print the infos |
8220 | 96 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
|
97 char **ptr=vc.user_comments; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
98 while(*ptr){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
99 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr); |
8220 | 100 /* replaygain */ |
101 read_vorbis_comment( *ptr, "replaygain_album_gain=", "%f", &rg_gain ); | |
102 read_vorbis_comment( *ptr, "rg_audiophile=", "%f", &rg_gain ); | |
103 if( !rg_gain ) { | |
104 read_vorbis_comment( *ptr, "replaygain_track_gain=", "%f", &rg_gain ); | |
105 read_vorbis_comment( *ptr, "rg_radio=", "%f", &rg_gain ); | |
106 } | |
107 read_vorbis_comment( *ptr, "replaygain_album_peak=", "%f", &rg_peak ); | |
108 if( !rg_peak ) { | |
109 read_vorbis_comment( *ptr, "replaygain_track_peak=", "%f", &rg_peak ); | |
110 read_vorbis_comment( *ptr, "rg_peak=", "%f", &rg_peak ); | |
111 } | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
112 ++ptr; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
113 } |
8220 | 114 /* replaygain: scale */ |
115 if(!rg_gain) | |
116 ov->rg_scale = 1.f; /* just in case pow() isn't standard-conformant */ | |
117 else | |
118 ov->rg_scale = pow(10.f, rg_gain/20); | |
119 /* replaygain: anticlip */ | |
120 if(ov->rg_scale * rg_peak > 1.f) | |
121 ov->rg_scale = 1.f / rg_peak; | |
122 /* replaygain: security */ | |
123 if(ov->rg_scale > 15.) | |
124 ov->rg_scale = 15.; | |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
125 #ifdef TREMOR |
8946
9821db5b213f
1000l, this clips!! IMO rg_scale nonsense should be removed with
rfelker
parents:
8343
diff
changeset
|
126 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
|
127 #endif |
8220 | 128 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
|
129 (ov->vi.bitrate_lower!=ov->vi.bitrate_nominal)||(ov->vi.bitrate_upper!=ov->vi.bitrate_nominal)?'V':'C'); |
8220 | 130 if(rg_gain || rg_peak) |
131 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
|
132 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
|
133 } |
5775 | 134 vorbis_comment_clear(&vc); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
135 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
136 // 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
|
137 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
138 // Setup the decoder |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
139 sh->channels=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
140 sh->samplerate=ov->vi.rate; |
13374
e94036364011
fix reimar's 10l...no actually imho it's arpi's 100l for writing the
rfelker
parents:
9169
diff
changeset
|
141 sh->samplesize=2; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
142 // 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
|
143 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
|
144 sh->context = ov; |
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 /// Finish the decoder init |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
151 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
152 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
153 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
154 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
|
155 { |
5775 | 156 struct ov_struct_st *ov = sh->context; |
13641 | 157 vorbis_dsp_clear(&ov->vd); |
5775 | 158 vorbis_block_clear(&ov->vb); |
159 vorbis_info_clear(&ov->vi); | |
160 free(ov); | |
5427
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 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
|
164 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
165 switch(cmd) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
166 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
167 #if 0 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
168 case ADCTRL_RESYNC_STREAM: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
169 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
170 case ADCTRL_SKIP_FRAME: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
171 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
172 #endif |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
173 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
174 return CONTROL_UNKNOWN; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
175 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
176 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
177 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
|
178 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
179 int len = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
180 int samples; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
181 float **pcm; |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
182 float scale; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
183 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
|
184 while(len < minlen) { |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
185 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
|
186 ogg_packet op; |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
187 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
|
188 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
|
189 if(op.bytes<=0) break; |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
190 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
|
191 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
|
192 } |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
193 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
|
194 while(samples>0){ |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
195 int i,j; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
196 int clipflag=0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
197 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
|
198 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
|
199 |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
200 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
|
201 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
202 /* 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
|
203 interleave */ |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
204 #ifdef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 ogg_int16_t *ptr=convbuffer+i; |
8342
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
209 ogg_int32_t *mono=pcm[i]; |
86835828d5b5
Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents:
8220
diff
changeset
|
210 for(j=0;j<bout;j++){ |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
211 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
|
212 /* 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
|
213 if(val>32767){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
214 val=32767; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
215 clipflag=1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
216 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
217 if(val<-32768){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
218 val=-32768; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
219 clipflag=1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
220 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
221 *ptr=val; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
222 ptr+=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
223 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
224 } |
8947
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
225 } else |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
226 #endif /* TREMOR */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
227 { |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
228 #ifndef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
229 scale = 32767.f * ov->rg_scale; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
230 #endif |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
231 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
|
232 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
|
233 ogg_int16_t *ptr=convbuffer+i; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
234 #ifdef TREMOR |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
235 ogg_int32_t *mono=pcm[i]; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
236 for(j=0;j<bout;j++){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
237 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
|
238 #else |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
239 float *mono=pcm[i]; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
240 for(j=0;j<bout;j++){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
241 int val=mono[j]*scale; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
242 /* might as well guard against clipping */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
243 if(val>32767){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
244 val=32767; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
245 clipflag=1; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
246 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
247 if(val<-32768){ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
248 val=-32768; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
249 clipflag=1; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
250 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
251 #endif /* TREMOR */ |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
252 *ptr=val; |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
253 ptr+=ov->vi.channels; |
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 } |
1c8e98dba92f
don't waste time on rg_scale nonsense if not necessary.
rfelker
parents:
8946
diff
changeset
|
256 } |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
257 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
258 if(clipflag) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 samples-=bout; |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
263 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
|
264 many samples we |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
265 actually consumed */ |
9169
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
266 } //while(samples>0) |
f49a2bf04229
- fixed the input buffering (don't read input unless we're already processed
arpi
parents:
8947
diff
changeset
|
267 // 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
|
268 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
269 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
270 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
271 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
272 return len; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
273 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
274 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
275 #endif /* !HAVE_OGGVORBIS */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
276 |