convert soft tabs to hard tabs and add a modeline

This commit is contained in:
Andrew Kelley
2009-07-16 03:30:31 -07:00
parent 2009d71015
commit c7205351c2
6 changed files with 462 additions and 452 deletions

View File

@@ -1,9 +1,9 @@
/*
* audio_file_mp3.h - Audio-device which encodes mp3-stream and writes it
* into an mp3-file. This is used for song-export.
* into an mp3-file. This is used for song-export.
*
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 2009 Andrew Kelley <superjoe30@gmail.com>
* 2009 Andrew Kelley <superjoe30@gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -69,9 +69,9 @@ public:
private:
short int rescale(float sample); // convert float flame to short int frame
short int rescale(float sample); // convert float flame to short int frame
// overloaded functions
// overloaded functions
virtual void writeBuffer( const surroundSampleFrame * _ab,
const fpp_t _frames,
float _master_gain );
@@ -80,15 +80,16 @@ private:
void finishEncoding( void );
// handle to lame
lame_global_flags *m_lgf;
LameLibrary m_lame;
// handle to lame
lame_global_flags *m_lgf;
LameLibrary m_lame;
QFile * m_outfile;
bool m_hq_mode; // true if we want really high quality
QFile * m_outfile;
bool m_hq_mode; // true if we want really high quality
} ;
#endif
/* vim: set tw=0 noexpandtab: */

View File

