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

@@ -1,7 +1,7 @@
/*
* audio_alsa.h - device-class that implements ALSA-PCM-output
*
* 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
*
@@ -51,7 +51,7 @@ class QLineEdit;
class audioALSA : public audioDevice, public QThread
{
public:
audioALSA( Uint32 _sample_rate, bool & _success_ful );
audioALSA( const sample_rate_t _sample_rate, bool & _success_ful );
~audioALSA();
inline static QString name( void )
@@ -83,7 +83,8 @@ private:
virtual void stopProcessing( void );
virtual void run( void );
int FASTCALL setHWParams( Uint32 _sample_rate, Uint32 _channels,
int FASTCALL setHWParams( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
snd_pcm_access_t _access );
int setSWParams( void );
int FASTCALL handleError( int _err );

View File

@@ -63,7 +63,8 @@ class audioPort;
class audioDevice
{
public:
audioDevice( Uint32 _sample_rate, Uint8 _channels );
audioDevice( const sample_rate_t _sample_rate,
const ch_cnt_t _channels );
virtual ~audioDevice();
inline void lock( void )
@@ -86,12 +87,12 @@ public:
virtual void renamePort( audioPort * _port );
inline Uint32 sampleRate( void ) const
inline sample_rate_t sampleRate( void ) const
{
return( m_sampleRate );
}
Uint8 channels( void ) const
ch_cnt_t channels( void ) const
{
return( m_channels );
}
@@ -127,43 +128,45 @@ public:
protected:
// subclasses can overload this for being used in conjunction with
// subclasses can re-implement this for being used in conjunction with
// processNextBuffer()
virtual void FASTCALL writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
float _master_gain )
virtual void FASTCALL writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain )
{
}
// called by according driver for fetching new sound-data
Uint32 FASTCALL getNextBuffer( surroundSampleFrame * _ab );
fpab_t FASTCALL getNextBuffer( surroundSampleFrame * _ab );
// convert a given audio-buffer to a buffer in signed 16-bit samples
// returns num of bytes in outbuf
int FASTCALL convertToS16( surroundSampleFrame * _ab, Uint32 _frames,
float _master_gain,
outputSampleType * _output_buffer,
bool _convert_endian = FALSE );
Uint32 FASTCALL convertToS16( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain,
int_sample_t * _output_buffer,
const bool _convert_endian = FALSE );
// clear given signed-int-16-buffer
void FASTCALL clearS16Buffer( outputSampleType * _outbuf,
Uint32 _frames );
void FASTCALL clearS16Buffer( int_sample_t * _outbuf,
const fpab_t _frames );
// resample given buffer from samplerate _src_src to samplerate _dst_src
// resample given buffer from samplerate _src_sr to samplerate _dst_sr
void FASTCALL 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 );
inline void setSampleRate( Uint32 _new_sr )
inline void setSampleRate( const sample_rate_t _new_sr )
{
m_sampleRate = _new_sr;
}
private:
Uint32 m_sampleRate;
Uint8 m_channels;
sample_rate_t m_sampleRate;
ch_cnt_t m_channels;
QMutex m_devMutex;
#ifdef HAVE_SAMPLERATE_H

View File

@@ -2,7 +2,7 @@
* audio_file_device.h - 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
*
@@ -47,34 +47,40 @@
class audioFileDevice : public audioDevice
{
public:
audioFileDevice( Uint32 _sample_rate, Uint8 _channels,
const QString & _file, bool _use_vbr,
Uint16 _nom_bitrate, Uint16 _min_bitrate,
Uint16 _max_bitrate );
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 );
virtual ~audioFileDevice();
protected:
int FASTCALL writeData( const void * _data, int _len );
Sint32 FASTCALL writeData( const void * _data, Sint32 _len );
void seekToBegin( void );
inline bool useVBR( void ) const
{
return( m_useVbr );
}
inline Uint16 nominalBitrate( void ) const
inline bitrate_t nominalBitrate( void ) const
{
return( m_nomBitrate );
}
inline Uint16 minBitrate( void ) const
inline bitrate_t minBitrate( void ) const
{
return( m_minBitrate );
}
inline Uint16 maxBitrate( void ) const
inline bitrate_t maxBitrate( void ) const
{
return( m_maxBitrate );
}
inline bool outputFileOpened( void ) const
{
return( m_outputFile.isOpen() );
@@ -86,9 +92,9 @@ private:
bool m_useVbr;
Uint16 m_nomBitrate;
Uint16 m_minBitrate;
Uint16 m_maxBitrate;
bitrate_t m_nomBitrate;
bitrate_t m_minBitrate;
bitrate_t m_maxBitrate;
} ;

View File

@@ -2,7 +2,7 @@
* audio_file_ogg.h - Audio-device which encodes wave-stream and writes it
* into an OGG-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
*
@@ -42,19 +42,24 @@
class audioFileOgg : public audioFileDevice
{
public:
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 );
virtual ~audioFileOgg();
static audioFileDevice * getInst( Uint32 _sample_rate, Uint32 _channels,
bool & _success_ful,
const QString & _file,
bool _use_vbr,
Uint16 _nom_bitrate,
Uint16 _min_bitrate,
Uint16 _max_bitrate )
static audioFileDevice * getInst( 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 )
{
return( new audioFileOgg( _sample_rate, _channels, _success_ful,
_file, _use_vbr, _nom_bitrate,
@@ -63,26 +68,24 @@ public:
private:
virtual void FASTCALL writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
float _master_gain );
virtual void FASTCALL writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain );
bool startEncoding( void );
void finishEncoding( void );
inline int writePage( void );
inline Sint32 writePage( void );
int m_channels;
long m_rate;
ch_cnt_t m_channels;
sample_rate_t m_rate;
// Various bitrate/quality options
int m_managed;
int m_bitrate;
int m_minBitrate;
int m_maxBitrate;
bitrate_t m_minBitrate;
bitrate_t m_maxBitrate;
unsigned int m_serialNo;
Uint32 m_serialNo;
vorbis_comment * m_comments;

View File

@@ -2,7 +2,7 @@
* audio_file_wave.h - Audio-device which encodes wave-stream and writes it
* into an 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
*
@@ -35,29 +35,35 @@
class audioFileWave : public audioFileDevice
{
public:
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( 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 );
virtual ~audioFileWave();
static audioFileDevice * getInst( Uint32 _sample_rate, Uint32 _channels,
bool & _success_ful,
const QString & _file, bool _use_vbr,
Uint16 _nom_bitrate,
Uint16 _min_bitrate,
Uint16 _max_bitrate )
static audioFileDevice * getInst( 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 )
{
return( new audioFileWave( _sample_rate, _channels,
_success_ful, _file, _use_vbr,
_nom_bitrate, _min_bitrate,
_max_bitrate ) );
_max_bitrate ) );
}
private:
virtual void FASTCALL writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
virtual void FASTCALL writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
float _master_gain );
bool startEncoding( void );

View File

@@ -1,7 +1,7 @@
/*
* audio_oss.h - device-class that implements OSS-PCM-output
*
* 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
*
@@ -47,8 +47,8 @@ class QLineEdit;
class audioOSS : public audioDevice, public QThread
{
public:
audioOSS( Uint32 _sample_rate, bool & _success_ful );
~audioOSS();
audioOSS( const sample_rate_t _sample_rate, bool & _success_ful );
virtual ~audioOSS();
inline static QString name( void )
{

View File

@@ -1,7 +1,7 @@
/*
* audio_port.h - base-class for objects providing sound at a port
*
* Copyright (c) 2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2005-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -71,15 +71,17 @@ public:
// next effect-channel after this audio-port
// (-1 = none 0 = master)
inline fxChnl nextFxChannel( void ) const
inline fx_ch_t nextFxChannel( void ) const
{
return( m_nextFxChannel );
}
void setNextFxChannel( fxChnl _chnl )
void setNextFxChannel( const fx_ch_t _chnl )
{
m_nextFxChannel = _chnl;
}
const QString & name( void ) const
{
return( m_name );
@@ -87,6 +89,7 @@ public:
void setName( const QString & _new_name );
enum bufferUsages
{
NONE, FIRST, BOTH
@@ -97,7 +100,7 @@ private:
surroundSampleFrame * m_firstBuffer;
surroundSampleFrame * m_secondBuffer;
bool m_extOutputEnabled;
fxChnl m_nextFxChannel;
fx_ch_t m_nextFxChannel;
QString m_name;

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,12 +33,12 @@
#ifdef QT4
#include <QVector>
#include <QList>
#include <QPair>
#else
#include <qvaluevector.h>
#include <qvaluelist.h>
#include <qpair.h>
#endif
@@ -53,21 +53,21 @@ class sampleBuffer;
class audioSampleRecorder : public audioDevice
{
public:
audioSampleRecorder( Uint32 _sample_rate, Uint32 _channels,
bool & _success_ful );
~audioSampleRecorder();
audioSampleRecorder( const sample_rate_t _sample_rate,
const ch_cnt_t _channels, bool & _success_ful );
virtual ~audioSampleRecorder();
Uint32 framesRecorded( void ) const;
f_cnt_t framesRecorded( void ) const;
void FASTCALL createSampleBuffer( sampleBuffer * * _sample_buf ) const;
private:
virtual void FASTCALL writeBuffer( surroundSampleFrame * _ab,
Uint32 _frames,
float _master_gain );
virtual void FASTCALL writeBuffer( const surroundSampleFrame * _ab,
const fpab_t _frames,
const float _master_gain );
typedef vvector<QPair<sampleFrame *, Uint32> > bufferVector;
bufferVector m_buffers;
typedef vlist<QPair<sampleFrame *, fpab_t> > bufferList;
bufferList m_buffers;
} ;

View File

@@ -1,7 +1,7 @@
/*
* audio_sdl.h - device-class that performs PCM-output via SDL
*
* 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
*
@@ -51,8 +51,8 @@ class QLineEdit;
class audioSDL : public audioDevice
{
public:
audioSDL( Uint32 _sample_rate, bool & _success_ful );
~audioSDL();
audioSDL( const sample_rate_t _sample_rate, bool & _success_ful );
virtual ~audioSDL();
inline static QString name( void )
{

View File

@@ -2,9 +2,9 @@
* basic_filters.h - simple but powerful filter-class with most used filters
*
* original file by ???
* modified and enhanced by Tobias Doerffel, 2004
* modified and enhanced by Tobias Doerffel
*
* 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,9 +39,9 @@
#include "mixer.h"
#include "templates.h"
const int MOOG_VOLTAGE = 40000;
//const int MOOG_VOLTAGE = 40000;
template<Uint8 CHANNELS = DEFAULT_CHANNELS>
template<ch_cnt_t CHANNELS = DEFAULT_CHANNELS>
class basicFilters
{
public:
@@ -70,17 +70,17 @@ public:
SIMPLE_FLT_CNT ) );
}
inline basicFilters( const float _sampleRate ) :
inline basicFilters( const sample_rate_t _sample_rate ) :
m_b0a0( 0.0f ),
m_b1a0( 0.0f ),
m_b2a0( 0.0f ),
m_a1a0( 0.0f ),
m_a2a0( 0.0f ),
m_sampleRate( _sampleRate ),
m_sampleRate( 1.0f / _sample_rate ),
m_subFilter( NULL )
{
// reset in/out history
for( Uint8 _chnl = 0; _chnl < CHANNELS; ++_chnl )
for( ch_cnt_t _chnl = 0; _chnl < CHANNELS; ++_chnl )
{
// reset in/out history for simple filters
m_ou1[_chnl] = m_ou2[_chnl] = m_in1[_chnl] =
@@ -97,15 +97,15 @@ public:
delete m_subFilter;
}
inline sampleType update( sampleType _in0, Uint8 _chnl )
inline sample_t update( sample_t _in0, ch_cnt_t _chnl )
{
sampleType out;
sample_t out;
switch( m_type )
{
case MOOG:
case DOUBLE_MOOG:
{
sampleType x = _in0 - m_r*m_y4[_chnl];
sample_t x = _in0 - m_r*m_y4[_chnl];
// four cascaded onepole filters
// (bilinear transform)
@@ -207,10 +207,12 @@ public:
m_ou1[_chnl] = out;
break;
}
if( m_subFilter != NULL )
{
return( m_subFilter->update( out, _chnl ) );
}
// Clipper band limited sigmoid
return( out );
}
@@ -233,7 +235,7 @@ public:
{
m_subFilter =
new basicFilters<CHANNELS>(
m_sampleRate );
static_cast<sample_rate_t>( 1.0f / m_sampleRate ) );
}
m_subFilter->calcFilterCoeffs( MOOG, _freq,
_q );
@@ -242,7 +244,7 @@ public:
case MOOG:
{
// [ 0 - 1 ]
const float f = 2 * _freq / m_sampleRate;
const float f = 2 * _freq * m_sampleRate;
// (Empirical tunning)
m_k = 3.6f*f - 1.6f*f*f - 1;
m_p = (m_k+1)*0.5f;
@@ -256,7 +258,7 @@ public:
{
m_subFilter =
new basicFilters<CHANNELS>(
m_sampleRate );
1.0f / m_sampleRate );
}
m_subFilter->calcFilterCoeffs( MOOG2, _freq,
_q );
@@ -264,8 +266,8 @@ public:
case MOOG2:
{
const float kfc = 2 * _freq / m_sampleRate;
const float kf = _freq / m_sampleRate;
const float kfc = 2 * _freq * m_sampleRate;
const float kf = _freq * m_sampleRate;
const float kfcr = 1.8730 * ( kfc*kfc*kfc ) +
0.4955 * ( kfc*kfc ) +
0.6490 * kfc + 0.9988;
@@ -280,7 +282,7 @@ public:
default:
{
// other filters
const float omega = 2.0f * M_PI * _freq /
const float omega = 2.0f * M_PI * _freq *
m_sampleRate;
const float tsin = sinf( omega );
const float tcos = cosf( omega );
@@ -290,14 +292,14 @@ public:
//alpha = tsin*sinhf(logf(2.0f)/2.0f*q*omega/
// tsin);
//else
const float alpha = tsin / ( 2.0f * _q );
const float alpha = 0.5f * tsin / _q;
const float a0 = 1.0f / ( 1.0f+alpha );
const float a0 = 1.0f / ( 1.0f + alpha );
if( m_type == LOWPASS ||
m_type == DOUBLE_LOWPASS )
{
m_b0a0 = ((1.0f-tcos)/2.0f)*a0;
m_b0a0 = ((1.0f-tcos)*0.5f)*a0;
m_b1a0 = (1.0f-tcos)*a0;
m_b2a0 = m_b0a0;//((1.0f-tcos)/2.0f)*a0;
m_a1a0 = (-2.0f*tcos)*a0;
@@ -306,26 +308,25 @@ public:
if( m_subFilter == NULL )
{
m_subFilter =
new basicFilters<CHANNELS>( m_sampleRate );
new basicFilters<CHANNELS>( static_cast<sample_rate_t>(
1.0f / m_sampleRate ) );
}
m_subFilter->calcFilterCoeffs(
LOWPASS,
_freq,
_q );
LOWPASS, _freq, _q );
}
}
else if( m_type == HIPASS )
{
m_b0a0 = ((1.0f+tcos)/2.0f)*a0;
m_b0a0 = ((1.0f+tcos)*0.5f)*a0;
m_b1a0 = (-1.0f-tcos)*a0;
m_b2a0 = m_b0a0;//((1.0f+tcos)/2.0f)*a0;
m_a1a0 = (-2.0f*tcos)*a0;
}
else if( m_type == BANDPASS_CSG )
{
m_b0a0 = (tsin/2.0f)*a0;
m_b0a0 = tsin*0.5f*a0;
m_b1a0 = 0.0f;
m_b2a0 = (-tsin/2.0f)*a0;
m_b2a0 = -tsin*0.5f*a0;
m_a1a0 = (-2.0f*tcos)*a0;
}
else if( m_type == BANDPASS_CZPG )
@@ -364,7 +365,7 @@ private:
// coeffs for moog-filter
float m_r, m_p, m_k;
typedef sampleType frame[CHANNELS];
typedef sample_t frame[CHANNELS];
// in/out history
frame m_ou1, m_ou2, m_in1, m_in2;

View File

@@ -1,7 +1,7 @@
/*
* effect_board.h - stuff for effect-board
*
* 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
*
@@ -22,15 +22,14 @@
*
*/
#ifndef _EFFECT_BOARD_H
#define _EFFECT_BOARD_H
#include "types.h"
const int MIN_EFFECT_CHANNEL = 0;
const int MAX_EFFECT_CHANNEL = 63;
const int DEFAULT_EFFECT_CHANNEL = MIN_EFFECT_CHANNEL;
typedef Sint8 fxChnl;
const fx_ch_t MIN_EFFECT_CHANNEL = 0;
const fx_ch_t MAX_EFFECT_CHANNEL = 63;
const fx_ch_t DEFAULT_EFFECT_CHANNEL = MIN_EFFECT_CHANNEL;
#endif

