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.2 2002/08/08 22:28:22 sam 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 /*****************************************************************************
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
40 static void Close ( vlc_object_t * );
41 static int SetFormat ( aout_instance_t * );
42 static void Play ( aout_instance_t *, aout_buffer_t * );
44 /*****************************************************************************
46 *****************************************************************************/
47 #define FORMAT_TEXT N_("Output format")
48 #define FORMAT_LONGTEXT N_("one of \"u8\", \"s8\", \"u16\", \"s16\"," \
49 " \"u16_le\", \"s16_le\", \"u16_be\"," \
50 " \"s16_be\", \"fixed32\", \"float32\" or \"spdif\"")
52 static char *format_list[] = { "u8", "s8", "u16", "s16", "u16_le", "s16_le",
53 "u16_be", "s16_be", "fixed32", "float32",
55 static int format_int[] = { AOUT_FMT_U8, AOUT_FMT_S8, AOUT_FMT_U16_NE,
56 AOUT_FMT_S16_NE, AOUT_FMT_U16_LE, AOUT_FMT_S16_LE,
57 AOUT_FMT_U16_BE, AOUT_FMT_S16_BE, AOUT_FMT_FIXED32,
58 AOUT_FMT_FLOAT32, AOUT_FMT_A52 };
60 #define PATH_TEXT N_("Path of the output file")
61 #define PATH_LONGTEXT N_("By default samples.raw")
64 add_category_hint( N_("Audio"), NULL );
65 add_string_from_list( "format", "s16", format_list, NULL,
66 FORMAT_TEXT, FORMAT_LONGTEXT );
67 add_string( "path", "samples.raw", NULL, PATH_TEXT, PATH_LONGTEXT );
68 set_description( _("file output module") );
69 set_capability( "audio output", 0 );
70 add_shortcut( "file" );
71 set_callbacks( Open, Close );
74 /*****************************************************************************
75 * Open: open a dummy audio device
76 *****************************************************************************/
77 static int Open( vlc_object_t * p_this )
79 aout_instance_t * p_aout = (aout_instance_t *)p_this;
81 char * psz_name = config_GetPsz( p_this, "path" );
83 (FILE *)p_aout->output.p_sys = p_file = fopen( psz_name, "wb" );
85 if ( p_file == NULL ) return -1;
87 p_aout->output.pf_setformat = SetFormat;
88 p_aout->output.pf_play = Play;
93 /*****************************************************************************
94 * Close: close our file
95 *****************************************************************************/
96 static void Close( vlc_object_t * p_this )
98 aout_instance_t * p_aout = (aout_instance_t *)p_this;
100 fclose( (FILE *)p_aout->output.p_sys );
103 /*****************************************************************************
104 * SetFormat: pretend to set the dsp output format
105 *****************************************************************************/
106 static int SetFormat( aout_instance_t * p_aout )
108 char * psz_format = config_GetPsz( p_aout, "format" );
109 char ** ppsz_compare = format_list;
112 while ( *ppsz_compare != NULL )
114 if ( !strncmp( *ppsz_compare, psz_format, strlen(*ppsz_compare) ) )
121 if ( *ppsz_compare == NULL )
123 msg_Err( p_aout, "Cannot understand the format string (%s)",
128 p_aout->output.output.i_format = format_int[i];
129 p_aout->output.i_nb_samples = 2048;
133 /*****************************************************************************
134 * Play: pretend to play a sound
135 *****************************************************************************/
136 static void Play( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
138 if( fwrite( p_buffer->p_buffer,
139 p_buffer->i_nb_samples
140 * aout_FormatToBytes( &p_aout->output.output ), 1,
141 (FILE *)p_aout->output.p_sys ) != 1 )
143 msg_Err( p_aout, "write error (%s)", strerror(errno) );
146 aout_BufferFree( p_buffer );