@@ -1,9 +1,9 @@
/*
* lame_library.h - Manages loading and unloading of lame library dynamically
*
*
*
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 2009 Andrew Kelley <superjoe30@gmail.com>
* 2009 Andrew Kelley <superjoe30@gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -34,113 +34,115 @@
#include "config_mgr.h"
class LameLibrary {
private:
// functions we'll be importing from lame
typedef lame_global_flags *lame_init_t(void);
typedef int lame_init_params_t(lame_global_flags*);
typedef const char* get_lame_version_t(void);
private:
// functions we'll be importing from lame
typedef lame_global_flags *lame_init_t(void);
typedef int lame_init_params_t(lame_global_flags*);
typedef const char* get_lame_version_t(void);
typedef int lame_encode_buffer_t (
lame_global_flags* gf,
const short int buffer_l [],
const short int buffer_r [],
const int nsamples,
unsigned char * mp3buf,
const int mp3buf_size );
typedef int lame_encode_buffer_t (
lame_global_flags* gf,
const short int buffer_l [],
const short int buffer_r [],
const int nsamples,
unsigned char * mp3buf,
const int mp3buf_size );
typedef int lame_encode_buffer_interleaved_t(
lame_global_flags* gf,
short int pcm[],
int num_samples, /* per channel */
unsigned char* mp3buf,
int mp3buf_size );
typedef int lame_encode_buffer_interleaved_t(
lame_global_flags* gf,
short int pcm[],
int num_samples, /* per channel */
unsigned char* mp3buf,
int mp3buf_size );
typedef int lame_encode_flush_t(
lame_global_flags *gf,
unsigned char* mp3buf,
int size );
typedef int lame_encode_flush_t(
lame_global_flags *gf,
unsigned char* mp3buf,
int size );
typedef int lame_close_t(lame_global_flags*);
typedef int lame_close_t(lame_global_flags*);
typedef int lame_set_in_samplerate_t(lame_global_flags*, int);
typedef int lame_set_out_samplerate_t(lame_global_flags*, int);
typedef int lame_set_num_channels_t(lame_global_flags*, int );
typedef int lame_set_quality_t(lame_global_flags*, int);
typedef int lame_set_brate_t(lame_global_flags*, int);
typedef int lame_set_VBR_t(lame_global_flags *, vbr_mode);
typedef int lame_set_VBR_q_t(lame_global_flags *, int);
typedef int lame_set_VBR_min_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_set_mode_t(lame_global_flags *, MPEG_mode);
typedef int lame_set_preset_t(lame_global_flags *, int);
typedef int lame_set_error_protection_t(lame_global_flags *, int);
typedef int lame_set_disable_reservoir_t(lame_global_flags *, int);
typedef int lame_set_padding_type_t(lame_global_flags *, Padding_type);
typedef int lame_set_bWriteVbrTag_t(lame_global_flags *, int);
typedef size_t lame_get_lametag_frame_t(const lame_global_flags *, unsigned char* buffer, size_t size);
typedef void lame_mp3_tags_fid_t(lame_global_flags *, FILE *);
typedef int lame_set_in_samplerate_t(lame_global_flags*, int);
typedef int lame_set_out_samplerate_t(lame_global_flags*, int);
typedef int lame_set_num_channels_t(lame_global_flags*, int );
typedef int lame_set_quality_t(lame_global_flags*, int);
typedef int lame_set_brate_t(lame_global_flags*, int);
typedef int lame_set_VBR_t(lame_global_flags *, vbr_mode);
typedef int lame_set_VBR_q_t(lame_global_flags *, int);
typedef int lame_set_VBR_min_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_set_mode_t(lame_global_flags *, MPEG_mode);
typedef int lame_set_preset_t(lame_global_flags *, int);
typedef int lame_set_error_protection_t(lame_global_flags *, int);
typedef int lame_set_disable_reservoir_t(lame_global_flags *, int);
typedef int lame_set_padding_type_t(lame_global_flags *, Padding_type);
typedef int lame_set_bWriteVbrTag_t(lame_global_flags *, int);
typedef size_t lame_get_lametag_frame_t(const lame_global_flags *, unsigned char* buffer, size_t size);
typedef void lame_mp3_tags_fid_t(lame_global_flags *, FILE *);
typedef int lame_set_findReplayGain_t(lame_global_flags *, int);
typedef int lame_set_VBR_quality_t(lame_global_flags *, float);
typedef int lame_set_VBR_mean_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_set_VBR_max_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_set_findReplayGain_t(lame_global_flags *, int);
typedef int lame_set_VBR_quality_t(lame_global_flags *, float);
typedef int lame_set_VBR_mean_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_set_VBR_max_bitrate_kbps_t(lame_global_flags *, int);
typedef int lame_decode_init_t(void);
typedef int lame_decode1_headers_t(unsigned char *, int, short *,
short *, mp3data_struct *);
typedef int lame_decode_headers_t(unsigned char *, int, short *,
short *, mp3data_struct *);
typedef int lame_decode_t(unsigned char *, int, short *, short *);
typedef int lame_decode_exit_t(void);
typedef int lame_decode_init_t(void);
typedef int lame_decode1_headers_t(unsigned char *, int, short *,
short *, mp3data_struct *);
typedef int lame_decode_headers_t(unsigned char *, int, short *,
short *, mp3data_struct *);
typedef int lame_decode_t(unsigned char *, int, short *, short *);
typedef int lame_decode_exit_t(void);
public:
public:
LameLibrary(); // loads lame library
~LameLibrary(); // unloads lame library
LameLibrary(); // loads lame library
~LameLibrary(); // unloads lame library
bool isLoaded(); // returns whether or not lame is correctly attached
bool isLoaded(); // returns whether or not lame is correctly attached
/* function pointers to the symbols we get from the library */
lame_init_t* lame_init;
lame_init_params_t* lame_init_params;
lame_encode_buffer_t* lame_encode_buffer;
lame_encode_buffer_interleaved_t* lame_encode_buffer_interleaved;
lame_encode_flush_t* lame_encode_flush;
lame_close_t* lame_close;
get_lame_version_t* get_lame_version;
/* function pointers to the symbols we get from the library */
lame_init_t* lame_init;
lame_init_params_t* lame_init_params;
lame_encode_buffer_t* lame_encode_buffer;
lame_encode_buffer_interleaved_t* lame_encode_buffer_interleaved;
lame_encode_flush_t* lame_encode_flush;
lame_close_t* lame_close;
get_lame_version_t* get_lame_version;
lame_set_in_samplerate_t* lame_set_in_samplerate;
lame_set_out_samplerate_t* lame_set_out_samplerate;
lame_set_num_channels_t* lame_set_num_channels;
lame_set_quality_t* lame_set_quality;
lame_set_brate_t* lame_set_brate;
lame_set_VBR_t* lame_set_VBR;
lame_set_VBR_q_t* lame_set_VBR_q;
lame_set_VBR_min_bitrate_kbps_t* lame_set_VBR_min_bitrate_kbps;
lame_set_mode_t* lame_set_mode;
lame_set_preset_t* lame_set_preset;
lame_set_error_protection_t* lame_set_error_protection;
lame_set_disable_reservoir_t *lame_set_disable_reservoir;
lame_set_padding_type_t *lame_set_padding_type;
lame_set_bWriteVbrTag_t *lame_set_bWriteVbrTag;
lame_get_lametag_frame_t *lame_get_lametag_frame;
lame_mp3_tags_fid_t *lame_mp3_tags_fid;
lame_set_findReplayGain_t *lame_set_findReplayGain;
lame_set_VBR_quality_t *lame_set_VBR_quality;
lame_set_VBR_mean_bitrate_kbps_t *lame_set_VBR_mean_bitrate_kbps;
lame_set_VBR_max_bitrate_kbps_t *lame_set_VBR_max_bitrate_kbps;
lame_set_in_samplerate_t* lame_set_in_samplerate;
lame_set_out_samplerate_t* lame_set_out_samplerate;
lame_set_num_channels_t* lame_set_num_channels;
lame_set_quality_t* lame_set_quality;
lame_set_brate_t* lame_set_brate;
lame_set_VBR_t* lame_set_VBR;
lame_set_VBR_q_t* lame_set_VBR_q;
lame_set_VBR_min_bitrate_kbps_t* lame_set_VBR_min_bitrate_kbps;
lame_set_mode_t* lame_set_mode;
lame_set_preset_t* lame_set_preset;
lame_set_error_protection_t* lame_set_error_protection;
lame_set_disable_reservoir_t *lame_set_disable_reservoir;
lame_set_padding_type_t *lame_set_padding_type;
lame_set_bWriteVbrTag_t *lame_set_bWriteVbrTag;
lame_get_lametag_frame_t *lame_get_lametag_frame;
lame_mp3_tags_fid_t *lame_mp3_tags_fid;
lame_set_findReplayGain_t *lame_set_findReplayGain;
lame_set_VBR_quality_t *lame_set_VBR_quality;
lame_set_VBR_mean_bitrate_kbps_t *lame_set_VBR_mean_bitrate_kbps;
lame_set_VBR_max_bitrate_kbps_t *lame_set_VBR_max_bitrate_kbps;
lame_decode_init_t *lame_decode_init;
lame_decode1_headers_t *lame_decode1_headers;
lame_decode_headers_t *lame_decode_headers;
lame_decode_t *lame_decode;
lame_decode_exit_t *lame_decode_exit;
lame_decode_init_t *lame_decode_init;
lame_decode1_headers_t *lame_decode1_headers;
lame_decode_headers_t *lame_decode_headers;
lame_decode_t *lame_decode;
lame_decode_exit_t *lame_decode_exit;
private:
QLibrary * m_lameLib; // lame .so file
private:
QLibrary * m_lameLib; // lame .so file
};
#endif
/* vim: set tw=0 expandtab: */

