annotate dec_audio.c @ 4239:acadddf56508

updated, colorkey support, pontscho reported it's working fine, only faulting with very-very-very big resolution
author alex
date Fri, 18 Jan 2002 18:14:10 +0000
parents c92c23a42e91
children ed500b952d2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
1
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
2 #define USE_G72X
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
3 //#define USE_LIBAC3
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
4
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
5 #include <stdio.h>
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
6 #include <stdlib.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1410
diff changeset
7 #include <unistd.h>
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
8
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
9 #include "config.h"
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1529
diff changeset
10 #include "mp_msg.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
11 #include "help_mp.h"
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1529
diff changeset
12
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
13 extern int verbose; // defined in mplayer.c
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
14
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
15 #include "stream.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
16 #include "demuxer.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
17
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
18 #include "codec-cfg.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
19 #include "stheader.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
20
2563
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
21 #include "dec_audio.h"
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
22
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
23 //==========================================================================
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
24
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
25 #include "libao2/afmt.h"
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
26
2049
df41903fd7d7 VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents: 1973
diff changeset
27 #include "dll_init.h"
df41903fd7d7 VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents: 1973
diff changeset
28
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
29 #include "mp3lib/mp3.h"
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
30
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
31 #ifdef USE_LIBAC3
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
32 #include "libac3/ac3.h"
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
33 #endif
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
34
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
35 #include "liba52/a52.h"
3907
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
36 #include "liba52/mm_accel.h"
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
37 static sample_t * a52_samples;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
38 static a52_state_t a52_state;
3907
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
39 static uint32_t a52_accel=0;
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
40 static uint32_t a52_flags=0;
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
41
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
42 #ifdef USE_G72X
3426
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
43 #include "g72x/g72x.h"
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
44 static G72x_DATA g72x_data;
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
45 #endif
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
46
883
ef5d1ab14218 using alaw.h instead of alaw.c
arpi_esp
parents: 758
diff changeset
47 #include "alaw.h"
ef5d1ab14218 using alaw.h instead of alaw.c
arpi_esp
parents: 758
diff changeset
48
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
49 #include "xa/xa_gsm.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
50
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
51 #include "ac3-iec958.h"
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
52
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
53 #include "adpcm.h"
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
54
3145
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
55 #include "cpudetect.h"
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
56
3182
95bbd21e8e1f moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents: 3181
diff changeset
57 /* used for ac3surround decoder - set using -channels option */
95bbd21e8e1f moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents: 3181
diff changeset
58 int audio_output_channels = 2;
95bbd21e8e1f moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents: 3181
diff changeset
59
2563
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
60 #ifdef USE_FAKE_MONO
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
61 int fakemono=0;
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
62 #endif
fc124f9db88e more cleanup, warnings fixed
arpi
parents: 2547
diff changeset
63
1291
36ed1692c0b8 video codec stuff moved to dec_video.c
arpi
parents: 1289
diff changeset
64 #ifdef USE_DIRECTSHOW
3947
2eb8c8aacca7 using dshow headers from dshow/ instead of c++ version
arpi
parents: 3933
diff changeset
65 #include "loader/dshow/DS_AudioDecoder.h"
2eb8c8aacca7 using dshow headers from dshow/ instead of c++ version
arpi
parents: 3933
diff changeset
66 static DS_AudioDecoder* ds_adec=NULL;
1291
36ed1692c0b8 video codec stuff moved to dec_video.c
arpi
parents: 1289
diff changeset
67 #endif
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1020
diff changeset
68
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
69 #ifdef HAVE_OGGVORBIS
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
70 /* XXX is math.h really needed? - atmos */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
71 #include <math.h>
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
72 #include <vorbis/codec.h>
2341
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
73
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
74 typedef struct ov_struct_st {
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
75 ogg_sync_state oy; /* sync and verify incoming physical bitstream */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
76 ogg_stream_state os; /* take physical pages, weld into a logical
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
77 stream of packets */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
78 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
79 ogg_packet op; /* one raw packet of data for decode */
3145
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
80
2341
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
81 vorbis_info vi; /* struct that stores all the static vorbis bitstream
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
82 settings */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
83 vorbis_comment vc; /* struct that stores all the bitstream user comments */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
84 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
85 vorbis_block vb; /* local working space for packet->PCM decode */
62be13447906 oggvorbis stuff moved out from stheader.h
arpi
parents: 2049
diff changeset
86 } ov_struct_t;
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
87 #endif
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
88
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
89 #ifdef USE_LIBAVCODEC
2496
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2434
diff changeset
90 #ifdef USE_LIBAVCODEC_SO
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2434
diff changeset
91 #include <libffmpeg/avcodec.h>
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2434
diff changeset
92 #else
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
93 #include "libavcodec/avcodec.h"
2496
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2434
diff changeset
94 #endif
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
95 static AVCodec *lavc_codec=NULL;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
96 static AVCodecContext lavc_context;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
97 extern int avcodec_inited;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
98 #endif
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
99
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
100
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
101
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
102 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
103 #include <mad.h>
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
104
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
105 #define MAD_SINGLE_BUFFER_SIZE 8192
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
106 #define MAD_TOTAL_BUFFER_SIZE ((MAD_SINGLE_BUFFER_SIZE)*3)
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
107
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
108 static struct mad_stream mad_stream;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
109 static struct mad_frame mad_frame;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
110 static struct mad_synth mad_synth;
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
111 static char* mad_in_buffer = 0; /* base pointer of buffer */
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
112
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
113 // ensure buffer is filled with some data
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
114 static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
115 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
116 if(sh_audio->a_in_buffer_len < length) {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
117 int len = demux_read_data(sh_audio->ds, sh_audio->a_in_buffer+sh_audio->a_in_buffer_len, length-sh_audio->a_in_buffer_len);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
118 sh_audio->a_in_buffer_len += len;
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
119 // printf("mad_prepare_buffer: read %d bytes\n", len);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
120 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
121 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
122
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
123 static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
124 {
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
125 /* rotate buffer while possible, in order to reduce the overhead of endless memcpy */
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
126 int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer;
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
127 if((unsigned long)(sh_audio->a_in_buffer) - (unsigned long)mad_in_buffer <
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
128 (MAD_TOTAL_BUFFER_SIZE - MAD_SINGLE_BUFFER_SIZE - delta)) {
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
129 sh_audio->a_in_buffer += delta;
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
130 sh_audio->a_in_buffer_len -= delta;
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
131 } else {
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
132 sh_audio->a_in_buffer = mad_in_buffer;
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
133 sh_audio->a_in_buffer_len -= delta;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
134 memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
135 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
136 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
137
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
138 static inline
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
139 signed short mad_scale(mad_fixed_t sample)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
140 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
141 /* round */
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
142 sample += (1L << (MAD_F_FRACBITS - 16));
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
143
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
144 /* clip */
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
145 if (sample >= MAD_F_ONE)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
146 sample = MAD_F_ONE - 1;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
147 else if (sample < -MAD_F_ONE)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
148 sample = -MAD_F_ONE;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
149
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
150 /* quantize */
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
151 return sample >> (MAD_F_FRACBITS + 1 - 16);
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
152
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
153 }
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
154
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
155 static void mad_sync(sh_audio_t* sh_audio, struct mad_stream* ms)
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
156 {
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
157 int len;
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
158 #if 1
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
159 int skipped = 0;
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
160
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
161 // printf("buffer len: %d\n", sh_audio->a_in_buffer_len);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
162 while(sh_audio->a_in_buffer_len - skipped)
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
163 {
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
164 len = mp_decode_mp3_header(sh_audio->a_in_buffer+skipped);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
165 if (len != -1)
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
166 {
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
167 // printf("Frame len=%d\n", len);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
168 break;
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
169 }
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
170 else
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
171 skipped++;
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
172 }
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
173 if (skipped)
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
174 {
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
175 printf("Audio synced, skipped bytes: %d\n", skipped);
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
176 // ms->skiplen += skipped;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
177 // printf("skiplen: %d (skipped: %d)\n", ms->skiplen, skipped);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
178
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
179 // if (sh_audio->a_in_buffer_len - skipped < MAD_BUFFER_GUARD)
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
180 // printf("Mad reports: too small buffer\n");
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
181
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
182 // mad_stream_buffer(ms, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len-skipped);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
183 // mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_len-skipped);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
184
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
185 /* move frame to the beginning of the buffer and fill up to a_in_buffer_size */
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
186 sh_audio->a_in_buffer_len -= skipped;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
187 memcpy(sh_audio->a_in_buffer, sh_audio->a_in_buffer+skipped, sh_audio->a_in_buffer_len);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
188 mad_prepare_buffer(sh_audio, ms, sh_audio->a_in_buffer_size);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
189 mad_stream_buffer(ms, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
190 // printf("bufflen: %d\n", sh_audio->a_in_buffer_len);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
191
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
192 // len = mp_decode_mp3_header(sh_audio->a_in_buffer);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
193 // printf("len: %d\n", len);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
194 ms->md_len = len;
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
195 }
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
196 #else
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
197 len = mad_stream_sync(&ms);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
198 if (len == -1)
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
199 {
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
200 printf("Mad sync failed\n");
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
201 }
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
202 #endif
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
203 }
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
204
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
205 static void mad_print_error(struct mad_stream *mad_stream)
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
206 {
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
207 printf("error (0x%x): ", mad_stream->error);
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
208 switch(mad_stream->error)
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
209 {
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
210 case MAD_ERROR_BUFLEN: printf("buffer too small"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
211 case MAD_ERROR_BUFPTR: printf("invalid buffer pointer"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
212 case MAD_ERROR_NOMEM: printf("not enought memory"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
213 case MAD_ERROR_LOSTSYNC: printf("lost sync"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
214 case MAD_ERROR_BADLAYER: printf("bad layer"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
215 case MAD_ERROR_BADBITRATE: printf("bad bitrate"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
216 case MAD_ERROR_BADSAMPLERATE: printf("bad samplerate"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
217 case MAD_ERROR_BADEMPHASIS: printf("bad emphasis"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
218 case MAD_ERROR_BADCRC: printf("bad crc"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
219 case MAD_ERROR_BADBITALLOC: printf("forbidden bit alloc val"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
220 case MAD_ERROR_BADSCALEFACTOR: printf("bad scalefactor index"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
221 case MAD_ERROR_BADFRAMELEN: printf("bad frame length"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
222 case MAD_ERROR_BADBIGVALUES: printf("bad bigvalues count"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
223 case MAD_ERROR_BADBLOCKTYPE: printf("reserved blocktype"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
224 case MAD_ERROR_BADSCFSI: printf("bad scalefactor selinfo"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
225 case MAD_ERROR_BADDATAPTR: printf("bad maindatabegin ptr"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
226 case MAD_ERROR_BADPART3LEN: printf("bad audio data len"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
227 case MAD_ERROR_BADHUFFTABLE: printf("bad huffman table sel"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
228 case MAD_ERROR_BADHUFFDATA: printf("huffman data overrun"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
229 case MAD_ERROR_BADSTEREO: printf("incomp. blocktype for JS"); break;
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
230 default:
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
231 printf("unknown error");
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
232 }
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
233 printf("\n");
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
234 }
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
235 #endif
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
236
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
237
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
238 static int a52_fillbuff(sh_audio_t *sh_audio){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
239 int length=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
240 int flags=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
241 int sample_rate=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
242 int bit_rate=0;
3834
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
243
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
244 sh_audio->a_in_buffer_len=0;
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
245 // sync frame:
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
246 while(1){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
247 while(sh_audio->a_in_buffer_len<7){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
248 int c=demux_getc(sh_audio->ds);
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
249 if(c<0) return -1; // EOF
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
250 sh_audio->a_in_buffer[sh_audio->a_in_buffer_len++]=c;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
251 }
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
252 length = a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate);
3834
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
253 if(length>=7 && length<=3840) break; // we're done.
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
254 // bad file => resync
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
255 memcpy(sh_audio->a_in_buffer,sh_audio->a_in_buffer+1,6);
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
256 --sh_audio->a_in_buffer_len;
bc85116eaf5e a52 sync fixed
arpi
parents: 3829
diff changeset
257 }
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
258 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"a52: len=%d flags=0x%X %d Hz %d bit/s\n",length,flags,sample_rate,bit_rate);
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
259 sh_audio->samplerate=sample_rate;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
260 sh_audio->i_bps=bit_rate/8;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
261 demux_read_data(sh_audio->ds,sh_audio->a_in_buffer+7,length-7);
3891
e87f69a44813 a52: CRC check for AC3 frames
arpi
parents: 3887
diff changeset
262
e87f69a44813 a52: CRC check for AC3 frames
arpi
parents: 3887
diff changeset
263 if(crc16_block(sh_audio->a_in_buffer+2,length-2)!=0)
e87f69a44813 a52: CRC check for AC3 frames
arpi
parents: 3887
diff changeset
264 mp_msg(MSGT_DECAUDIO,MSGL_STATUS,"a52: CRC check failed! \n");
e87f69a44813 a52: CRC check for AC3 frames
arpi
parents: 3887
diff changeset
265
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
266 return length;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
267 }
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
268
3887
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
269 // returns: number of available channels
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
270 static int a52_printinfo(sh_audio_t *sh_audio){
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
271 int flags, sample_rate, bit_rate;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
272 char* mode="unknown";
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
273 int channels=0;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
274 a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate);
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
275 switch(flags&A52_CHANNEL_MASK){
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
276 case A52_CHANNEL: mode="channel"; channels=2; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
277 case A52_MONO: mode="mono"; channels=1; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
278 case A52_STEREO: mode="stereo"; channels=2; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
279 case A52_3F: mode="3f";channels=3;break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
280 case A52_2F1R: mode="2f+1r";channels=3;break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
281 case A52_3F1R: mode="3f+1r";channels=4;break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
282 case A52_2F2R: mode="2f+2r";channels=4;break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
283 case A52_3F2R: mode="3f+2r";channels=5;break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
284 case A52_CHANNEL1: mode="channel1"; channels=2; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
285 case A52_CHANNEL2: mode="channel2"; channels=2; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
286 case A52_DOLBY: mode="dolby"; channels=2; break;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
287 }
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
288 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AC3: %d.%d (%s%s) %d Hz %3.1f kbit/s\n",
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
289 channels, (flags&A52_LFE)?1:0,
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
290 mode, (flags&A52_LFE)?"+lfe":"",
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
291 sample_rate, bit_rate*0.001f);
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
292 return (flags&A52_LFE) ? (channels+1) : channels;
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
293 }
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
294
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
295 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen);
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
296
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
297
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
298 static sh_audio_t* dec_audio_sh=NULL;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
299
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
300 #ifdef USE_LIBAC3
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
301 // AC3 decoder buffer callback:
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
302 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
303 int len=ds_get_packet(dec_audio_sh->ds,start);
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
304 //printf("<ac3:%d>\n",len);
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
305 if(len<0)
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
306 *start = *end = NULL;
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
307 else
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
308 *end = *start + len;
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
309 }
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
310 #endif
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
311
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
312 // MP3 decoder buffer callback:
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
313 int mplayer_audio_read(char *buf,int size){
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
314 int len;
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
315 len=demux_read_data(dec_audio_sh->ds,buf,size);
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
316 return len;
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
317 }
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
318
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
319 int init_audio(sh_audio_t *sh_audio){
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
320 int driver=sh_audio->codec->driver;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
321
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
322 sh_audio->samplesize=2;
1320
18374d49befa On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents: 1313
diff changeset
323 #if WORDS_BIGENDIAN
18374d49befa On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents: 1313
diff changeset
324 sh_audio->sample_format=AFMT_S16_BE;
18374d49befa On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents: 1313
diff changeset
325 #else
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
326 sh_audio->sample_format=AFMT_S16_LE;
1320
18374d49befa On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents: 1313
diff changeset
327 #endif
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
328 sh_audio->samplerate=0;
401
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
329 //sh_audio->pcm_bswap=0;
1529
81aa2d701ae0 o_bps changes for hwac3 driver
arpi
parents: 1528
diff changeset
330 sh_audio->o_bps=0;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
331
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
332 sh_audio->a_buffer_size=0;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
333 sh_audio->a_buffer=NULL;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
334
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
335 sh_audio->a_in_buffer_len=0;
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
336
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
337 // setup required min. in/out buffer size:
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
338 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
339
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
340 switch(driver){
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
341 case AFM_ACM:
1517
0e9c29538a86 Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents: 1485
diff changeset
342 #ifndef USE_WIN32DLL
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
343 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoACMSupport);
1309
598e3047ce13 Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents: 1291
diff changeset
344 driver=0;
598e3047ce13 Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents: 1291
diff changeset
345 #else
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
346 // Win32 ACM audio codec:
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
347 if(init_acm_audio_codec(sh_audio)){
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
348 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
349 sh_audio->channels=sh_audio->o_wf.nChannels;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
350 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
351 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
352 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
353 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST)
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
354 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
355 } else {
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
356 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ACMiniterror);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
357 driver=0;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
358 }
1309
598e3047ce13 Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents: 1291
diff changeset
359 #endif
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
360 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
361 case AFM_DSHOW:
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
362 #ifndef USE_DIRECTSHOW
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
363 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoDShowAudio);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
364 driver=0;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
365 #else
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
366 // Win32 DShow audio codec:
340
1f7c824033fb less, and more informal printfs
arpi_esp
parents: 303
diff changeset
367 // printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate);
3442
62b452b7ddf9 changed for updated DShow wrapper api
arpi
parents: 3426
diff changeset
368 if(!(ds_adec=DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf))){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
369 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
370 driver=0;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
371 } else {
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
372 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
373 sh_audio->channels=sh_audio->wf->nChannels;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
374 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
375 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
376 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
377 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
378 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
379 sh_audio->a_in_buffer_len=0;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
380 sh_audio->audio_out_minsize=16384;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
381 }
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
382 #endif
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
383 break;
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
384 case AFM_VORBIS:
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
385 #ifndef HAVE_OGGVORBIS
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
386 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoOggVorbis);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
387 driver=0;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
388 #else
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
389 /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
390 sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
391 #endif
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
392 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
393 case AFM_PCM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
394 case AFM_DVDPCM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
395 case AFM_ALAW:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
396 // PCM, aLaw
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
397 sh_audio->audio_out_minsize=2048;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
398 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
399 case AFM_AC3:
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
400 case AFM_A52:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
401 // Dolby AC3 audio:
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3145
diff changeset
402 // however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3145
diff changeset
403 sh_audio->audio_out_minsize=audio_output_channels*2*256*6;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
404 break;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
405 case AFM_HWAC3:
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
406 // Dolby AC3 audio:
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
407 sh_audio->audio_out_minsize=4*256*6;
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
408 sh_audio->sample_format = AFMT_AC3;
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
409 sh_audio->channels=1;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
410 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
411 case AFM_GSM:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
412 // MS-GSM audio codec:
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
413 sh_audio->audio_out_minsize=4*320;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
414 break;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
415 case AFM_IMAADPCM:
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
416 sh_audio->audio_out_minsize=4096;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
417 sh_audio->ds->ss_div=IMA_ADPCM_SAMPLES_PER_BLOCK;
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
418 sh_audio->ds->ss_mul=IMA_ADPCM_BLOCK_SIZE;
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
419 break;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
420 case AFM_MSADPCM:
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
421 sh_audio->audio_out_minsize=sh_audio->wf->nBlockAlign * 8;
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
422 sh_audio->ds->ss_div = MS_ADPCM_SAMPLES_PER_BLOCK;
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
423 sh_audio->ds->ss_mul = sh_audio->wf->nBlockAlign;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
424 break;
3933
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
425 case AFM_FOX61ADPCM:
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
426 sh_audio->audio_out_minsize=FOX61_ADPCM_SAMPLES_PER_BLOCK * 4;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
427 sh_audio->ds->ss_div=FOX61_ADPCM_SAMPLES_PER_BLOCK;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
428 sh_audio->ds->ss_mul=FOX61_ADPCM_BLOCK_SIZE;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
429 break;
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
430 case AFM_FOX62ADPCM:
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
431 sh_audio->audio_out_minsize=FOX62_ADPCM_SAMPLES_PER_BLOCK * 4;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
432 sh_audio->ds->ss_div=FOX62_ADPCM_SAMPLES_PER_BLOCK;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
433 sh_audio->ds->ss_mul=FOX62_ADPCM_BLOCK_SIZE;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
434 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
435 case AFM_MPEG:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
436 // MPEG Audio:
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
437 sh_audio->audio_out_minsize=4608;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
438 break;
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
439 #ifdef USE_G72X
3426
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
440 case AFM_G72X:
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
441 // g72x_reader_init(&g72x_data,G723_16_BITS_PER_SAMPLE);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
442 g72x_reader_init(&g72x_data,G723_24_BITS_PER_SAMPLE);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
443 // g72x_reader_init(&g72x_data,G721_32_BITS_PER_SAMPLE);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
444 // g72x_reader_init(&g72x_data,G721_40_BITS_PER_SAMPLE);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
445 sh_audio->audio_out_minsize=g72x_data.samplesperblock*4;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
446 break;
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
447 #endif
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
448 case AFM_FFMPEG:
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
449 #ifndef USE_LIBAVCODEC
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
450 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoLAVCsupport);
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
451 return 0;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
452 #else
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
453 // FFmpeg Audio:
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
454 sh_audio->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
455 break;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
456 #endif
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
457
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
458 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
459 case AFM_MAD:
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
460 printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
461 sh_audio->audio_out_minsize=4608;
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
462 if(sh_audio->audio_in_minsize<MAD_SINGLE_BUFFER_SIZE) sh_audio->audio_in_minsize=MAD_SINGLE_BUFFER_SIZE;
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
463 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
4208
c92c23a42e91 libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com>
arpi
parents: 4151
diff changeset
464 mad_in_buffer = sh_audio->a_in_buffer = malloc(MAD_TOTAL_BUFFER_SIZE);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
465 sh_audio->a_in_buffer_len=0;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
466 break;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
467 #endif
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
468 }
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
469
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
470 if(!driver) return 0;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
471
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
472 // allocate audio out buffer:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
473 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc.
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
474
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1529
diff changeset
475 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n",
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
476 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
477
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
478 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
479 if(!sh_audio->a_buffer){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
480 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
481 return 0;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
482 }
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
483 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
484 sh_audio->a_buffer_len=0;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
485
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
486 switch(driver){
1517
0e9c29538a86 Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents: 1485
diff changeset
487 #ifdef USE_WIN32DLL
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
488 case AFM_ACM: {
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
489 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size);
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
490 if(ret<0){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
491 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"ACM decoding error: %d\n",ret);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
492 driver=0;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
493 }
640
ef7249823af2 clicks/noise at start fixed
arpi_esp
parents: 604
diff changeset
494 sh_audio->a_buffer_len=ret;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
495 break;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
496 }
1309
598e3047ce13 Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents: 1291
diff changeset
497 #endif
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
498 case AFM_PCM: {
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
499 // AVI PCM Audio:
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
500 WAVEFORMATEX *h=sh_audio->wf;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
501 sh_audio->i_bps=h->nAvgBytesPerSec;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
502 sh_audio->channels=h->nChannels;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
503 sh_audio->samplerate=h->nSamplesPerSec;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
504 sh_audio->samplesize=(h->wBitsPerSample+7)/8;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
505 switch(sh_audio->format){ // hardware formats:
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
506 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
507 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
508 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
509 case 0x50: sh_audio->sample_format=AFMT_MPEG;break;
2547
77a3f73c04d5 support for twos
arpi
parents: 2496
diff changeset
510 case 0x736F7774: sh_audio->sample_format=AFMT_S16_LE;sh_audio->codec->driver=AFM_DVDPCM;break;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
511 // case 0x2000: sh_audio->sample_format=AFMT_AC3;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
512 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
513 }
401
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
514 break;
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
515 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
516 case AFM_DVDPCM: {
401
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
517 // DVD PCM Audio:
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
518 sh_audio->channels=2;
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
519 sh_audio->samplerate=48000;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
520 sh_audio->i_bps=2*2*48000;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
521 // sh_audio->pcm_bswap=1;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
522 break;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
523 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
524 case AFM_AC3: {
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
525 #ifndef USE_LIBAC3
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
526 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"WARNING: libac3 support is disabled. (hint: upgrade codecs.conf)\n");
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
527 driver=0;
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
528 #else
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
529 // Dolby AC3 audio:
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
530 dec_audio_sh=sh_audio; // save sh_audio for the callback:
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
531 ac3_config.fill_buffer_callback = ac3_fill_buffer;
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3145
diff changeset
532 ac3_config.num_output_ch = audio_output_channels;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
533 ac3_config.flags = 0;
3145
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
534 if(gCpuCaps.hasMMX){
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
535 ac3_config.flags |= AC3_MMX_ENABLE;
3145
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
536 }
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
537 if(gCpuCaps.has3DNow){
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
538 ac3_config.flags |= AC3_3DNOW_ENABLE;
3145
78e11396f431 runtime cpu detection
michael
parents: 2563
diff changeset
539 }
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
540 ac3_init();
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
541 sh_audio->ac3_frame = ac3_decode_frame();
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
542 if(sh_audio->ac3_frame){
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
543 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame;
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
544 sh_audio->samplerate=fr->sampling_rate;
3181
c8edb0691f09 Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents: 3145
diff changeset
545 sh_audio->channels=ac3_config.num_output_ch;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
546 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
547 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256);
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
548 sh_audio->i_bps=fr->bit_rate*(1000/8);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
549 } else {
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
550 driver=0; // bad frame -> disable audio
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
551 }
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
552 #endif
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
553 break;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
554 }
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
555 case AFM_A52: {
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
556 sample_t level=1, bias=384;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
557 int flags=0;
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
558 // Dolby AC3 audio:
3907
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
559 if(gCpuCaps.hasSSE) a52_accel|=MM_ACCEL_X86_SSE;
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
560 if(gCpuCaps.hasMMX) a52_accel|=MM_ACCEL_X86_MMX;
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
561 if(gCpuCaps.hasMMX2) a52_accel|=MM_ACCEL_X86_MMXEXT;
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
562 if(gCpuCaps.has3DNow) a52_accel|=MM_ACCEL_X86_3DNOW;
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
563 a52_samples=a52_init (a52_accel);
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
564 if (a52_samples == NULL) {
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
565 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
566 driver=0;break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
567 }
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
568 sh_audio->a_in_buffer_size=3840;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
569 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
570 sh_audio->a_in_buffer_len=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
571 if(a52_fillbuff(sh_audio)<0){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
572 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
573 driver=0;break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
574 }
3887
2bafb3aaae46 print AC3 info + hotfix for channels upmix
arpi
parents: 3886
diff changeset
575 // 'a52 cannot upmix' hotfix:
3968
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
576 a52_printinfo(sh_audio);
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
577 // if(audio_output_channels<sh_audio->channels)
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
578 // sh_audio->channels=audio_output_channels;
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
579 // channels setup:
3968
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
580 sh_audio->channels=audio_output_channels;
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
581 while(sh_audio->channels>0){
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
582 switch(sh_audio->channels){
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
583 case 1: a52_flags=A52_MONO; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
584 // case 2: a52_flags=A52_STEREO; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
585 case 2: a52_flags=A52_DOLBY; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
586 // case 3: a52_flags=A52_3F; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
587 case 3: a52_flags=A52_2F1R; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
588 case 4: a52_flags=A52_2F2R; break; // 2+2
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
589 case 5: a52_flags=A52_3F2R; break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
590 case 6: a52_flags=A52_3F2R|A52_LFE; break; // 5.1
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
591 }
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
592 // test:
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
593 flags=a52_flags|A52_ADJUST_LEVEL;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
594 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags before a52_frame: 0x%X\n",flags);
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
595 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
596 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: error decoding frame -> nosound\n");
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
597 driver=0;break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
598 }
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
599 mp_msg(MSGT_DECAUDIO,MSGL_V,"A52 flags after a52_frame: 0x%X\n",flags);
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
600 // frame decoded, let's init resampler:
3968
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
601 if(a52_resample_init(a52_accel,flags,sh_audio->channels)) break;
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
602 --sh_audio->channels; // try to decrease no. of channels
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
603 }
3bbaeba57939 iterated a52 channel setup
arpi
parents: 3947
diff changeset
604 if(sh_audio->channels<=0){
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
605 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: no resampler. try different channel setup!\n");
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
606 driver=0;break;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
607 }
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
608 break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
609 }
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
610 case AFM_HWAC3: {
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
611 // Dolby AC3 passthrough:
3907
6312aa265429 pass accel flags to a52_resample_init
arpi
parents: 3906
diff changeset
612 a52_samples=a52_init (a52_accel);
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
613 if (a52_samples == NULL) {
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
614 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n");
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
615 driver=0;break;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
616 }
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
617 sh_audio->a_in_buffer_size=3840;
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
618 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
619 sh_audio->a_in_buffer_len=0;
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
620 if(a52_fillbuff(sh_audio)<0) {
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
621 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
622 driver=0;break;
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
623 }
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
624
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
625 //sh_audio->samplerate=ai.samplerate; // SET by a52_fillbuff()
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
626 //sh_audio->samplesize=ai.framesize;
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
627 //sh_audio->i_bps=ai.bitrate*(1000/8); // SET by a52_fillbuff()
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
628 //sh_audio->ac3_frame=malloc(6144);
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
629 //sh_audio->o_bps=sh_audio->i_bps; // XXX FIXME!!! XXX
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
630
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
631 // o_bps is calculated from samplesize*channels*samplerate
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
632 // a single ac3 frame is always translated to 6144 byte packet. (zero padding)
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
633 sh_audio->channels=1;
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
634 sh_audio->samplesize=4; // 1*4*(6*256) = 6144 (very TRICKY!)
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
635
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
636 break;
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
637 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
638 case AFM_ALAW: {
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
639 // aLaw audio codec:
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
640 sh_audio->channels=sh_audio->wf->nChannels;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
641 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
642 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
643 break;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
644 }
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
645 #ifdef USE_G72X
3426
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
646 case AFM_G72X: {
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
647 // GSM 723 audio codec:
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
648 sh_audio->channels=sh_audio->wf->nChannels;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
649 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
650 sh_audio->i_bps=(sh_audio->samplerate/g72x_data.samplesperblock)*g72x_data.blocksize;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
651 break;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
652 }
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
653 #endif
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
654 #ifdef USE_LIBAVCODEC
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
655 case AFM_FFMPEG: {
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
656 int x;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
657 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
658 if(!avcodec_inited){
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
659 avcodec_init();
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
660 avcodec_register_all();
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
661 avcodec_inited=1;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
662 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
663 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll);
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
664 if(!lavc_codec){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
665 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll);
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
666 return 0;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
667 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
668 memset(&lavc_context, 0, sizeof(lavc_context));
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
669 /* open it */
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
670 if (avcodec_open(&lavc_context, lavc_codec) < 0) {
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
671 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec);
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
672 return 0;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
673 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
674 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n");
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
675
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
676 // Decode at least 1 byte: (to get header filled)
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
677 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size);
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
678 if(x>0) sh_audio->a_buffer_len=x;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
679
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
680 #if 1
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
681 sh_audio->channels=lavc_context.channels;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
682 sh_audio->samplerate=lavc_context.sample_rate;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
683 sh_audio->i_bps=lavc_context.bit_rate/8;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
684 #else
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
685 sh_audio->channels=sh_audio->wf->nChannels;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
686 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
687 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
688 #endif
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
689 break;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
690 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
691 #endif
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
692 case AFM_GSM: {
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
693 // MS-GSM audio codec:
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
694 GSM_Init();
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
695 sh_audio->channels=sh_audio->wf->nChannels;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 401
diff changeset
696 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
697 // decodes 65 byte -> 320 short
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
698 // 1 sec: sh_audio->channels*sh_audio->samplerate samples
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
699 // 1 frame: 320 samples
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
700 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
701 break;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
702 }
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
703 case AFM_IMAADPCM:
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
704 // IMA-ADPCM 4:1 audio codec:
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
705 sh_audio->channels=sh_audio->wf->nChannels;
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
706 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
707 // decodes 34 byte -> 64 short
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
708 sh_audio->i_bps=IMA_ADPCM_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA_ADPCM_SAMPLES_PER_BLOCK; // 1:4
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
709 break;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
710 case AFM_MSADPCM:
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
711 sh_audio->channels=sh_audio->wf->nChannels;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
712 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
713 sh_audio->i_bps = sh_audio->wf->nBlockAlign *
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
714 (sh_audio->channels*sh_audio->samplerate) / MS_ADPCM_SAMPLES_PER_BLOCK;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
715 break;
3933
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
716 case AFM_FOX61ADPCM:
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
717 sh_audio->channels=sh_audio->wf->nChannels;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
718 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
719 sh_audio->i_bps=FOX61_ADPCM_BLOCK_SIZE*
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
720 (sh_audio->channels*sh_audio->samplerate) / FOX61_ADPCM_SAMPLES_PER_BLOCK;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
721 break;
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
722 case AFM_FOX62ADPCM:
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
723 sh_audio->channels=sh_audio->wf->nChannels;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
724 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
725 sh_audio->i_bps=FOX62_ADPCM_BLOCK_SIZE*
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
726 (sh_audio->channels*sh_audio->samplerate) / FOX62_ADPCM_SAMPLES_PER_BLOCK;
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
727 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
728 case AFM_MPEG: {
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
729 // MPEG Audio:
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1058
diff changeset
730 dec_audio_sh=sh_audio; // save sh_audio for the callback:
732
e14114170e01 applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents: 640
diff changeset
731 #ifdef USE_FAKE_MONO
e14114170e01 applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents: 640
diff changeset
732 MP3_Init(fakemono);
e14114170e01 applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents: 640
diff changeset
733 #else
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
734 MP3_Init();
732
e14114170e01 applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents: 640
diff changeset
735 #endif
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
736 MP3_samplerate=MP3_channels=0;
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
737 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1);
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
738 sh_audio->channels=2; // hack
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
739 sh_audio->samplerate=MP3_samplerate;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
740 sh_audio->i_bps=MP3_bitrate*(1000/8);
4151
6ad5da34c463 added mp3_printheader for mp3lib init\n
alex
parents: 4001
diff changeset
741 MP3_PrintHeader();
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
742 break;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
743 }
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
744 #ifdef HAVE_OGGVORBIS
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
745 case AFM_VORBIS: {
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
746 // OggVorbis Audio:
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
747 #if 0 /* just here for reference - atmos */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
748 ogg_sync_state oy; /* sync and verify incoming physical bitstream */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
749 ogg_stream_state os; /* take physical pages, weld into a logical
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
750 stream of packets */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
751 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
752 ogg_packet op; /* one raw packet of data for decode */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
753
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
754 vorbis_info vi; /* struct that stores all the static vorbis bitstream
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
755 settings */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
756 vorbis_comment vc; /* struct that stores all the bitstream user comments */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
757 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
758 vorbis_block vb; /* local working space for packet->PCM decode */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
759 #else
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
760 /* nix, nada, rien, nothing, nem, nüx */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
761 #endif
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
762
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
763 uint32_t hdrsizes[3];/* stores vorbis header sizes from AVI audio header,
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
764 maybe use ogg_uint32_t */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
765 //int i;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
766 int ret;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
767 char *buffer;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
768 ogg_packet hdr;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
769 //ov_struct_t *s=&sh_audio->ov;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
770 sh_audio->ov=malloc(sizeof(ov_struct_t));
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
771 //s=&sh_audio->ov;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
772
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
773 vorbis_info_init(&sh_audio->ov->vi);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
774 vorbis_comment_init(&sh_audio->ov->vc);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
775
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
776 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
777 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t));
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
778 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
779 /*for(i=12; i <= 40; i+=2) { // header bruteforce :)
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
780 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t));
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
781 printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
782 }*/
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
783
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
784 /* read headers */ // FIXME disable sound on errors here, we absolutely need this headers! - atmos
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
785 hdr.packet=NULL;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
786 hdr.b_o_s = 1; /* beginning of stream for first packet */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
787 hdr.bytes = hdrsizes[0];
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
788 hdr.packet = realloc(hdr.packet,hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
789 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
790 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
791 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: initial (identification) header broken!\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
792 hdr.b_o_s = 0;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
793 hdr.bytes = hdrsizes[1];
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
794 hdr.packet = realloc(hdr.packet,hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
795 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
796 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
797 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: comment header broken!\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
798 hdr.bytes = hdrsizes[2];
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
799 hdr.packet = realloc(hdr.packet,hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
800 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
801 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
802 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
803 hdr.bytes=0;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
804 hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
805 /* done with the headers */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
806
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
807
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
808 /* Throw the comments plus a few lines about the bitstream we're
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
809 decoding */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
810 {
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
811 char **ptr=sh_audio->ov->vc.user_comments;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
812 while(*ptr){
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
813 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
814 ++ptr;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
815 }
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
816 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C');
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
817 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
818 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
819 sh_audio->channels=sh_audio->ov->vi.channels;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
820 sh_audio->samplerate=sh_audio->ov->vi.rate;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
821 sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
822
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
823 // printf("[\n");
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
824 // sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels;
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
825 // printf("]\n");
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
826
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
827 /* OK, got and parsed all three headers. Initialize the Vorbis
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
828 packet->PCM decoder. */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
829 vorbis_synthesis_init(&sh_audio->ov->vd,&sh_audio->ov->vi); /* central decode state */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
830 vorbis_block_init(&sh_audio->ov->vd,&sh_audio->ov->vb); /* local state for most of the decode
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
831 so multiple block decodes can
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
832 proceed in parallel. We could init
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
833 multiple vorbis_block structures
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
834 for vd here */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
835 //printf("OggVorbis: synthesis and block init done.\n");
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
836 ogg_sync_init(&sh_audio->ov->oy); /* Now we can read pages */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
837
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
838 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
839 if(ret == -1)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
840 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
841 else
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
842 if(ret == 0) {
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
843 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: need more data to verify page, reading more data.\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
844 /* submit a a_buffer_len block to libvorbis' Ogg layer */
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
845 buffer=ogg_sync_buffer(&sh_audio->ov->oy,256);
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
846 ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,256));
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
847 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
848 }
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
849 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: successfull.\n");
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
850 ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
851 as they'll also become apparent
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
852 at packetout */
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
853
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
854 /* Get the serial number and set up the rest of decode. */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
855 /* serialno first; use it to set up a logical stream */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
856 ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og));
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
857
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
858 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n");
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
859
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
860 break;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
861 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
862 #endif
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
863
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
864 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
865 case AFM_MAD:
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
866 {
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
867 printf("%s %s %s (%s)\n", mad_version, mad_copyright, mad_author, mad_build);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
868
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
869 printf(__FILE__ ":%d:mad: initialising\n", __LINE__);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
870 mad_frame_init(&mad_frame);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
871 mad_stream_init(&mad_stream);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
872
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
873 printf(__FILE__ ":%d:mad: preparing buffer\n", __LINE__);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
874 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
875 mad_stream_buffer(&mad_stream, (unsigned char*)(sh_audio->a_in_buffer), sh_audio->a_in_buffer_len);
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
876 // mad_stream_sync(&mad_stream);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
877 mad_sync(sh_audio, &mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
878 mad_synth_init(&mad_synth);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
879
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
880 if(mad_frame_decode(&mad_frame, &mad_stream) == 0)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
881 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
882 printf(__FILE__ ":%d:mad: post processing buffer\n", __LINE__);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
883 mad_postprocess_buffer(sh_audio, &mad_stream);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
884 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
885 else
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
886 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
887 printf(__FILE__ ":%d:mad: frame decoding failed\n", __LINE__);
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
888 mad_print_error(&mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
889 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
890
2434
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
891 switch (mad_frame.header.mode)
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
892 {
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
893 case MAD_MODE_SINGLE_CHANNEL:
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
894 sh_audio->channels=1;
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
895 break;
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
896 case MAD_MODE_DUAL_CHANNEL:
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
897 case MAD_MODE_JOINT_STEREO:
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
898 case MAD_MODE_STEREO:
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
899 sh_audio->channels=2;
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
900 break;
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
901 default:
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
902 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "mad: unknown number of channels\n");
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
903 }
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
904 mp_msg(MSGT_DECAUDIO, MSGL_HINT, "mad: channels: %d (mad channel mode: %d)\n",
571538d73e08 audio channels nr is identified from libmad's channel mode
alex
parents: 2432
diff changeset
905 sh_audio->channels, mad_frame.header.mode);
2432
b02c2679e5a9 libmad fix (see comment)
alex
parents: 2424
diff changeset
906 /* var. name changed in 0.13.0 (beta) (libmad/CHANGES) -- alex */
b02c2679e5a9 libmad fix (see comment)
alex
parents: 2424
diff changeset
907 #if (MAD_VERSION_MAJOR >= 0) && (MAD_VERSION_MINOR >= 13)
b02c2679e5a9 libmad fix (see comment)
alex
parents: 2424
diff changeset
908 sh_audio->samplerate=mad_frame.header.samplerate;
b02c2679e5a9 libmad fix (see comment)
alex
parents: 2424
diff changeset
909 #else
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
910 sh_audio->samplerate=mad_frame.header.sfreq;
2432
b02c2679e5a9 libmad fix (see comment)
alex
parents: 2424
diff changeset
911 #endif
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
912 sh_audio->i_bps=mad_frame.header.bitrate;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
913 printf(__FILE__ ":%d:mad: continuing\n", __LINE__);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
914 break;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
915 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
916 #endif
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
917 }
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
918
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
919 if(!sh_audio->channels || !sh_audio->samplerate){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
920 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
921 driver=0;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
922 }
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
923
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
924 if(!driver){
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
925 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
1313
d797ecb9778f sh_audio->a_buffer is freed twice (here and in mplayer.c), can result to
jkeil
parents: 1309
diff changeset
926 sh_audio->a_buffer=NULL;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
927 return 0;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
928 }
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
929
1529
81aa2d701ae0 o_bps changes for hwac3 driver
arpi
parents: 1528
diff changeset
930 if(!sh_audio->o_bps)
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
931 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
932 return driver;
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
933 }
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
934
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
935 // Audio decoding:
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
936
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
937 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc)
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
938 // buffer length is 'maxlen' bytes, it shouldn't be exceeded...
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
939
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
940 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
941 int len=-1;
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 296
diff changeset
942 switch(sh_audio->codec->driver){
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
943 #ifdef USE_LIBAVCODEC
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
944 case AFM_FFMPEG: {
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
945 unsigned char *start=NULL;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
946 int y;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
947 while(len<minlen){
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
948 int len2=0;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
949 int x=ds_get_packet(sh_audio->ds,&start);
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
950 if(x<=0) break; // error
2049
df41903fd7d7 VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents: 1973
diff changeset
951 y=avcodec_decode_audio(&lavc_context,(INT16*)buf,&len2,start,x);
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1927
diff changeset
952 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; }
1927
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
953 if(y<x) sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!)
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
954 if(len2>0){
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
955 //len=len2;break;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
956 if(len<0) len=len2; else len+=len2;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
957 buf+=len2;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
958 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
959 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2);
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
960 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
961 }
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
962 break;
296208b47fd4 FFmpeg audio codecs support
arpi
parents: 1849
diff changeset
963 #endif
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
964 case AFM_MPEG: // MPEG layer 2 or 3
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
965 len=MP3_DecodeFrame(buf,-1);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1456
diff changeset
966 // len=MP3_DecodeFrame(buf,3);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
967 break;
1830
46347c4075da OOOPS, miaaing ifdef.
atmos4
parents: 1828
diff changeset
968 #ifdef HAVE_OGGVORBIS
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
969 case AFM_VORBIS: { // OggVorbis
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
970 /* note: good minlen would be 4k or 8k IMHO - atmos */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
971 int ret;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
972 char *buffer;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
973 int bytes;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
974 int samples;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
975 float **pcm;
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
976 //ogg_int16_t convbuffer[4096];
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
977 // int convsize;
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
978 int readlen=1024;
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
979 len=0;
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
980 // convsize=minlen/sh_audio->ov->vi.channels;
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
981
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
982 while(len < minlen) { /* double loop allows for break in inner loop */
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
983 while(len < minlen) { /* without aborting the outer loop - atmos */
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
984 ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op);
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
985 if(ret==0) {
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
986 int xxx=0;
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
987 //printf("OggVorbis: Packetout: need more data, paging!\n");
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
988 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
989 if(ret == -1)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
990 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
991 else
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
992 if(ret == 0) {
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
993 //printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n");
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
994 /* submit a readlen k block to libvorbis' Ogg layer */
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
995 buffer=ogg_sync_buffer(&sh_audio->ov->oy,readlen);
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
996 bytes=demux_read_data(sh_audio->ds,buffer,readlen);
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
997 xxx+=bytes;
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
998 ogg_sync_wrote(&sh_audio->ov->oy,bytes);
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
999 if(bytes==0)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1000 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: 0Bytes written, possible End of Stream\n");
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1001 }
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1002 }
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1003 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[sync: %d ]\n",xxx);
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1004 //printf("OggVorbis: Pageout: successfull, pagin in.\n");
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1005 if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1006 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pagein failed!\n");
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1007 break;
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1008 } else if(ret<0) {
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1009 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Packetout: missing or corrupt data, skipping packet!\n");
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1010 break;
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1011 } else {
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1012
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1013 /* we have a packet. Decode it */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1014
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1015 if(vorbis_synthesis(&sh_audio->ov->vb,&sh_audio->ov->op)==0) /* test for success! */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1016 vorbis_synthesis_blockin(&sh_audio->ov->vd,&sh_audio->ov->vb);
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1017
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1018 /* **pcm is a multichannel float vector. In stereo, for
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1019 example, pcm[0] is left, and pcm[1] is right. samples is
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1020 the size of each channel. Convert the float values
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1021 (-1.<=range<=1.) to whatever PCM format and write it out */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1022
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1023 while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1024 int i,j;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1025 int clipflag=0;
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1026 int convsize=(maxlen-len)/(2*sh_audio->ov->vi.channels); // max size!
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1027 int bout=(samples<convsize?samples:convsize);
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1028
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1029 if(bout<=0) break;
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1030
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1031 /* convert floats to 16 bit signed ints (host order) and
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1032 interleave */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1033 for(i=0;i<sh_audio->ov->vi.channels;i++){
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1034 ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1035 ogg_int16_t *ptr=convbuffer+i;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1036 float *mono=pcm[i];
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1037 for(j=0;j<bout;j++){
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1038 #if 1
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1039 int val=mono[j]*32767.f;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1040 #else /* optional dither */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1041 int val=mono[j]*32767.f+drand48()-0.5f;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1042 #endif
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1043 /* might as well guard against clipping */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1044 if(val>32767){
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1045 val=32767;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1046 clipflag=1;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1047 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1048 if(val<-32768){
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1049 val=-32768;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1050 clipflag=1;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1051 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1052 *ptr=val;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1053 ptr+=sh_audio->ov->vi.channels;
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1054 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1055 }
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1056
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1057 if(clipflag)
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1058 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence));
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1059
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1060 //fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1061 //memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout);
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1062 len+=2*sh_audio->ov->vi.channels*bout;
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1063
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1064 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples);
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1065
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1066 vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1067 many samples we
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1068 actually consumed */
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1069 }
1834
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1070 } // from else, packetout ok
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1071 } // while len
3f8da9408f04 Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents: 1831
diff changeset
1072 } // outer while len
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1073 if(ogg_page_eos(&sh_audio->ov->og))
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1074 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1075
1837
9fd8b5e0b864 ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents: 1834
diff changeset
1076 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[len: %d ]\n",len);
1828
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1077
60afe3421c04 OggVorbis support, ALPHA state!
atmos4
parents: 1567
diff changeset
1078 break;
1831
57afd6a8ae78 Ehh colaCounter++
atmos4
parents: 1830
diff changeset
1079 }
1830
46347c4075da OOOPS, miaaing ifdef.
atmos4
parents: 1828
diff changeset
1080 #endif
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1081 case AFM_PCM: // AVI PCM
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1038
diff changeset
1082 len=demux_read_data(sh_audio->ds,buf,minlen);
401
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
1083 break;
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1084 case AFM_DVDPCM: // DVD PCM
401
835fac6382be DVD PCM audio support
arpi_esp
parents: 340
diff changeset
1085 { int j;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1086 len=demux_read_data(sh_audio->ds,buf,minlen);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1087 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; }
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1088 // swap endian:
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1089 for(j=0;j<len;j+=2){
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1090 char x=buf[j];
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1091 buf[j]=buf[j+1];
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1092 buf[j+1]=x;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1093 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1094 break;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1095 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1096 case AFM_ALAW: // aLaw decoder
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1097 { int l=demux_read_data(sh_audio->ds,buf,minlen/2);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1098 unsigned short *d=(unsigned short *) buf;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1099 unsigned char *s=buf;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1100 len=2*l;
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1101 if(sh_audio->format==6){
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1102 // aLaw
883
ef5d1ab14218 using alaw.h instead of alaw.c
arpi_esp
parents: 758
diff changeset
1103 while(l>0){ --l; d[l]=alaw2short[s[l]]; }
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1104 } else {
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1105 // uLaw
883
ef5d1ab14218 using alaw.h instead of alaw.c
arpi_esp
parents: 758
diff changeset
1106 while(l>0){ --l; d[l]=ulaw2short[s[l]]; }
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1107 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1108 break;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1109 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1110 case AFM_GSM: // MS-GSM decoder
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
1111 { unsigned char ibuf[65]; // 65 bytes / frame
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
1112 if(demux_read_data(sh_audio->ds,ibuf,65)!=65) break; // EOF
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
1113 XA_MSGSM_Decoder(ibuf,(unsigned short *) buf); // decodes 65 byte -> 320 short
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1114 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1115 len=2*320;
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1116 break;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1117 }
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
1118 #ifdef USE_G72X
3426
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1119 case AFM_G72X: // GSM 723 decoder
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1120 { if(demux_read_data(sh_audio->ds,g72x_data.block, g72x_data.blocksize)!=g72x_data.blocksize) break; // EOF
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1121 g72x_decode_block(&g72x_data);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1122 len=2*g72x_data.samplesperblock;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1123 memcpy(buf,g72x_data.samples,len);
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1124 break;
ca4beb5dd3f7 g72x support
arpi
parents: 3417
diff changeset
1125 }
3866
50d7eec1d4b9 g72x is optional (caused problems wiht opendivx)
arpi
parents: 3834
diff changeset
1126 #endif
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1127 case AFM_IMAADPCM:
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
1128 { unsigned char ibuf[IMA_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
1129 if (demux_read_data(sh_audio->ds, ibuf,
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1130 IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) !=
3756
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
1131 IMA_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels)
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
1132 break; // EOF
734d0c0a8ab0 Initial support for unified ADPCM decoder
melanson
parents: 3442
diff changeset
1133 len=2*ima_adpcm_decode_block((unsigned short*)buf,ibuf, sh_audio->wf->nChannels);
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1134 break;
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1135 }
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1136 case AFM_MSADPCM:
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1137 { static unsigned char *ibuf = NULL;
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1138 if (!ibuf)
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1139 ibuf = (unsigned char *)malloc
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1140 (sh_audio->wf->nBlockAlign * sh_audio->wf->nChannels);
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1141 if (demux_read_data(sh_audio->ds, ibuf,
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1142 sh_audio->wf->nBlockAlign) !=
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1143 sh_audio->wf->nBlockAlign)
3787
55603340d1b2 implemented open source MS ADPCM decoder
melanson
parents: 3756
diff changeset
1144 break; // EOF
3875
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1145 len= 2 * ms_adpcm_decode_block(
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1146 (unsigned short*)buf,ibuf, sh_audio->wf->nChannels,
e3caff2daa98 fixed stereo MS ADPCM decoder and reinstated opensource decoder as the
melanson
parents: 3874
diff changeset
1147 sh_audio->wf->nBlockAlign);
2420
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
1148 break;
311676805f20 ima4 mov audio support
arpi
parents: 2418
diff changeset
1149 }
3933
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1150 case AFM_FOX61ADPCM:
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1151 { unsigned char ibuf[FOX61_ADPCM_BLOCK_SIZE]; // bytes / stereo frame
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1152 if (demux_read_data(sh_audio->ds, ibuf, FOX61_ADPCM_BLOCK_SIZE) !=
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1153 FOX61_ADPCM_BLOCK_SIZE)
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1154 break; // EOF
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1155 len=2*fox61_adpcm_decode_block((unsigned short*)buf,ibuf);
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1156 break;
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1157 }
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1158 case AFM_FOX62ADPCM:
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1159 { unsigned char ibuf[FOX62_ADPCM_BLOCK_SIZE * 2]; // bytes / stereo frame
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1160 if (demux_read_data(sh_audio->ds, ibuf,
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1161 FOX62_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels) !=
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1162 FOX62_ADPCM_BLOCK_SIZE * sh_audio->wf->nChannels)
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1163 break; // EOF
3933
60db4273246d added initial support for format 0x61 ADPCM (sounds good, but still pops)
melanson
parents: 3911
diff changeset
1164 len = 2 * fox62_adpcm_decode_block(
4001
ae6f97724b84 fixed format 0x62 ADPCM audio
melanson
parents: 3968
diff changeset
1165 (unsigned short*)buf,ibuf);
3826
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1166 break;
8a88ed2473aa added initial, not-yet-functional, support for fox62 audio
melanson
parents: 3787
diff changeset
1167 }
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1168 #ifdef USE_LIBAC3
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1169 case AFM_AC3: // AC3 decoder
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1170 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1171 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame();
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1172 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout);
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1173 if(sh_audio->ac3_frame){
296
c3d7a28a0d1a audio init moved to dec_audio.c
arpi_esp
parents: 291
diff changeset
1174 len = 256 * 6 *sh_audio->channels*sh_audio->samplesize;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 432
diff changeset
1175 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1176 sh_audio->ac3_frame=NULL;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1177 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1178 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1179 break;
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1180 #endif
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1181 case AFM_A52: { // AC3 decoder
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
1182 sample_t level=1, bias=384;
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
1183 int flags=a52_flags|A52_ADJUST_LEVEL;
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1184 int i;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1185 if(!sh_audio->a_in_buffer_len)
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1186 if(a52_fillbuff(sh_audio)<0) break; // EOF
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1187 sh_audio->a_in_buffer_len=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1188 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1189 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n");
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1190 break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1191 }
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1192 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1193
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1194 // frame decoded, let's resample:
3911
0c1e7b47d35c a52 resampler init moved to init
arpi
parents: 3907
diff changeset
1195 //a52_resample_init(a52_accel,flags,sh_audio->channels);
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1196 len=0;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1197 for (i = 0; i < 6; i++) {
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1198 if (a52_block (&a52_state, a52_samples)){
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1199 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n");
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1200 break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1201 }
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1202 len+=2*a52_resample(a52_samples,&buf[len]);
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1203 }
3417
2066402f300d Remove annoying debug printf.
atmos4
parents: 3413
diff changeset
1204 // printf("len = %d \n",len); // 6144 on all vobs I tried so far... (5.1 and 2.0) ::atmos
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1205 break;
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1206 }
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
1207 case AFM_HWAC3: // AC3 through SPDIF
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1208 if(!sh_audio->a_in_buffer_len)
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1209 if((len=a52_fillbuff(sh_audio))<0) break; //EOF
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1210 sh_audio->a_in_buffer_len=0;
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1211 len = ac3_iec958_build_burst(len, 0x01, 1, sh_audio->a_in_buffer, buf);
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1212 // len = 6144 = 4*(6*256)
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
1213 break;
1517
0e9c29538a86 Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents: 1485
diff changeset
1214 #ifdef USE_WIN32DLL
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1215 case AFM_ACM:
758
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1216 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1217 // if(len<minlen) len=minlen; else
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1218 // if(len>maxlen) len=maxlen;
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1219 // len=acm_decode_audio(sh_audio,buf,len);
5a92a5601666 better audio out buffering & sample_format added
arpi_esp
parents: 754
diff changeset
1220 len=acm_decode_audio(sh_audio,buf,minlen,maxlen);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1221 break;
1309
598e3047ce13 Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents: 1291
diff changeset
1222 #endif
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 732
diff changeset
1223
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1224 #ifdef USE_DIRECTSHOW
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1225 case AFM_DSHOW: // DirectShow
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1226 { int size_in=0;
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1227 int size_out=0;
3442
62b452b7ddf9 changed for updated DShow wrapper api
arpi
parents: 3426
diff changeset
1228 int srcsize=DS_AudioDecoder_GetSrcSize(ds_adec, maxlen);
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1529
diff changeset
1229 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen);
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1230 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!!
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1231 if(sh_audio->a_in_buffer_len<srcsize){
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1232 sh_audio->a_in_buffer_len+=
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1233 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len],
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1234 srcsize-sh_audio->a_in_buffer_len);
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1235 }
3442
62b452b7ddf9 changed for updated DShow wrapper api
arpi
parents: 3426
diff changeset
1236 DS_AudioDecoder_Convert(ds_adec, sh_audio->a_in_buffer,sh_audio->a_in_buffer_len,
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1237 buf,maxlen, &size_in,&size_out);
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1529
diff changeset
1238 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"DShow: audio %d -> %d converted (in_buf_len=%d of %d) %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds));
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1239 if(size_in>=sh_audio->a_in_buffer_len){
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1240 sh_audio->a_in_buffer_len=0;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1241 } else {
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1242 sh_audio->a_in_buffer_len-=size_in;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1243 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len);
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1244 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1245 len=size_out;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1246 break;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1247 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1248 #endif
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1249
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1250 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1251 case AFM_MAD:
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1252 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1253 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1254 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1255 // mad_stream_sync(&mad_stream);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1256 mad_sync(sh_audio, &mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1257 if(mad_frame_decode(&mad_frame, &mad_stream) == 0)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1258 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1259 mad_synth_frame(&mad_synth, &mad_frame);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1260 mad_postprocess_buffer(sh_audio, &mad_stream);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1261
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1262 /* and fill buffer */
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1263
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1264 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1265 int i;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1266 int end_size = mad_synth.pcm.length;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1267 signed short* samples = (signed short*)buf;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1268 if(end_size > maxlen/4)
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1269 end_size=maxlen/4;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1270
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1271 for(i=0; i<mad_synth.pcm.length; ++i) {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1272 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1273 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1274 // *buf++ = mad_scale(mad_synth.pcm.sampAles[1][i]);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1275 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1276 len = end_size*4;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1277 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1278 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1279 else
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1280 {
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1281 printf(__FILE__ ":%d:mad: frame decoding failed (error: %d)\n", __LINE__,
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1282 mad_stream.error);
3874
8b76388de734 more mad fix
alex
parents: 3871
diff changeset
1283 mad_print_error(&mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1284 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1285
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1286 break;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1287 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1288 #endif
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1289 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1290 return len;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1291 }
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1292
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1293 void resync_audio_stream(sh_audio_t *sh_audio){
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1294 switch(sh_audio->codec->driver){
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1295 case AFM_MPEG:
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1296 MP3_DecodeFrame(NULL,-2); // resync
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1297 MP3_DecodeFrame(NULL,-2); // resync
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1298 MP3_DecodeFrame(NULL,-2); // resync
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1299 break;
1849
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1300 #ifdef HAVE_OGGVORBIS
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1301 case AFM_VORBIS:
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1302 //printf("OggVorbis: resetting stream.\n");
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1303 ogg_sync_reset(&sh_audio->ov->oy);
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1304 ogg_stream_reset(&sh_audio->ov->os);
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1305 break;
5f246fcc2971 Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents: 1837
diff changeset
1306 #endif
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1307 #ifdef USE_LIBAC3
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1308 case AFM_AC3:
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1309 ac3_bitstream_reset(); // reset AC3 bitstream buffer
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1310 // if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);}
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1311 sh_audio->ac3_frame=ac3_decode_frame(); // resync
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1312 // if(verbose) printf(" OK!\n");
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1313 break;
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1314 #endif
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1315 case AFM_A52:
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1316 case AFM_ACM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1317 case AFM_DSHOW:
1528
a444bd456fcc ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents: 1517
diff changeset
1318 case AFM_HWAC3:
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1319 sh_audio->a_in_buffer_len=0; // reset ACM/DShow audio buffer
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1320 break;
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1321
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1322 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1323 case AFM_MAD:
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1324 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1325 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1326 // mad_stream_sync(&mad_stream);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1327 mad_sync(sh_audio, &mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1328 mad_postprocess_buffer(sh_audio, &mad_stream);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1329 break;
2418
eab58e827cf7 did not compile (bad place for } )
pl
parents: 2415
diff changeset
1330 #endif
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1331 }
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1332 }
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents:
diff changeset
1333
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1334 void skip_audio_frame(sh_audio_t *sh_audio){
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1335 switch(sh_audio->codec->driver){
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1336 case AFM_MPEG: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1337 #ifdef USE_LIBAC3
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1338 case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame
3886
779b58bf6d42 libac3 disabled
arpi
parents: 3875
diff changeset
1339 #endif
3829
30b4f0c45b6e hwac3 fixes by Steven Brookes <stevenjb@mda.co.uk>
arpi
parents: 3826
diff changeset
1340 case AFM_HWAC3:
3413
6236baa23bde -ac a52 implemented
arpi
parents: 3182
diff changeset
1341 case AFM_A52: a52_fillbuff(sh_audio);break; // skip AC3 frame
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1342 case AFM_ACM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1343 case AFM_DSHOW: {
1408
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1344 int skip=sh_audio->wf->nBlockAlign;
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1345 if(skip<16){
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1346 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7);
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1347 if(skip<16) skip=16;
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1348 }
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1349 demux_read_data(sh_audio->ds,NULL,skip);
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1350 break;
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1351 }
1410
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1352 case AFM_PCM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1353 case AFM_DVDPCM:
eda16e490ae7 using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents: 1408
diff changeset
1354 case AFM_ALAW: {
1408
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1355 int skip=sh_audio->i_bps/16;
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1356 skip=skip&(~3);
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1357 demux_read_data(sh_audio->ds,NULL,skip);
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1358 break;
71ad3e1ba014 some cleanup, asf/mpg seek precision improved
arpi
parents: 1327
diff changeset
1359 }
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1360 #ifdef USE_LIBMAD
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1361 case AFM_MAD:
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1362 {
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1363 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1364 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1365 mad_stream_skip(&mad_stream, 2);
3871
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1366 // mad_stream_sync(&mad_stream);
8d08da7d9d5e mad sync fix
alex
parents: 3866
diff changeset
1367 mad_sync(sh_audio, &mad_stream);
2415
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1368 mad_postprocess_buffer(sh_audio, &mad_stream);
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1369 break;
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1370 }
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1371 #endif
58ea110b4036 libmad (ARM) patch by jeroen.dobbelaere@acunia.com
arpi
parents: 2341
diff changeset
1372
1327
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1373 default: ds_fill_buffer(sh_audio->ds); // skip PCM frame
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1374 }
b12e1817bcc2 some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents: 1320
diff changeset
1375 }