1 /*****************************************************************************
2 * file.c : audio output which writes the samples to a file
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: file.c,v 1.11 2002/09/18 21:21:23 massiot Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include "aout_internal.h"
36 #define FRAME_SIZE 2048
37 #define A52_FRAME_NB 1536
39 /*****************************************************************************
41 *****************************************************************************/
42 static int Open ( vlc_object_t * );
43 static void Close ( vlc_object_t * );
44 static void Play ( aout_instance_t * );
46 /*****************************************************************************
48 *****************************************************************************/
49 #define FORMAT_TEXT N_("output format")
50 #define FORMAT_LONGTEXT N_("one of \"u8\", \"s8\", \"u16\", \"s16\"," \
51 " \"u16_le\", \"s16_le\", \"u16_be\"," \
52 " \"s16_be\", \"fixed32\", \"float32\" or \"spdif\"")
54 static char *format_list[] = { "u8", "s8", "u16", "s16", "u16_le", "s16_le",
55 "u16_be", "s16_be", "fixed32", "float32",
57 static int format_int[] = { AOUT_FMT_U8, AOUT_FMT_S8, AOUT_FMT_U16_NE,
58 AOUT_FMT_S16_NE, AOUT_FMT_U16_LE, AOUT_FMT_S16_LE,
59 AOUT_FMT_U16_BE, AOUT_FMT_S16_BE, AOUT_FMT_FIXED32,
60 AOUT_FMT_FLOAT32, AOUT_FMT_SPDIF };
62 #define PATH_TEXT N_("path of the output file")
63 #define PATH_LONGTEXT N_("By default samples.raw")
66 add_category_hint( N_("Audio"), NULL );
67 add_string_from_list( "format", "s16", format_list, NULL,
68 FORMAT_TEXT, FORMAT_LONGTEXT );
69 add_string( "path", "samples.raw", NULL, PATH_TEXT, PATH_LONGTEXT );
70 set_description( _("file output module") );
71 set_capability( "audio output", 0 );
72 add_shortcut( "file" );
73 set_callbacks( Open, Close );
76 /*****************************************************************************
77 * Open: open a dummy audio device
78 *****************************************************************************/
79 static int Open( vlc_object_t * p_this )
81 aout_instance_t * p_aout = (aout_instance_t *)p_this;
83 char * psz_name = config_GetPsz( p_this, "path" );
84 char * psz_format = config_GetPsz( p_aout, "format" );
85 char ** ppsz_compare = format_list;
89 p_file = fopen( psz_name, "wb" );
90 p_aout->output.p_sys = (void *)p_file;
92 if ( p_file == NULL ) return -1;
94 p_aout->output.pf_play = Play;
95 aout_VolumeSoftInit( p_aout );
97 while ( *ppsz_compare != NULL )
99 if ( !strncmp( *ppsz_compare, psz_format, strlen(*ppsz_compare) ) )
106 if ( *ppsz_compare == NULL )
108 msg_Err( p_aout, "Cannot understand the format string (%s)",
113 p_aout->output.output.i_format = format_int[i];
114 if ( p_aout->output.output.i_format == AOUT_FMT_SPDIF )
116 p_aout->output.i_nb_samples = A52_FRAME_NB;
117 p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
118 p_aout->output.output.i_frame_length = A52_FRAME_NB;
122 p_aout->output.i_nb_samples = FRAME_SIZE;
127 /*****************************************************************************
128 * Close: close our file
129 *****************************************************************************/
130 static void Close( vlc_object_t * p_this )
132 aout_instance_t * p_aout = (aout_instance_t *)p_this;
134 fclose( (FILE *)p_aout->output.p_sys );
137 /*****************************************************************************
138 * Play: pretend to play a sound
139 *****************************************************************************/
140 static void Play( aout_instance_t * p_aout )
142 aout_buffer_t * p_buffer;
144 p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo );
146 if( fwrite( p_buffer->p_buffer, p_buffer->i_nb_bytes, 1,
147 (FILE *)p_aout->output.p_sys ) != 1 )
149 msg_Err( p_aout, "write error (%s)", strerror(errno) );
152 aout_BufferFree( p_buffer );