View File

@@ -222,8 +222,8 @@ private:
ch_cnt_t & _channels,
sample_rate_t & _sample_rate );
f_cnt_t decodeSampleMp3( QString & file, int_sample_t * & _buf,
ch_cnt_t & _channels, sample_rate_t & _samplerate );
f_cnt_t decodeSampleMp3( QString & file, int_sample_t * & _buf,
ch_cnt_t & _channels, sample_rate_t & _samplerate );
QString m_audioFile;
sampleFrame * m_origData;
@@ -253,3 +253,5 @@ signals:
#endif
/* vim: set tw=0 expandtab: */

View File

@@ -1,9 +1,9 @@
/*
* audo_file_mp3.cpp - audio-device which encodes mp3-stream and writes it
* into an mp3-file. This is used for song-export.
* audo_file_mp3.cpp - audio-device which encodes mp3-stream and writes it
* into an mp3-file. This is used for song-export.
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 2009 Andrew Kelley <superjoe30@gmail.com>
* 2009 Andrew Kelley <superjoe30@gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -35,16 +35,16 @@ using namespace std;
AudioFileMp3::AudioFileMp3( 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,
const int _depth, mixer * _mixer ) :
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,
const int _depth, mixer * _mixer ) :
audioFileDevice( _sample_rate, _channels, _file, _use_vbr, _nom_bitrate,
_min_bitrate, _max_bitrate, _depth, _mixer ),
m_lgf( NULL ),
m_lame( LameLibrary() ),
m_outfile( NULL ),
m_hq_mode( false )
_min_bitrate, _max_bitrate, _depth, _mixer ),
m_lgf( NULL ),
m_lame( LameLibrary() ),
m_outfile( NULL ),
m_hq_mode( false )
{
_success_ful = m_lame.isLoaded() && startEncoding();
}
@@ -55,143 +55,144 @@ AudioFileMp3::~AudioFileMp3()
{
finishEncoding();
if( m_outfile )
{
if( m_outfile->isOpen() )
m_outfile->close();
if( m_outfile )
{
if( m_outfile->isOpen() )
m_outfile->close();
delete m_outfile;
}
delete m_outfile;
}
}
void AudioFileMp3::finishEncoding( void )
{
if( m_lgf )
{
// flush
int bufSize = 7200;
unsigned char * out = new unsigned char[bufSize];
int rc = m_lame.lame_encode_flush(m_lgf, out, bufSize);
if( m_lgf )
{
// flush
int bufSize = 7200;
unsigned char * out = new unsigned char[bufSize];
int rc = m_lame.lame_encode_flush(m_lgf, out, bufSize);
if( m_outfile && m_outfile->isOpen() ){
m_outfile->write( (const char *) out, rc );
if( m_outfile && m_outfile->isOpen() ){
m_outfile->write( (const char *) out, rc );
m_outfile->close();
delete m_outfile;
m_outfile = NULL;
}
m_outfile->close();
delete m_outfile;
m_outfile = NULL;
}
// cleanup
delete[] out;
// cleanup
delete[] out;
// close any open handles we may have
m_lame.lame_close(m_lgf);
m_lgf = NULL;
}
// close any open handles we may have
m_lame.lame_close(m_lgf);
m_lgf = NULL;
}
}
bool AudioFileMp3::startEncoding( void )
{
// open any handles, files, etc
m_lgf = m_lame.lame_init();
if( m_lgf == NULL ){
printf("AudioFileMp3: Unable to initialize lame\n");
return false;
}
// open any handles, files, etc
m_lgf = m_lame.lame_init();
if( m_lgf == NULL ){
printf("AudioFileMp3: Unable to initialize lame\n");
return false;
}
if( channels() > 2 )
printf("I don't think lame can do more than 2 channels\n");
if( channels() > 2 )
printf("I don't think lame can do more than 2 channels\n");
m_lame.lame_set_in_samplerate(m_lgf, sampleRate() );
m_lame.lame_set_num_channels(m_lgf, channels() );
m_lame.lame_set_in_samplerate(m_lgf, sampleRate() );
m_lame.lame_set_num_channels(m_lgf, channels() );
if( m_hq_mode )
m_lame.lame_set_quality(m_lgf, 0); // best, very slow
else
m_lame.lame_set_quality(m_lgf, 2); // near-best, not too slow
m_lame.lame_set_mode(m_lgf, STEREO);
m_lame.lame_set_findReplayGain(m_lgf, 1); // perform ReplayGain analysis
if( m_hq_mode )
m_lame.lame_set_quality(m_lgf, 0); // best, very slow
else
m_lame.lame_set_quality(m_lgf, 2); // near-best, not too slow
m_lame.lame_set_mode(m_lgf, STEREO);
m_lame.lame_set_findReplayGain(m_lgf, 1); // perform ReplayGain analysis
if( useVBR() == 0 )
{
m_lame.lame_set_VBR(m_lgf, vbr_off);
m_lame.lame_set_brate(m_lgf, nominalBitrate() );
}
else
{
m_lame.lame_set_VBR(m_lgf, vbr_abr);
m_lame.lame_set_VBR_quality(m_lgf, 2);
m_lame.lame_set_VBR_mean_bitrate_kbps(m_lgf, nominalBitrate() );
m_lame.lame_set_VBR_min_bitrate_kbps(m_lgf, minBitrate() );
m_lame.lame_set_VBR_max_bitrate_kbps(m_lgf, maxBitrate() );
}
{
m_lame.lame_set_VBR(m_lgf, vbr_off);
m_lame.lame_set_brate(m_lgf, nominalBitrate() );
}
else
{
m_lame.lame_set_VBR(m_lgf, vbr_abr);
m_lame.lame_set_VBR_quality(m_lgf, 2);
m_lame.lame_set_VBR_mean_bitrate_kbps(m_lgf, nominalBitrate() );
m_lame.lame_set_VBR_min_bitrate_kbps(m_lgf, minBitrate() );
m_lame.lame_set_VBR_max_bitrate_kbps(m_lgf, maxBitrate() );
}
if( m_lame.lame_init_params( m_lgf ) < 0 )
return false;
if( m_lame.lame_init_params( m_lgf ) < 0 )
return false;
// open the file
m_outfile = new QFile( outputFile() );
if( ! m_outfile->open( QIODevice::WriteOnly ) )
{
printf("AudioFileMp3: unable to open file for output\n");
return false;
}
// open the file
m_outfile = new QFile( outputFile() );
if( ! m_outfile->open( QIODevice::WriteOnly ) )
{
printf("AudioFileMp3: unable to open file for output\n");
return false;
}
// write the headers and such
// TODO: add a comment "created with LMMS"
// write the headers and such
// TODO: add a comment "created with LMMS"
return true;
return true;
}
short int AudioFileMp3::rescale(float sample) {
return (qMax<float>(qMin<float>(sample, 1), -1) / 1) * std::numeric_limits<short int>::max();
return (qMax<float>(qMin<float>(sample, 1), -1) / 1)
* std::numeric_limits<short int>::max();
}
// encode data and write to file
void AudioFileMp3::writeBuffer( const surroundSampleFrame * _ab,
const fpp_t _frames, const float _master_gain )
const fpp_t _frames, const float _master_gain )
{
// encode with lame
int bufSize = 1.25 * _frames + 7200;
short int * in = new short int[_frames*2];
unsigned char * out = new unsigned char[bufSize];
// scale to short int instead of float
for(int i=0; i < _frames; ++i)
{
in[i*2] = rescale( _ab[i][0] );
in[i*2+1] = rescale( _ab[i][1] );
}
// encode with lame
int bufSize = 1.25 * _frames + 7200;
short int * in = new short int[_frames*2];
unsigned char * out = new unsigned char[bufSize];
// scale to short int instead of float
for(int i=0; i < _frames; ++i)
{
in[i*2] = rescale( _ab[i][0] );
in[i*2+1] = rescale( _ab[i][1] );
}
int rc = m_lame.lame_encode_buffer_interleaved( m_lgf, in, _frames,
out, bufSize);
int rc = m_lame.lame_encode_buffer_interleaved( m_lgf, in, _frames,
out, bufSize);
switch(rc){
case -1:
printf("AudioFileMp3: encode error: buffer too small.\n");
return;
case -2:
printf("AudioFileMp3: encode error: out of memory\n");
return;
case -3:
printf("AudioFileMp3: encode error: lame_init_params not called\n");
return;
case -4:
printf("AudioFileMp3: encode error: psycho acoustic problems\n");
return;
}
switch(rc){
case -1:
printf("AudioFileMp3: encode error: buffer too small.\n");
return;
case -2:
printf("AudioFileMp3: encode error: out of memory\n");
return;
case -3:
printf("AudioFileMp3: encode error: lame_init_params not called\n");
return;
case -4:
printf("AudioFileMp3: encode error: psycho acoustic problems\n");
return;
}
// write to file
m_outfile->write( (const char *) out, rc );
// write to file
m_outfile->write( (const char *) out, rc );
// clean up
delete[] out;
delete[] in;
// clean up
delete[] out;
delete[] in;
}
@@ -199,3 +200,4 @@ void AudioFileMp3::writeBuffer( const surroundSampleFrame * _ab,
/* vim: set tw=0 noexpandtab: */

