2
2
* audio_device.cpp - base-class for audio-devices used by LMMS-mixer
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>
6
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
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
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() ) )
42
45
#ifdef HAVE_SAMPLERATE_H
63
66
#ifdef HAVE_SAMPLERATE_H
64
67
src_delete( m_srcState );
69
bufferAllocator::free( m_buffer );
72
void audioDevice::writeBuffer( surroundSampleFrame * _ab, Uint32 _frames,
73
Uint32 _src_sample_rate, float _master_output )
76
void audioDevice::processNextBuffer( void )
78
const Uint32 frames = getNextBuffer( m_buffer );
79
writeBuffer( m_buffer, frames, mixer::inst()->masterGain() );
85
Uint32 audioDevice::getNextBuffer( surroundSampleFrame * _ab )
87
Uint32 frames = mixer::inst()->framesPerAudioBuffer();
88
const surroundSampleFrame * b = mixer::inst()->renderNextBuffer();
75
90
// make sure, no other thread is accessing device
77
// now were save to access the device
78
if( _src_sample_rate != m_sampleRate )
93
// now were safe to access the device
94
if( mixer::inst()->sampleRate() != m_sampleRate )
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(),
98
frames = frames * m_sampleRate / mixer::inst()->sampleRate();
90
writeBufferToDev( _ab, _frames, _master_output );
102
memcpy( _ab, b, frames * sizeof( surroundSampleFrame ) );
114
void audioDevice::registerPort( audioPort * )
121
void audioDevice::unregisterPort( audioPort * _port )
128
void audioDevice::renamePort( audioPort * )
97
135
#ifndef HAVE_SAMPLERATE_H
129
void FASTCALL audioDevice::resample( surroundSampleFrame * _src, Uint32 _frames,
167
void FASTCALL audioDevice::resample( const surroundSampleFrame * _src,
130
169
surroundSampleFrame * _dst,
131
170
Uint32 _src_sr, Uint32 _dst_sr )
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;
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 )