summaryrefslogtreecommitdiffstats
path: root/krec/ogg_export
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch)
tree9047cf9e6b5c43878d5bf82660adae77ceee097a /krec/ogg_export
downloadtdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz
tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krec/ogg_export')
-rw-r--r--krec/ogg_export/Makefile.am22
-rw-r--r--krec/ogg_export/krec_exportogg.desktop60
-rw-r--r--krec/ogg_export/krecexport_ogg.cpp254
-rw-r--r--krec/ogg_export/krecexport_ogg.h63
4 files changed, 399 insertions, 0 deletions
diff --git a/krec/ogg_export/Makefile.am b/krec/ogg_export/Makefile.am
new file mode 100644
index 00000000..a54940c7
--- /dev/null
+++ b/krec/ogg_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_ogg.la
+
+libkrecexport_ogg_la_SOURCES = krecexport_ogg.cpp
+libkrecexport_ogg_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(KDE_RPATH)
+libkrecexport_ogg_la_LIBADD = ../lib_krec_common.la $(VORBISENC_LIBS) $(VORBIS_LIBS)
+
+kde_services_DATA = krec_exportogg.desktop
+
diff --git a/krec/ogg_export/krec_exportogg.desktop b/krec/ogg_export/krec_exportogg.desktop
new file mode 100644
index 00000000..5c2baf90
--- /dev/null
+++ b/krec/ogg_export/krec_exportogg.desktop
@@ -0,0 +1,60 @@
+[Desktop Entry]
+Type=Service
+Name=OGG-Export
+Name[bg]=Експортиране в OGG
+Name[bn]=অগ-রপ্তানি
+Name[br]=Ezporzh OGG
+Name[ca]=Exportació OGG
+Name[cs]=Export do OGG
+Name[cy]=Allforio OGG
+Name[da]=OGG-Eksport
+Name[el]=Εξαγωγή OGG
+Name[eo]=OGG-Eksporto
+Name[es]=Exportador de OGG
+Name[et]=OGG-eksport
+Name[eu]=OGG-esportazioa
+Name[fa]=صادرات OGG
+Name[fi]=OGG-vienti
+Name[fr]=Exportation en OGG
+Name[ga]=Easpórtáil OGG
+Name[gl]=Exportación a OGG
+Name[he]=יצוא OGG
+Name[hi]=OGG-निर्यात
+Name[hu]=Exportálás - OGG
+Name[is]=OGG útflutningur
+Name[it]=Esporta-OGG
+Name[ja]=OGG エクスポート
+Name[kk]=OGG-экспорттау
+Name[km]=នាំចេញ-OGG
+Name[ko]=OGG 추출
+Name[lt]=OGG eksportavimas
+Name[mk]=OGG-изнесување
+Name[nb]=OGG-eksport
+Name[nds]=Ogg-Export
+Name[ne]=OGG-निर्यात
+Name[nl]=OGG-export
+Name[nn]=OGG-eksport
+Name[pa]=OGG-ਨਿਰਯਾਤ
+Name[pl]=Eksport OGG
+Name[pt]=Exportação de OGG
+Name[pt_BR]=Exportar-OGG
+Name[ro]=Exportare OGG
+Name[ru]=Экспорт в ogg
+Name[sk]=Export do OGG
+Name[sl]=Izvoz v OGG
+Name[sr]=Извоз у OGG
+Name[sr@Latn]=Izvoz u OGG
+Name[sv]=Ogg-export
+Name[ta]=OGG-ஏற்றுமதி
+Name[tg]=Содироти OGG
+Name[th]=ส่งออกเป็น OGG
+Name[tr]=OGG Aktarımı
+Name[uk]=Експорт OGG
+Name[uz]=OGG eksport
+Name[uz@cyrillic]=OGG экспорт
+Name[zh_CN]=OGG 导出
+Name[zh_HK]=OGG-匯出
+Name[zh_TW]=OGG 匯出
+X-KDE-Library=libkrecexport_ogg
+ServiceTypes=KRec/exportplugin
+X-KDE-ExportSuffix=ogg,OGG
diff --git a/krec/ogg_export/krecexport_ogg.cpp b/krec/ogg_export/krecexport_ogg.cpp
new file mode 100644
index 00000000..6a5d5735
--- /dev/null
+++ b/krec/ogg_export/krecexport_ogg.cpp
@@ -0,0 +1,254 @@
+/***************************************************************************
+ 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 <config.h>
+
+#ifdef HAVE_VORBIS
+
+#include "krecexport_ogg.h"
+#include "krecexport_ogg.moc"
+
+#include "krecglobal.h"
+
+#include <kdebug.h>
+#include <ktempfile.h>
+#include <qfile.h>
+#include <qtimer.h>
+#include <kconfig.h>
+#include <stdlib.h>
+#include <time.h>
+#include <qdatetime.h>
+#include <kgenericfactory.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+K_EXPORT_COMPONENT_FACTORY( libkrecexport_ogg, KGenericFactory<KRecExport_OGG> )
+
+KRecExport_OGG krecExportOGG( 0 );
+
+KRecExport_OGG::KRecExport_OGG( QObject* p, const char* n, const QStringList& )
+ : KRecExportItem( p,n )
+ , _file( 0 )
+ , init_done( false )
+{
+kdDebug( 60005 ) << k_funcinfo << endl;
+ registerAtGlobal( this );
+kdDebug( 60005 ) << "Registered Exports: " << KRecGlobal::the()->exportFormats() << endl;
+}
+KRecExport_OGG::~KRecExport_OGG() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+}
+
+KRecExport_OGG* KRecExport_OGG::newItem() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ return new KRecExport_OGG( 0 );
+}
+
+QStringList KRecExport_OGG::extensions() {
+ //kdDebug( 60005 ) << k_funcinfo << endl;
+ QStringList tmp;
+ tmp << "*.ogg" << "*.OGG";
+ return tmp;
+}
+
+bool KRecExport_OGG::initialize( const QString &filename ) {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ if ( !_file &&
+ !( samplingRate()!=44100 && bits()!=16 && channels()!=2 &&
+ KMessageBox::warningContinueCancel( KRecGlobal::the()->mainWidget(),
+ i18n( "At this time OGG-export only supports files in 44kHz " \
+ "samplingrate, 16bit and 2 channels." )
+ ) == KMessageBox::Cancel
+ )
+ ) {
+ KMessageBox::information( KRecGlobal::the()->mainWidget(),
+ i18n( "Please note that this plugin takes its qualitysettings from" \
+ " the corresponding section of the audiocd:/ configuration. Make use" \
+ " of the Control Center to configure these settings." ),
+ i18n( "Quality Configuration" ), "qualityinfo_ogg" );
+ _file = new QFile( filename );
+ if ( _file->open( IO_Raw|IO_WriteOnly ) ) {
+ if ( ! init_done ) {
+ setOggParameters();
+ vorbis_analysis_init( &vd, &vi );
+ vorbis_block_init( &vd, &vb );
+
+ srand( time( NULL ) );
+ ogg_stream_init( &os, rand() );
+ }
+ if ( _file->size() == 0 ) {
+ ogg_packet header;
+ ogg_packet header_comm;
+ ogg_packet header_code;
+
+ vorbis_comment_init( &vc );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "kde-encoder" ),
+ const_cast<char *>( "KRec" ) );
+ if ( write_vorbis_comments ) {
+ QDateTime dt = QDateTime::currentDateTime();
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "title" ),
+ const_cast<char *>( "" ) );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "artist" ),
+ const_cast<char *>( "" ) );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "album" ),
+ const_cast<char *>( "" ) );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "genre" ),
+ const_cast<char *>( "" ) );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "tracknumber" ),
+ const_cast<char *>( "" ) );
+ vorbis_comment_add_tag ( &vc, const_cast<char *>( "date" ),
+ const_cast<char *>( dt.toString( "yyyy-MM-dd hh:mm:ss" ).utf8().data() ) );
+ }
+ vorbis_analysis_headerout( &vd, &vc, &header, &header_comm, &header_code );
+
+ ogg_stream_packetin( &os, &header );
+ ogg_stream_packetin( &os, &header_comm );
+ ogg_stream_packetin( &os, &header_code );
+
+ while ( ogg_stream_flush( &os, &og ) ) {
+ //kdDebug( 60005 ) << "Writing Ogg/Vorbis Header." << endl;
+ _file->writeBlock( reinterpret_cast<char *>( og.header ), og.header_len );
+ _file->writeBlock( reinterpret_cast<char *>( og.body ), og.body_len );
+ }
+ } else
+ _file->at( _file->size() );
+ init_done = true;
+ } else return false;
+ return true;
+ }
+ return false;
+}
+bool KRecExport_OGG::process() {
+ //kdDebug( 60005 ) << k_funcinfo << endl;
+ if ( _file ) {
+ if ( running() ) {
+ QByteArray bytearray( 4096 );
+ emit getData( bytearray );
+ float **buffer = vorbis_analysis_buffer( &vd, bytearray.size() >> 2 );
+
+ // uninterleave samples
+ unsigned int i;
+ int index = 0;
+ int16_t sample;
+ unsigned char *packet = reinterpret_cast<unsigned char *>( bytearray.data() );
+ for ( i = 0; i < ( bytearray.size() >> 2 ); i++ ) {
+ sample = packet[ index ] | ( packet[ index + 1 ] << 8 );
+ index += 2;
+ buffer[ 0 ][ i ] = sample / 32768.0;
+ sample = packet[ index ] | ( packet[ index + 1 ] << 8 );
+ index += 2;
+ buffer[ 1 ][ i ] = sample / 32768.0;
+ }
+
+ vorbis_analysis_wrote( &vd, i );
+
+ while ( vorbis_analysis_blockout( &vd, &vb ) == 1 ) {
+#if HAVE_VORBIS >= 2
+ vorbis_analysis( &vb, NULL );
+ vorbis_bitrate_addblock( &vb );
+ while ( vorbis_bitrate_flushpacket( &vd, &op ) ) {
+#else
+ // Support for very old libvorbis
+ vorbis_analysis( &vb, &op );
+ {
+#endif
+ ogg_stream_packetin( &os, &op );
+ while ( ogg_stream_pageout( &os, &og ) ) {
+ _file->writeBlock( reinterpret_cast<char *>( og.header ), og.header_len );
+ _file->writeBlock( reinterpret_cast<char *>( og.body ), og.body_len );
+ }
+ }
+ }
+ QTimer::singleShot( 10, this, SLOT( process() ) );
+ }
+ return true;
+ } else return false;
+}
+bool KRecExport_OGG::finalize() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ if ( _file ) {
+ ogg_stream_clear( &os );
+ vorbis_block_clear( &vb );
+ vorbis_dsp_clear( &vd );
+ vorbis_info_clear( &vi );
+
+ _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_OGG::setOggParameters() {
+kdDebug( 60005 ) << k_funcinfo << endl;
+ KConfig *config;
+ config = new KConfig( "kcmaudiocdrc" );
+
+ config->setGroup( "Vorbis" );
+
+ // 0 for quality, 1 for managed bitrate
+ int vorbis_encode_method = config->readNumEntry( "encmethod", 0 );
+ // default quality level of 3, to match oggenc
+ double vorbis_quality = config->readDoubleNumEntry( "quality",3.0 );
+
+ int vorbis_bitrate_lower = -1;
+ if ( config->readBoolEntry( "set_vorbis_min_bitrate",false ) )
+ vorbis_bitrate_lower = config->readNumEntry( "vorbis_min_bitrate",40 ) * 1000;
+
+ int vorbis_bitrate_upper = -1;
+ if ( config->readBoolEntry( "set_vorbis_max_bitrate",false ) )
+ vorbis_bitrate_upper = config->readNumEntry( "vorbis_max_bitrate",350 ) * 1000;
+
+ // this is such a hack!
+ int vorbis_bitrate;
+ if ( vorbis_bitrate_upper != -1 && vorbis_bitrate_lower != -1 )
+ vorbis_bitrate = 104000; // empirically determined ...?!
+ else
+ vorbis_bitrate = 160 * 1000;
+
+ int vorbis_bitrate_nominal = -1;
+ if ( config->readBoolEntry( "set_vorbis_nominal_bitrate",true ) ) {
+ vorbis_bitrate_nominal = config->readNumEntry( "vorbis_nominal_bitrate",160 ) * 1000;
+ vorbis_bitrate = vorbis_bitrate_nominal;
+ }
+
+ write_vorbis_comments = config->readBoolEntry( "vorbis_comments",true );
+
+ vorbis_info_init( &vi );
+ switch ( vorbis_encode_method ) {
+ case 0:
+ // Support very old libvorbis by simply falling through
+#if HAVE_VORBIS >= 2
+ vorbis_encode_init_vbr( &vi, 2/*this->channels()*/,
+ 44100/*this->samplingRate()*/,
+ vorbis_quality/10.0 );
+ break;
+#endif
+ case 1:
+ vorbis_encode_init( &vi, 2/*this->channels()*/,
+ 44100/*this->samplingRate()*/,
+ vorbis_bitrate_upper, vorbis_bitrate_nominal,
+ vorbis_bitrate_lower );
+ break;
+ }
+
+ delete config;
+}
+
+#endif // vorbis
+
+// vim:sw=4:ts=4
diff --git a/krec/ogg_export/krecexport_ogg.h b/krec/ogg_export/krecexport_ogg.h
new file mode 100644
index 00000000..43b79d54
--- /dev/null
+++ b/krec/ogg_export/krecexport_ogg.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ 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_OGG_H
+#define KREC_EXPORT_OGG_H
+
+#include <config.h>
+
+#ifdef HAVE_VORBIS
+
+#include "krecexport_template.h"
+
+#include <vorbis/vorbisenc.h>
+
+class KTempFile;
+class QFile;
+
+class KRecExport_OGG : public KRecExportItem {
+ Q_OBJECT
+public:
+ KRecExport_OGG( QObject*, const char* =0, const QStringList& =0 );
+ ~KRecExport_OGG();
+
+ KRecExport_OGG* newItem();
+
+ QStringList extensions();
+ QString exportFormat() { return QString( "OGG-Vorbis" ); }
+public slots:
+ bool initialize( const QString & );
+ bool process();
+ bool finalize();
+
+private:
+ QFile* _file;
+
+ bool init_done;
+
+ void setOggParameters();
+ ogg_stream_state os; // take physical pages, weld into a logical stream of packets
+ ogg_page og; // one Ogg bitstream page. Vorbis packets are inside
+ ogg_packet op; // one raw packet of data for decode
+ vorbis_info vi; // struct that stores all the static vorbis bitstream settings
+ vorbis_comment vc; // struct that stores all the user comments
+ vorbis_dsp_state vd; // central working state for the packet->PCM decoder
+ vorbis_block vb; // local working space for packet->PCM decode
+ bool write_vorbis_comments;
+};
+
+#endif
+
+#endif
+
+// vim:sw=4:ts=4