View File

@@ -1,9 +1,9 @@
/*
* lame_library.cpp - Manages loading and unloading of lame library dynamically
*
*
*
* Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* 2009 Andrew Kelley <superjoe30@gmail.com>
* 2009 Andrew Kelley <superjoe30@gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -32,151 +32,152 @@
#include "lame_library.h"
LameLibrary::LameLibrary() :
m_lameLib( NULL )
m_lameLib( NULL )
{
// dynamically load the lame library
m_lameLib = new QLibrary(configManager::inst()->lameLibrary());
if( ! m_lameLib->load() )
{
QMessageBox::information( NULL, QObject::tr( "Unable to load LAME" ),
QObject::tr( "LMMS was unable to load Lame MP3 encoder. "
"Please make sure "
"you have Lame installed and then check your folder settings "
"and make sure you tell LMMS where libmp3lame.so.0 is." ),
QMessageBox::Ok | QMessageBox::Default );
delete m_lameLib;
m_lameLib = NULL;
}
// dynamically load the lame library
m_lameLib = new QLibrary(configManager::inst()->lameLibrary());
if( ! m_lameLib->load() )
{
QMessageBox::information( NULL, QObject::tr( "Unable to load LAME" ),
QObject::tr( "LMMS was unable to load Lame MP3 encoder. "
"Please make sure "
"you have Lame installed and then check your folder settings "
"and make sure you tell LMMS where libmp3lame.so.0 is." ),
QMessageBox::Ok | QMessageBox::Default );
delete m_lameLib;
m_lameLib = NULL;
}
// grab the functions and stuff we need
lame_init = (lame_init_t *)
m_lameLib->resolve("lame_init");
get_lame_version = (get_lame_version_t *)
m_lameLib->resolve("get_lame_version");
lame_init_params = (lame_init_params_t *)
m_lameLib->resolve("lame_init_params");
lame_encode_buffer = (lame_encode_buffer_t *)
m_lameLib->resolve("lame_encode_buffer");
lame_encode_buffer_interleaved = (lame_encode_buffer_interleaved_t *)
m_lameLib->resolve("lame_encode_buffer_interleaved");
lame_encode_flush = (lame_encode_flush_t *)
m_lameLib->resolve("lame_encode_flush");
lame_close = (lame_close_t *)
m_lameLib->resolve("lame_close");
// grab the functions and stuff we need
lame_init = (lame_init_t *)
m_lameLib->resolve("lame_init");
get_lame_version = (get_lame_version_t *)
m_lameLib->resolve("get_lame_version");
lame_init_params = (lame_init_params_t *)
m_lameLib->resolve("lame_init_params");
lame_encode_buffer = (lame_encode_buffer_t *)
m_lameLib->resolve("lame_encode_buffer");
lame_encode_buffer_interleaved = (lame_encode_buffer_interleaved_t *)
m_lameLib->resolve("lame_encode_buffer_interleaved");
lame_encode_flush = (lame_encode_flush_t *)
m_lameLib->resolve("lame_encode_flush");
lame_close = (lame_close_t *)
m_lameLib->resolve("lame_close");
lame_set_in_samplerate = (lame_set_in_samplerate_t *)
m_lameLib->resolve("lame_set_in_samplerate");
lame_set_out_samplerate = (lame_set_out_samplerate_t *)
m_lameLib->resolve("lame_set_out_samplerate");
lame_set_num_channels = (lame_set_num_channels_t *)
m_lameLib->resolve("lame_set_num_channels");
lame_set_quality = (lame_set_quality_t *)
m_lameLib->resolve("lame_set_quality");
lame_set_brate = (lame_set_brate_t *)
m_lameLib->resolve("lame_set_brate");
lame_set_VBR = (lame_set_VBR_t *)
m_lameLib->resolve("lame_set_VBR");
lame_set_VBR_q = (lame_set_VBR_q_t *)
m_lameLib->resolve("lame_set_VBR_q");
lame_set_VBR_min_bitrate_kbps = (lame_set_VBR_min_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_min_bitrate_kbps");
lame_set_mode = (lame_set_mode_t *)
m_lameLib->resolve("lame_set_mode");
lame_set_preset = (lame_set_preset_t *)
m_lameLib->resolve("lame_set_preset");
lame_set_error_protection = (lame_set_error_protection_t *)
m_lameLib->resolve("lame_set_error_protection");
lame_set_disable_reservoir = (lame_set_disable_reservoir_t *)
m_lameLib->resolve("lame_set_disable_reservoir");
lame_set_padding_type = (lame_set_padding_type_t *)
m_lameLib->resolve("lame_set_padding_type");
lame_set_bWriteVbrTag = (lame_set_bWriteVbrTag_t *)
m_lameLib->resolve("lame_set_bWriteVbrTag");
lame_set_in_samplerate = (lame_set_in_samplerate_t *)
m_lameLib->resolve("lame_set_in_samplerate");
lame_set_out_samplerate = (lame_set_out_samplerate_t *)
m_lameLib->resolve("lame_set_out_samplerate");
lame_set_num_channels = (lame_set_num_channels_t *)
m_lameLib->resolve("lame_set_num_channels");
lame_set_quality = (lame_set_quality_t *)
m_lameLib->resolve("lame_set_quality");
lame_set_brate = (lame_set_brate_t *)
m_lameLib->resolve("lame_set_brate");
lame_set_VBR = (lame_set_VBR_t *)
m_lameLib->resolve("lame_set_VBR");
lame_set_VBR_q = (lame_set_VBR_q_t *)
m_lameLib->resolve("lame_set_VBR_q");
lame_set_VBR_min_bitrate_kbps = (lame_set_VBR_min_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_min_bitrate_kbps");
lame_set_mode = (lame_set_mode_t *)
m_lameLib->resolve("lame_set_mode");
lame_set_preset = (lame_set_preset_t *)
m_lameLib->resolve("lame_set_preset");
lame_set_error_protection = (lame_set_error_protection_t *)
m_lameLib->resolve("lame_set_error_protection");
lame_set_disable_reservoir = (lame_set_disable_reservoir_t *)
m_lameLib->resolve("lame_set_disable_reservoir");
lame_set_padding_type = (lame_set_padding_type_t *)
m_lameLib->resolve("lame_set_padding_type");
lame_set_bWriteVbrTag = (lame_set_bWriteVbrTag_t *)
m_lameLib->resolve("lame_set_bWriteVbrTag");
lame_set_findReplayGain = (lame_set_findReplayGain_t *)
m_lameLib->resolve("lame_set_findReplayGain");
lame_set_VBR_quality = (lame_set_VBR_quality_t *)
m_lameLib->resolve("lame_set_VBR_quality");
lame_set_VBR_mean_bitrate_kbps = (lame_set_VBR_mean_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_mean_bitrate_kbps");
lame_set_VBR_max_bitrate_kbps = (lame_set_VBR_max_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_max_bitrate_kbps");
lame_set_findReplayGain = (lame_set_findReplayGain_t *)
m_lameLib->resolve("lame_set_findReplayGain");
lame_set_VBR_quality = (lame_set_VBR_quality_t *)
m_lameLib->resolve("lame_set_VBR_quality");
lame_set_VBR_mean_bitrate_kbps = (lame_set_VBR_mean_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_mean_bitrate_kbps");
lame_set_VBR_max_bitrate_kbps = (lame_set_VBR_max_bitrate_kbps_t *)
m_lameLib->resolve("lame_set_VBR_max_bitrate_kbps");
lame_decode_init = (lame_decode_init_t*)
m_lameLib->resolve("lame_decode_init");
lame_decode1_headers = (lame_decode1_headers_t*)
m_lameLib->resolve("lame_decode1_headers");
lame_decode_headers = (lame_decode_headers_t*)
m_lameLib->resolve("lame_decode_headers");
lame_decode = (lame_decode_t*)
m_lameLib->resolve("lame_decode");
lame_decode_exit = (lame_decode_exit_t*)
m_lameLib->resolve("lame_decode_exit");
lame_decode_init = (lame_decode_init_t*)
m_lameLib->resolve("lame_decode_init");
lame_decode1_headers = (lame_decode1_headers_t*)
m_lameLib->resolve("lame_decode1_headers");
lame_decode_headers = (lame_decode_headers_t*)
m_lameLib->resolve("lame_decode_headers");
lame_decode = (lame_decode_t*)
m_lameLib->resolve("lame_decode");
lame_decode_exit = (lame_decode_exit_t*)
m_lameLib->resolve("lame_decode_exit");
// These are optional
lame_get_lametag_frame = (lame_get_lametag_frame_t *)
m_lameLib->resolve("lame_get_lametag_frame");
lame_mp3_tags_fid = (lame_mp3_tags_fid_t *)
m_lameLib->resolve("lame_mp3_tags_fid");
// These are optional
lame_get_lametag_frame = (lame_get_lametag_frame_t *)
m_lameLib->resolve("lame_get_lametag_frame");
lame_mp3_tags_fid = (lame_mp3_tags_fid_t *)
m_lameLib->resolve("lame_mp3_tags_fid");
if (!lame_init ||
!get_lame_version ||
!lame_init_params ||
!lame_encode_buffer ||
!lame_encode_buffer_interleaved ||
!lame_encode_flush ||
!lame_close ||
!lame_set_in_samplerate ||
!lame_set_out_samplerate ||
!lame_set_num_channels ||
!lame_set_quality ||
!lame_set_brate ||
!lame_set_VBR ||
!lame_set_VBR_q ||
!lame_set_mode ||
!lame_set_preset ||
!lame_set_error_protection ||
!lame_set_disable_reservoir ||
!lame_set_padding_type ||
!lame_set_bWriteVbrTag ||
!lame_set_findReplayGain ||
!lame_set_VBR_quality ||
!lame_set_VBR_mean_bitrate_kbps ||
!lame_set_VBR_max_bitrate_kbps ||
!lame_decode_init ||
!lame_decode1_headers ||
!lame_decode_headers ||
!lame_decode ||
!lame_decode_exit)
{
// some symbols are missing
QMessageBox::information( NULL, QObject::tr( "LAME missing symbols" ),
QObject::tr( "Some symbols are missing from your Lame library. "
"Make sure you have the latest version of Lame and/or LMMS "
"installed." ), QMessageBox::Ok | QMessageBox::Default );
m_lameLib->unload();
delete m_lameLib;
m_lameLib = NULL;
}
if (!lame_init ||
!get_lame_version ||
!lame_init_params ||
!lame_encode_buffer ||
!lame_encode_buffer_interleaved ||
!lame_encode_flush ||
!lame_close ||
!lame_set_in_samplerate ||
!lame_set_out_samplerate ||
!lame_set_num_channels ||
!lame_set_quality ||
!lame_set_brate ||
!lame_set_VBR ||
!lame_set_VBR_q ||
!lame_set_mode ||
!lame_set_preset ||
!lame_set_error_protection ||
!lame_set_disable_reservoir ||
!lame_set_padding_type ||
!lame_set_bWriteVbrTag ||
!lame_set_findReplayGain ||
!lame_set_VBR_quality ||
!lame_set_VBR_mean_bitrate_kbps ||
!lame_set_VBR_max_bitrate_kbps ||
!lame_decode_init ||
!lame_decode1_headers ||
!lame_decode_headers ||
!lame_decode ||
!lame_decode_exit)
{
// some symbols are missing
QMessageBox::information( NULL, QObject::tr( "LAME missing symbols" ),
QObject::tr( "Some symbols are missing from your Lame library. "
"Make sure you have the latest version of Lame and/or LMMS "
"installed." ), QMessageBox::Ok | QMessageBox::Default );
m_lameLib->unload();
delete m_lameLib;
m_lameLib = NULL;
}
}
LameLibrary::~LameLibrary()
{
// release resources
if( m_lameLib )
{
if( m_lameLib->isLoaded() )
m_lameLib->unload();
// release resources
if( m_lameLib )
{
if( m_lameLib->isLoaded() )
m_lameLib->unload();
delete m_lameLib;
m_lameLib = NULL;
}
delete m_lameLib;
m_lameLib = NULL;
}
}
// returns whether or not lame is correctly attached
bool LameLibrary::isLoaded()
{
return m_lameLib != NULL;
return m_lameLib != NULL;
}
/* vim: set tw=0 expandtab: */

