better VST support and bugfixes

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@77 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Tobias Doerffel
2006-02-06 12:52:58 +00:00
parent af3d57b67f
commit de00678815
43 changed files with 966 additions and 668 deletions

View File

@@ -54,9 +54,9 @@
audioALSA::audioALSA( Uint32 _sample_rate, bool & _success_ful ) :
audioDevice( _sample_rate, tLimit<int>( configManager::inst()->value(
"audioalsa", "channels" ).toInt(),
audioALSA::audioALSA( const sample_rate_t _sample_rate, bool & _success_ful ) :
audioDevice( _sample_rate, tLimit<ch_cnt_t>(
configManager::inst()->value( "audioalsa", "channels" ).toInt(),
DEFAULT_CHANNELS, SURROUND_CHANNELS ) ),
m_handle( NULL ),
m_hwParams( NULL ),
@@ -214,21 +214,20 @@ void audioALSA::run( void )
surroundSampleFrame * temp =
bufferAllocator::alloc<surroundSampleFrame>(
mixer::inst()->framesPerAudioBuffer() );
outputSampleType * outbuf =
bufferAllocator::alloc<outputSampleType>(
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
mixer::inst()->framesPerAudioBuffer() *
channels() );
m_quit = FALSE;
while( m_quit == FALSE )
{
const Uint32 frames = getNextBuffer( temp );
const f_cnt_t frames = getNextBuffer( temp );
convertToS16( temp, frames, mixer::inst()->masterGain(), outbuf,
m_littleEndian != isLittleEndian() );
Uint32 frame = 0;
outputSampleType * ptr = outbuf;
f_cnt_t frame = 0;
int_sample_t * ptr = outbuf;
while( frame < frames )
{
@@ -261,7 +260,8 @@ void audioALSA::run( void )
int audioALSA::setHWParams( Uint32 _sample_rate, Uint32 _channels,
int audioALSA::setHWParams( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
snd_pcm_access_t _access )
{
int err, dir;

View File

@@ -1,7 +1,7 @@
/*
* audio_device.cpp - base-class for audio-devices used by LMMS-mixer
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -36,7 +36,8 @@
audioDevice::audioDevice( Uint32 _sample_rate, Uint8 _channels ) :
audioDevice::audioDevice( const sample_rate_t _sample_rate,
const ch_cnt_t _channels ) :
m_sampleRate( _sample_rate ),
m_channels( _channels ),
m_buffer( bufferAllocator::alloc<surroundSampleFrame>(
@@ -75,16 +76,16 @@ audioDevice::~audioDevice()
void audioDevice::processNextBuffer( void )
{
const Uint32 frames = getNextBuffer( m_buffer );
const fpab_t frames = getNextBuffer( m_buffer );
writeBuffer( m_buffer, frames, mixer::inst()->masterGain() );
}
Uint32 audioDevice::getNextBuffer( surroundSampleFrame * _ab )
fpab_t audioDevice::getNextBuffer( surroundSampleFrame * _ab )
{
Uint32 frames = mixer::inst()->framesPerAudioBuffer();
fpab_t frames = mixer::inst()->framesPerAudioBuffer();
const surroundSampleFrame * b = mixer::inst()->renderNextBuffer();
// make sure, no other thread is accessing device
@@ -165,9 +166,10 @@ const float LP_FILTER_COEFFS[LP_FILTER_TAPS] =
void FASTCALL audioDevice::resample( const surroundSampleFrame * _src,
Uint32 _frames,
const fpab_t _frames,
surroundSampleFrame * _dst,
Uint32 _src_sr, Uint32 _dst_sr )
const sample_rate_t _src_sr,
const sample_rate_t _dst_sr )
{
#ifdef HAVE_SAMPLERATE_H
if( m_srcState == NULL )
@@ -247,18 +249,20 @@ void FASTCALL audioDevice::resample( const surroundSampleFrame * _src,
} ;
static Uint8 oldest = 0;
for( Uint32 frame = 0; frame < _frames; ++frame )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( Uint8 chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < SURROUND_CHANNELS;
++chnl )
{
lp_hist[oldest][chnl] = _src[frame][chnl];
if( frame % 2==0 )
if( frame % 2 == 0 )
{
_dst[frame/2][chnl] = 0.0f;
const fpab_t f = frame / 2;
_dst[f][chnl] = 0.0f;
for( Uint8 tap = 0;
tap < LP_FILTER_TAPS; ++tap )
{
_dst[frame / 2][chnl] +=
_dst[f][chnl] +=
LP_FILTER_COEFFS[tap] * lp_hist[( oldest + tap ) % LP_FILTER_TAPS][chnl];
}
}
@@ -278,17 +282,18 @@ LP_FILTER_COEFFS[tap] * lp_hist[( oldest + tap ) % LP_FILTER_TAPS][chnl];
int FASTCALL audioDevice::convertToS16( surroundSampleFrame * _ab,
Uint32 _frames, float _master_gain,
outputSampleType * _output_buffer,
bool _convert_endian )
Uint32 FASTCALL audioDevice::convertToS16( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain,
int_sample_t * _output_buffer,
const bool _convert_endian )
{
for( Uint32 frame = 0; frame < _frames; ++frame )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( Uint8 chnl = 0; chnl < channels(); ++chnl )
for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
{
( _output_buffer + frame * channels() )[chnl] =
static_cast<outputSampleType>(
static_cast<int_sample_t>(
mixer::clip( _ab[frame][chnl] *
_master_gain ) *
OUTPUT_SAMPLE_MULTIPLIER );
@@ -296,34 +301,34 @@ int FASTCALL audioDevice::convertToS16( surroundSampleFrame * _ab,
}
if( _convert_endian )
{
for( Uint32 frame = 0; frame < _frames; ++frame )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( Uint8 chnl = 0; chnl < channels(); ++chnl )
for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
{
Sint8 * ptr = reinterpret_cast<Sint8 *>(
_output_buffer +
frame * channels() +
chnl );
*(outputSampleType *)ptr =
( ( outputSampleType )*ptr << 8
*(int_sample_t *)ptr =
( ( int_sample_t )*ptr << 8
) |
( ( outputSampleType ) *
( ( int_sample_t ) *
( ptr+1 ) );
}
}
}
return( _frames * channels() * BYTES_PER_OUTPUT_SAMPLE );
return( _frames * channels() * BYTES_PER_INT_SAMPLE );
}
void FASTCALL audioDevice::clearS16Buffer( outputSampleType * _outbuf,
Uint32 _frames )
void FASTCALL audioDevice::clearS16Buffer( int_sample_t * _outbuf,
const fpab_t _frames )
{
#ifdef LMMS_DEBUG
assert( _outbuf != NULL );
#endif
memset( _outbuf, 0, _frames * channels() * BYTES_PER_OUTPUT_SAMPLE );
memset( _outbuf, 0, _frames * channels() * BYTES_PER_INT_SAMPLE );
}

View File

@@ -2,7 +2,7 @@
* audio_file_device.cpp - base-class for audio-device-classes which write
* their output into a file
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -42,12 +42,13 @@
#include "buffer_allocator.h"
audioFileDevice::audioFileDevice( Uint32 _sample_rate, Uint8 _channels,
const QString & _file,
bool _use_vbr,
Uint16 _nom_bitrate,
Uint16 _min_bitrate,
Uint16 _max_bitrate ) :
audioFileDevice::audioFileDevice( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate ) :
audioDevice( _sample_rate, _channels),
m_outputFile( _file ),
m_useVbr( _use_vbr ),
@@ -86,12 +87,12 @@ audioFileDevice::~audioFileDevice()
int audioFileDevice::writeData( const void * _data, int _len )
Sint32 audioFileDevice::writeData( const void * _data, Sint32 _len )
{
#ifdef QT4
return( m_outputFile.write( (const char *)_data, _len ) );
return( m_outputFile.write( (const char *) _data, _len ) );
#else
return( m_outputFile.writeBlock( (const char *)_data, _len ) );
return( m_outputFile.writeBlock( (const char *) _data, _len ) );
#endif
}

View File

@@ -5,7 +5,7 @@
* This file is based on encode.c from vorbis-tools-source, for more information
* see below.
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -39,10 +39,14 @@
#include <cstring>
audioFileOgg::audioFileOgg( Uint32 _sample_rate, Uint32 _channels,
bool & _success_ful, const QString & _file,
bool _use_vbr, Uint16 _nom_bitrate,
Uint16 _min_bitrate, Uint16 _max_bitrate ) :
audioFileOgg::audioFileOgg( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
bool & _success_ful,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate ) :
audioFileDevice( _sample_rate, _channels, _file, _use_vbr,
_nom_bitrate, _min_bitrate, _max_bitrate )
{
@@ -60,9 +64,9 @@ audioFileOgg::~audioFileOgg()
inline int audioFileOgg::writePage( void )
inline Sint32 audioFileOgg::writePage( void )
{
int written = writeData( m_og.header, m_og.header_len );
Sint32 written = writeData( m_og.header, m_og.header_len );
written += writeData( m_og.body, m_og.body_len );
return( written );
}
@@ -75,7 +79,7 @@ bool audioFileOgg::startEncoding( void )
vorbis_comment vc;
char * comments = "Cool=This song has been made using Linux "
"MultiMedia Studio";
int comment_length = strlen( comments );
Sint32 comment_length = strlen( comments );
vc.user_comments = &comments;
vc.comment_lengths = &comment_length;
@@ -86,18 +90,15 @@ bool audioFileOgg::startEncoding( void )
// vbr enabled?
if( useVBR() == 0 )
{
m_managed = -1; // we don't want vbr
m_minBitrate = nominalBitrate(); // min for vbr
m_maxBitrate = nominalBitrate(); // max for vbr
}
else
{
m_managed = 0; // let's use vbr
m_minBitrate = minBitrate(); // min for vbr
m_maxBitrate = maxBitrate(); // max for vbr
}
m_bitrate = nominalBitrate(); // nominal bitrate
m_rate = sampleRate(); // default-samplerate
m_serialNo = 0; // track-num?
m_comments = &vc; // comments for ogg-file
@@ -107,7 +108,7 @@ bool audioFileOgg::startEncoding( void )
if( vorbis_encode_setup_managed( &m_vi, m_channels, m_rate,
( m_maxBitrate > 0 )? m_maxBitrate * 1000 : -1,
m_bitrate * 1000,
nominalBitrate() * 1000,
( m_minBitrate > 0 )? m_minBitrate * 1000 : -1 ) )
{
printf( "Mode initialization failed: invalid parameters for "
@@ -116,11 +117,11 @@ bool audioFileOgg::startEncoding( void )
return( FALSE );
}
if( m_managed && m_bitrate < 0 )
if( useVBR() == FALSE )
{
vorbis_encode_ctl( &m_vi, OV_ECTL_RATEMANAGE_AVG, NULL );
}
else if( !m_managed )
else if( useVBR() == TRUE )
{
// Turn off management entirely (if it was turned on).
vorbis_encode_ctl( &m_vi, OV_ECTL_RATEMANAGE_SET, NULL );
@@ -159,7 +160,7 @@ bool audioFileOgg::startEncoding( void )
{
break;
}
int ret = writePage();
Sint32 ret = writePage();
if( ret != m_og.header_len + m_og.body_len )
{
// clean up
@@ -174,18 +175,18 @@ bool audioFileOgg::startEncoding( void )
void FASTCALL audioFileOgg::writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
float _master_gain )
void FASTCALL audioFileOgg::writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain )
{
int eos = 0;
float * * buffer = vorbis_analysis_buffer( &m_vd, _frames *
BYTES_PER_SAMPLE *
channels() );
for( Uint32 frame = 0; frame < _frames; ++frame )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( Uint8 chnl = 0; chnl < channels(); ++chnl )
for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl )
{
buffer[chnl][frame] = _ab[frame][chnl] * _master_gain;
}

View File

@@ -2,7 +2,7 @@
* audio_file_wave.cpp - audio-device which encodes wave-stream and writes it
* into a WAVE-file. This is used for song-export.
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -32,10 +32,13 @@
#include <cstring>
audioFileWave::audioFileWave( Uint32 _sample_rate, Uint32 _channels,
bool & _success_ful, const QString & _file,
bool _use_vbr, Uint16 _nom_bitrate,
Uint16 _min_bitrate, Uint16 _max_bitrate ) :
audioFileWave::audioFileWave( const sample_rate_t _sample_rate,
const ch_cnt_t _channels, bool & _success_ful,
const QString & _file,
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate ) :
audioFileDevice( _sample_rate, _channels, _file, _use_vbr,
_nom_bitrate, _min_bitrate, _max_bitrate )
{
@@ -67,14 +70,13 @@ bool audioFileWave::startEncoding( void )
memcpy( m_waveFileHeader.wave_fmt_str, "WAVEfmt ", 8 );
m_waveFileHeader.bitrate_1 =
m_waveFileHeader.bitrate_2 =
swap16IfBE( BYTES_PER_OUTPUT_SAMPLE * 8 );
swap16IfBE( BYTES_PER_INT_SAMPLE * 8 );
m_waveFileHeader.uncompressed = swap16IfBE( 1 );
m_waveFileHeader.channels = swap16IfBE( channels() );
m_waveFileHeader.sample_rate = swap32IfBE( sampleRate() );
m_waveFileHeader.bytes_per_second = swap32IfBE( sampleRate() *
BYTES_PER_OUTPUT_SAMPLE *
channels() );
m_waveFileHeader.block_alignment = swap16IfBE( BYTES_PER_OUTPUT_SAMPLE *
BYTES_PER_INT_SAMPLE * channels() );
m_waveFileHeader.block_alignment = swap16IfBE( BYTES_PER_INT_SAMPLE *
channels() );
memcpy ( m_waveFileHeader.data_chunk_id, "data", 4 );
m_waveFileHeader.data_bytes = swap32IfBE( 0 );
@@ -87,13 +89,13 @@ bool audioFileWave::startEncoding( void )
void FASTCALL audioFileWave::writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
float _master_gain )
void FASTCALL audioFileWave::writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain )
{
outputSampleType * outbuf = bufferAllocator::alloc<outputSampleType>(
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
_frames * channels() );
int bytes = convertToS16( _ab, _frames, _master_gain, outbuf,
Uint32 bytes = convertToS16( _ab, _frames, _master_gain, outbuf,
!isLittleEndian() );
writeData( outbuf, bytes );

View File

@@ -91,9 +91,9 @@
audioOSS::audioOSS( Uint32 _sample_rate, bool & _success_ful ) :
audioDevice( _sample_rate, tLimit<int>( configManager::inst()->value(
"audiooss", "channels" ).toInt(),
audioOSS::audioOSS( const sample_rate_t _sample_rate, bool & _success_ful ) :
audioDevice( _sample_rate, tLimit<ch_cnt_t>(
configManager::inst()->value( "audiooss", "channels" ).toInt(),
DEFAULT_CHANNELS, SURROUND_CHANNELS ) ),
m_convertEndian( FALSE ),
m_quit( FALSE )
@@ -124,9 +124,9 @@ audioOSS::audioOSS( Uint32 _sample_rate, bool & _success_ful ) :
}
int frag_spec;
for( frag_spec = 0; static_cast<unsigned int>( 0x01 << frag_spec ) <
for( frag_spec = 0; static_cast<int>( 0x01 << frag_spec ) <
mixer::inst()->framesPerAudioBuffer() * channels() *
BYTES_PER_OUTPUT_SAMPLE;
BYTES_PER_INT_SAMPLE;
++frag_spec )
{
}
@@ -317,8 +317,7 @@ void audioOSS::run( void )
surroundSampleFrame * temp =
bufferAllocator::alloc<surroundSampleFrame>(
mixer::inst()->framesPerAudioBuffer() );
outputSampleType * outbuf =
bufferAllocator::alloc<outputSampleType>(
int_sample_t * outbuf = bufferAllocator::alloc<int_sample_t>(
mixer::inst()->framesPerAudioBuffer() *
channels() );
m_quit = FALSE;

View File

@@ -3,7 +3,7 @@
* surround-audio-buffers into RAM, maybe later
* also harddisk
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -33,7 +33,8 @@
audioSampleRecorder::audioSampleRecorder( Uint32 _sample_rate, Uint32 _channels,
audioSampleRecorder::audioSampleRecorder( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
bool & _success_ful ) :
audioDevice( _sample_rate, _channels ),
m_buffers()
@@ -59,10 +60,10 @@ audioSampleRecorder::~audioSampleRecorder()
Uint32 audioSampleRecorder::framesRecorded( void ) const
{
Uint32 frames = 0;
for( bufferVector::const_iterator it = m_buffers.begin();
for( bufferList::const_iterator it = m_buffers.begin();
it != m_buffers.end(); ++it )
{
frames += it->second;
frames += ( *it ).second;
}
return( frames );
}
@@ -73,7 +74,7 @@ Uint32 audioSampleRecorder::framesRecorded( void ) const
void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
const
{
Uint32 frames = framesRecorded();
f_cnt_t frames = framesRecorded();
// create buffer to store all recorded buffers in
sampleFrame * data = bufferAllocator::alloc<sampleFrame>( frames );
// make sure buffer is cleaned up properly at the end...
@@ -83,11 +84,12 @@ void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
assert( data != NULL );
#endif
// now copy all buffers into big buffer
for( bufferVector::const_iterator it = m_buffers.begin();
for( bufferList::const_iterator it = m_buffers.begin();
it != m_buffers.end(); ++it )
{
memcpy( data, it->first, it->second * sizeof( sampleFrame ) );
data += it->second;
memcpy( data, ( *it ).first, ( *it ).second *
sizeof( sampleFrame ) );
data += ( *it ).second;
}
// create according sample-buffer out of big buffer
*_sample_buf = new sampleBuffer( ac.ptr(), frames );
@@ -96,13 +98,13 @@ void audioSampleRecorder::createSampleBuffer( sampleBuffer * * _sample_buf )
void audioSampleRecorder::writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames, float )
void audioSampleRecorder::writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames, const float )
{
sampleFrame * buf = bufferAllocator::alloc<sampleFrame>( _frames );
for( Uint32 frame = 0; frame < _frames; ++frame )
for( fpab_t frame = 0; frame < _frames; ++frame )
{
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
buf[frame][chnl] = _ab[frame][chnl];
}

View File

@@ -48,7 +48,7 @@
audioSDL::audioSDL( Uint32 _sample_rate, bool & _success_ful ) :
audioSDL::audioSDL( const sample_rate_t _sample_rate, bool & _success_ful ) :
audioDevice( _sample_rate, DEFAULT_CHANNELS ),
m_outBuf( bufferAllocator::alloc<surroundSampleFrame>(
mixer::inst()->framesPerAudioBuffer() ) ),
@@ -142,11 +142,11 @@ void audioSDL::sdlAudioCallback( void * _udata, Uint8 * _buf, int _len )
assert( _this != NULL );
#endif
const Uint32 frames = _this->getNextBuffer( _this->m_outBuf );
const fpab_t frames = _this->getNextBuffer( _this->m_outBuf );
_this->convertToS16( _this->m_outBuf, frames,
mixer::inst()->masterGain(),
(outputSampleType *)( _buf ),
(int_sample_t *)( _buf ),
_this->m_convertEndian );
}

View File

@@ -41,6 +41,11 @@
#endif
#ifdef HAVE_SCHED_H
#include <sched.h>
#endif
#include "lmms_main_win.h"
#include "embed.h"
#include "config_mgr.h"
@@ -224,6 +229,17 @@ int main( int argc, char * * argv )
e->exportBtnClicked();
}
#ifdef HAVE_SCHED_H
struct sched_param sparam;
sparam.sched_priority = ( sched_get_priority_max( SCHED_FIFO ) +
sched_get_priority_min( SCHED_FIFO ) ) / 2;
if( sched_setscheduler( 0, SCHED_FIFO, &sparam ) == -1 )
{
printf( "could not set realtime priority.\n" );
}
#endif
return( app.exec() );
}

View File

@@ -1,7 +1,7 @@
/*
* mixer.cpp - audio-device-independent mixer for LMMS
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -54,7 +54,7 @@
Uint32 SAMPLE_RATES[QUALITY_LEVELS] = { 44100, 88200 } ;
sample_rate_t SAMPLE_RATES[QUALITY_LEVELS] = { 44100, 88200 } ;
mixer * mixer::s_instanceOfMe = NULL;
@@ -69,7 +69,9 @@ mixer::mixer() :
m_qualityLevel( DEFAULT_QUALITY_LEVEL ),
m_masterGain( 1.0f ),
m_audioDev( NULL ),
m_oldAudioDev( NULL )
m_oldAudioDev( NULL ),
m_mixMutex(),
m_mixMutexLockLevel( 0 )
{
// small hack because code calling mixer::inst() is called out of ctor
s_instanceOfMe = this;
@@ -252,7 +254,8 @@ void mixer::clear( bool _everything )
void FASTCALL mixer::clearAudioBuffer( sampleFrame * _ab, Uint32 _frames )
void FASTCALL mixer::clearAudioBuffer( sampleFrame * _ab,
const f_cnt_t _frames )
{
memset( _ab, 0, sizeof( *_ab ) * _frames );
}
@@ -261,7 +264,7 @@ void FASTCALL mixer::clearAudioBuffer( sampleFrame * _ab, Uint32 _frames )
#ifndef DISABLE_SURROUND
void FASTCALL mixer::clearAudioBuffer( surroundSampleFrame * _ab,
Uint32 _frames )
const f_cnt_t _frames )
{
memset( _ab, 0, sizeof( *_ab ) * _frames );
}
@@ -269,18 +272,19 @@ void FASTCALL mixer::clearAudioBuffer( surroundSampleFrame * _ab,
void FASTCALL mixer::bufferToPort( sampleFrame * _buf, Uint32 _frames,
Uint32 _frames_ahead,
volumeVector & _volume_vector,
void FASTCALL mixer::bufferToPort( const sampleFrame * _buf,
const fpab_t _frames,
const fpab_t _frames_ahead,
const volumeVector & _volume_vector,
audioPort * _port )
{
const Uint32 start_frame = _frames_ahead % m_framesPerAudioBuffer;
Uint32 end_frame = start_frame + _frames;
const Uint32 loop1_frame = tMin( end_frame, m_framesPerAudioBuffer );
const fpab_t start_frame = _frames_ahead % m_framesPerAudioBuffer;
fpab_t end_frame = start_frame + _frames;
const fpab_t loop1_frame = tMin( end_frame, m_framesPerAudioBuffer );
for( Uint32 frame = start_frame; frame < loop1_frame; ++frame )
for( fpab_t frame = start_frame; frame < loop1_frame; ++frame )
{
for( Uint8 chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
{
_port->firstBuffer()[frame][chnl] +=
_buf[frame - start_frame][chnl %
@@ -291,12 +295,13 @@ void FASTCALL mixer::bufferToPort( sampleFrame * _buf, Uint32 _frames,
if( end_frame > m_framesPerAudioBuffer )
{
Uint32 frames_done = m_framesPerAudioBuffer - start_frame;
fpab_t frames_done = m_framesPerAudioBuffer - start_frame;
end_frame = tMin( end_frame -= m_framesPerAudioBuffer,
m_framesPerAudioBuffer );
for( Uint32 frame = 0; frame < end_frame; ++frame )
for( fpab_t frame = 0; frame < end_frame; ++frame )
{
for( Uint8 chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < SURROUND_CHANNELS;
++chnl )
{
_port->secondBuffer()[frame][chnl] +=
_buf[frames_done + frame][chnl %
@@ -361,7 +366,7 @@ void FASTCALL mixer::setAudioDevice( audioDevice * _dev, bool _hq )
m_audioDev = _dev;
}
m_qualityLevel = _hq ? 1 : 0;
m_qualityLevel = _hq ? HIGH_QUALITY_LEVEL : DEFAULT_QUALITY_LEVEL;
emit sampleRateChanged();
}
@@ -375,11 +380,13 @@ void mixer::restoreAudioDevice( void )
delete m_audioDev; // dtor automatically calls
// stopProcessing()
m_audioDev = m_oldAudioDev;
for( Uint8 qli = 0; qli < QUALITY_LEVELS; ++qli )
for( Uint8 qli = DEFAULT_QUALITY_LEVEL;
qli < QUALITY_LEVELS; ++qli )
{
if( SAMPLE_RATES[qli] == m_audioDev->sampleRate() )
{
m_qualityLevel = qli;
m_qualityLevel =
static_cast<qualityLevels>( qli );
emit sampleRateChanged();
break;
}
@@ -544,12 +551,13 @@ midiClient * mixer::tryMIDIClients( void )
void mixer::processBuffer( surroundSampleFrame * _buf, fxChnl/* _fx_chnl */ )
void mixer::processBuffer( const surroundSampleFrame * _buf,
fx_ch_t/* _fx_chnl */ )
{
// TODO: effect-implementation
for( Uint32 frame = 0; frame < m_framesPerAudioBuffer; ++frame )
for( fpab_t frame = 0; frame < m_framesPerAudioBuffer; ++frame )
{
for( Uint8 chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
{
m_curBuf[frame][chnl] += _buf[frame][chnl];
}

View File

@@ -522,7 +522,7 @@ trackContentObject * FASTCALL trackContentWidget::getTCO( csize _tco_num )
return( m_trackContentObjects[_tco_num] );
}
printf( "called trackContentWidget::getTCO( %d, TRUE ), "
" but TCO %d doesn't exist\n", _tco_num, _tco_num );
"but TCO %d doesn't exist\n", _tco_num, _tco_num );
return( getTrack()->addTCO( getTrack()->createTCO( _tco_num * 64 ) ) );
// return( NULL );
}
@@ -1264,18 +1264,28 @@ track::~track()
track * FASTCALL track::create( trackTypes _tt, trackContainer * _tc )
{
// while adding track, pause mixer for not getting into any trouble
// because of track being not created completely so far
mixer::inst()->pause();
track * t = NULL;
switch( _tt )
{
case CHANNEL_TRACK: return( new channelTrack( _tc ) );
case BB_TRACK: return( new bbTrack( _tc ) );
case SAMPLE_TRACK: return( new sampleTrack( _tc ) );
case CHANNEL_TRACK: t = new channelTrack( _tc ); break;
case BB_TRACK: t = new bbTrack( _tc ); break;
case SAMPLE_TRACK: t = new sampleTrack( _tc ); break;
// case EVENT_TRACK:
// case VIDEO_TRACK:
default: break;
}
qFatal( "Attempt to create track with invalid type %d!",
static_cast<int>( _tt ) );
return( NULL );
assert( t != NULL );
// allow mixer to continue
mixer::inst()->play();
return( t );
}
@@ -1286,9 +1296,6 @@ track * FASTCALL track::create( const QDomElement & _this,
{
track * t = create( static_cast<trackTypes>( _this.attribute(
"type" ).toInt() ), _tc );
#ifdef LMMS_DEBUG
assert( t != NULL );
#endif
t->loadSettings( _this );
return( t );
}

View File

@@ -1,7 +1,7 @@
/*
* oscillator.cpp - implementation of powerful oscillator-class
*
* Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -27,17 +27,16 @@
oscillator::oscillator( modulationAlgos _modulation_algo, float _freq,
Sint16 _phase_offset, float _volume_factor,
oscillator * _sub_osc ) :
m_freq(_freq),
m_volumeFactor(_volume_factor),
m_phaseOffset(_phase_offset),
m_subOsc(_sub_osc),
oscillator::oscillator( const modulationAlgos _modulation_algo,
const float _freq, const Sint16 _phase_offset,
const float _volume_factor, oscillator * _sub_osc ) :
m_freq( _freq ),
m_volumeFactor( _volume_factor ),
m_phaseOffset( _phase_offset ),
m_subOsc( _sub_osc ),
m_userWaveData( &ZERO_FRAME ),
m_userWaveFrames( 1 )
{
if( m_subOsc != NULL )
{
switch( _modulation_algo )
@@ -70,9 +69,10 @@ oscillator::oscillator( modulationAlgos _modulation_algo, float _freq,
// if we have no sub-osc, we can't do any modulation... just get our samples
#define defineNoSubUpdateFor(x,getSampleFunction) \
void x::updateNoSub( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
void x::updateNoSub( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ) \
{ \
for( Uint16 frame = 0; frame < _frames; ++frame ) \
for( fpab_t frame = 0; frame < _frames; ++frame ) \
{ \
_ab[frame][_chnl] = getSampleFunction( ++m_sample * \
m_oscCoeff ) * m_volumeFactor; \
@@ -82,10 +82,11 @@ void x::updateNoSub( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
// do fm by using sub-osc as modulator
#define defineFMUpdateFor(x,getSampleFunction) \
void x::updateFM( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
void x::updateFM( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ) \
{ \
m_subOsc->update( _ab, _frames, _chnl ); \
for( Uint16 frame = 0; frame < _frames; ++frame ) \
for( fpab_t frame = 0; frame < _frames; ++frame ) \
{ \
_ab[frame][_chnl] = getSampleFunction( ++m_sample * \
m_oscCoeff + \
@@ -103,10 +104,11 @@ void x::updateFM( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
// do am by using sub-osc as modulator
#define defineAMUpdateFor(x,getSampleFunction) \
void x::updateAM( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
void x::updateAM( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ) \
{ \
m_subOsc->update( _ab, _frames, _chnl ); \
for( Uint16 frame = 0; frame < _frames; ++frame ) \
for( fpab_t frame = 0; frame < _frames; ++frame ) \
{ \
_ab[frame][_chnl] *= getSampleFunction( ++m_sample * \
m_oscCoeff ) * m_volumeFactor; \
@@ -116,10 +118,11 @@ void x::updateAM( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
// do mix by using sub-osc as mix-sample
#define defineMixUpdateFor(x,getSampleFunction) \
void x::updateMix( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
void x::updateMix( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ) \
{ \
m_subOsc->update( _ab, _frames, _chnl ); \
for( Uint16 frame = 0; frame < _frames; ++frame ) \
for( fpab_t frame = 0; frame < _frames; ++frame ) \
{ \
_ab[frame][_chnl] += getSampleFunction( ++m_sample * \
m_oscCoeff ) * m_volumeFactor; \
@@ -130,9 +133,10 @@ void x::updateMix( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
// sync with sub-osc (every time sub-osc starts new period, we also start new
// period)
#define defineSyncUpdateFor(x,getSampleFunction) \
void x::updateSync( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
void x::updateSync( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ) \
{ \
for( Uint16 frame = 0; frame < _frames ; ++frame ) \
for( fpab_t frame = 0; frame < _frames ; ++frame ) \
{ \
if( m_subOsc->syncOk() ) \
{ \
@@ -149,24 +153,28 @@ void x::updateSync( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl ) \
class x : public oscillator \
{ \
public: \
x( modulationAlgos modulation_algo, float _freq, Sint16 _phase_offset, \
float _volume_factor, oscillator * _sub_osc) : \
oscillator (modulation_algo, _freq, _phase_offset, _volume_factor, \
_sub_osc ) \
x( const modulationAlgos modulation_algo, const float _freq, \
const Sint16 _phase_offset, const float _volume_factor, \
oscillator * _sub_osc ) FASTCALL : \
oscillator( modulation_algo, _freq, _phase_offset, \
_volume_factor, _sub_osc ) \
{ \
} \
virtual ~x() \
{ \
} \
\
protected: \
void updateNoSub( sampleFrame * _ab, Uint32 _frames, \
Uint8 _chnl ); \
void updateFM( sampleFrame * _ab, Uint32 _frames, \
Uint8 _chnl ); \
void updateAM( sampleFrame * _ab, Uint32 _frames, \
Uint8 _chnl ); \
void updateMix( sampleFrame * _ab, Uint32 _frames, \
Uint8 _chnl ); \
void updateSync( sampleFrame * _ab, Uint32 _frames, \
Uint8 _chnl ); \
void updateNoSub( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ); \
void updateFM( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ); \
void updateAM( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ); \
void updateMix( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ); \
void updateSync( sampleFrame * _ab, const fpab_t _frames, \
const ch_cnt_t _chnl ); \
\
} ; \
\
@@ -188,10 +196,11 @@ generateOscillatorCodeFor( userWaveOsc, userWaveSample );
oscillator * oscillator::createOsc( waveShapes _wave_shape,
modulationAlgos _modulation_algo,
float _freq, Sint16 _phase_offset,
float _volume_factor,
oscillator * oscillator::createOsc( const waveShapes _wave_shape,
const modulationAlgos _modulation_algo,
const float _freq,
const Sint16 _phase_offset,
const float _volume_factor,
oscillator * _sub_osc )
{
switch( _wave_shape )
@@ -244,7 +253,7 @@ void oscillator::recalcOscCoeff( const float additional_phase_offset )
{
m_oscCoeff = m_freq / static_cast<float>( mixer::inst()->sampleRate() );
m_sample = static_cast<Uint32>( ( m_phaseOffset * ( 1.0f / 360.0f ) +
m_sample = static_cast<f_cnt_t>( ( m_phaseOffset * ( 1.0f / 360.0f ) +
additional_phase_offset ) *
( mixer::inst()->sampleRate() /
m_freq ) );

View File

@@ -131,7 +131,7 @@ sampleBuffer::sampleBuffer( const QString & _audio_file,
sampleBuffer::sampleBuffer( const sampleFrame * _data, Uint32 _frames ) :
sampleBuffer::sampleBuffer( const sampleFrame * _data, const f_cnt_t _frames ) :
QObject(),
m_audioFile( "" ),
m_origData( NULL ),
@@ -160,7 +160,7 @@ sampleBuffer::sampleBuffer( const sampleFrame * _data, Uint32 _frames ) :
sampleBuffer::sampleBuffer( Uint32 _frames ) :
sampleBuffer::sampleBuffer( const f_cnt_t _frames ) :
QObject(),
m_audioFile( "" ),
m_origData( NULL ),
@@ -253,9 +253,9 @@ void sampleBuffer::update( bool _keep_settings )
#else
file.ascii();
#endif
Sint16 * buf = NULL;
Uint8 channels = DEFAULT_CHANNELS;
Uint32 samplerate = SAMPLE_RATES[DEFAULT_QUALITY_LEVEL];
int_sample_t * buf = NULL;
ch_cnt_t channels = DEFAULT_CHANNELS;
sample_rate_t samplerate = SAMPLE_RATES[DEFAULT_QUALITY_LEVEL];
#ifdef HAVE_SNDFILE_H
if( m_frames == 0 )
@@ -290,28 +290,28 @@ void sampleBuffer::update( bool _keep_settings )
// scaling
if( m_reversed )
{
for( Uint32 frame = 0; frame < m_frames;
for( f_cnt_t frame = 0; frame < m_frames;
++frame )
{
for( Uint8 chnl = 0;
for( ch_cnt_t chnl = 0;
chnl < DEFAULT_CHANNELS;
++chnl )
{
const Uint32 idx = ( m_frames - frame ) * channels + ( chnl % channels );
const f_cnt_t idx = ( m_frames - frame ) * channels + ( chnl % channels );
m_data[frame][chnl] = buf[idx] * fac;
}
}
}
else
{
for( Uint32 frame = 0; frame < m_frames;
for( f_cnt_t frame = 0; frame < m_frames;
++frame )
{
for( Uint8 chnl = 0;
for( ch_cnt_t chnl = 0;
chnl < DEFAULT_CHANNELS;
++chnl )
{
const Uint32 idx = frame * channels + ( chnl % channels );
const f_cnt_t idx = frame * channels + ( chnl % channels );
m_data[frame][chnl] = buf[idx] * fac;
}
}
@@ -379,9 +379,10 @@ m_data[frame][chnl] = buf[idx] * fac;
#ifdef SDL_SDL_SOUND_H
Uint32 sampleBuffer::decodeSampleSDL( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _samplerate )
f_cnt_t sampleBuffer::decodeSampleSDL( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _samplerate )
{
Sound_AudioInfo STD_AUDIO_INFO =
{
@@ -389,7 +390,7 @@ Uint32 sampleBuffer::decodeSampleSDL( const char * _f, Sint16 * & _buf,
_channels,
_samplerate,
} ;
Uint32 frames = 0;
f_cnt_t frames = 0;
Sound_Sample * snd_sample = Sound_NewSampleFromFile( _f,
&STD_AUDIO_INFO, 16384 );
@@ -400,9 +401,9 @@ Uint32 sampleBuffer::decodeSampleSDL( const char * _f, Sint16 * & _buf,
( void )Sound_DecodeAll( snd_sample );
_channels = snd_sample->actual.channels;
_samplerate = snd_sample->actual.rate;
frames = snd_sample->buffer_size / ( BYTES_PER_OUTPUT_SAMPLE *
frames = snd_sample->buffer_size / ( BYTES_PER_INT_SAMPLE *
_channels );
_buf = new Sint16[frames * _channels];
_buf = new int_sample_t[frames * _channels];
memcpy( _buf, snd_sample->buffer, snd_sample->buffer_size );
Sound_FreeSample( snd_sample );
@@ -415,13 +416,14 @@ Uint32 sampleBuffer::decodeSampleSDL( const char * _f, Sint16 * & _buf,
#ifdef HAVE_SNDFILE_H
Uint32 sampleBuffer::decodeSampleSF( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _samplerate )
f_cnt_t sampleBuffer::decodeSampleSF( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _samplerate )
{
SNDFILE * snd_file;
SF_INFO sf_info;
Uint32 frames = 0;
f_cnt_t frames = 0;
#ifdef OLD_SNDFILE
if( ( snd_file = sf_open_read( _f, &sf_info ) ) != NULL )
{
@@ -431,7 +433,7 @@ Uint32 sampleBuffer::decodeSampleSF( const char * _f, Sint16 * & _buf,
{
frames = sf_info.frames;
#endif
_buf = new Sint16[sf_info.channels * frames];
_buf = new int_sample_t[sf_info.channels * frames];
frames = sf_read_short( snd_file, _buf, frames );
_channels = sf_info.channels;
_samplerate = sf_info.samplerate;
@@ -458,7 +460,7 @@ Uint32 sampleBuffer::decodeSampleSF( const char * _f, Sint16 * & _buf,
size_t qfileReadCallback( void * _ptr, size_t _size, size_t _n, void * _udata )
{
return( static_cast<QFile *>( _udata )->read( (char*)_ptr,
return( static_cast<QFile *>( _udata )->read( (char*) _ptr,
_size * _n ) );
}
@@ -504,9 +506,10 @@ long qfileTellCallback( void * _udata )
Uint32 sampleBuffer::decodeSampleOGGVorbis( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _samplerate )
f_cnt_t sampleBuffer::decodeSampleOGGVorbis( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _samplerate )
{
static ov_callbacks callbacks =
{
@@ -518,7 +521,7 @@ Uint32 sampleBuffer::decodeSampleOGGVorbis( const char * _f, Sint16 * & _buf,
OggVorbis_File vf;
Uint32 frames = 0;
f_cnt_t frames = 0;
QFile * f = new QFile( _f );
#ifdef QT4
@@ -569,7 +572,7 @@ Uint32 sampleBuffer::decodeSampleOGGVorbis( const char * _f, Sint16 * & _buf,
ogg_int64_t total = ov_pcm_total( &vf, -1 );
_buf = new Sint16[total * _channels];
_buf = new int_sample_t[total * _channels];
int bitstream = 0;
long bytes_read = 0;
@@ -577,14 +580,14 @@ Uint32 sampleBuffer::decodeSampleOGGVorbis( const char * _f, Sint16 * & _buf,
{
bytes_read = ov_read( &vf, (char *) &_buf[frames * _channels],
( total - frames ) * _channels *
sizeof( Sint16 ),
isLittleEndian()? 0 : 1,
sizeof( Sint16 ), 1, &bitstream );
BYTES_PER_INT_SAMPLE,
isLittleEndian() ? 0 : 1,
BYTES_PER_INT_SAMPLE, 1, &bitstream );
if( bytes_read < 0 )
{
break;
}
frames += bytes_read / ( _channels * sizeof( Sint16 ) );
frames += bytes_read / ( _channels * BYTES_PER_INT_SAMPLE );
}
while( bytes_read != 0 && bitstream == 0 );
@@ -642,10 +645,12 @@ void sampleBuffer::destroyResamplingContext( SRC_STATE * _context )
bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
Uint32 _frames, float _freq,
bool _looped,
void * * _resampling_data )
bool FASTCALL sampleBuffer::play( sampleFrame * _ab,
const f_cnt_t _start_frame,
const fpab_t _frames,
const float _freq,
const bool _looped,
void * * _resampling_data )
{
mixer::inst()->clearAudioBuffer( _ab, _frames );
@@ -657,10 +662,10 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
const double freq_factor = (double) _freq / (double) BASE_FREQ;
const Sint16 freq_diff = static_cast<Sint16>( BASE_FREQ - _freq );
Uint32 frames_to_process = _frames;
fpab_t frames_to_process = _frames;
// calculate how many frames we have in requested pitch
const Uint32 total_frames_for_current_pitch = static_cast<Uint32>( (
const f_cnt_t total_frames_for_current_pitch = static_cast<f_cnt_t>( (
m_endFrame - m_startFrame ) /
freq_factor );
if( total_frames_for_current_pitch == 0 )
@@ -676,11 +681,11 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
}
// this holds the number of the first frame to play
const Uint32 play_frame = m_startFrame + ( _start_frame %
const f_cnt_t play_frame = m_startFrame + ( _start_frame %
total_frames_for_current_pitch );
// this holds the number of remaining frames in current loop
Uint32 frames_for_loop = total_frames_for_current_pitch -
f_cnt_t frames_for_loop = total_frames_for_current_pitch -
( play_frame - m_startFrame );
// make sure, data isn't accessed in any other way (e.g. deleting
@@ -691,7 +696,7 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
{
frames_to_process = frames_for_loop;
}
const Uint32 f1 = static_cast<Uint32>( play_frame * freq_factor );
const f_cnt_t f1 = static_cast<f_cnt_t>( play_frame * freq_factor );
/* Uint32 f2 = 0;
while( f2 < f1 )
{
@@ -723,7 +728,7 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
}
m_srcData.data_in = start_frame[0];
m_srcData.data_out = _ab[0];
m_srcData.input_frames = static_cast<Uint32>( frames_for_loop *
m_srcData.input_frames = static_cast<f_cnt_t>( frames_for_loop *
freq_factor );
m_srcData.output_frames = frames_to_process;
m_srcData.src_ratio = 1.0 / freq_factor;
@@ -734,12 +739,12 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
src_strerror( error ) );
}
#else
Uint32 src_frame_base = 0;
f_cnt_t src_frame_base = 0;
// check whether we're in high-quality-mode
if( mixer::inst()->highQuality() == TRUE )
{
// we are, so let's use cubic interpolation...
for( Uint32 frame = 0; frame < frames_to_process;
for( f_cnt_t frame = 0; frame < frames_to_process;
++frame )
{
// current loop done?
@@ -753,10 +758,10 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
}
const float src_frame_idx = frame * freq_factor;
Uint32 frame_num = static_cast<Uint32>(
f_cnt_t frame_num = static_cast<f_cnt_t>(
src_frame_idx) - src_frame_base;
const float frac_pos = src_frame_idx -
static_cast<Uint32>( src_frame_idx );
static_cast<f_cnt_t>( src_frame_idx );
// because of cubic interpolation we have to
// access start_frame[frame_num-1], so make
@@ -766,7 +771,7 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
{
frame_num = 1;
}
for ( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
++chnl )
{
_ab[frame][chnl] = cubicInterpolate(
@@ -782,10 +787,10 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
{
// just normal mode, so we can use linear
// interpolation...
for( Uint32 frame = 0; frame < frames_to_process;
for( f_cnt_t frame = 0; frame < frames_to_process;
++frame )
{
if( _looped && ( frame-src_frame_base ) >
if( _looped && ( frame - src_frame_base ) >
frames_for_loop )
{
start_frame = loop_start;
@@ -794,11 +799,11 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
total_frames_for_current_pitch;
}
const float src_frame_idx = frame * freq_factor;
const Uint32 frame_num = (Uint32)src_frame_idx -
src_frame_base + 0;
const f_cnt_t frame_num =
(f_cnt_t)src_frame_idx-src_frame_base;
const float frac_pos = src_frame_idx -
(Uint32) src_frame_idx;
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS;
(f_cnt_t) src_frame_idx;
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
++chnl )
{
_ab[frame][chnl] = linearInterpolate(
@@ -816,7 +821,7 @@ bool FASTCALL sampleBuffer::play( sampleFrame * _ab, Uint32 _start_frame,
// as is into pitched-copy-buffer
if( _looped && frames_for_loop < frames_to_process )
{
Uint32 total_frames_copied = 0;
f_cnt_t total_frames_copied = 0;
while( total_frames_copied < frames_to_process )
{
memcpy( _ab[total_frames_copied], start_frame,
@@ -878,13 +883,14 @@ void sampleBuffer::drawWaves( QPainter & _p, QRect _dr, drawMethods _dm )
float old_x = _dr.x();
float old_y[DEFAULT_CHANNELS] = { y_base, y_base };
float fpp = tMax<float>( tMin<float>( m_frames / (float)w,
const float fpp = tMax<float>( tMin<float>( m_frames / (float)w,
20.0f ), 1.0f );
for( float frame = 0; frame < m_frames; frame += fpp )
{
const float x = frame*w / m_frames + _dr.x();
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
++chnl )
{
const float y = y_base +
m_data[static_cast<int>( frame )][chnl] * y_space;
@@ -898,15 +904,15 @@ void sampleBuffer::drawWaves( QPainter & _p, QRect _dr, drawMethods _dm )
int old_x = _dr.x();
int old_y[DEFAULT_CHANNELS] = { y_base, y_base };
Uint32 fpp = tMax<Uint32>( tMin<Uint32>( m_frames / w, 20 ),
1 );
const f_cnt_t fpp = tMax<f_cnt_t>( tMin<f_cnt_t>( m_frames / w,
20 ), 1 );
for( Uint32 frame = 0; frame < m_frames; frame += fpp )
for( f_cnt_t frame = 0; frame < m_frames; frame += fpp )
{
const int x = static_cast<int>( frame /
(float) m_frames * w ) +
_dr.x();
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
const Uint16 y = y_base +
static_cast<Uint16>( m_data[frame][chnl] * y_space );
@@ -920,10 +926,10 @@ void sampleBuffer::drawWaves( QPainter & _p, QRect _dr, drawMethods _dm )
}
else if( _dm == DOTS )
{
for( Uint32 frame = 0; frame < m_frames; ++frame )
for( f_cnt_t frame = 0; frame < m_frames; ++frame )
{
const int x = frame*w / m_frames + _dr.x();
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
const int x = frame * w / m_frames + _dr.x();
for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{
_p.drawPoint( x, y_base +
static_cast<Uint16>( m_data[frame][chnl] * y_space ) );
@@ -1077,7 +1083,7 @@ QString & sampleBuffer::toBase64( QString & _dst ) const
}
#ifdef HAVE_FLAC_STREAM_ENCODER_H
const Uint32 FRAMES_PER_BUF = 1152;
const f_cnt_t FRAMES_PER_BUF = 1152;
FLAC__StreamEncoder * flac_enc = FLAC__stream_encoder_new();
FLAC__stream_encoder_set_channels( flac_enc, DEFAULT_CHANNELS );
@@ -1102,15 +1108,15 @@ QString & sampleBuffer::toBase64( QString & _dst ) const
{
printf( "error within FLAC__stream_encoder_init()!\n" );
}
Uint32 frame_cnt = 0;
f_cnt_t frame_cnt = 0;
while( frame_cnt < m_frames )
{
Uint32 remaining = tMin<Uint32>( FRAMES_PER_BUF,
f_cnt_t remaining = tMin<f_cnt_t>( FRAMES_PER_BUF,
m_frames - frame_cnt );
FLAC__int32 buf[FRAMES_PER_BUF * DEFAULT_CHANNELS];
for( Uint32 f = 0; f < remaining; ++f )
for( f_cnt_t f = 0; f < remaining; ++f )
{
for( Uint8 ch = 0; ch < DEFAULT_CHANNELS; ++ch )
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
{
buf[f*DEFAULT_CHANNELS+ch] = (FLAC__int32)(
mixer::clip( m_data[f+frame_cnt][ch] ) *
@@ -1144,11 +1150,11 @@ QString & sampleBuffer::toBase64( QString & _dst ) const
sampleBuffer * sampleBuffer::resample( sampleFrame * _data,
const Uint32 _frames,
const Uint32 _src_sr,
const Uint32 _dst_sr )
const f_cnt_t _frames,
const sample_rate_t _src_sr,
const sample_rate_t _dst_sr )
{
const Uint32 dst_frames = static_cast<Uint32>( _frames /
const f_cnt_t dst_frames = static_cast<f_cnt_t>( _frames /
(float) _src_sr * (float) _dst_sr );
sampleBuffer * dst_sb = new sampleBuffer( dst_frames );
sampleFrame * dst_buf = dst_sb->m_origData;
@@ -1165,7 +1171,7 @@ sampleBuffer * sampleBuffer::resample( sampleFrame * _data,
src_data.data_out = dst_buf[0];
src_data.input_frames = _frames;
src_data.output_frames = dst_frames;
src_data.src_ratio = (float) _dst_sr / _src_sr;
src_data.src_ratio = (double) _dst_sr / _src_sr;
int error;
if( ( error = src_process( state, &src_data ) ) )
{
@@ -1180,15 +1186,15 @@ sampleBuffer * sampleBuffer::resample( sampleFrame * _data,
}
#else
// no libsamplerate, so do simple cubic interpolation
for( Uint32 frame = 0; frame < dst_frames; ++frame )
for( f_cnt_t frame = 0; frame < dst_frames; ++frame )
{
const float src_frame_float = frame * (float) _src_sr / _dst_sr;
const float frac_pos = src_frame_float -
static_cast<Uint32>( src_frame_float );
const Uint32 src_frame = tLimit<Uint32>(
static_cast<Uint32>( src_frame_float ),
static_cast<f_cnt_t>( src_frame_float );
const f_cnt_t src_frame = tLimit<f_cnt_t>(
static_cast<f_cnt_t>( src_frame_float ),
1, _frames - 2 );
for( Uint8 ch = 0; ch < DEFAULT_CHANNELS; ++ch )
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
{
dst_buf[frame][ch] = cubicInterpolate(
_data[src_frame - 1][ch],
@@ -1282,8 +1288,8 @@ FLAC__StreamDecoderWriteStatus flacStreamDecoderWriteCallback(
return( FLAC__STREAM_DECODER_WRITE_STATUS_ABORT );
}
const Uint32 frames = _frame->header.blocksize;
for( Uint32 frame = 0; frame < frames; ++frame )
const f_cnt_t frames = _frame->header.blocksize;
for( f_cnt_t frame = 0; frame < frames; ++frame )
{
sampleFrame sframe = { _buffer[0][frame] /
OUTPUT_SAMPLE_MULTIPLIER,
@@ -1397,7 +1403,7 @@ void sampleBuffer::loadFromBase64( const QString & _data )
void sampleBuffer::setStartFrame( Uint32 _s )
void sampleBuffer::setStartFrame( const f_cnt_t _s )
{
// don't set this parameter while playing
m_dataMutex.lock();
@@ -1408,7 +1414,7 @@ void sampleBuffer::setStartFrame( Uint32 _s )
void sampleBuffer::setEndFrame( Uint32 _e )
void sampleBuffer::setEndFrame( const f_cnt_t _e )
{
// don't set this parameter while playing
m_dataMutex.lock();

View File

@@ -188,17 +188,18 @@ void groupBox::animate( void )
void groupBox::updatePixmap( void )
{
QColor bg_color = QApplication::palette().active().background();
QPixmap pm( size() );
pm.fill( QColor( 96, 96, 96 ) );
pm.fill( bg_color.dark( 132 ) );
QPainter p( &pm );
// outer rect
p.setPen( QColor( 64, 64, 64 ) );
p.setPen( bg_color.dark( 200 ) );
p.drawRect( 0, 0, width(), height() );
// brighter line at bottom/right
p.setPen( QColor( 160, 160, 160 ) );
p.setPen( bg_color.light( 125 ) );
p.drawLine( width() - 1, 0, width() - 1, height() - 1 );
p.drawLine( 0, height() - 1, width() - 1, height() - 1 );
@@ -206,17 +207,18 @@ void groupBox::updatePixmap( void )
p.drawPixmap( 2, 2, *s_ledBg );
// draw groupbox-titlebar
p.fillRect( 2, 2, width() - 4, 9, QColor( 30, 45, 60 ) );
p.fillRect( 2, 2, width() - 4, 9, bg_color.dark( 300 ) );
// draw line below titlebar
p.setPen( QColor( 0, 0, 0 ) );
p.setPen( bg_color.dark( 400 ) );
p.drawLine( 2 + s_ledBg->width(), 11, width() - 3, 11 );
// black inner rect
p.drawRect( 1, 1, width() - 2, height() - 2 );
p.setPen( QColor( 255, 255, 255 ) );
//p.setPen( QColor( 255, 255, 255 ) );
p.setPen( colorGroup().highlight() );
p.setFont( pointSize<7>( font() ) );
p.drawText( 22, 10, m_caption );
@@ -226,7 +228,7 @@ void groupBox::updatePixmap( void )
/* pal.setColor( QPalette::Background, QColor( 96, 96, 96 ) );*/
setPalette( pal );
#else
setPaletteBackgroundColor( QColor( 96, 96, 96 ) );
setPaletteBackgroundColor( bg_color.dark( 132 ) );
setErasePixmap( pm );
#endif
}

View File

@@ -64,7 +64,7 @@ visualizationWidget::visualizationWidget( const QPixmap & _bg, QWidget * _p,
setFixedSize( s_background.width(), s_background.height() );
const Uint32 frames = mixer::inst()->framesPerAudioBuffer();
const fpab_t frames = mixer::inst()->framesPerAudioBuffer();
m_buffer = bufferAllocator::alloc<surroundSampleFrame>( frames );
mixer::inst()->clearAudioBuffer( m_buffer, frames );
@@ -78,9 +78,9 @@ visualizationWidget::visualizationWidget( const QPixmap & _bg, QWidget * _p,
}
connect( mixer::inst(), SIGNAL( nextAudioBuffer(
const surroundSampleFrame *, Uint32 ) ),
const surroundSampleFrame *, const fpab_t ) ),
this, SLOT( setAudioBuffer(
const surroundSampleFrame *, Uint32 ) ) );
const surroundSampleFrame *, const fpab_t ) ) );
toolTip::add( this, tr( "click to enable/disable visualization of "
"master-output" ) );
@@ -97,7 +97,7 @@ visualizationWidget::~visualizationWidget()
void visualizationWidget::setAudioBuffer( const surroundSampleFrame * _ab,
Uint32 _frames )
const fpab_t _frames )
{
if( m_enabled == TRUE )
{
@@ -136,12 +136,12 @@ void visualizationWidget::paintEvent( QPaintEvent * )
float max_level = 0.0;
const Uint32 frames = mixer::inst()->framesPerAudioBuffer();
const fpab_t frames = mixer::inst()->framesPerAudioBuffer();
// analyse wave-stream for max-level
for( Uint32 frame = 0; frame < frames; ++frame )
for( fpab_t frame = 0; frame < frames; ++frame )
{
for( Uint8 chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
for( ch_cnt_t chnl = 0; chnl < SURROUND_CHANNELS; ++chnl )
{
if( tAbs<float>( m_buffer[frame][chnl] ) >
max_level )
@@ -166,7 +166,7 @@ void visualizationWidget::paintEvent( QPaintEvent * )
}
// now draw all that stuff
for( Uint32 frame = 0; frame < frames; ++frame )
for( fpab_t frame = 0; frame < frames; ++frame )
{
for( Uint8 chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
{