2
* AudioFileWave.cpp - audio-device which encodes wave-stream and writes it
3
* into a WAVE-file. This is used for song-export.
5
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (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 GNU
17
* General Public License for more details.
19
* You should have received a copy of the GNU General Public
20
* License along with this program (see COPYING); if not, write to the
21
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
* Boston, MA 02110-1301 USA.
26
#include "AudioFileWave.h"
27
#include "endian_handling.h"
30
AudioFileWave::AudioFileWave( const sample_rate_t _sample_rate,
31
const ch_cnt_t _channels, bool & _success_ful,
32
const QString & _file,
34
const bitrate_t _nom_bitrate,
35
const bitrate_t _min_bitrate,
36
const bitrate_t _max_bitrate,
39
AudioFileDevice( _sample_rate, _channels, _file, _use_vbr,
40
_nom_bitrate, _min_bitrate, _max_bitrate,
43
_success_ful = startEncoding();
49
AudioFileWave::~AudioFileWave()
57
bool AudioFileWave::startEncoding()
59
m_si.samplerate = sampleRate();
60
m_si.channels = channels();
61
m_si.frames = getMixer()->framesPerPeriod();
67
case 32: m_si.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; break;
69
default: m_si.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; break;
71
m_sf = sf_open( outputFile().toUtf8().constData(), SFM_WRITE, &m_si );
78
void AudioFileWave::writeBuffer( const surroundSampleFrame * _ab,
80
const float _master_gain )
84
float * buf = new float[_frames*channels()];
85
for( fpp_t frame = 0; frame < _frames; ++frame )
87
for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
89
buf[frame*channels()+chnl] = _ab[frame][chnl] *
93
sf_writef_float( m_sf, buf, _frames );
98
int_sample_t * buf = new int_sample_t[_frames * channels()];
99
convertToS16( _ab, _frames, _master_gain, buf,
102
sf_writef_short( m_sf, buf, _frames );
110
void AudioFileWave::finishEncoding()