![]() |
Mixxx
|
00001 /**************************************************************************** 00002 encodermp3.h - mp3 encoder for mixxx 00003 ------------------- 00004 copyright : (C) 2007 by Wesley Stessens 00005 (C) 2009 by Phillip Whelan (rewritten for mp3) 00006 (C) 2010 by Tobias Rafreider (fixes for shoutcast, dynamic loading of lame_enc.dll, etc) 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef ENCODERMP3_H 00019 #define ENCODERMP3_H 00020 00021 #include <QObject> 00022 #include "defs.h" 00023 #include "configobject.h" 00024 #include "encoder.h" 00025 00027 #include <QLibrary> 00028 /* 00029 * We load the library explicitly to avoid legal issues 00030 * On Linux make sure the file libmp3lame.so is in /usr/lib. 00031 * If not use your package manager to install. 00032 * You might need to create a hard-link with ln -l if your distro names the file other than libmp3lame.so 00033 */ 00034 00035 class EngineAbstractRecord; 00036 class TrackInfoObject; 00037 00038 class EncoderMp3 : public Encoder { 00039 Q_OBJECT 00040 public: 00041 EncoderMp3(EngineAbstractRecord *engine=0); 00042 virtual ~EncoderMp3(); 00043 int initEncoder(int bitrate); 00045 void encodeBuffer(const CSAMPLE *samples, const int size); 00047 void updateMetaData(char* artist, char* title, char* album); 00049 void flush(); 00050 00051 private: 00052 void initStream(); 00053 int bufferOutGrow(int size); 00054 int bufferInGrow(int size); 00055 00056 00057 //For lame 00058 struct lame_global_struct; 00059 typedef struct lame_global_struct lame_global_flags; 00060 typedef lame_global_flags *lame_t; 00061 lame_global_flags *m_lameFlags; 00062 00063 /* MPEG modes */ 00064 typedef enum MPEG_mode_e { 00065 STEREO = 0, 00066 JOINT_STEREO, 00067 DUAL_CHANNEL, /* LAME doesn't supports this! */ 00068 MONO, 00069 NOT_SET, 00070 MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 00071 } MPEG_mode; 00072 00073 //Function pointer for lame 00074 typedef lame_global_flags* (*lame_init__)(void); 00075 typedef int (*lame_set_num_channels__)(lame_global_flags *, int); 00076 typedef int (*lame_set_in_samplerate__)(lame_global_flags *, int); 00077 typedef int (*lame_set_out_samplerate__)(lame_global_flags *, int); 00078 typedef int (*lame_set_brate__)(lame_global_flags *, int); 00079 typedef int (*lame_set_mode__)(lame_global_flags *, MPEG_mode); 00080 typedef int (*lame_set_quality__)(lame_global_flags *, int); 00081 typedef int (*lame_set_bWriteVbrTag__)(lame_global_flags *, int); 00082 typedef int (*lame_init_params__)(lame_global_flags *); 00083 typedef int (*lame_close__)(lame_global_flags *); 00084 typedef int (*lame_encode_flush__)( 00085 lame_global_flags * gfp, /* global context handle */ 00086 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 00087 int size); /* number of valid octets in this stream */ 00088 typedef int (*lame_encode_buffer_float__)( 00089 lame_global_flags* gfp, /* global context handle */ 00090 const float buffer_l [], /* PCM data for left channel */ 00091 const float buffer_r [], /* PCM data for right channel */ 00092 const int nsamples, /* number of samples per channel */ 00093 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 00094 const int mp3buf_size ); 00095 00096 lame_init__ lame_init; 00097 lame_set_num_channels__ lame_set_num_channels; 00098 lame_set_in_samplerate__ lame_set_in_samplerate; 00099 lame_set_out_samplerate__ lame_set_out_samplerate; 00100 lame_set_brate__ lame_set_brate; 00101 lame_set_mode__ lame_set_mode; 00102 lame_set_quality__ lame_set_quality; 00103 lame_set_bWriteVbrTag__ lame_set_bWriteVbrTag; 00104 lame_init_params__ lame_init_params; 00105 lame_close__ lame_close; 00106 lame_encode_flush__ lame_encode_flush; 00107 lame_encode_buffer_float__ lame_encode_buffer_float; 00108 00109 // Function pointers for ID3 Tags 00110 typedef void (*id3tag_init__)(lame_global_flags *); 00111 typedef void (*id3tag_set_title__)(lame_global_flags *, const char* title); 00112 typedef void (*id3tag_set_artist__)(lame_global_flags *, const char* artist); 00113 typedef void (*id3tag_set_album__)(lame_global_flags *, const char* album); 00114 00115 id3tag_init__ id3tag_init; 00116 id3tag_set_title__ id3tag_set_title; 00117 id3tag_set_artist__ id3tag_set_artist; 00118 id3tag_set_album__ id3tag_set_album; 00119 00120 char *m_metaDataTitle; 00121 char *m_metaDataArtist; 00122 char *m_metaDataAlbum; 00123 00124 unsigned char *m_bufferOut; 00125 int m_bufferOutSize; 00126 float *m_bufferIn[2]; 00127 int m_bufferInSize; 00128 00129 EngineAbstractRecord *m_pEngine; 00130 TrackPointer m_pMetaData; 00131 QLibrary* m_library; 00132 QFile m_mp3file; 00133 ControlObjectThread* m_samplerate; 00134 }; 00135 00136 #endif