View File

@@ -1,7 +1,7 @@
/*
* export.h - header which is needed 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
*
@@ -31,14 +31,14 @@
class audioFileDevice;
typedef audioFileDevice * ( * getDeviceInst)( Uint32 _sample_rate,
Uint32 _channels,
typedef audioFileDevice * ( * getDeviceInst)( const sample_rate_t _sample_rate,
const ch_cnt_t _channels,
bool & _success_ful,
const QString & _file,
bool _use_vbr,
Uint16 _nom_bitrate,
Uint16 _min_bitrate,
Uint16 _max_bitrate );
const bool _use_vbr,
const bitrate_t _nom_bitrate,
const bitrate_t _min_bitrate,
const bitrate_t _max_bitrate );
enum fileTypes

View File

@@ -61,26 +61,31 @@ class plugin;
class audioPort;
const int DEFAULT_BUFFER_SIZE = 512;
const fpab_t DEFAULT_BUFFER_SIZE = 512;
const Uint8 DEFAULT_CHANNELS = 2;
const ch_cnt_t DEFAULT_CHANNELS = 2;
const Uint8 SURROUND_CHANNELS =
const ch_cnt_t SURROUND_CHANNELS =
#ifndef DISABLE_SURROUND
4;
#else
2;
#endif
const Uint8 QUALITY_LEVELS = 2;
const Uint32 DEFAULT_QUALITY_LEVEL = 0;
const Uint32 HIGH_QUALITY_LEVEL = DEFAULT_QUALITY_LEVEL+1;
extern Uint32 SAMPLE_RATES[QUALITY_LEVELS];
const Uint32 DEFAULT_SAMPLE_RATE = 44100;
enum qualityLevels
{
DEFAULT_QUALITY_LEVEL,
HIGH_QUALITY_LEVEL,
QUALITY_LEVELS
} ;
extern sample_rate_t SAMPLE_RATES[QUALITY_LEVELS];
const sample_rate_t DEFAULT_SAMPLE_RATE = 44100;
typedef sampleType sampleFrame[DEFAULT_CHANNELS];
typedef sampleType surroundSampleFrame[SURROUND_CHANNELS];
typedef sample_t sampleFrame[DEFAULT_CHANNELS];
typedef sample_t surroundSampleFrame[SURROUND_CHANNELS];
typedef struct
{
@@ -88,10 +93,10 @@ typedef struct
} volumeVector;
const Uint32 BYTES_PER_SAMPLE = sizeof( sampleType );
const Uint32 BYTES_PER_FRAME = sizeof( sampleFrame );
const Uint32 BYTES_PER_SURROUND_FRAME = sizeof( surroundSampleFrame );
const Uint32 BYTES_PER_OUTPUT_SAMPLE = sizeof( outputSampleType );
const Uint8 BYTES_PER_SAMPLE = sizeof( sample_t );
const Uint8 BYTES_PER_INT_SAMPLE = sizeof( int_sample_t );
const Uint8 BYTES_PER_FRAME = sizeof( sampleFrame );
const Uint8 BYTES_PER_SURROUND_FRAME = sizeof( surroundSampleFrame );
const float OUTPUT_SAMPLE_MULTIPLIER = 32767.0f;
@@ -116,11 +121,13 @@ public:
}
void FASTCALL bufferToPort( sampleFrame * _buf, Uint32 _frames,
Uint32 _framesAhead,
volumeVector & _volumeVector,
audioPort * _port );
inline Uint32 framesPerAudioBuffer( void ) const
void FASTCALL bufferToPort( const sampleFrame * _buf,
const fpab_t _frames,
const fpab_t _framesAhead,
const volumeVector & _volumeVector,
audioPort * _port );
inline fpab_t framesPerAudioBuffer( void ) const
{
return( m_framesPerAudioBuffer );
}
@@ -205,7 +212,7 @@ public:
inline Uint32 sampleRate( void )
inline sample_rate_t sampleRate( void )
{
return( SAMPLE_RATES[m_qualityLevel] );
}
@@ -222,7 +229,7 @@ public:
}
static inline sampleType clip( sampleType _s )
static inline sample_t clip( const sample_t _s )
{
if( _s > 1.0f )
{
@@ -238,22 +245,31 @@ public:
void pause( void )
{
m_mixMutex.lock();
if( m_mixMutexLockLevel == 0 )
{
m_mixMutex.lock();
}
++m_mixMutexLockLevel;
}
void play( void )
{
m_mixMutex.unlock();
if( m_mixMutexLockLevel == 1 )
{
m_mixMutex.unlock();
}
--m_mixMutexLockLevel;
}
void FASTCALL clear( bool _everything = FALSE );
void FASTCALL clear( const bool _everything = FALSE );
void FASTCALL clearAudioBuffer( sampleFrame * _ab, Uint32 _frames );
void FASTCALL clearAudioBuffer( sampleFrame * _ab,
const f_cnt_t _frames );
#ifndef DISABLE_SURROUND
void FASTCALL clearAudioBuffer( surroundSampleFrame * _ab,
Uint32 _frames );
const f_cnt_t _frames );
#endif
inline bool haveNoRunningNotes( void ) const
@@ -264,13 +280,15 @@ public:
const surroundSampleFrame * renderNextBuffer( void );
public slots:
void setHighQuality( bool _hq_on = FALSE );
signals:
void sampleRateChanged( void );
void nextAudioBuffer( const surroundSampleFrame *, Uint32 _frames );
void nextAudioBuffer( const surroundSampleFrame *,
const fpab_t _frames );
private:
@@ -293,13 +311,14 @@ private:
audioDevice * tryAudioDevices( void );
midiClient * tryMIDIClients( void );
void processBuffer( surroundSampleFrame * _buf, fxChnl _fx_chnl );
void processBuffer( const surroundSampleFrame * _buf,
const fx_ch_t _fx_chnl );
vvector<audioPort *> m_audioPorts;
Uint32 m_framesPerAudioBuffer;
fpab_t m_framesPerAudioBuffer;
surroundSampleFrame * m_curBuf;
surroundSampleFrame * m_nextBuf;
@@ -309,7 +328,7 @@ private:
playHandleVector m_playHandles;
playHandleVector m_playHandlesToRemove;
Uint8 m_qualityLevel;
qualityLevels m_qualityLevel;
float m_masterGain;
@@ -323,6 +342,7 @@ private:
QMutex m_mixMutex;
Uint8 m_mixMutexLockLevel;
friend class lmmsMainWin;

View File

@@ -1,7 +1,7 @@
/*
* oscillator.h - header-file for oscillator.cpp, a 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
*
@@ -42,7 +42,8 @@
class oscillator;
typedef void ( oscillator:: * oscFuncPtr )
( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl );
( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl );
const sampleFrame ZERO_FRAME = { 0.0f, 0.0f } ;
@@ -68,14 +69,16 @@ public:
FREQ_MODULATION, AMP_MODULATION, MIX, SYNC
} ;
oscillator( modulationAlgos _modulation_algo, float _freq,
Sint16 _phase_offset, float _volume_factor,
oscillator * _m_subOsc );
inline virtual ~oscillator()
oscillator( const modulationAlgos _modulation_algo, const float _freq,
const Sint16 _phase_offset, const float _volume_factor,
oscillator * _m_subOsc ) FASTCALL;
virtual ~oscillator()
{
delete m_subOsc;
}
inline void setUserWave( const sampleFrame * _data, Uint32 _frames )
inline void setUserWave( const sampleFrame * _data,
const f_cnt_t _frames )
{
if( m_userWaveFrames > 0 )
{
@@ -88,11 +91,14 @@ public:
m_userWaveFrames = 1;
}
}
inline void update( sampleFrame * _ab, Uint32 _frames, Uint8 _chnl )
inline void update( sampleFrame * _ab, const fpab_t _frames,
const ch_cnt_t _chnl )
{
( this->*m_callUpdate )( _ab, _frames, _chnl );
}
inline void setNewFreq( float _new_freq )
inline void setNewFreq( const float _new_freq )
{
// save current state - we need it later for restoring same
// phase (otherwise we'll get clicks in the audio-stream)
@@ -101,9 +107,11 @@ public:
recalcOscCoeff( fraction( v ) );
}
static oscillator * FASTCALL createOsc( waveShapes _wave_shape,
modulationAlgos _modulation_algo, float _freq,
Sint16 _phase_offset, float _volume_factor,
static oscillator * FASTCALL createOsc( const waveShapes _wave_shape,
const modulationAlgos _modulation_algo,
const float _freq,
const Sint16 _phase_offset,
const float _volume_factor,
oscillator * _m_subOsc = NULL );
inline bool syncOk( void )
{
@@ -126,13 +134,12 @@ public:
// now follow the wave-shape-routines...
static inline sampleType sinSample( float _sample )
static inline sample_t sinSample( const float _sample )
{
return( sinf( _sample * static_cast<sampleType>( 2.0f * M_PI
) ) );
return( sinf( _sample * 2.0f * M_PI ) );
}
static inline sampleType triangleSample( float _sample )
static inline sample_t triangleSample( const float _sample )
{
const float ph = fraction( _sample );
if( ph <= 0.25f )
@@ -146,17 +153,17 @@ public:
return( ph * 4.0f - 4.0f );
}
static inline sampleType sawSample( float _sample )
static inline sample_t sawSample( const float _sample )
{
return( -1.0f + fraction( _sample ) * 2.0f );
}
static inline sampleType squareSample( float _sample )
static inline sample_t squareSample( const float _sample )
{
return( ( fraction( _sample ) > 0.5f ) ? -1.0f : 1.0f );
}
static inline sampleType moogSawSample( float _sample )
static inline sample_t moogSawSample( const float _sample )
{
const float ph = fraction( _sample );
if( ph < 0.5f )
@@ -166,7 +173,7 @@ public:
return( 1.0f - 2.0f * ph );
}
static inline sampleType expSample( float _sample )
static inline sample_t expSample( const float _sample )
{
float ph = fraction( _sample );
if( ph > 0.5f )
@@ -176,22 +183,25 @@ public:
return( -1.0f + 8.0f * ph * ph );
}
static inline sampleType noiseSample( float )
static inline sample_t noiseSample( const float )
{
return( 1.0f - 2.0f * ( ( float )rand() * ( 1.0f /
RAND_MAX ) ) );
}
static inline sampleType userWaveSample( float _sample,
const sampleFrame * _user_wave, Uint32 _user_wave_frames )
static inline sample_t userWaveSample( const float _sample,
const sampleFrame * _user_wave,
const f_cnt_t _user_wave_frames )
{
const float frame = fraction( _sample ) * _user_wave_frames;
const Uint32 f1 = static_cast<Uint32>( frame );
const Uint32 f2 = ( f1 + 1 ) % _user_wave_frames;
const f_cnt_t f1 = static_cast<f_cnt_t>( frame );
const f_cnt_t f2 = ( f1 + 1 ) % _user_wave_frames;
return( linearInterpolate( _user_wave[f1][0],
_user_wave[f2][0],
fraction( frame ) ) );
}
inline sampleType userWaveSample( float _sample )
inline sample_t userWaveSample( const float _sample )
{
return( userWaveSample( _sample, m_userWaveData,
m_userWaveFrames ) );
@@ -203,28 +213,34 @@ protected:
float m_volumeFactor;
Sint16 m_phaseOffset;
oscillator * m_subOsc;
Uint32 m_sample;
f_cnt_t m_sample;
float m_oscCoeff;
sampleFrame const * m_userWaveData;
Uint32 m_userWaveFrames;
f_cnt_t m_userWaveFrames;
oscFuncPtr m_callUpdate;
virtual void FASTCALL updateNoSub( sampleFrame * _ab, Uint32 _frames,
Uint8 _chnl ) = 0;
virtual void FASTCALL updateFM( sampleFrame * _ab, Uint32 _frames,
Uint8 _chnl ) = 0;
virtual void FASTCALL updateAM( sampleFrame * _ab, Uint32 _frames,
Uint8 _chnl ) = 0;
virtual void FASTCALL updateMix( sampleFrame * _ab, Uint32 _frames,
Uint8 _chnl ) = 0;
virtual void FASTCALL updateSync( sampleFrame * _ab, Uint32 _frames,
Uint8 _chnl ) = 0;
virtual void FASTCALL updateNoSub( sampleFrame * _ab,
const fpab_t _frames,
const ch_cnt_t _chnl ) = 0;
virtual void FASTCALL updateFM( sampleFrame * _ab,
const fpab_t _frames,
const ch_cnt_t _chnl ) = 0;
virtual void FASTCALL updateAM( sampleFrame * _ab,
const fpab_t _frames,
const ch_cnt_t _chnl ) = 0;
virtual void FASTCALL updateMix( sampleFrame * _ab,
const fpab_t _frames,
const ch_cnt_t _chnl ) = 0;
virtual void FASTCALL updateSync( sampleFrame * _ab,
const fpab_t _frames,
const ch_cnt_t _chnl ) = 0;
inline void sync( void )
{
m_sample = 0;
}
void FASTCALL recalcOscCoeff( const float _additional_phase_offset =
0.0 );

View File

@@ -71,15 +71,16 @@ public:
// base64-data out of string
sampleBuffer( const QString & _audio_file = "",
bool _is_base64_data = FALSE );
sampleBuffer( const sampleFrame * _data, Uint32 _frames );
sampleBuffer( Uint32 _frames );
sampleBuffer( const sampleFrame * _data, const f_cnt_t _frames );
sampleBuffer( const f_cnt_t _frames );
~sampleBuffer();
bool FASTCALL play( sampleFrame * _ab, Uint32 _start_frame,
Uint32 _frames =
bool FASTCALL play( sampleFrame * _ab, const f_cnt_t _start_frame,
const fpab_t _frames =
mixer::inst()->framesPerAudioBuffer(),
float _freq = BASE_FREQ, bool _looped = FALSE,
const float _freq = BASE_FREQ,
const bool _looped = FALSE,
void * * _resampling_data = NULL );
void FASTCALL drawWaves( QPainter & _p, QRect _dr,
@@ -90,17 +91,17 @@ public:
return( m_audioFile );
}
inline Uint32 startFrame( void ) const
inline f_cnt_t startFrame( void ) const
{
return( m_startFrame );
}
inline Uint32 endFrame( void ) const
inline f_cnt_t endFrame( void ) const
{
return( m_endFrame );
}
inline Uint32 frames( void ) const
inline f_cnt_t frames( void ) const
{
return( m_frames );
}
@@ -128,14 +129,14 @@ public:
static sampleBuffer * FASTCALL 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 );
static inline sampleBuffer * FASTCALL resample(
sampleBuffer * _buf,
const Uint32 _src_sr,
const Uint32 _dst_sr )
const sampleBuffer * _buf,
const sample_rate_t _src_sr,
const sample_rate_t _dst_sr )
{
return( resample( _buf->m_data, _buf->m_frames, _src_sr,
_dst_sr ) );
@@ -145,8 +146,8 @@ public:
public slots:
void setAudioFile( const QString & _audio_file );
void loadFromBase64( const QString & _data );
void setStartFrame( Uint32 _s );
void setEndFrame( Uint32 _e );
void setStartFrame( const f_cnt_t _s );
void setEndFrame( const f_cnt_t _e );
void setAmplification( float _a );
void setReversed( bool _on );
@@ -155,28 +156,31 @@ private:
void FASTCALL update( bool _keep_settings = FALSE );
#ifdef SDL_SDL_SOUND_H
Uint32 FASTCALL decodeSampleSDL( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _sample_rate );
f_cnt_t FASTCALL decodeSampleSDL( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _sample_rate );
#endif
#ifdef HAVE_SNDFILE_H
Uint32 FASTCALL decodeSampleSF( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _sample_rate );
f_cnt_t FASTCALL decodeSampleSF( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _sample_rate );
#endif
#ifdef HAVE_VORBIS_VORBISFILE_H
Uint32 FASTCALL decodeSampleOGGVorbis( const char * _f, Sint16 * & _buf,
Uint8 & _channels,
Uint32 & _sample_rate );
f_cnt_t FASTCALL decodeSampleOGGVorbis( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _sample_rate );
#endif
QString m_audioFile;
sampleFrame * m_origData;
Uint32 m_origFrames;
f_cnt_t m_origFrames;
sampleFrame * m_data;
Uint32 m_frames;
Uint32 m_startFrame;
Uint32 m_endFrame;
f_cnt_t m_frames;
f_cnt_t m_startFrame;
f_cnt_t m_endFrame;
float m_amplification;
bool m_reversed;
QMutex m_dataMutex;

View File

@@ -1,7 +1,7 @@
/*
* types.h - typedefs for common types that are used in the whole app
*
* 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
*
@@ -22,10 +22,10 @@
*
*/
#ifndef _TYPES_H
#define _TYPES_H
typedef unsigned char Uint8;
typedef signed char Sint8;
typedef unsigned short Uint16;
@@ -42,8 +42,16 @@ typedef Uint8 volume;
typedef Sint8 panning;
typedef float sampleType;
typedef Sint16 outputSampleType;
typedef float sample_t; // standard sample-type
typedef Sint16 int_sample_t; // 16-bit-int-sample
typedef Uint32 sample_rate_t; // sample-rate
typedef Uint16 fpab_t; // frames per audio-buffer (0-16384)
typedef Uint32 f_cnt_t; // standard frame-count
typedef Uint8 ch_cnt_t; // channel-count (0-SURROUND_CHANNELS)
typedef Uint16 bpm_t; // tempo (MIN_BPM to MAX_BPM)
typedef Uint16 bitrate_t; // bitrate in kbps
typedef Sint8 fx_ch_t; // FX-channel (0 to MAX_EFFECT_CHANNEL)
#endif

View File

@@ -65,7 +65,7 @@ protected:
protected slots:
void setAudioBuffer( const surroundSampleFrame * _ab, Uint32 _frames );
void setAudioBuffer( const surroundSampleFrame * _ab, const fpab_t _frames );
private:
@@ -73,7 +73,6 @@ private:
bool m_enabled;
surroundSampleFrame * m_buffer;
Uint32 m_frames;
QTimer * m_updateTimer;