Mercurial > mplayer.hg
annotate libmpcodecs/ad_libvorbis.c @ 7618:555ef64dfe1c
sync, shorter messages in help screen
author | rtognimp |
---|---|
date | Sun, 06 Oct 2002 13:19:21 +0000 |
parents | 1eadce15446c |
children | 393f1350b6e8 |
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> |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
5 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
6 #include "config.h" |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
7 #include "ad_internal.h" |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
8 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
9 #ifdef HAVE_OGGVORBIS |
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 static ad_info_t info = |
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 "Ogg/Vorbis audio decoder", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
14 "libvorbis", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
15 "Felix Buenemann, A'rpi", |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
16 "libvorbis", |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
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 |
7174 | 20 LIBAD_EXTERN(libvorbis) |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
21 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
22 #include <vorbis/codec.h> |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
23 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
24 // 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
|
25 typedef struct ov_struct_st { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
26 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
|
27 settings */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
28 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
|
29 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
|
30 vorbis_block vb; /* local working space for packet->PCM decode */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
31 } ov_struct_t; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
32 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
33 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
|
34 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
35 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
|
36 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
37 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
38 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
39 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
|
40 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
41 ogg_packet op; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
42 vorbis_comment vc; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
43 struct ov_struct_st *ov; |
7071
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
44 #define ERROR() { \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
45 vorbis_comment_clear(&vc); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
46 vorbis_info_clear(&ov->vi); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
47 free(ov); \ |
acc51ad47911
- functions inside of functions are invalid in icc. replaced with #define's
arpi
parents:
6587
diff
changeset
|
48 return 0; \ |
5775 | 49 } |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
50 /// 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
|
51 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
|
52 vorbis_info_init(&ov->vi); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
53 vorbis_comment_init(&vc); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
54 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
|
55 op.b_o_s = 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
56 /// Header |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
57 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
|
58 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
|
59 ERROR(); |
5427
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 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
|
62 op.b_o_s = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
63 /// Comments |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
64 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
|
65 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
|
66 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
67 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
68 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
|
69 //// Codebook |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
70 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
|
71 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
|
72 ERROR(); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
73 } else { /// Print the infos |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
74 char **ptr=vc.user_comments; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
75 while(*ptr){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
76 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
77 ++ptr; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
78 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
79 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %dHz, %dbit/s %cBR\n",(int)ov->vi.channels,(int)ov->vi.rate,(int)ov->vi.bitrate_nominal, |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
80 (ov->vi.bitrate_lower!=ov->vi.bitrate_nominal)||(ov->vi.bitrate_upper!=ov->vi.bitrate_nominal)?'V':'C'); |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
81 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
|
82 } |
5775 | 83 vorbis_comment_clear(&vc); |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
84 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
85 // 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
|
86 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
87 // Setup the decoder |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
88 sh->channels=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
89 sh->samplerate=ov->vi.rate; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
90 // 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
|
91 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
|
92 sh->context = ov; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
93 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
94 /// Finish the decoder init |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
99 return 1; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
100 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
101 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
102 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
|
103 { |
5775 | 104 struct ov_struct_st *ov = sh->context; |
105 vorbis_block_clear(&ov->vb); | |
106 vorbis_info_clear(&ov->vi); | |
107 free(ov); | |
5427
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
108 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
109 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
110 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
|
111 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
112 switch(cmd) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
113 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
114 #if 0 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
115 case ADCTRL_RESYNC_STREAM: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
116 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
117 case ADCTRL_SKIP_FRAME: |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
118 return CONTROL_TRUE; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
119 #endif |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
120 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
121 return CONTROL_UNKNOWN; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
122 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
123 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
124 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
|
125 { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
126 int len = 0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
127 int samples; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
128 float **pcm; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
129 ogg_packet op; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
130 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
|
131 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
|
132 while(len < minlen) { |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
133 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
|
134 if(!op.packet) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
135 break; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 int i,j; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
140 int clipflag=0; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
141 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
|
142 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
|
143 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
144 if(bout<=0) break; |
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 /* 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
|
147 interleave */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 float *mono=pcm[i]; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
152 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
|
153 #if 1 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
154 int val=mono[j]*32767.f; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
155 #else /* optional dither */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
156 int val=mono[j]*32767.f+drand48()-0.5f; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
157 #endif |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
158 /* 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
|
159 if(val>32767){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
160 val=32767; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
161 clipflag=1; |
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 if(val<-32768){ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
164 val=-32768; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
165 clipflag=1; |
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 *ptr=val; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
168 ptr+=ov->vi.channels; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
169 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
170 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
171 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
172 if(clipflag) |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 many samples we |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
178 actually consumed */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
179 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
180 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
181 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
182 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
183 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
184 return len; |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
185 } |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
186 |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
187 #endif /* !HAVE_OGGVORBIS */ |
0b5462a620fc
vorbis driver ported, and also fixed a bug, as nominal_bitrate can be -1
arpi
parents:
diff
changeset
|
188 |