+ aout_VolumeSoftInit( p_aout );
+ }
+
+ /* Channels number */
+ i_channels = var_CreateGetInteger( p_this, "audiofile-channels" );
+
+ if( i_channels > 0 && i_channels <= CHANNELS_MAX )
+ {
+ p_aout->output.output.i_physical_channels =
+ pi_channels_maps[i_channels];
+ }
+
+ /* WAV header */
+ p_aout->output.p_sys->b_add_wav_header = var_CreateGetBool( p_this,
+ "audiofile-wav" );
+
+ if( p_aout->output.p_sys->b_add_wav_header )
+ {
+ /* Write wave header */
+ WAVEHEADER *wh = &p_aout->output.p_sys->waveh;
+
+ memset( wh, 0, sizeof(*wh) );
+
+ switch( p_aout->output.output.i_format )
+ {
+ case VLC_CODEC_FL32:
+ wh->Format = WAVE_FORMAT_IEEE_FLOAT;
+ wh->BitsPerSample = sizeof(float) * 8;
+ break;
+ case VLC_CODEC_U8:
+ wh->Format = WAVE_FORMAT_PCM;
+ wh->BitsPerSample = 8;
+ break;
+ case VLC_CODEC_S16L:
+ default:
+ wh->Format = WAVE_FORMAT_PCM;
+ wh->BitsPerSample = 16;
+ break;
+ }
+
+ wh->MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
+ wh->Length = 0; /* temp, to be filled in as we go */
+ wh->ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
+ wh->SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
+ wh->SubChunkLength = 16;
+
+ wh->Modus = aout_FormatNbChannels( &p_aout->output.output );
+ wh->SampleFreq = p_aout->output.output.i_rate;
+ wh->BytesPerSample = wh->Modus * ( wh->BitsPerSample / 8 );
+ wh->BytesPerSec = wh->BytesPerSample * wh->SampleFreq;
+
+ wh->DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
+ wh->DataLength = 0; /* temp, to be filled in as we go */
+
+ /* Header -> little endian format */
+ SetWLE( &wh->Format, wh->Format );
+ SetWLE( &wh->BitsPerSample, wh->BitsPerSample );
+ SetDWLE( &wh->SubChunkLength, wh->SubChunkLength );
+ SetWLE( &wh->Modus, wh->Modus );
+ SetDWLE( &wh->SampleFreq, wh->SampleFreq );
+ SetWLE( &wh->BytesPerSample, wh->BytesPerSample );
+ SetDWLE( &wh->BytesPerSec, wh->BytesPerSec );
+
+ if( fwrite( wh, sizeof(WAVEHEADER), 1,
+ p_aout->output.p_sys->p_file ) != 1 )
+ {
+ msg_Err( p_aout, "write error (%m)" );
+ }