~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to src/audio/audio_device.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * audio_device.cpp - base-class for audio-devices used by LMMS-mixer
3
3
 *
4
 
 * Linux MultiMedia Studio
5
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
 
4
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 * 
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
6
7
 *
7
8
 * This program is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU General Public
37
38
 
38
39
audioDevice::audioDevice( Uint32 _sample_rate, Uint8 _channels ) :
39
40
        m_sampleRate( _sample_rate ),
40
 
        m_channels( _channels )
 
41
        m_channels( _channels ),
 
42
        m_buffer( bufferAllocator::alloc<surroundSampleFrame>(
 
43
                                mixer::inst()->framesPerAudioBuffer() ) )
41
44
{
42
45
#ifdef HAVE_SAMPLERATE_H
43
46
        int error;
63
66
#ifdef HAVE_SAMPLERATE_H
64
67
        src_delete( m_srcState );
65
68
#endif
 
69
        bufferAllocator::free( m_buffer );
66
70
        unlock();
67
71
}
68
72
 
69
73
 
70
74
 
71
75
 
72
 
void audioDevice::writeBuffer( surroundSampleFrame * _ab, Uint32 _frames,
73
 
                                Uint32 _src_sample_rate, float _master_output )
74
 
{
 
76
void audioDevice::processNextBuffer( void )
 
77
{
 
78
        const Uint32 frames = getNextBuffer( m_buffer );
 
79
        writeBuffer( m_buffer, frames, mixer::inst()->masterGain() );
 
80
}
 
81
 
 
82
 
 
83
 
 
84
 
 
85
Uint32 audioDevice::getNextBuffer( surroundSampleFrame * _ab )
 
86
{
 
87
        Uint32 frames = mixer::inst()->framesPerAudioBuffer();
 
88
        const surroundSampleFrame * b = mixer::inst()->renderNextBuffer();
 
89
 
75
90
        // make sure, no other thread is accessing device
76
91
        lock();
77
 
        // now were save to access the device
78
 
        if( _src_sample_rate != m_sampleRate )
 
92
 
 
93
        // now were safe to access the device
 
94
        if( mixer::inst()->sampleRate() != m_sampleRate )
79
95
        {
80
 
                surroundSampleFrame * temp = 
81
 
                                bufferAllocator::alloc<surroundSampleFrame>(
82
 
                                                        _frames * channels() );
83
 
                resample( _ab, _frames, temp, _src_sample_rate, m_sampleRate );
84
 
                writeBufferToDev( temp, _frames * m_sampleRate /
85
 
                                        _src_sample_rate, _master_output );
86
 
                bufferAllocator::free( temp );
 
96
                resample( b, frames, _ab, mixer::inst()->sampleRate(),
 
97
                                                                m_sampleRate );
 
98
                frames = frames * m_sampleRate / mixer::inst()->sampleRate();
87
99
        }
88
100
        else
89
101
        {
90
 
                writeBufferToDev( _ab, _frames, _master_output );
 
102
                memcpy( _ab, b, frames * sizeof( surroundSampleFrame ) );
91
103
        }
 
104
 
92
105
        // release lock
93
106
        unlock();
94
 
}
 
107
 
 
108
        return( frames );
 
109
}
 
110
 
 
111
 
 
112
 
 
113
 
 
114
void audioDevice::registerPort( audioPort * )
 
115
{
 
116
}
 
117
 
 
118
 
 
119
 
 
120
 
 
121
void audioDevice::unregisterPort( audioPort * _port )
 
122
{
 
123
}
 
124
 
 
125
 
 
126
 
 
127
 
 
128
void audioDevice::renamePort( audioPort * )
 
129
{
 
130
}
 
131
 
 
132
 
95
133
 
96
134
 
97
135
#ifndef HAVE_SAMPLERATE_H
126
164
#endif
127
165
 
128
166
 
129
 
void FASTCALL audioDevice::resample( surroundSampleFrame * _src, Uint32 _frames,
 
167
void FASTCALL audioDevice::resample( const surroundSampleFrame * _src,
 
168
                                                Uint32 _frames,
130
169
                                                surroundSampleFrame * _dst,
131
170
                                                Uint32 _src_sr, Uint32 _dst_sr )
132
171
{
137
176
        }
138
177
        m_srcData.input_frames = _frames;
139
178
        m_srcData.output_frames = _frames;
140
 
        m_srcData.data_in = _src[0];
 
179
        m_srcData.data_in = (float *) _src[0];
141
180
        m_srcData.data_out = _dst[0];
142
181
        m_srcData.src_ratio = (float) _dst_sr / _src_sr;
143
182
 
148
187
                                                        src_strerror( error ) );
149
188
        }
150
189
#else
151
 
        if( _src_sr == 2*SAMPLE_RATES[DEFAULT_QUALITY_LEVEL] )
 
190
        if( _src_sr == 2 * SAMPLE_RATES[DEFAULT_QUALITY_LEVEL] )
152
191
        {
153
192
                // we use a simple N-tap FIR-Filter with
154
193
                // precalculated/-designed LP-Coeffs
240
279
 
241
280
 
242
281
int FASTCALL audioDevice::convertToS16( surroundSampleFrame * _ab,
243
 
                                        Uint32 _frames, float _master_output,
 
282
                                        Uint32 _frames, float _master_gain,
244
283
                                        outputSampleType * _output_buffer,
245
284
                                        bool _convert_endian )
246
285
{
251
290
                        ( _output_buffer + frame * channels() )[chnl] =
252
291
                                static_cast<outputSampleType>(
253
292
                                        mixer::clip( _ab[frame][chnl] *
254
 
                                                        _master_output ) *
 
293
                                                        _master_gain ) *
255
294
                                                OUTPUT_SAMPLE_MULTIPLIER );
256
295
                }
257
296
        }