summaryrefslogtreecommitdiffstats
path: root/krec/mp3_export
diff options
context:
space:
mode:
Diffstat (limited to 'krec/mp3_export')
-rw-r--r--krec/mp3_export/Makefile.am22
-rw-r--r--krec/mp3_export/krec_exportmp3.desktop59
-rw-r--r--krec/mp3_export/krecexport_mp3.cpp234
-rw-r--r--krec/mp3_export/krecexport_mp3.h52
4 files changed, 367 insertions, 0 deletions
diff --git a/krec/mp3_export/Makefile.am b/krec/mp3_export/Makefile.am
new file mode 100644
index 00000000..191d7db3
--- /dev/null
+++ b/krec/mp3_export/Makefile.am
@@ -0,0 +1,22 @@
+
+INCLUDES= \
+ -I$(top_builddir)/arts/gui/common \
+ -I$(top_builddir)/arts/midi \
+ -I$(top_builddir)/arts/modules/common \
+ -I$(top_builddir)/arts/modules/synth \
+ -I$(top_builddir)/arts/modules/effects \
+ -I$(top_srcdir)/arts/gui/kde \
+ -I$(top_srcdir)/arts/tools \
+ -I$(top_srcdir)/krec \
+ -I$(arts_includes) $(all_includes)
+
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = libkrecexport_mp3.la
+
+libkrecexport_mp3_la_SOURCES = krecexport_mp3.cpp
+libkrecexport_mp3_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(KDE_RPATH)
+libkrecexport_mp3_la_LIBADD = ../lib_krec_common.la $(LAME_LIBS)
+
+kde_services_DATA = krec_exportmp3.desktop
+
diff --git a/krec/mp3_export/krec_exportmp3.desktop b/krec/mp3_export/krec_exportmp3.desktop
new file mode 100644
index 00000000..18d097c5
--- /dev/null
+++ b/krec/mp3_export/krec_exportmp3.desktop
@@ -0,0 +1,59 @@
+[Desktop Entry]
+Type=Service
+Name=MP3-Export
+Name[bg]=Експортиране в MP3
+Name[bn]=এম-পি-৩ রপ্তানি
+Name[br]=Ezporzh MP3
+Name[ca]=Exportació MP3
+Name[cs]=Export do MP3
+Name[cy]=Allforio MP3
+Name[da]=MP3-Eksport
+Name[el]=Εξαγωγή MP3
+Name[eo]=MP3-Eksporto
+Name[es]=Exportador de MP3
+Name[et]=MP3-eksport
+Name[eu]=MP3-esportazioa
+Name[fa]=صادرات MP3
+Name[fi]=MP3-vienti
+Name[fr]=Exportation en MP3
+Name[ga]=Easpórtáil MP3
+Name[gl]=Exportación a MP3
+Name[he]=יצוא MP3
+Name[hi]=MP3-निर्यात
+Name[hu]=Exportálás - MP3
+Name[is]=MP3 útflutningur
+Name[it]=Esporta-MP3
+Name[ja]=MP3 エクスポート
+Name[kk]=MP3-экспорттау
+Name[km]=នាំចេញ-MP3
+Name[ko]=MP3 추출
+Name[lt]=MP3 eksportas
+Name[mk]=MP3-изнесување
+Name[nb]=MP3-eksport
+Name[ne]=MP3-निर्यात
+Name[nl]=MP3-export
+Name[nn]=MP3-eksport
+Name[pa]=MP3-ਨਿਰਯਾਤ
+Name[pl]=Eksport MP3
+Name[pt]=Exportação de MP3
+Name[pt_BR]=Exportar-MP3
+Name[ro]=Exportare MP3
+Name[ru]=Экспорт в mp3
+Name[sk]=Export do MP3
+Name[sl]=Izvoz v MP3
+Name[sr]=Извоз у MP3
+Name[sr@Latn]=Izvoz u MP3
+Name[sv]=MP3-export
+Name[ta]=MP3-ஏற்றுமதி
+Name[tg]=Содироти MP3
+Name[th]=ส่งออกเป็น MP3
+Name[tr]=MP3 Aktarımı
+Name[uk]=Експорт MP3
+Name[uz]=MP3 eksport
+Name[uz@cyrillic]=MP3 экспорт
+Name[zh_CN]=MP3-导出
+Name[zh_HK]=MP3-匯出
+Name[zh_TW]=MP3 匯出
+X-KDE-Library=libkrecexport_mp3
+ServiceTypes=KRec/exportplugin
+X-KDE-ExportSuffix=mp3,MP3
diff --git a/krec/mp3_export/krecexport_mp3.cpp b/krec/mp3_export/krecexport_mp3.cpp
new file mode 100644
index 00000000..85418688
--- /dev/null
+++ b/krec/mp3_export/krecexport_mp3.cpp
@@ -0,0 +1,234 @@
+/***************************************************************************
+ copyright : (C) 2003 by Arnold Krille
+ email : arnold@arnoldarts.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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; version 2 of the License. *
+ * *
+ ***************************************************************************/
+
+#include "krecexport_mp3.h"
+#include "krecexport_mp3.moc"
+
+#include "krecglobal.h"
+
+#include <kdebug.h>
+#include <ktempfile.h>
+#include <qfile.h>
+#include <qtimer.h>
+#include <kgenericfactory.h>
+#include <stdlib.h>
+#include <time.h>
+#include <qdatetime.h>
+#include <kmessagebox.h>
+#include <kconfig.h>
+#include <kmessagebox.h>
+
+// Error code definitions from lame.h
+static const char *lame_error[] =
+{
+ I18N_NOOP( "Unknown encoding error." ),
+ I18N_NOOP( "Buffer was too small." ),
+ I18N_NOOP( "Memory allocation problem." ),
+ I18N_NOOP( "Parameter initialisation not performed." ),
+ I18N_NOOP( "Psycho acoustic problems." ),
+ I18N_NOOP( "OGG cleanup encoding error." ),
+ I18N_NOOP( "OGG frame encoding error" )
+};
+
+K_EXPORT_COMPONENT_FACTORY( libkrecexport_mp3, KGenericFactory<KRecExport_MP3> )
+
+KRecExport_MP3 krecExportMP3( 0 );
+
+KRecExport_MP3::KRecExport_MP3( QObject* p, const char* n, const QStringList& )
+ : KRecExportItem( p,n )
+ , _file( 0 )
+ , error_occurred( false )
+ , init_done( false )
+{
+kdDebug( 60005 ) << k_funcinfo << endl;
+ registerAtGlobal( this );
+kdDebug( 60005 ) << "Registered Exports: " << KRecGlobal::the()->exportFormats() << endl;
+}
+KRecExport_MP3::~KRecExport_MP3() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+}
+
+KRecExport_MP3* KRecExport_MP3::newItem() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ return new KRecExport_MP3( 0 );
+}
+
+QStringList KRecExport_MP3::extensions() {
+ //kdDebug( 60005 ) << k_funcinfo << endl;
+ QStringList tmp;
+ tmp << "*.wav" << "*.WAV";
+ return tmp;
+}
+
+bool KRecExport_MP3::initialize( const QString &filename ) {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ if ( !_file &&
+ !( bits()!=16 && channels()!=2 &&
+ KMessageBox::warningContinueCancel( KRecGlobal::the()->mainWidget(),
+ i18n( "At this time MP3-Export only supports files in stereo and 16bit." )
+ ) == KMessageBox::Cancel
+ )
+ ) {
+ KMessageBox::information( KRecGlobal::the()->mainWidget(),
+ i18n( "Please note that this plugin takes its qualitysettings from" \
+ " the corresponding section of the Audio CDs Control Center module" \
+ " configuration. Make use" \
+ " of the Control Center to configure these settings." ),
+ i18n( "Quality Configuration" ), "qualityinfo_mp3" );
+ _file = new QFile( filename );
+ if ( _file->open( IO_Raw|IO_WriteOnly ) ) {
+ if ( ! init_done ) {
+ gfp = lame_init();
+ setLameParameters();
+ if ( write_id3 ) {
+ id3tag_init( gfp );
+ id3tag_v1_only ( gfp );
+ id3tag_set_album ( gfp, "" );
+ id3tag_set_artist ( gfp, "" );
+ id3tag_set_title ( gfp, "" );
+ id3tag_set_comment( gfp, "krec" );
+ }
+ /// Set input parameters right
+ lame_set_in_samplerate( gfp, this->samplingRate() );
+ lame_set_num_channels( gfp, this->channels() );
+ lame_init_params( gfp );
+ }
+ if ( _file->size() >= 128 )
+ _file->at( _file->size() - 128 );
+ else
+ _file->at( _file->size() );
+ } else return false;
+ return true;
+ } else return false;
+}
+bool KRecExport_MP3::process() {
+ //kdDebug( 60005 ) << k_funcinfo << running << endl;
+ if ( _file ) {
+ if ( running() ) {
+ QByteArray bytearray( 4096 );
+ emit getData( bytearray );
+ int mp3bytes = lame_encode_buffer_interleaved( gfp,
+ reinterpret_cast<short int *>( bytearray.data() ),
+ bytearray.size() >> 2, mp3buf, sizeof( mp3buf ) );
+ if ( mp3bytes > 0 )
+ _file->writeBlock( reinterpret_cast<char *>( mp3buf ), mp3bytes );
+ if ( mp3bytes < 0 && ! error_occurred ) {
+ int code = ( mp3bytes < -6 ) ? 0 : -mp3bytes;
+ KMessageBox::detailedError( 0, i18n( "MP3 encoding error." ),
+ i18n( lame_error[ code ] ) );
+ error_occurred = true;
+ }
+ QTimer::singleShot( 10, this, SLOT( process() ) );
+ }
+ return true;
+ } else return false;
+}
+bool KRecExport_MP3::finalize() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ if ( _file ) {
+ int mp3bytes = lame_encode_flush( gfp, mp3buf, sizeof( mp3buf ) );
+ if ( mp3bytes > 0 )
+ _file->writeBlock( reinterpret_cast<char *>( mp3buf ), mp3bytes );
+ if ( mp3bytes < 0 && ! error_occurred ) {
+ int code = ( mp3bytes < -6 ) ? 0 : -mp3bytes;
+ KMessageBox::detailedError( 0, i18n( "MP3 encoding error." ),
+ i18n( lame_error[ code ] ) );
+ error_occurred = true;
+ }
+ lame_close( gfp );
+
+ _file->close();
+ delete _file;
+ _file = 0;
+
+ return true;
+ } else return false;
+}
+
+// Derived from kdemultimedia/kioslave/audiocd/audiocd.cpp.
+// We use the encoding settings from kcmaudiocd.
+void KRecExport_MP3::setLameParameters() {
+ KConfig *config;
+ config = new KConfig( "kcmaudiocdrc" );
+
+ config->setGroup( "MP3" );
+
+ int quality = config->readNumEntry( "quality",2 );
+
+ if ( quality < 0 ) quality = 0;
+ if ( quality > 9 ) quality = 9;
+
+ int method = config->readNumEntry( "encmethod",0 );
+ if ( method == 0 ) {
+ // Constant Bitrate Encoding
+ lame_set_VBR( gfp, vbr_off );
+ lame_set_brate( gfp,config->readNumEntry( "cbrbitrate",160 ) );
+ lame_set_quality( gfp, quality );
+ } else {
+ // Variable Bitrate Encoding
+ if ( config->readBoolEntry( "set_vbr_avr",true ) ) {
+ lame_set_VBR( gfp,vbr_abr );
+ lame_set_VBR_mean_bitrate_kbps( gfp,
+ config->readNumEntry( "vbr_average_bitrate",0 ) );
+ } else {
+ if ( lame_get_VBR( gfp ) == vbr_off ) lame_set_VBR( gfp, vbr_default );
+ if ( config->readBoolEntry( "set_vbr_min",true ) )
+ lame_set_VBR_min_bitrate_kbps( gfp,
+ config->readNumEntry( "vbr_min_bitrate",0 ) );
+ if ( config->readBoolEntry( "vbr_min_hard",true ) )
+ lame_set_VBR_hard_min( gfp, 1 );
+ if ( config->readBoolEntry( "set_vbr_max",true ) )
+ lame_set_VBR_max_bitrate_kbps( gfp,
+ config->readNumEntry( "vbr_max_bitrate",0 ) );
+ lame_set_VBR_q( gfp, quality );
+ }
+
+ if ( config->readBoolEntry( "write_xing_tag",true ) )
+ lame_set_bWriteVbrTag( gfp, 1 );
+ }
+
+ switch ( config->readNumEntry( "mode",0 ) ) {
+ case 0: lame_set_mode( gfp, STEREO ); break;
+ case 1: lame_set_mode( gfp, JOINT_STEREO ); break;
+ case 2: lame_set_mode( gfp, DUAL_CHANNEL ); break;
+ case 3: lame_set_mode( gfp, MONO ); break;
+ default: lame_set_mode( gfp,STEREO ); break;
+ }
+
+ lame_set_copyright( gfp, config->readBoolEntry( "copyright",false ) );
+ lame_set_original( gfp, config->readBoolEntry( "original",true ) );
+ lame_set_strict_ISO( gfp, config->readBoolEntry( "iso",false ) );
+ lame_set_error_protection( gfp, config->readBoolEntry( "crc",false ) );
+
+ write_id3 = config->readBoolEntry( "id3",true );
+
+ if ( config->readBoolEntry( "enable_lowpassfilter",false ) ) {
+ lame_set_lowpassfreq( gfp,
+ config->readNumEntry( "lowpassfilter_freq",0 ) );
+ if ( config->readBoolEntry( "set_lowpassfilter_width",false ) )
+ lame_set_lowpasswidth( gfp,
+ config->readNumEntry( "lowpassfilter_width",0 ) );
+ }
+
+ if ( config->readBoolEntry( "enable_highpassfilter",false ) ) {
+ lame_set_highpassfreq( gfp,
+ config->readNumEntry( "highpassfilter_freq",0 ) );
+ if ( config->readBoolEntry( "set_highpassfilter_width",false ) )
+ lame_set_highpasswidth( gfp,
+ config->readNumEntry( "highpassfilter_width",0 ) );
+ }
+
+ delete config;
+}
+
+// vim:sw=4:ts=4
diff --git a/krec/mp3_export/krecexport_mp3.h b/krec/mp3_export/krecexport_mp3.h
new file mode 100644
index 00000000..8bf243b3
--- /dev/null
+++ b/krec/mp3_export/krecexport_mp3.h
@@ -0,0 +1,52 @@
+/***************************************************************************
+ copyright : (C) 2003 by Arnold Krille
+ email : arnold@arnoldarts.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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; version 2 of the License. *
+ * *
+ ***************************************************************************/
+
+#ifndef KREC_EXPORT_MP3_H
+#define KREC_EXPORT_MP3_H
+
+#include "krecexport_template.h"
+
+#include <lame/lame.h>
+
+class KTempFile;
+class QFile;
+
+class KRecExport_MP3 : public KRecExportItem {
+ Q_OBJECT
+public:
+ KRecExport_MP3( QObject*, const char* =0, const QStringList& =0 );
+ ~KRecExport_MP3();
+
+ KRecExport_MP3* newItem();
+
+ QStringList extensions();
+ QString exportFormat() { return QString( "Wave" ); }
+public slots:
+ bool initialize( const QString & );
+ bool process();
+ bool finalize();
+
+private:
+ QFile* _file;
+ // Lame MP3 encoder
+ void setLameParameters();
+ lame_global_flags *gfp;
+ unsigned char mp3buf[ LAME_MAXMP3BUFFER ];
+ bool error_occurred;
+ bool write_id3;
+ bool init_done;
+};
+
+#endif
+
+// vim:sw=4:ts=4