annotate libmpcodecs/ad_libvorbis.c @ 8258:41dcb4b3e3ea

reversing warning fix (requested by alex)
author michael
date Sat, 23 Nov 2002 17:31:44 +0000
parents 393f1350b6e8
children 86835828d5b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
5 #include <stdarg.h>
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
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
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
11 #ifdef USE_SETLOCALE
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
12 #include <locale.h>
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
13 #endif
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
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
7672615cc811 sync driver names with codec-cfg
arpi
parents: 7172
diff changeset
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
28 #include <vorbis/codec.h>
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
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
37 float rg_scale; /* replaygain scale */
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
38 } ov_struct_t;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
39
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
40 static int read_vorbis_comment( char* ptr, char* comment, char* format, ... ) {
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
41 va_list va;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
42 int clen, ret;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
43
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
44 va_start( va, format );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
45 clen = strlen( comment );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
46 #ifdef USE_SETLOCALE
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
47 setlocale( LC_NUMERIC, "C" );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
48 #endif
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
49 ret = strncasecmp( ptr, comment, clen) == 0 ? vsscanf( ptr+clen, format, va ) : 0;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
50 #ifdef USE_SETLOCALE
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
51 setlocale( LC_NUMERIC, "" );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
52 #endif
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
53 va_end( va );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
54
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
55 return ret;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
56 }
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
57
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
58 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
59 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
60 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
61 return 1;
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
64 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
65 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
66 ogg_packet op;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
67 vorbis_comment vc;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
68 struct ov_struct_st *ov;
7071
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
69 #define ERROR() { \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
70 vorbis_comment_clear(&vc); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
71 vorbis_info_clear(&ov->vi); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
72 free(ov); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
73 return 0; \
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
74 }
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
75 /// 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
76 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
77 vorbis_info_init(&ov->vi);
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
78 vorbis_comment_init(&vc);
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
79 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
80 op.b_o_s = 1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
81 /// Header
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
82 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
83 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
84 ERROR();
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
85 }
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 = 0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
88 /// Comments
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: comment 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 //// Codebook
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
95 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
96 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
97 ERROR();
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
98 } else { /// Print the infos
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
99 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
100 char **ptr=vc.user_comments;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
101 while(*ptr){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
102 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
103 /* replaygain */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
104 read_vorbis_comment( *ptr, "replaygain_album_gain=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
105 read_vorbis_comment( *ptr, "rg_audiophile=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
106 if( !rg_gain ) {
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
107 read_vorbis_comment( *ptr, "replaygain_track_gain=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
108 read_vorbis_comment( *ptr, "rg_radio=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
109 }
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
110 read_vorbis_comment( *ptr, "replaygain_album_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
111 if( !rg_peak ) {
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
112 read_vorbis_comment( *ptr, "replaygain_track_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
113 read_vorbis_comment( *ptr, "rg_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
114 }
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
115 ++ptr;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
116 }
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
117 /* replaygain: scale */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
118 if(!rg_gain)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
119 ov->rg_scale = 1.f; /* just in case pow() isn't standard-conformant */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
120 else
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
121 ov->rg_scale = pow(10.f, rg_gain/20);
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
122 /* replaygain: anticlip */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
123 if(ov->rg_scale * rg_peak > 1.f)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
124 ov->rg_scale = 1.f / rg_peak;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
125 /* replaygain: security */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
126 if(ov->rg_scale > 15.)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
127 ov->rg_scale = 15.;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
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
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
130 if(rg_gain || rg_peak)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
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
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
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;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
141 // 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
142 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
143 sh->context = ov;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
144
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
145 /// Finish the decoder init
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
146 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
147 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
148 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
149
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
150 return 1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
151 }
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 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
154 {
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
155 struct ov_struct_st *ov = sh->context;
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
156 vorbis_block_clear(&ov->vb);
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
157 vorbis_info_clear(&ov->vi);
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
158 free(ov);
5427
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
161 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
162 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
163 switch(cmd)
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 #if 0
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
166 case ADCTRL_RESYNC_STREAM:
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
167 return CONTROL_TRUE;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
168 case ADCTRL_SKIP_FRAME:
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 #endif
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
171 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
172 return CONTROL_UNKNOWN;
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
175 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
176 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
177 int len = 0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
178 int samples;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
179 float **pcm;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
180 ogg_packet op;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
181 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
182 op.b_o_s = op.e_o_s = 0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
183 while(len < minlen) {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
184 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
185 if(!op.packet)
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
186 break;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
187 if(vorbis_synthesis(&ov->vb,&op)==0) /* test for success! */
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
188 vorbis_synthesis_blockin(&ov->vd,&ov->vb);
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
189 while((samples=vorbis_synthesis_pcmout(&ov->vd,&pcm))>0){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
190 int i,j;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
191 int clipflag=0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
192 int convsize=(maxlen-len)/(2*ov->vi.channels); // max size!
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
193 int bout=(samples<convsize?samples:convsize);
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
194
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
195 if(bout<=0) break;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
196
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
197 /* 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
198 interleave */
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
199 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
200 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
201 ogg_int16_t *ptr=convbuffer+i;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
202 float *mono=pcm[i];
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
203 for(j=0;j<bout;j++){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
204 #if 1
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
205 int val=mono[j]*32767.f*ov->rg_scale;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
206 #else /* optional dither */
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
207 int val=mono[j]*32767.f*ov->rg_scale+drand48()-0.5f;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
208 #endif
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
209 /* 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
210 if(val>32767){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
211 val=32767;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
212 clipflag=1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
213 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
214 if(val<-32768){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
215 val=-32768;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
216 clipflag=1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
217 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
218 *ptr=val;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
219 ptr+=ov->vi.channels;
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 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
222
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
223 if(clipflag)
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
224 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
225 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
226 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples);
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
227 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
228 many samples we
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
229 actually consumed */
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
230 }
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
233
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
234
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
235 return len;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
236 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
237
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
238 #endif /* !HAVE_OGGVORBIS */
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
239