audio_output.h 5.95 KB
Newer Older
1
/*****************************************************************************
2
 * audio_output.h : audio output interface
3
 *****************************************************************************
4
 * Copyright (C) 2002 VideoLAN
5
 * $Id: audio_output.h,v 1.58 2002/08/14 00:23:59 massiot Exp $
6
 *
7
 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 9 10 11 12
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
13
 * 
14 15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
18
 *
19 20 21
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * 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
Michel Kaempf's avatar
Michel Kaempf committed
30
{
Sam Hocevar's avatar
 
Sam Hocevar committed
31 32
    int                 i_format;
    int                 i_rate;
33
    int                 i_channels;
34 35
    /* Optional - for A52, SPDIF and DTS types */
    int                 i_bytes_per_sec;
36
};
Michel Kaempf's avatar
Michel Kaempf committed
37

38 39 40 41 42 43 44 45 46
#define AOUT_FMT_MU_LAW     0x00000001
#define AOUT_FMT_A_LAW      0x00000002
#define AOUT_FMT_IMA_ADPCM  0x00000004
#define AOUT_FMT_U8         0x00000008
#define AOUT_FMT_S16_LE     0x00000010            /* Little endian signed 16 */
#define AOUT_FMT_S16_BE     0x00000020               /* Big endian signed 16 */
#define AOUT_FMT_S8         0x00000040
#define AOUT_FMT_U16_LE     0x00000080                  /* Little endian U16 */
#define AOUT_FMT_U16_BE     0x00000100                     /* Big endian U16 */
47 48 49 50 51
#define AOUT_FMT_SPDIF      0x00000400            /* S/PDIF hardware support */
#define AOUT_FMT_FLOAT32    0x00010000
#define AOUT_FMT_FIXED32    0x00020000
#define AOUT_FMT_A52        0x00100000
#define AOUT_FMT_DTS        0x00200000
52 53

#define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
54 55 56 57
    ((p_first)->i_format == (p_second)->i_format)                           \
      && ((p_first)->i_rate == (p_second)->i_rate)                          \
      && ((p_first)->i_channels == (p_second)->i_channels                   \
           || (p_first)->i_channels == -1 || (p_second)->i_channels == -1) )
58

Sam Hocevar's avatar
 
Sam Hocevar committed
59
#ifdef WORDS_BIGENDIAN
60 61
#   define AOUT_FMT_S16_NE AOUT_FMT_S16_BE
#   define AOUT_FMT_U16_NE AOUT_FMT_U16_BE
Sam Hocevar's avatar
 
Sam Hocevar committed
62
#else
63 64
#   define AOUT_FMT_S16_NE AOUT_FMT_S16_LE
#   define AOUT_FMT_U16_NE AOUT_FMT_U16_LE
65 66
#endif

67
#define AOUT_FMT_NON_LINEAR( p_format )                                    \
68 69 70
    ( ((p_format)->i_format == AOUT_FMT_SPDIF)                             \
       || ((p_format)->i_format == AOUT_FMT_A52)                           \
       || ((p_format)->i_format == AOUT_FMT_DTS) )
71

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
/*
 * Fixed-point format: 0xABBBBBBB
 * A == whole part      (sign + 3 bits)
 * B == fractional part (28 bits) 
 *
 * Values are signed two's complement, so the effective range is:
 * 0x80000000 to 0x7fffffff
 *       -8.0 to +7.9999999962747097015380859375
 *
 * The smallest representable value is:
 * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
 *
 * 28 bits of fractional accuracy represent about
 * 8.6 digits of decimal accuracy.
 * 
 * Fixed-point numbers can be added or subtracted as normal
 * integers, but multiplication requires shifting the 64-bit result
 * from 56 fractional bits back to 28 (and rounding.)
 */
typedef s32 vlc_fixed_t;
#define FIXED32_FRACBITS 28
#define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
#define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
#define FIXED32_ONE ((vlc_fixed_t) 0x10000000)


99 100 101 102 103
/*****************************************************************************
 * aout_buffer_t : audio output buffer
 *****************************************************************************/
struct aout_buffer_t
{
104
    byte_t *                p_buffer;
105
    int                     i_alloc_type;
106 107 108
    /* i_size is the real size of the buffer (normally unused), i_nb_bytes
     * is the number of significative bytes in it. */
    size_t                  i_size, i_nb_bytes;
109 110
    int                     i_nb_samples;
    mtime_t                 start_date, end_date;
111

112 113
    struct aout_buffer_t *  p_next;
};
114

Christophe Massiot's avatar
Christophe Massiot committed
115 116
/* Size of a frame for S/PDIF output. */
#define AOUT_SPDIF_SIZE 6144
117

118
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
119
 * Prototypes
120
 *****************************************************************************/
121 122 123 124 125 126 127
/* From audio_output.c : */
#define aout_NewInstance(a) __aout_NewInstance(VLC_OBJECT(a))
VLC_EXPORT( aout_instance_t *, __aout_NewInstance,    ( vlc_object_t * ) );
VLC_EXPORT( void,              aout_DeleteInstance, ( aout_instance_t * ) );
VLC_EXPORT( aout_buffer_t *, aout_BufferNew, ( aout_instance_t *, aout_input_t *, size_t ) );
VLC_EXPORT( void, aout_BufferDelete, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
VLC_EXPORT( void, aout_BufferPlay, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) );
128
VLC_EXPORT( int, aout_FormatToByterate, ( audio_sample_format_t * p_format ) );
129 130 131 132 133 134 135 136

/* From input.c : */
#define aout_InputNew(a,b,c) __aout_InputNew(VLC_OBJECT(a),b,c)
VLC_EXPORT( aout_input_t *, __aout_InputNew, ( vlc_object_t *, aout_instance_t **, audio_sample_format_t * ) );
VLC_EXPORT( void, aout_InputDelete, ( aout_instance_t *, aout_input_t * ) );

/* From output.c : */
VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t ) );
Sam Hocevar's avatar
 
Sam Hocevar committed
137