~ubuntu-branches/ubuntu/precise/lmms/precise-proposed

« back to all changes in this revision

Viewing changes to src/core/audio/AudioFileWave.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-12 13:32:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101112133232-vdld83iyji8srqti
Tags: 0.4.7-2ubuntu1
* Re-sync with Debian (LP: #606533):
  - Replace build-dep on libwine-dev with libwine-dev-unstable to build
    against the newer Wine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * AudioFileWave.cpp - audio-device which encodes wave-stream and writes it
 
3
 *                     into a WAVE-file. This is used for song-export.
 
4
 *
 
5
 * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
6
 *
 
7
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
24
 */
 
25
 
 
26
#include "AudioFileWave.h"
 
27
#include "endian_handling.h"
 
28
 
 
29
 
 
30
AudioFileWave::AudioFileWave( const sample_rate_t _sample_rate,
 
31
                                const ch_cnt_t _channels, bool & _success_ful,
 
32
                                const QString & _file,
 
33
                                const bool _use_vbr,
 
34
                                const bitrate_t _nom_bitrate,
 
35
                                const bitrate_t _min_bitrate,
 
36
                                const bitrate_t _max_bitrate,
 
37
                                const int _depth,
 
38
                                mixer * _mixer ) :
 
39
        AudioFileDevice( _sample_rate, _channels, _file, _use_vbr,
 
40
                        _nom_bitrate, _min_bitrate, _max_bitrate,
 
41
                                                                _depth, _mixer )
 
42
{
 
43
        _success_ful = startEncoding();
 
44
}
 
45
 
 
46
 
 
47
 
 
48
 
 
49
AudioFileWave::~AudioFileWave()
 
50
{
 
51
        finishEncoding();
 
52
}
 
53
 
 
54
 
 
55
 
 
56
 
 
57
bool AudioFileWave::startEncoding()
 
58
{
 
59
        m_si.samplerate = sampleRate();
 
60
        m_si.channels = channels();
 
61
        m_si.frames = getMixer()->framesPerPeriod();
 
62
        m_si.sections = 1;
 
63
        m_si.seekable = 0;
 
64
 
 
65
        switch( depth() )
 
66
        {
 
67
                case 32: m_si.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; break;
 
68
                case 16:
 
69
                default: m_si.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; break;
 
70
        }
 
71
        m_sf = sf_open( outputFile().toUtf8().constData(), SFM_WRITE, &m_si );
 
72
        return true;
 
73
}
 
74
 
 
75
 
 
76
 
 
77
 
 
78
void AudioFileWave::writeBuffer( const surroundSampleFrame * _ab,
 
79
                                                const fpp_t _frames,
 
80
                                                const float _master_gain )
 
81
{
 
82
        if( depth() == 32 )
 
83
        {
 
84
                float *  buf = new float[_frames*channels()];
 
85
                for( fpp_t frame = 0; frame < _frames; ++frame )
 
86
                {
 
87
                        for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
 
88
                        {
 
89
                                buf[frame*channels()+chnl] = _ab[frame][chnl] *
 
90
                                                                _master_gain;
 
91
                        }
 
92
                }
 
93
                sf_writef_float( m_sf, buf, _frames );
 
94
                delete[] buf;
 
95
        }
 
96
        else
 
97
        {
 
98
                int_sample_t * buf = new int_sample_t[_frames * channels()];
 
99
                convertToS16( _ab, _frames, _master_gain, buf,
 
100
                                                        !isLittleEndian() );
 
101
 
 
102
                sf_writef_short( m_sf, buf, _frames );
 
103
                delete[] buf;
 
104
        }
 
105
}
 
106
 
 
107
 
 
108
 
 
109
 
 
110
void AudioFileWave::finishEncoding()
 
111
{
 
112
        sf_close( m_sf );
 
113
}
 
114