annotate libmpcodecs/ad_libvorbis.c @ 34394:6f190a6ae713

Update copyright year.
author cehoyos
date Sun, 01 Jan 2012 04:09:35 +0000
parents a93891202051
children ca073f3f4d4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
5427
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 #include <stdio.h>
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
20 #include <stdlib.h>
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
21 #include <unistd.h>
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
22 #include <stdarg.h>
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
23 #include <math.h>
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 #include "config.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 30504
diff changeset
26 #include "mp_msg.h"
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
27 #include "ad_internal.h"
26988
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
28 #include "libaf/reorder_ch.h"
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
29
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
30 static const ad_info_t info =
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
31 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
32 "Ogg/Vorbis audio decoder",
27980
21779d5ea61c Create a separate codecs.conf entry for Tremor and use it if MPlayer is
diego
parents: 27397
diff changeset
33 #ifdef CONFIG_TREMOR
21779d5ea61c Create a separate codecs.conf entry for Tremor and use it if MPlayer is
diego
parents: 27397
diff changeset
34 "tremor",
21779d5ea61c Create a separate codecs.conf entry for Tremor and use it if MPlayer is
diego
parents: 27397
diff changeset
35 #else
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
36 "libvorbis",
27980
21779d5ea61c Create a separate codecs.conf entry for Tremor and use it if MPlayer is
diego
parents: 27397
diff changeset
37 #endif
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
38 "Felix Buenemann, A'rpi",
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
39 "libvorbis",
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
40 ""
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
41 };
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
42
7174
7672615cc811 sync driver names with codec-cfg
arpi
parents: 7172
diff changeset
43 LIBAD_EXTERN(libvorbis)
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
44
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
45 #ifdef CONFIG_TREMOR
8342
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
46 #include <tremor/ivorbiscodec.h>
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
47 #else
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
48 #include <vorbis/codec.h>
8342
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
49 #endif
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
50
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
51 // 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
52 typedef struct ov_struct_st {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
53 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
54 settings */
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
55 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
56 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
57 vorbis_block vb; /* local working space for packet->PCM decode */
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
58 float rg_scale; /* replaygain scale */
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
59 #ifdef CONFIG_TREMOR
8342
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
60 int rg_scale_int;
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
61 #endif
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
62 } ov_struct_t;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
63
19104
2ec2301183cd marks several read-only string parameters which aren't modified inside the called function as const. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents: 18879
diff changeset
64 static int read_vorbis_comment( char* ptr, const char* comment, const char* format, ... ) {
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
65 va_list va;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
66 int clen, ret;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
67
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
68 va_start( va, format );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
69 clen = strlen( comment );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
70 ret = strncasecmp( ptr, comment, clen) == 0 ? vsscanf( ptr+clen, format, va ) : 0;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
71 va_end( va );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
72
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
73 return ret;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
74 }
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
75
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
76 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
77 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
78 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
79 return 1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
80 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
81
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
82 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
83 {
17093
e13c1bce5ad5 ad_libvorbis.c:119: warning: assignment from incompatible pointer type
rathann
parents: 16183
diff changeset
84 unsigned int offset, i, length, hsizes[3];
e13c1bce5ad5 ad_libvorbis.c:119: warning: assignment from incompatible pointer type
rathann
parents: 16183
diff changeset
85 void *headers[3];
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
86 unsigned char* extradata;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
87 ogg_packet op;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
88 vorbis_comment vc;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
89 struct ov_struct_st *ov;
7071
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
90 #define ERROR() { \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
91 vorbis_comment_clear(&vc); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
92 vorbis_info_clear(&ov->vi); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
93 free(ov); \
acc51ad47911 - functions inside of functions are invalid in icc. replaced with #define's
arpi
parents: 6587
diff changeset
94 return 0; \
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
95 }
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
96
15425
2071633f9bdc initialize vorbis structure before calling ERROR()
nicodvb
parents: 15420
diff changeset
97 /// Init the decoder with the 3 header packets
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18771
diff changeset
98 ov = malloc(sizeof(struct ov_struct_st));
15425
2071633f9bdc initialize vorbis structure before calling ERROR()
nicodvb
parents: 15420
diff changeset
99 vorbis_info_init(&ov->vi);
2071633f9bdc initialize vorbis structure before calling ERROR()
nicodvb
parents: 15420
diff changeset
100 vorbis_comment_init(&vc);
2071633f9bdc initialize vorbis structure before calling ERROR()
nicodvb
parents: 15420
diff changeset
101
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
102 if(! sh->wf) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
103 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ad_vorbis, extradata seems to be absent! exit\n");
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
104 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
105 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
106
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
107 if(! sh->wf->cbSize) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
108 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ad_vorbis, extradata seems to be absent!, exit\n");
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
109 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
110 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
111
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
112 mp_msg(MSGT_DECAUDIO,MSGL_V,"ad_vorbis, extradata seems is %d bytes long\n", sh->wf->cbSize);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
113 extradata = (char*) (sh->wf+1);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
114 if(!extradata) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
115 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ad_vorbis, extradata seems to be NULL!, exit\n");
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
116 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
117 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
118
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
119 if(*extradata != 2) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
120 mp_msg (MSGT_DEMUX, MSGL_WARN, "ad_vorbis: Vorbis track does not contain valid headers.\n");
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
121 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
122 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
123
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
124 offset = 1;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
125 for (i=0; i < 2; i++) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
126 length = 0;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
127 while ((extradata[offset] == (unsigned char) 0xFF) && length < sh->wf->cbSize) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
128 length += 255;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
129 offset++;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
130 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
131 if(offset >= (sh->wf->cbSize - 1)) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
132 mp_msg (MSGT_DEMUX, MSGL_WARN, "ad_vorbis: Vorbis track does not contain valid headers.\n");
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
133 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
134 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
135 length += extradata[offset];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
136 offset++;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
137 mp_msg (MSGT_DEMUX, MSGL_V, "ad_vorbis, offset: %u, length: %u\n", offset, length);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
138 hsizes[i] = length;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
139 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
140
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
141 headers[0] = &extradata[offset];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
142 headers[1] = &extradata[offset + hsizes[0]];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
143 headers[2] = &extradata[offset + hsizes[0] + hsizes[1]];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
144 hsizes[2] = sh->wf->cbSize - offset - hsizes[0] - hsizes[1];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
145 mp_msg (MSGT_DEMUX, MSGL_V, "ad_vorbis, header sizes: %d %d %d\n", hsizes[0], hsizes[1], hsizes[2]);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
146
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
147 for(i=0; i<3; i++) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
148 op.bytes = hsizes[i];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
149 op.packet = headers[i];
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
150 op.b_o_s = (i == 0);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
151 if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) {
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17093
diff changeset
152 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: header n. %d broken! len=%ld\n", i, op.bytes);
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
153 ERROR();
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
154 }
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
155 if(i == 2) {
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
156 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
157 char **ptr=vc.user_comments;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
158 while(*ptr){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
159 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
160 /* replaygain */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
161 read_vorbis_comment( *ptr, "replaygain_album_gain=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
162 read_vorbis_comment( *ptr, "rg_audiophile=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
163 if( !rg_gain ) {
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
164 read_vorbis_comment( *ptr, "replaygain_track_gain=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
165 read_vorbis_comment( *ptr, "rg_radio=", "%f", &rg_gain );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
166 }
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
167 read_vorbis_comment( *ptr, "replaygain_album_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
168 if( !rg_peak ) {
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
169 read_vorbis_comment( *ptr, "replaygain_track_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
170 read_vorbis_comment( *ptr, "rg_peak=", "%f", &rg_peak );
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
171 }
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
172 ++ptr;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
173 }
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
174 /* replaygain: scale */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
175 if(!rg_gain)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
176 ov->rg_scale = 1.f; /* just in case pow() isn't standard-conformant */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
177 else
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
178 ov->rg_scale = pow(10.f, rg_gain/20);
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
179 /* replaygain: anticlip */
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
180 if(ov->rg_scale * rg_peak > 1.f)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
181 ov->rg_scale = 1.f / rg_peak;
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
182 /* replaygain: security */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27980
diff changeset
183 if(ov->rg_scale > 15.)
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
184 ov->rg_scale = 15.;
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
185 #ifdef CONFIG_TREMOR
8946
9821db5b213f 1000l, this clips!! IMO rg_scale nonsense should be removed with
rfelker
parents: 8343
diff changeset
186 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
187 #endif
8220
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
188 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
189 (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
190 if(rg_gain || rg_peak)
393f1350b6e8 Added support for VorbisGain tags.
rguyom
parents: 7191
diff changeset
191 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
192 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",vc.vendor);
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
193 }
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
194 }
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 14542
diff changeset
195
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
196 vorbis_comment_clear(&vc);
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
197
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
198 // 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
199
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
200 // Setup the decoder
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27980
diff changeset
201 sh->channels=ov->vi.channels;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
202 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
203 sh->samplesize=2;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
204 // 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
205 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
206 sh->context = ov;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
207
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
208 /// Finish the decoder init
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
209 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
210 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
211 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
212
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
213 return 1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
214 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
215
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
216 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
217 {
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
218 struct ov_struct_st *ov = sh->context;
13641
a22f1b86ec0f some memory leaks fixed
reimar
parents: 13374
diff changeset
219 vorbis_dsp_clear(&ov->vd);
5775
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
220 vorbis_block_clear(&ov->vb);
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
221 vorbis_info_clear(&ov->vi);
e4c2a5541a6a Added uninit
albeu
parents: 5427
diff changeset
222 free(ov);
5427
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
225 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
226 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
227 switch(cmd)
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
228 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27980
diff changeset
229 #if 0
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
230 case ADCTRL_RESYNC_STREAM:
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
231 return CONTROL_TRUE;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
232 case ADCTRL_SKIP_FRAME:
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
233 return CONTROL_TRUE;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
234 #endif
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
235 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
236 return CONTROL_UNKNOWN;
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
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
239 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
240 {
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
241 int len = 0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
242 int samples;
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
243 #ifdef CONFIG_TREMOR
16183
8c342c68f665 tremor uses integer types
rathann
parents: 15425
diff changeset
244 ogg_int32_t **pcm;
8c342c68f665 tremor uses integer types
rathann
parents: 15425
diff changeset
245 #else
23380
8ef36374e8c5 Move variable declaration into conditional to avoid an unused variable warning.
diego
parents: 19104
diff changeset
246 float scale;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
247 float **pcm;
16183
8c342c68f665 tremor uses integer types
rathann
parents: 15425
diff changeset
248 #endif
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
249 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
250 while(len < minlen) {
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
251 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
252 ogg_packet op;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
253 double pts;
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
254 memset(&op,0,sizeof(op)); //op.b_o_s = op.e_o_s = 0;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
255 op.bytes = ds_get_packet_pts(sh->ds,&op.packet, &pts);
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
256 if(op.bytes<=0) break;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
257 if (pts != MP_NOPTS_VALUE) {
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
258 sh->pts = pts;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
259 sh->pts_bytes = 0;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
260 }
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
261 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
262 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
263 }
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
264 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
265 while(samples>0){
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
266 int i,j;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
267 int clipflag=0;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
268 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
269 int bout=((samples<convsize)?samples:convsize);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27980
diff changeset
270
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
271 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
272
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
273 /* 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
274 interleave */
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
275 #ifdef CONFIG_TREMOR
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
276 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
277 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
278 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
279 ogg_int16_t *ptr=convbuffer+i;
8342
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
280 ogg_int32_t *mono=pcm[i];
86835828d5b5 Add Tremor (an integer-only Vorbis decoder) support.
rguyom
parents: 8220
diff changeset
281 for(j=0;j<bout;j++){
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
282 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
283 /* 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
284 if(val>32767){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
285 val=32767;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
286 clipflag=1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
287 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
288 if(val<-32768){
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
289 val=-32768;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
290 clipflag=1;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
291 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
292 *ptr=val;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
293 ptr+=ov->vi.channels;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
294 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
295 }
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
296 } else
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
297 #endif /* CONFIG_TREMOR */
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
298 {
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
299 #ifndef CONFIG_TREMOR
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
300 scale = 32767.f * ov->rg_scale;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
301 #endif
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
302 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
303 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
304 ogg_int16_t *ptr=convbuffer+i;
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
305 #ifdef CONFIG_TREMOR
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
306 ogg_int32_t *mono=pcm[i];
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
307 for(j=0;j<bout;j++){
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
308 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
309 #else
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
310 float *mono=pcm[i];
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
311 for(j=0;j<bout;j++){
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
312 int val=mono[j]*scale;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
313 /* might as well guard against clipping */
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
314 if(val>32767){
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
315 val=32767;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
316 clipflag=1;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
317 }
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
318 if(val<-32768){
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
319 val=-32768;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
320 clipflag=1;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
321 }
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 26988
diff changeset
322 #endif /* CONFIG_TREMOR */
8947
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
323 *ptr=val;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
324 ptr+=ov->vi.channels;
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
325 }
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
326 }
1c8e98dba92f don't waste time on rg_scale nonsense if not necessary.
rfelker
parents: 8946
diff changeset
327 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 27980
diff changeset
328
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
329 if(clipflag)
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
330 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
331 len+=2*ov->vi.channels*bout;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
332 sh->pts_bytes += 2*ov->vi.channels*bout;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
333 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
334 samples-=bout;
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
335 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
336 many samples we
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
337 actually consumed */
9169
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
338 } //while(samples>0)
f49a2bf04229 - fixed the input buffering (don't read input unless we're already processed
arpi
parents: 8947
diff changeset
339 // 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
340 }
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
341
26988
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
342 if (len > 0 && ov->vi.channels >= 5) {
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
343 reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_VORBIS_DEFAULT,
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
344 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
345 ov->vi.channels, len / sh->samplesize,
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
346 sh->samplesize);
21ce55d8dde0 Fix channel order for libvorbis decoder, original patched by Nicolas George.
ulion
parents: 23380
diff changeset
347 }
5427
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
348
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
349
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
350 return len;
0b5462a620fc vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff changeset
351 }