LameLibrary - separated lame functionality

LameLibrary can now be easily used to access lame functionality.
This way we can use the same lame structure for SampleBuffer
This commit is contained in:
Andrew Kelley
2009-07-15 10:20:38 -07:00
parent 1eb7490185
commit 2741eb217a
5 changed files with 332 additions and 246 deletions

View File

@@ -29,16 +29,11 @@
#define _AUDIO_FILE_MP3_H
#include <QFile>
#include <QLibrary>
#include "lame_library.h"
#include "lmmsconfig.h"
#include "audio_file_device.h"
#include "lame.h"
#include <sndfile.h>
class AudioFileMp3 : public audioFileDevice
{
public:
@@ -74,58 +69,6 @@ public:
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_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_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_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);
bool initLame(QString libpath);
short int rescale(float sample); // convert float flame to short int frame
// overloaded functions
@@ -136,45 +79,14 @@ private:
bool startEncoding( void );
void finishEncoding( void );
bool m_ok; // true if we need to close the handle in finishEncoding
// handle to lame
lame_global_flags *m_lgf;
QLibrary * m_lame; // lame .so file
LameLibrary m_lame;
QFile * m_outfile;
bool m_hq_mode; // true if we want really high quality
/* 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;
} ;

132
include/lame_library.h Normal file
View File

@@ -0,0 +1,132 @@
/*
* 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>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef _LAME_LIBRARY_H_
#define _LAME_LIBRARY_H_
#include <QLibrary>
#include "lame.h"
#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);
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_flush_t(
lame_global_flags *gf,
unsigned char* mp3buf,
int size );
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_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);
public:
LameLibrary(); // loads lame library
~LameLibrary(); // unloads lame library
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;
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;
private:
QLibrary * m_lameLib; // lame .so file
};
#endif