View File

@@ -194,22 +194,22 @@ void sampleBuffer::update( bool _keep_settings )
"than 100 MB" );
}
else
{
// PCM wave
if( m_frames == 0 )
m_frames = decodeSampleSF( f, buf, channels, samplerate );
{
// PCM wave
if( m_frames == 0 )
m_frames = decodeSampleSF( f, buf, channels, samplerate );
#ifdef LMMS_HAVE_OGGVORBIS
if( m_frames == 0 )
m_frames = decodeSampleOGGVorbis(f, buf, channels, samplerate);
if( m_frames == 0 )
m_frames = decodeSampleOGGVorbis(f, buf, channels, samplerate);
#endif
if( m_frames == 0 )
m_frames = decodeSampleDS( f, buf, channels, samplerate );
if( m_frames == 0 )
m_frames = decodeSampleDS( f, buf, channels, samplerate );
// MP3
if( m_frames == 0 )
m_frames = decodeSampleMp3( file, buf, channels, samplerate );
// MP3
if( m_frames == 0 )
m_frames = decodeSampleMp3( file, buf, channels, samplerate );
delete[] f;
delete[] f;
}
if( m_frames > 0 && buf != NULL )
@@ -260,15 +260,15 @@ void sampleBuffer::update( bool _keep_settings )
m_loopStartFrame = m_startFrame = 0;
m_loopEndFrame = m_endFrame = 1;
QString decoders = tr( "wav, ogg, mp3" );
QMessageBox::information( NULL,
QObject::tr( "Unrecognized audio format" ),
QObject::tr( "None of the available audio decoders "
"recognized the format you are trying to load. Try "
"converting the file to a format LMMS understands.\n\n"
"Your file: %1\n"
"Available decoders: %2\n").arg( file, decoders ),
QMessageBox::Ok | QMessageBox::Default );
QString decoders = tr( "wav, ogg, mp3" );
QMessageBox::information( NULL,
QObject::tr( "Unrecognized audio format" ),
QObject::tr( "None of the available audio decoders "
"recognized the format you are trying to load. Try "
"converting the file to a format LMMS understands.\n\n"
"Your file: %1\n"
"Available decoders: %2\n").arg( file, decoders ),
QMessageBox::Ok | QMessageBox::Default );
}
}
@@ -500,112 +500,112 @@ f_cnt_t sampleBuffer::decodeSampleOGGVorbis( const char * _f,
int lame_decode_fromfile(QFile &in, short pcm_l[], short pcm_r[],
mp3data_struct * mp3data, LameLibrary &lame)
mp3data_struct * mp3data, LameLibrary &lame)
{
int ret = 0;
size_t len = 0;
unsigned char buf[1024];
int ret = 0;
size_t len = 0;
unsigned char buf[1024];
/* first see if we still have data buffered in the decoder: */
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret != 0)
return ret;
/* first see if we still have data buffered in the decoder: */
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret != 0)
return ret;
/* read until we get a valid output frame */
while (1) {
len = in.read((char *)buf, 1024);
if (len == 0) {
/* we are done reading the file, but check for buffered data */
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret <= 0) {
//lame.lame_decode_exit(); /* release mp3decoder memory */
//return -1; /* done with file */
/* read until we get a valid output frame */
while (1) {
len = in.read((char *)buf, 1024);
if (len == 0) {
/* we are done reading the file, but check for buffered data */
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret <= 0) {
//lame.lame_decode_exit(); /* release mp3decoder memory */
//return -1; /* done with file */
return 0;
}
break;
}
return 0;
}
break;
}
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret == -1) {
lame.lame_decode_exit(); /* release mp3decoder memory */
return -1;
}
if (ret > 0)
break;
}
return ret;
ret = lame.lame_decode1_headers(buf, len, pcm_l, pcm_r, mp3data);
if (ret == -1) {
lame.lame_decode_exit(); /* release mp3decoder memory */
return -1;
}
if (ret > 0)
break;
}
return ret;
}
f_cnt_t sampleBuffer::decodeSampleMp3( QString & file, int_sample_t * & _buf,
ch_cnt_t & _channels, sample_rate_t & _samplerate )
ch_cnt_t & _channels, sample_rate_t & _samplerate )
{
// create instance of LameLibrary to decode
LameLibrary lame;
// open the file
QFile in(file);
// create instance of LameLibrary to decode
LameLibrary lame;
// open the file
QFile in(file);
if( ! in.open(QIODevice::ReadOnly) ){
printf("sampleBuffer::decodeSampleMp3: error opening %s for reading\n",
file.toStdString().c_str());
return 0;
}
if( ! in.open(QIODevice::ReadOnly) ){
printf("sampleBuffer::decodeSampleMp3: error opening %s for reading\n",
file.toStdString().c_str());
return 0;
}
// initialize lame decoder
lame.lame_decode_init();
// initialize lame decoder
lame.lame_decode_init();
short int pcm_l[1152];
short int pcm_r[1152];
mp3data_struct mp3data;
short int pcm_l[1152];
short int pcm_r[1152];
mp3data_struct mp3data;
// TODO: calc _buf size
// TODO: calc _buf size
int bufPos = 0;
bool initBuf = false;
int bufPos = 0;
bool initBuf = false;
while(1)
{
int ret = lame_decode_fromfile(in, pcm_l, pcm_r, &mp3data, lame);
if( ret == -1 ){
delete[] _buf;
printf("error decoding mp3\n");
return 0;
} else if( ret == 0 ) {
break;
}
while(1)
{
int ret = lame_decode_fromfile(in, pcm_l, pcm_r, &mp3data, lame);
if( ret == -1 ){
delete[] _buf;
printf("error decoding mp3\n");
return 0;
} else if( ret == 0 ) {
break;
}
if( ! initBuf )
{
if( mp3data.header_parsed == 0 )
{
printf("failed to parse header\n");
return 0;
}
else
{
// process header
_samplerate = mp3data.samplerate;
_channels = mp3data.stereo;
_buf = new int_sample_t[mp3data.totalframes *
mp3data.framesize * _channels];
initBuf = true;
}
}
if( ! initBuf )
{
if( mp3data.header_parsed == 0 )
{
printf("failed to parse header\n");
return 0;
}
else
{
// process header
_samplerate = mp3data.samplerate;
_channels = mp3data.stereo;
_buf = new int_sample_t[mp3data.totalframes *
mp3data.framesize * _channels];
initBuf = true;
}
}
// convert the decoded PCM into sample
for(int i = 0; i<ret; ++i)
{
_buf[bufPos++] = pcm_l[i];
if( _channels == 2 )
_buf[bufPos++] = pcm_r[i];
}
}
lame.lame_decode_exit();
// convert the decoded PCM into sample
for(int i = 0; i<ret; ++i)
{
_buf[bufPos++] = pcm_l[i];
if( _channels == 2 )
_buf[bufPos++] = pcm_r[i];
}
}
lame.lame_decode_exit();
return bufPos / _channels;
}
@@ -1327,3 +1327,5 @@ sampleBuffer::handleState::~handleState()
#endif
/* vim: set tw=0 expandtab: */