]> git.sesse.net Git - vlc/blob - include/audio_output.h
716245c82f4ea9136f6a93e8631d5f23c8ab761c
[vlc] / include / audio_output.h
1 /*****************************************************************************
2  * audio_output.h : audio output interface
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: audio_output.h,v 1.69 2002/10/20 12:23:47 massiot Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * audio_sample_format_t
26  *****************************************************************************
27  * This structure defines a format for audio samples.
28  *****************************************************************************/
29 struct audio_sample_format_t
30 {
31     int                 i_format;
32     int                 i_rate;
33     int                 i_channels;
34     /* Optional - for A52, SPDIF and DTS types */
35     int                 i_bytes_per_frame;
36     int                 i_frame_length;
37     /* Please note that it may be completely arbitrary - buffers are not
38      * obliged to contain a integral number of so-called "frames". It's
39      * just here for the division :
40      * i_nb_samples * i_bytes_per_frame / i_frame_length */
41 };
42
43 #define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
44     ((p_first)->i_format == (p_second)->i_format)                           \
45       && ((p_first)->i_rate == (p_second)->i_rate)                          \
46       && ((p_first)->i_channels == (p_second)->i_channels                   \
47            || (p_first)->i_channels == -1 || (p_second)->i_channels == -1) )
48
49 /* Check if i_rate == i_rate and i_channels == i_channels */
50 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
51     ((p_first)->i_rate == (p_second)->i_rate)                               \
52       && ((p_first)->i_channels == (p_second)->i_channels                   \
53            || (p_first)->i_channels == -1 || (p_second)->i_channels == -1) )
54
55 #ifdef WORDS_BIGENDIAN
56 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','b')
57 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','b')
58 #else
59 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','l')
60 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','l')
61 #endif
62
63 #define AOUT_FMT_NON_LINEAR( p_format )                                    \
64     ( ((p_format)->i_format == VLC_FOURCC('s','p','d','i'))                \
65        || ((p_format)->i_format == VLC_FOURCC('a','5','2',' '))            \
66        || ((p_format)->i_format == VLC_FOURCC('d','t','s',' ')) )
67
68 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
69 /*
70  * Fixed-point format: 0xABBBBBBB
71  * A == whole part      (sign + 3 bits)
72  * B == fractional part (28 bits) 
73  *
74  * Values are signed two's complement, so the effective range is:
75  * 0x80000000 to 0x7fffffff
76  *       -8.0 to +7.9999999962747097015380859375
77  *
78  * The smallest representable value is:
79  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
80  *
81  * 28 bits of fractional accuracy represent about
82  * 8.6 digits of decimal accuracy.
83  * 
84  * Fixed-point numbers can be added or subtracted as normal
85  * integers, but multiplication requires shifting the 64-bit result
86  * from 56 fractional bits back to 28 (and rounding.)
87  */
88 typedef s32 vlc_fixed_t;
89 #define FIXED32_FRACBITS 28
90 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
91 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
92 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
93
94
95 /* Dual mono. Two independant mono channels */
96 #define AOUT_CHAN_CHANNEL   0x0000000B
97 #define AOUT_CHAN_MONO      0x00000001
98 #define AOUT_CHAN_STEREO    0x00000002
99 /* 3 front channels (left, center, right) */
100 #define AOUT_CHAN_3F        0x00000003
101 /* 2 front, 1 rear surround channels (L, R, S) */
102 #define AOUT_CHAN_2F1R      0x00000004
103 /* 3 front, 1 rear surround channels (L, C, R, S) */
104 #define AOUT_CHAN_3F1R      0x00000005
105 /* 2 front, 2 rear surround channels (L, R, LS, RS) */
106 #define AOUT_CHAN_2F2R      0x00000006
107 /* 3 front, 2 rear surround channels (L, C, R, LS, RS) */
108 #define AOUT_CHAN_3F2R      0x00000007
109 /* First of two mono channels */
110 #define AOUT_CHAN_CHANNEL1  0x00000008
111 /* Second of two mono channels */
112 #define AOUT_CHAN_CHANNEL2  0x00000009
113 /* Dolby surround compatible stereo */
114 #define AOUT_CHAN_DOLBY     0x0000000A
115
116 #define AOUT_CHAN_MASK      0x0000000F
117
118 /* Low frequency effects channel. Normally used to connect a subwoofer.
119  * Can be combined with any of the above channels. For example :
120  * AOUT_CHAN_3F2R | AOUT_CHAN_LFE -> 3 front, 2 rear, 1 LFE (5.1) */
121 #define AOUT_CHAN_LFE       0x00000010
122
123
124 /*****************************************************************************
125  * aout_buffer_t : audio output buffer
126  *****************************************************************************/
127 struct aout_buffer_t
128 {
129     byte_t *                p_buffer;
130     int                     i_alloc_type;
131     /* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
132      * is the number of significative bytes in it. */
133     size_t                  i_size, i_nb_bytes;
134     int                     i_nb_samples;
135     mtime_t                 start_date, end_date;
136
137     struct aout_buffer_t *  p_next;
138 };
139
140 /* Size of a frame for S/PDIF output. */
141 #define AOUT_SPDIF_SIZE 6144
142
143 /*****************************************************************************
144  * audio_date_t : date incrementation without long-term rounding errors
145  *****************************************************************************/
146 struct audio_date_t
147 {
148     mtime_t date;
149     u32     i_divider;
150     u32     i_remainder;
151 };
152
153 /*****************************************************************************
154  * Prototypes
155  *****************************************************************************/
156 /* From common.c : */
157 #define aout_New(a) __aout_New(VLC_OBJECT(a))
158 VLC_EXPORT( aout_instance_t *, __aout_New, ( vlc_object_t * ) );
159 VLC_EXPORT( void, aout_Delete, ( aout_instance_t * ) );
160 VLC_EXPORT( void, aout_DateInit, ( audio_date_t *, u32 ) );
161 VLC_EXPORT( void, aout_DateSet, ( audio_date_t *, mtime_t ) );
162 VLC_EXPORT( void, aout_DateMove, ( audio_date_t *, mtime_t ) );
163 VLC_EXPORT( mtime_t, aout_DateGet, ( const audio_date_t * ) );
164 VLC_EXPORT( mtime_t, aout_DateIncrement, ( audio_date_t *, u32 ) );
165
166 /* From dec.c : */
167 #define aout_DecNew(a, b, c) __aout_DecNew(VLC_OBJECT(a), b, c)
168 VLC_EXPORT( aout_input_t *, __aout_DecNew, ( vlc_object_t *, aout_instance_t **, audio_sample_format_t * ) );
169 VLC_EXPORT( int, aout_DecDelete, ( aout_instance_t *, aout_input_t * ) );
170 VLC_EXPORT( aout_buffer_t *, aout_DecNewBuffer, ( aout_instance_t *, aout_input_t *, size_t ) );
171 VLC_EXPORT( void, aout_DecDeleteBuffer, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
172 VLC_EXPORT( int, aout_DecPlay, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
173
174 /* From intf.c : */
175 VLC_EXPORT( int, aout_VolumeGet, ( aout_instance_t *, audio_volume_t * ) );
176 VLC_EXPORT( int, aout_VolumeSet, ( aout_instance_t *, audio_volume_t ) );
177 VLC_EXPORT( int, aout_VolumeInfos, ( aout_instance_t *, audio_volume_t * ) );
178 VLC_EXPORT( int, aout_VolumeUp, ( aout_instance_t *, int, audio_volume_t * ) );
179 VLC_EXPORT( int, aout_VolumeDown, ( aout_instance_t *, int, audio_volume_t * ) );
180 VLC_EXPORT( int, aout_Restart, ( aout_instance_t * p_aout ) );
181 VLC_EXPORT( void, aout_FindAndRestart, ( vlc_object_t * p_this ) );
182