]> git.sesse.net Git - vlc/blob - include/audio_output.h
Big round of fixes in the aout3.
[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.61 2002/08/21 22:41:59 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_FMT_MU_LAW     0x00000001
44 #define AOUT_FMT_A_LAW      0x00000002
45 #define AOUT_FMT_IMA_ADPCM  0x00000004
46 #define AOUT_FMT_U8         0x00000008
47 #define AOUT_FMT_S16_LE     0x00000010            /* Little endian signed 16 */
48 #define AOUT_FMT_S16_BE     0x00000020               /* Big endian signed 16 */
49 #define AOUT_FMT_S8         0x00000040
50 #define AOUT_FMT_U16_LE     0x00000080                  /* Little endian U16 */
51 #define AOUT_FMT_U16_BE     0x00000100                     /* Big endian U16 */
52 #define AOUT_FMT_SPDIF      0x00000400            /* S/PDIF hardware support */
53 #define AOUT_FMT_FLOAT32    0x00010000
54 #define AOUT_FMT_FIXED32    0x00020000
55 #define AOUT_FMT_A52        0x00100000
56 #define AOUT_FMT_DTS        0x00200000
57
58 #define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
59     ((p_first)->i_format == (p_second)->i_format)                           \
60       && ((p_first)->i_rate == (p_second)->i_rate)                          \
61       && ((p_first)->i_channels == (p_second)->i_channels                   \
62            || (p_first)->i_channels == -1 || (p_second)->i_channels == -1) )
63
64 /* Check if i_rate == i_rate and i_channels == i_channels */
65 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
66     ((p_first)->i_rate == (p_second)->i_rate)                               \
67       && ((p_first)->i_channels == (p_second)->i_channels                   \
68            || (p_first)->i_channels == -1 || (p_second)->i_channels == -1) )
69
70 #ifdef WORDS_BIGENDIAN
71 #   define AOUT_FMT_S16_NE AOUT_FMT_S16_BE
72 #   define AOUT_FMT_U16_NE AOUT_FMT_U16_BE
73 #else
74 #   define AOUT_FMT_S16_NE AOUT_FMT_S16_LE
75 #   define AOUT_FMT_U16_NE AOUT_FMT_U16_LE
76 #endif
77
78 #define AOUT_FMT_NON_LINEAR( p_format )                                    \
79     ( ((p_format)->i_format == AOUT_FMT_SPDIF)                             \
80        || ((p_format)->i_format == AOUT_FMT_A52)                           \
81        || ((p_format)->i_format == AOUT_FMT_DTS) )
82
83 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
84 /*
85  * Fixed-point format: 0xABBBBBBB
86  * A == whole part      (sign + 3 bits)
87  * B == fractional part (28 bits) 
88  *
89  * Values are signed two's complement, so the effective range is:
90  * 0x80000000 to 0x7fffffff
91  *       -8.0 to +7.9999999962747097015380859375
92  *
93  * The smallest representable value is:
94  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
95  *
96  * 28 bits of fractional accuracy represent about
97  * 8.6 digits of decimal accuracy.
98  * 
99  * Fixed-point numbers can be added or subtracted as normal
100  * integers, but multiplication requires shifting the 64-bit result
101  * from 56 fractional bits back to 28 (and rounding.)
102  */
103 typedef s32 vlc_fixed_t;
104 #define FIXED32_FRACBITS 28
105 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
106 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
107 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
108
109
110 /*****************************************************************************
111  * aout_buffer_t : audio output buffer
112  *****************************************************************************/
113 struct aout_buffer_t
114 {
115     byte_t *                p_buffer;
116     int                     i_alloc_type;
117     /* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
118      * is the number of significative bytes in it. */
119     size_t                  i_size, i_nb_bytes;
120     int                     i_nb_samples;
121     mtime_t                 start_date, end_date;
122
123     struct aout_buffer_t *  p_next;
124 };
125
126 /* Size of a frame for S/PDIF output. */
127 #define AOUT_SPDIF_SIZE 6144
128
129 /*****************************************************************************
130  * audio_date_t : date incrementation without long-term rounding errors
131  *****************************************************************************/
132 struct audio_date_t
133 {
134     mtime_t date;
135     u32     i_divider;
136     u32     i_remainder;
137 };
138
139 /*****************************************************************************
140  * Prototypes
141  *****************************************************************************/
142 /* From audio_output.c : */
143 #define aout_NewInstance(a) __aout_NewInstance(VLC_OBJECT(a))
144 VLC_EXPORT( aout_instance_t *, __aout_NewInstance,    ( vlc_object_t * ) );
145 VLC_EXPORT( void,              aout_DeleteInstance, ( aout_instance_t * ) );
146 VLC_EXPORT( aout_buffer_t *, aout_BufferNew, ( aout_instance_t *, aout_input_t *, size_t ) );
147 VLC_EXPORT( void, aout_BufferDelete, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
148 VLC_EXPORT( void, aout_BufferPlay, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
149 VLC_EXPORT( void, aout_DateInit, ( audio_date_t *, u32 ) );
150 VLC_EXPORT( void, aout_DateSet, ( audio_date_t *, mtime_t ) );
151 VLC_EXPORT( void, aout_DateMove, ( audio_date_t *, mtime_t ) );
152 VLC_EXPORT( mtime_t, aout_DateGet, ( const audio_date_t * ) );
153 VLC_EXPORT( mtime_t, aout_DateIncrement, ( audio_date_t *, u32 ) );
154
155 /* From input.c : */
156 #define aout_InputNew(a,b,c) __aout_InputNew(VLC_OBJECT(a),b,c)
157 VLC_EXPORT( aout_input_t *, __aout_InputNew, ( vlc_object_t *, aout_instance_t **, audio_sample_format_t * ) );
158 VLC_EXPORT( void, aout_InputDelete, ( aout_instance_t *, aout_input_t * ) );
159