You are here: Home Radio Resources Rivendell Ogg Vorbis Patch
Document Actions

Rivendell Ogg Vorbis Patch

Click here to get the file

Size 90.2 kB - File type text/x-patch

File contents

Index: ChangeLog
===================================================================
RCS file: /home/cvs/srl/rivendell/ChangeLog,v
retrieving revision 1.1267
diff -u -B -b -w -r1.1267 ChangeLog
--- ChangeLog	18 Dec 2006 14:51:37 -0000	1.1267
+++ ChangeLog	26 Dec 2006 23:43:29 -0000
@@ -8043,3 +8043,65 @@
 2006-12-18 Fred Gleason <fredg@salemradiolabs.com>
 	* Added a 'QT_BIN' export to the 'BNV_HAVE_QT' macro in
 	'autoinclude.m4'.
+2006-12-18 Darrick Servis <darrick@dcn.org>
+        * Added support for playback and recording of OggVorbis in
+	cae/cae_alsa.cpp, cae/cae_jack.cpp and cae/cae_hpi.cpp.  Only tested
+	with jack.
+	* Added Flac and OggVorbis codings to lib/rdcae.h.
+	* Applied Stefan's patch for handling ogg vorbis energy files to
+	lib/rdcart.cpp and lib/rdcut.cpp.
+	* Tied the import and export radio buttons to their labels in
+	lib/rdimport_audio.cpp.
+	* Changed from system call to QProcess for handling rd_import_file and
+	rd_export_file in lib/rdimport_audio.cpp.  Fixes problems with filenames which need to be
+	escaped or unicoded.
+	* Modified progress bar in lib/rdimport_audio.cpp to not guesstimate
+	the percentage complete (which is usually wrong for ogg files.)
+	Instead just make things look busy.
+	* Added Flac and OggVorbis encodings to lib/rdlibrary_conf.cpp and
+	rdlogedit_conf.cpp.  
+	TODO:
+	noticied that value of RDSettings::MpegL2 is sometimes hard coded as
+	1.  I've been going on the assumption that RDSettings::Format equals
+	RDCae::AudioCodings.  So I've also changed rd_import_file and
+	rd_export_file to match these.  All in all you'll want to reset your
+	encoding values in RDAdmin so they have the proper value stored.
+	Haven't looked to see what's hard-coded in librhpi yet.  If you also
+	compare the code between rdadmin/edit_rdlibrary.cpp and
+	rdadmin/edit_decks.cpp you'll see edit_decks setting the coding to 2
+	in the database while edit_rdlibrary and edit_rdlogedit sets the
+	coding to 1 for mpeg2. scripts/rd_export_file set MpegL2 coding as 2.
+	* Added OggVorbis options to rdadmin/edit_rdlibrary.cpp,
+	rdadmin/edit_decks.cpp and rdadmin/edit_rdlogedit.cpp
+	* Fixed bug in rdcatch where "add new cart" showed no groups when
+	added "download" events in rdcatch/edit_download.cpp
+	* Added OggVorbis support for importing and exporting in
+	rdcatchd/rdcatchd.cpp
+	* Added a better default setting for encoding quality until we have a
+	gui for it.  in rdlibrary/audio_cart.cpp.
+	* Added OggVorbis support for CD ripping in rdlibrary/cdripper.cpp and
+	rdlibrary/disk_ripper.cpp
+	* Added OggVorbis recording in rdlibrary/record_cut.cpp 
+	* Added OggVorbis recording in rdlogedit/voice_tracker.cpp.  This also
+	had MpegL2 coding hard coded as 1.
+	* Added OggVorbis export support in scripts/rd_export_file.  Changed
+	MpegL2 from 1 to 2.
+	* Added OggVorbis import function in scripts/rd_import_file and
+	scripts/rd_rip_cd.
+	* Modified regexp for getting the import files extension (sed command
+	only handled ascii characters) in scripts/rd_import_file.
+	* Stefan modified utils/rdfilewrite/rdfilewrite.cpp to write energy
+	cache files for imported audio.
+2006-12-26 Darrick Servis <darrick@dcn.org>
+        * Fixed race condition in cae/cae_jack.cpp where
+	FreeJackOutputStream(stream) could delete jack_play_ring[stream] while
+	jack_play_ring[stream] is being called by JackProcess().
+	* Fixed bugs in error handling for lib/rdimport_audio.cpp.
+	* Fixed ogg playback in cae/cae_alsa.cpp.  Tested.  Recording ogg
+	doesn't work but I believe it has to do with realtime control.
+	* Added --do-energy and --in-file switches to rdfilewrite.
+	--do-energy will create the energy file for stdin.  --in-file allows
+	for testing libradio formats by being able to use rdfilewrite to copy
+	between formats libradio supports.
+	* Added option for rdfilewrite to encode ogg files.  These changes
+	stream line the import/export process for ogg files.
Index: cae/cae_alsa.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/cae/cae_alsa.cpp,v
retrieving revision 1.29
diff -u -B -b -w -r1.29 cae_alsa.cpp
--- cae/cae_alsa.cpp	13 Oct 2006 21:55:42 -0000	1.29
+++ cae/cae_alsa.cpp	26 Dec 2006 23:43:29 -0000
@@ -32,6 +32,8 @@
 
 #include <cae.h>
 
+#include <rdsettings.h>
+
 #ifdef ALSA
 //
 // Callback Variables
@@ -778,12 +780,14 @@
   }
   if((alsa_play_wave[card][*stream]->getFormatTag()!=WAVE_FORMAT_PCM)||
      (alsa_play_wave[card][*stream]->getBitsPerSample()!=16)) {
+    if (alsa_play_wave[card][*stream]->getFormatTag()!=WAVE_FORMAT_VORBIS){
     delete alsa_play_wave[card][*stream];
     alsa_play_wave[card][*stream]=NULL;
     FreeAlsaOutputStream(card,*stream);
     *stream=-1;
     return false;
   }
+  }
   alsa_output_channels[card][*stream]=
     alsa_play_wave[card][*stream]->getChannels();
   alsa_stopping[card][*stream]=false;
@@ -892,7 +896,30 @@
 {
 #ifdef ALSA
   alsa_record_wave[card][stream]=new RWaveFile(wavename);
+   switch(coding){
+      case RDSettings::Pcm16:
   alsa_record_wave[card][stream]->setFormatTag(WAVE_FORMAT_PCM);
+         break;
+      case RDSettings::OggVorbis:
+         {
+         alsa_record_wave[card][stream]->setFormatTag(WAVE_FORMAT_VORBIS);
+         // TODO: RWaveFile::createWave does not use the bitrate when recording to OggVorbis.  It 
+         // instead use a quality setting valued between -0.1 and 1.0 for vbr recording.
+         alsa_record_wave[card][stream]->setHeadBitRate(bitrate);
+         alsa_record_wave[card][stream]->setEnergyTag(1);
+         // Need a way to pass the normalization value.  
+         // Either via the LR macro or else have caed query the value from the db.
+         int rip_level = 13;
+         double normal=pow(10.0,(double)(rip_level)/20.0);
+         alsa_record_wave[card][stream]->setNormalizeLevel(1);
+         }
+         break;
+      default:
+         delete alsa_record_wave[card][stream];
+         alsa_record_wave[card][stream]=NULL;
+         return false;
+         break;
+   }
   alsa_record_wave[card][stream]->setChannels(chans);
   alsa_record_wave[card][stream]->setSamplesPerSec(samprate);
   alsa_record_wave[card][stream]->setBitsPerSample(16);
Index: cae/cae_hpi.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/cae/cae_hpi.cpp,v
retrieving revision 1.26
diff -u -B -b -w -r1.26 cae_hpi.cpp
--- cae/cae_hpi.cpp	13 Oct 2006 21:55:42 -0000	1.26
+++ cae/cae_hpi.cpp	26 Dec 2006 23:43:29 -0000
@@ -24,6 +24,7 @@
 
 #include <rddebug.h>
 
+#include <rdsettings.h>
 void MainObject::hpiInit(RDStation *station)
 {
 #ifdef HPI
@@ -163,11 +164,17 @@
   record[card][stream]->nameWave(wavename);
   record[card][stream]->setChannels(chans);
   record[card][stream]->setSamplesPerSec(samprate);
-  if(coding==0) {                 // PCM16
+  switch(coding){
+     case RDSettings::Pcm16:                 // PCM16
     record[card][stream]->setFormatTag(WAVE_FORMAT_PCM);
     record[card][stream]->setBitsPerSample(16);
-  }
-  if((coding>=1)&&(coding<=2)) {  // MPEG-1
+        record[card][stream]->setBextChunk(true);
+        record[card][stream]->setCartChunk(true);
+        record[card][stream]->setLevlChunk(true);
+        break;
+     case RDSettings::MpegL1:
+     case RDSettings::MpegL2:
+        // MPEG-1
     record[card][stream]->setFormatTag(WAVE_FORMAT_MPEG);
     record[card][stream]->setHeadLayer(coding);
     record[card][stream]->setHeadBitRate(bitrate);
@@ -185,15 +192,30 @@
 	  return false;
     }
     record[card][stream]->setHeadFlags(ACM_MPEG_ID_MPEG1);
+        record[card][stream]->setBextChunk(true);
+        record[card][stream]->setCartChunk(true);
+        record[card][stream]->setLevlChunk(true);
+        break;
+     case RDSettings::OggVorbis: //OggVorbis
+        {
+         record[card][stream]->setFormatTag(WAVE_FORMAT_VORBIS);
+         // TODO: RWaveFile::createWave does not use the bitrate when recording to OggVorbis.  It 
+         // instead use a quality setting valued between -0.1 and 1.0 for vbr recording.
+         record[card][stream]->setHeadBitRate(bitrate);
+         record[card][stream]->setEnergyTag(1);
+         // Need a way to pass the normalization value.  
+         // Either via the LR macro or else have caed query the value from the db.
+         int rip_level = 13;
+         double normal=pow(10.0,(double)(rip_level)/20.0);
+         record[card][stream]->setNormalizeLevel(1);
   }
-  if(coding>2) {
+        break;
+     default:
     delete record[card][stream];
     record[card][stream]=NULL;
     return false;
+        break;
   }
-  record[card][stream]->setBextChunk(true);
-  record[card][stream]->setCartChunk(true);
-  record[card][stream]->setLevlChunk(true);
   if(record[card][stream]->createWave()!=RHPIRecordStream::Ok) {
     delete record[card][stream];
     record[card][stream]=NULL;
Index: cae/cae_jack.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/cae/cae_jack.cpp,v
retrieving revision 1.38
diff -u -B -b -w -r1.38 cae_jack.cpp
--- cae/cae_jack.cpp	13 Oct 2006 21:55:42 -0000	1.38
+++ cae/cae_jack.cpp	26 Dec 2006 23:43:29 -0000
@@ -30,6 +30,8 @@
 #include <rprofile.h>
 
 #include <cae.h>
+#include <rdsettings.h>
+
 
 #ifdef JACK
 //
@@ -57,6 +59,8 @@
 volatile bool jack_eof[RD_MAX_STREAMS];
 volatile bool jack_recording[RD_MAX_PORTS];
 volatile bool jack_ready[RD_MAX_PORTS];
+volatile bool jack_free_play_ring[RD_MAX_STREAMS];
+volatile bool jack_free_record_ring[RD_MAX_STREAMS];
 volatile int jack_output_pos[RD_MAX_STREAMS];
 volatile unsigned jack_sample_rate;
 int jack_input_mode[RD_MAX_CARDS][RD_MAX_PORTS];
@@ -178,6 +182,11 @@
                 (2*sizeof(jack_default_audio_sample_t));
             break;
       }
+    } else if(jack_free_record_ring[i])
+    {
+       delete jack_record_ring[i];
+       jack_record_ring[i]=NULL;
+       jack_free_record_ring[i];
     }
   }
 
@@ -237,6 +246,11 @@
 	}
       }
       jack_output_pos[i]+=n;
+    } else if(jack_free_play_ring[i])
+    {
+       delete jack_play_ring[i];
+       jack_play_ring[i]=NULL;
+       jack_free_play_ring[i]=false;
     }
   }
 
@@ -313,6 +327,7 @@
 {
   for(int i=0;i<RD_MAX_PORTS;i++) {
     jack_recording[i]=false;
+    jack_free_record_ring[i]=false;
     jack_ready[i]=false;
     jack_input_volume[i]=1.0;
     jack_input_vox[i]=0.0;
@@ -332,6 +347,7 @@
   }
   for(int i=0;i<RD_MAX_STREAMS;i++) {
     jack_play_ring[i]=NULL;
+    jack_free_play_ring[i]=false;
     jack_playing[i]=false;
   }
 }
@@ -543,13 +559,18 @@
     *stream=-1;
     return false;
   }
-  if((jack_play_wave[*stream]->getFormatTag()!=WAVE_FORMAT_PCM)||
-     (jack_play_wave[*stream]->getBitsPerSample()!=16)) {
+  switch (jack_play_wave[*stream]->type()){
+     case RWaveFile::Wave:
+     case RWaveFile::Ogg:
+     case RWaveFile::Mpeg:
+        break;
+     default:
     delete jack_play_wave[*stream];
     jack_play_wave[*stream]=NULL;
     FreeJackOutputStream(*stream);
     *stream=-1;
     return false;
+        break;
   }
   jack_output_channels[*stream]=jack_play_wave[*stream]->getChannels();
   jack_stopping[*stream]=false;
@@ -574,7 +595,8 @@
   jack_play_wave[stream]->closeWave();
   delete jack_play_wave[stream];
   jack_play_wave[stream]=NULL;
-  FreeJackOutputStream(stream);
+  jack_free_play_ring[stream]=true;
+//  FreeJackOutputStream(stream);
   return true;
 #else
   return false;
@@ -656,7 +678,30 @@
 {
 #ifdef JACK
   jack_record_wave[stream]=new RWaveFile(wavename);
+   switch(coding){
+      case RDSettings::Pcm16:
   jack_record_wave[stream]->setFormatTag(WAVE_FORMAT_PCM);
+         break;
+      case RDSettings::OggVorbis:
+         {
+         jack_record_wave[stream]->setFormatTag(WAVE_FORMAT_VORBIS);
+         // TODO: RWaveFile::createWave does not use the bitrate when recording to OggVorbis.  It 
+         // instead use a quality setting valued between -0.1 and 1.0 for vbr recording.
+         jack_record_wave[stream]->setHeadBitRate(bitrate);
+         jack_record_wave[stream]->setEnergyTag(1);
+         // Need a way to pass the normalization value.  
+         // Either via the LR macro or else have caed query the value from the db.
+         int rip_level = 13;
+         double normal=pow(10.0,(double)(rip_level)/20.0);
+         jack_record_wave[stream]->setNormalizeLevel(1);
+         }
+         break;
+      default:
+    delete jack_record_wave[stream];
+    jack_record_wave[stream]=NULL;
+    return false;
+    break;
+   }
   jack_record_wave[stream]->setChannels(chans);
   jack_record_wave[stream]->setSamplesPerSec(samprate);
   jack_record_wave[stream]->setBitsPerSample(16);
@@ -674,6 +719,7 @@
     return false;
   }
   jack_input_channels[stream]=chans; 
+  jack_free_record_ring[stream]=false;
   jack_record_ring[stream]=new RRingBuffer(RINGBUFFER_SIZE);
   jack_record_ring[stream]->reset();
   jack_ready[stream]=true;
@@ -693,8 +739,7 @@
   jack_record_wave[stream]->closeWave();
   delete jack_record_wave[stream];
   jack_record_wave[stream]=NULL;
-  delete jack_record_ring[stream];
-  jack_record_ring[stream]=NULL;
+  jack_free_record_ring[stream]=true;
   return true;
 #else
   return false;
@@ -956,6 +1001,7 @@
 #ifdef JACK
   for(int i=0;i<RD_MAX_STREAMS;i++) {
     if(jack_play_ring[i]==NULL) {
+      jack_free_play_ring[i]=false;
       jack_play_ring[i]=new RRingBuffer(RINGBUFFER_SIZE);
       return i;
     }
@@ -980,6 +1026,7 @@
 
 void MainObject::EmptyJackInputStream(int stream)
 {
+   if(jack_free_record_ring) return;
 #ifdef JACK
   int n=jack_record_ring[stream]->
     read((char *)jack_sample_buffer,RINGBUFFER_SIZE)/
@@ -1017,6 +1064,7 @@
 
 void MainObject::FillJackOutputStream(int stream)
 {
+   if(jack_free_play_ring[stream]) return;
 #ifdef JACK
   int free=
     jack_play_ring[stream]->writeSpace()/sizeof(jack_default_audio_sample_t)-1;
Index: lib/rdcae.h
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdcae.h,v
retrieving revision 1.22
diff -u -B -b -w -r1.22 rdcae.h
--- lib/rdcae.h	13 Oct 2006 21:55:42 -0000	1.22
+++ lib/rdcae.h	26 Dec 2006 23:43:29 -0000
@@ -43,7 +43,7 @@
  public:
   enum ChannelMode {Normal=0,Swap=1,LeftOnly=2,RightOnly=3};
   enum SourceType {Analog=0,AesEbu=1};
-  enum AudioCoding {Pcm16=0,MpegL1=1,MpegL2=2,MpegL3=3};
+  enum AudioCoding {Pcm16=0,MpegL1=1,MpegL2=2,MpegL3=3,Flac=4,OggVorbis=5};
   RDCae(QObject *parent=0,const char *name=0);
   ~RDCae();
   void connectHost(QString hostname,Q_UINT16 hostport,QString password);
Index: lib/rdcart.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdcart.cpp,v
retrieving revision 1.47
diff -u -B -b -w -r1.47 rdcart.cpp
--- lib/rdcart.cpp	13 Oct 2006 21:55:42 -0000	1.47
+++ lib/rdcart.cpp	26 Dec 2006 23:43:29 -0000
@@ -817,6 +817,7 @@
   filename=QString().sprintf("%s/%s.%s",RD_AUDIO_ROOT,
 			     (const char *)cutname,RD_AUDIO_EXTENSION);
   unlink(filename);
+  unlink(filename+".energy");
   sql=QString().sprintf("delete from CUTS where CUT_NAME=\"%s\"",
 			(const char *)cutname);
   q=new QSqlQuery(sql);
@@ -850,6 +851,8 @@
     while(q->next()) {
       unlink((const char *)QString().sprintf("%s/%s.%s",RD_AUDIO_ROOT,
 		     (const char *)q->value(0).toString(),RD_AUDIO_EXTENSION));
+      unlink((const char *)QString().sprintf("%s/%s.%s.energy",RD_AUDIO_ROOT,
+		     (const char *)q->value(0).toString(),RD_AUDIO_EXTENSION));
     }
     delete q;
     sql=QString().sprintf("delete from CUTS where CART_NUMBER=%u",cart_number);
Index: lib/rdcut.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdcut.cpp,v
retrieving revision 1.51
diff -u -B -b -w -r1.51 rdcut.cpp
--- lib/rdcut.cpp	13 Oct 2006 21:55:42 -0000	1.51
+++ lib/rdcut.cpp	26 Dec 2006 23:43:29 -0000
@@ -847,6 +847,7 @@
 				     (const char *)cutname,
 				     RD_AUDIO_EXTENSION);
   FileCopy(srcname,destname);
+  FileCopy(srcname+".energy",destname+".energy");
 
 #endif
   return true;
Index: lib/rdimport_audio.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdimport_audio.cpp,v
retrieving revision 1.12
diff -u -B -b -w -r1.12 rdimport_audio.cpp
--- lib/rdimport_audio.cpp	20 Oct 2006 17:36:16 -0000	1.12
+++ lib/rdimport_audio.cpp	26 Dec 2006 23:43:29 -0000
@@ -45,6 +45,8 @@
 
 #include <rdimport_audio.h>
 
+#include <qprocess.h>
+
 
 RDImportAudio::RDImportAudio(QString cutname,QString *path,
 			     RDSettings *settings,bool *import_metadata,
@@ -103,15 +105,11 @@
   //
   // Input Mode Button
   //
-  import_importmode_button=new QRadioButton(this,"import_importmode_button");
+  import_importmode_button=new QRadioButton(tr("Import File"), this,"import_importmode_button");
   import_mode_group->insert(import_importmode_button);
-  import_importmode_button->setGeometry(10,10,15,15);
+  import_importmode_button->setGeometry(10,10,sizeHint().width()-40,15);
+  import_importmode_button->setFont(mode_font);
   import_importmode_button->setChecked(true);
-  import_importmode_label=
-    new QLabel(import_importmode_button,tr("Import File"),this);
-  import_importmode_label->setGeometry(30,10,sizeHint().width()-40,15);
-  import_importmode_label->setFont(mode_font);
-  import_importmode_label->setAlignment(AlignVCenter|AlignLeft);
 
   //
   // Input Filename
@@ -194,14 +192,10 @@
   //
   // Output Mode Button
   //
-  import_exportmode_button=new QRadioButton(this,"import_exportmode_button");
+  import_exportmode_button=new QRadioButton(tr("Export File"),this,"import_exportmode_button");
   import_mode_group->insert(import_exportmode_button);
-  import_exportmode_button->setGeometry(10,120,15,15);
-  import_exportmode_label=
-    new QLabel(import_exportmode_button,tr("Export File"),this);
-  import_exportmode_label->setGeometry(30,120,sizeHint().width()-40,15);
-  import_exportmode_label->setFont(mode_font);
-  import_exportmode_label->setAlignment(AlignVCenter|AlignLeft);
+  import_exportmode_button->setGeometry(10,120,sizeHint().width()-40,15);
+  import_exportmode_button->setFont(mode_font);
 
   //
   // Output Filename
@@ -335,6 +329,8 @@
 
   filenameChangedData("");
   modeClickedData(import_mode_group->selectedId());
+
+  proc = NULL;
 }
 
 
@@ -358,7 +354,6 @@
 int RDImportAudio::exec(bool enable_import,bool enable_export)
 {
   import_importmode_button->setEnabled(enable_import);
-  import_importmode_label->setEnabled(enable_import);
   import_in_filename_label->setEnabled(enable_import);
   import_in_filename_edit->setEnabled(enable_import);
   import_in_metadata_box->setEnabled(enable_import&&(import_wavedata!=NULL));
@@ -373,7 +368,6 @@
   import_channels_box->setEnabled(enable_import);
 
   import_exportmode_button->setEnabled(enable_export);
-  import_exportmode_label->setEnabled(enable_export);
 
   if(enable_export&&(!enable_import)) {
     import_exportmode_button->setChecked(true);
@@ -449,20 +443,19 @@
 
 void RDImportAudio::selectInputFileData()
 {
-  QString filename;
 
   if(import_in_filename_edit->text().isEmpty()) {
-    filename=
+    import_in_filename=
       QFileDialog::getOpenFileName(*import_path,
 				   import_file_filter,this);
   }
   else {
-    filename=
+    import_in_filename=
       QFileDialog::getOpenFileName(import_in_filename_edit->text(),
 				   import_file_filter,this);
   }
-  if(!filename.isEmpty()) {
-    import_in_filename_edit->setText(filename);
+  if(!import_in_filename.isEmpty()) {
+    import_in_filename_edit->setText(import_in_filename);
     *import_path=RGetPathPart(import_in_filename_edit->text());
   }
 }
@@ -551,28 +544,26 @@
     return;
   }
 
-  if(!QFile::exists(import_in_filename_edit->text())) {
+  if(!QFile::exists(import_in_filename)) {
     QMessageBox::warning(this,tr("Import Audio File"),
 			 tr("File does not exist!"));
     return;
   }
-  RWaveFile *wave=new RWaveFile(import_in_filename_edit->text());
+  RWaveFile *wave=new RWaveFile(import_in_filename);
   if(!wave->openWave(import_wavedata)) {
     QMessageBox::warning(this,tr("Import Audio File"),tr("Cannot open file!"));
     delete wave;
     return;
   }
-  if(wave->type()==RWaveFile::Unknown) {
-    QMessageBox::warning(this,tr("Import Audio File"),
-			 tr("Unsupported file type!"));
-    wave->closeWave();
-    delete wave;
-    return;
-  }
+
   int samplerate=wave->getSamplesPerSec();
+  switch(wave->type()){
+     case RWaveFile::Atx:
+     case RWaveFile::Tmc:
+     case RWaveFile::Wave:
   switch(wave->getFormatTag()) {
       case WAVE_FORMAT_PCM:
-	format_in=0;
+              format_in=RDSettings::Pcm16;
 	import_temp_length=wave->getSampleLength()*
 	  wave->getChannels()*(wave->getBitsPerSample()/8);
 	break;
@@ -581,11 +572,27 @@
 	format_in=wave->getHeadLayer();
 	import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
 	break;
-
-      case WAVE_FORMAT_FLAC:
-	format_in=0;
+        }
+        break;
+     case RWaveFile::Mpeg:
+        format_in=wave->getHeadLayer();
 	import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
 	break;
+     case RWaveFile::Flac:
+        format_in=RDSettings::Flac;
+        import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
+        break;
+     case RWaveFile::Ogg:
+        format_in=RDSettings::OggVorbis;
+        import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
+        break;
+     default:
+        QMessageBox::warning(this,tr("Import Audio File"),
+              tr("Unsupported file type!"));
+        wave->closeWave();
+        delete wave;
+        return;
+        break;
   }
   delete wave;
 
@@ -623,14 +630,12 @@
     }
   }
 
-  int lib_fmt=0;
   switch(import_default_settings->format()) {
       case RDSettings::Pcm16:  // PCM16
 	import_finished_length=
 	  (int)(((double)import_temp_length/2.0)*
 		(double)(import_channels_box->currentItem()+1.0)*
 		(double)import_default_settings->sampleRate()/44100.0);
-	lib_fmt=0;
 	break;
 
       case RDSettings::MpegL2:  // MPEG-1 Layer 2
@@ -638,13 +643,16 @@
 	  (int)((double)import_temp_length*
 		(double)(import_channels_box->currentItem()+1)*
 		(double)import_default_settings->bitRate()/1411200.0);
-	lib_fmt=1;
 	break;
 
       case RDSettings::MpegL1:
       case RDSettings::MpegL3:
+	break;
       case RDSettings::Flac:
+	import_finished_length=0;
+	break;
       case RDSettings::OggVorbis:
+	import_finished_length=0;
 	break;
   }
 
@@ -655,47 +663,34 @@
   import_tempwav_name=tempname+".wav";
   import_tempdat_name=tempname+".dat";
 
-  QString cmd;
+  delete proc;
+  proc = new QProcess(QString("rd_import_file"));
+
   float normal=0.0;
   if(import_normalize_box->isChecked()) {
     normal=pow(10.0,(double)(import_normalize_spin->value())/20.0);
     import_multipass=true;
-    cmd=QString().
-      sprintf("rd_import_file %6.4f %d %d %s %d %d %d %d %s/%s.%s %s %s",
-	      normal,
-	      format_in,
-	      samplerate,
-	      (const char *)RDEscapeString(import_in_filename_edit->text()),  
-	      lib_fmt,
-	      import_channels_box->currentItem()+1,
-	      import_default_settings->sampleRate(),
-	      (import_channels_box->
-	       currentItem()+1)*import_default_settings->bitRate()/1000,
-	      (const char *)RD_AUDIO_ROOT,
-	      (const char *)import_cutname,
-	      (const char *)RD_AUDIO_EXTENSION,
-	      (const char *)import_tempdat_name,
-	      (const char *)import_tempwav_name);
+    proc->addArgument(QString().sprintf("%6.4f",normal));
   }
   else {
     import_multipass=false;
-    cmd=QString().
-      sprintf("rd_import_file 0 %d %d %s %d %d %d %d %s/%s.%s %s %s",
-	      format_in,
-	      samplerate,
-	      (const char *)RDEscapeString(import_in_filename_edit->text()),
-	      lib_fmt,
-	      import_channels_box->currentItem()+1,
-	      import_default_settings->sampleRate(),
-	      (import_channels_box->
-	       currentItem()+1)*import_default_settings->bitRate()/1000,
-	      (const char *)RD_AUDIO_ROOT,
-	      (const char *)import_cutname,
-	      (const char *)RD_AUDIO_EXTENSION,
-	      (const char *)import_tempdat_name,
-	      (const char *)import_tempwav_name);
+    proc->addArgument("0");
   }
-  // printf("CMD: %s\n",(const char *)cmd);
+  
+  proc->addArgument(QString().sprintf("%d",format_in));
+  proc->addArgument(QString().sprintf("%d",samplerate));
+  proc->addArgument(import_in_filename);
+  proc->addArgument(QString().sprintf("%d",import_default_settings->format()));
+  proc->addArgument(QString().sprintf("%d",import_channels_box->currentItem()+1));
+  proc->addArgument(QString().sprintf("%d",import_default_settings->sampleRate()));
+  proc->addArgument(QString().sprintf("%d",(import_channels_box-> currentItem()+1)*import_default_settings->bitRate()/1000));
+  proc->addArgument(RDCut::pathName(import_cutname));
+  proc->addArgument(import_tempdat_name);
+  proc->addArgument(import_tempwav_name);
+  
+   connect( proc, SIGNAL(processExited()),
+                         this, SLOT(importProcessExitedSlot()) );
+  if ( proc->start() == true){
   *import_running=true;
   import_import_aborted=false;
   import_in_selector_button->setDisabled(true);
@@ -704,32 +699,25 @@
   if(import_normalize_box->isChecked()) {
     bar_temp_file.setName(import_tempwav_name);
   }
-  if((import_script_pid=fork())==0) {
-    if(system(cmd)==0) {
-      chown(RDCut::pathName(import_cutname),import_config->uid(),
-	    import_config->gid());
-      chmod(RDCut::pathName(import_cutname),
-	    S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
-    }
-    else {
-      unlink(import_dest_filename);
-    }
-    exit(0);
-  }
-  else {
     import_bar->setProgress(0);
+    if(import_finished_length)
+    {
     import_bar->setPercentageVisible(true);
     import_bar_timer->start(IMPORT_BAR_INTERVAL,true);
   }
+    else
+    {
+       import_bar->setPercentageVisible(false);
+       import_bar_timer->start(IMPORT_BAR_INTERVAL/20,true);
+    }
+  }
 }
 
 
 void RDImportAudio::ImportProgress()
 {
-  QString cuts_sql;
-  QSqlQuery *q;
-
-  if(*import_running) {
+   if(proc->isRunning()) {
+      if(import_finished_length){
     if(import_multipass) {
       import_bar->
 	setProgress((int)(50.0*((double)bar_temp_file.
@@ -744,106 +732,18 @@
     import_bar_timer->start(IMPORT_BAR_INTERVAL,true);
   }
   else {
-    import_bar->setPercentageVisible(false);
-    import_bar->reset();
-    RDCut *cut=new RDCut(import_cutname);
-    cut->reset();
-    cut->setOriginName(import_station->name());
-    if(import_autotrim_box->isChecked()) {
-      AutoTrim();
+         static bool reverse_progress=false;
+         int currentPos = import_bar->progress();
+         if(currentPos == import_bar->totalSteps())
+            reverse_progress=true;
+         else if(currentPos == 0)
+            reverse_progress=false;
+         if(reverse_progress)
+            import_bar->setProgress(--currentPos);
+         else 
+            import_bar->setProgress(++currentPos);
+         import_bar_timer->start(IMPORT_BAR_INTERVAL/20,true);
     }
-
-    //
-    // Update Metadata
-    //
-    if(import_wavedata!=NULL) {
-      if(import_wavedata->title().isEmpty()) {
-	import_wavedata->
-	  setTitle(QString().sprintf("Imported from %s",
-				     (const char *)RGetBasePart(import_in_filename_edit->text())));
-      }
-      if(import_in_metadata_box->isChecked()&&import_wavedata->metadataFound()) {
-	cuts_sql="update CUTS set ";
-	cuts_sql+=QString().sprintf("DESCRIPTION=\"%s\",",
-				    (const char *)import_wavedata->title());
-	if(!import_wavedata->outCue().isEmpty()) {
-	  cuts_sql+=QString().sprintf("OUTCUE=\"%s\",",
-				      (const char *)import_wavedata->outCue());
-	}
-	else {
-	  switch(import_wavedata->endType()) {
-	      case RWaveData::FadeEnd:
-		cuts_sql+="OUTCUE=\"[music fades]\",";
-		break;
-		
-	      case RWaveData::ColdEnd:
-		cuts_sql+="OUTCUE=\"[music ends cold]\",";
-		break;
-		
-	      case RWaveData::UnknownEnd:
-		break;
-	  }
-	}
-	if(!import_wavedata->isrc().isEmpty()) {
-	  cuts_sql+=QString().sprintf("ISRC=\"%s\",",
-				      (const char *)import_wavedata->isrc());
-	}
-	if(import_wavedata->introLength()>0) {
-	  cuts_sql+=QString().sprintf("TALK_START_POINT=%d,TALK_END_POINT=%d,",
-				      cut->startPoint(),
-				      import_wavedata->introLength());
-	}
-	if(import_wavedata->segueLength()>0) {
-	  cuts_sql+=QString().sprintf("SEGUE_START_POINT=%d,SEGUE_END_POINT=%d,",
-				      import_wavedata->segueLength(),
-				      cut->endPoint());
-	}
-	if((!import_wavedata->startDate().isNull())&&
-	   (!import_wavedata->startTime().isNull())) {
-	  cuts_sql+=QString().sprintf("START_DATETIME=\"%s %s\",",
-				      (const char *)import_wavedata->startDate().
-				      toString("yyyy-MM-dd"),
-				      (const char *)import_wavedata->startTime().
-				      toString("hh:mm:ss"));
-	}
-	if((!import_wavedata->endDate().isNull())&&
-	   (!import_wavedata->endTime().isNull())) {
-	  cuts_sql+=QString().sprintf("END_DATETIME=\"%s %s\",",
-				      (const char *)import_wavedata->endDate().
-				      toString("yyyy-MM-dd"),
-				      (const char *)import_wavedata->endTime().
-				      toString("hh:mm:ss"));
-	}
-	cuts_sql=cuts_sql.left(cuts_sql.length()-1);
-	cuts_sql+=QString().
-	  sprintf(" where CUT_NAME=\"%s\"",(const char *)import_cutname);
-	q=new QSqlQuery(cuts_sql);
-	delete q;
-      }
-      delete cut;
-    }
-    if(QFile::exists(import_dest_filename)) {
-      import_in_selector_button->setEnabled(import_wavedata!=NULL);
-      import_import_button->setEnabled(true);
-      import_cancel_button->setEnabled(true);
-      QMessageBox::information(this,tr("Import Complete"),
-			       tr("Import complete!"));
-    }
-    else {
-      if(import_import_aborted) {
-	QMessageBox::information(this,tr("Import Aborted"),
-				 tr("The import has been aborted."));
-      }
-      else {
-	QMessageBox::warning(this,tr("Import Failed"),
-			     tr("The importer encountered an error.\n\
-Please check your importer configuration and try again."));
-      }
-    }
-    *import_import_metadata=import_in_metadata_box->isChecked();
-    unlink(import_tempwav_name);
-    unlink(import_tempdat_name);
-    done(0);
   }
 }
 
@@ -871,17 +771,15 @@
     delete wave;
     return;
   }
-  if(wave->type()==RWaveFile::Unknown) {
-    QMessageBox::warning(this,tr("File Error"),
-			 tr("Unsupported file type in archive!"));
-    wave->closeWave();
-    delete wave;
-    return;
-  }
-  int samplerate=wave->getSamplesPerSec();
+   //enum Type {Unknown=0,Wave=1,Mpeg=2,Ogg=3,Atx=4,Tmc=5,Flac=6};
+   // Guesstimate infile decoded length.
+   switch(wave->type()){
+      case RWaveFile::Wave:
+      case RWaveFile::Atx:
+      case RWaveFile::Tmc:
   switch(wave->getFormatTag()) {
       case WAVE_FORMAT_PCM:
-	format_in=0;
+               format_in=RDSettings::Pcm16;
 	import_temp_length=wave->getSampleLength()*
 	  wave->getChannels()*(wave->getBitsPerSample()/8);
 	break;
@@ -891,6 +789,29 @@
 	import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
 	break;
   }
+         break;
+      case RWaveFile::Mpeg:
+         format_in=wave->getHeadLayer();
+         import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
+         break;
+      case RWaveFile::Ogg:
+         format_in = RDSettings::OggVorbis;
+         import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
+         break;
+      case RWaveFile::Flac:
+         format_in = RDSettings::Flac;
+         import_temp_length=wave->getSampleLength()*wave->getChannels()*2;
+         break;
+      default:
+         QMessageBox::warning(this,tr("File Error"),
+               tr("Unsupported file type in archive!"));
+         wave->closeWave();
+         delete wave;
+         return;
+         break;
+   }
+   int samplerate=wave->getSamplesPerSec();
+
   import_import_aborted=false;
 
   int fd=open(import_dest_filename,
@@ -930,13 +851,19 @@
 
       case RDSettings::Flac:
       case RDSettings::OggVorbis:
-	  import_finished_length=
-	    (int)((double)import_temp_length*
-		  (double)RDSettings::bytesPerSec(import_settings->format(),
-						  import_settings->quality())/
-		  176400.0);
+         import_finished_length=0;
+         import_bar->setTotalSteps(100);
+         break;
+      default:
+         QMessageBox::warning(this,tr("File Error"),
+               tr("Unsupported file type for export!"));
+         wave->closeWave();
+         delete wave;
+         return;
 	break;
   }
+   wave->closeWave();
+   delete wave;
 
   //
   // Generate Temporary Filenames
@@ -945,110 +872,78 @@
   import_tempwav_name=tempname+".wav";
   import_tempdat_name=tempname+".dat";
 
-  QString cmd;
+   delete proc;
+   proc = new QProcess(QString("rd_export_file"));
   float normal=0.0;
   if(import_normalize_box->isChecked()) {
     normal=pow(10.0,(double)(import_normalize_spin->value())/20.0);
-    import_multipass=true;
-    cmd=QString().
-      sprintf("rd_export_file %6.4f %d %d %s/%s.%s %d %d %d %d %d %s %s %s",
-	      normal,
-	      format_in,
-	      samplerate,
-	      (const char *)RD_AUDIO_ROOT,
-	      (const char *)import_cutname,
-	      (const char *)RD_AUDIO_EXTENSION,
-	      import_settings->format(),
-	      import_settings->channels(),
-	      import_settings->sampleRate(),
-	      import_settings->bitRate()/1000,
-	      import_settings->quality(),
-	      (const char *)RDEscapeString(import_out_filename_edit->text()),
-	      (const char *)import_tempdat_name,
-	      (const char *)import_tempwav_name);
+      proc->addArgument(QString().sprintf("%6.4f",normal));
   }
   else {
-    import_multipass=false;
-    cmd=QString().
-      sprintf("rd_export_file 0 %d %d %s/%s.%s %d %d %d %d %d %s %s %s",
-	      format_in,
-	      samplerate,
-	      (const char *)RD_AUDIO_ROOT,
-	      (const char *)import_cutname,
-	      (const char *)RD_AUDIO_EXTENSION,
-	      import_settings->format(),
-	      import_settings->channels(),
-	      import_settings->sampleRate(),
-	      import_settings->bitRate()/1000,
-	      import_settings->quality(),
-	      (const char *)RDEscapeString(import_out_filename_edit->text()),  
-	      (const char *)import_tempdat_name,
-	      (const char *)import_tempwav_name);
+      proc->addArgument("0");
   }
-  // printf("CMD: %s\n",(const char *)cmd);
+   proc->addArgument(QString().sprintf("%d",format_in));
+   proc->addArgument(QString().sprintf("%d",samplerate));
+   proc->addArgument(RDCut::pathName(import_cutname));
+   proc->addArgument(QString().sprintf("%d",import_settings->format()));
+   proc->addArgument(QString().sprintf("%d",import_settings->channels()));
+   proc->addArgument(QString().sprintf("%d",import_settings->sampleRate()));
+   proc->addArgument(QString().sprintf("%d",import_settings->bitRate()/1000));
+   proc->addArgument(QString().sprintf("%d",import_settings->quality()));
+   proc->addArgument(import_out_filename_edit->text());
+   proc->addArgument(import_tempdat_name);
+   proc->addArgument(import_tempwav_name);
+
+   connect( proc, SIGNAL(processExited()),
+         this, SLOT(exportProcessExitedSlot()) );
+   if ( proc->start() == true){
+      import_multipass=true;
   *import_running=true;
   import_import_aborted=false;
-  import_out_selector_button->setDisabled(true);
+      import_in_selector_button->setDisabled(true);
   import_import_button->setDisabled(true);
   import_cancel_button->setDisabled(true);
   if(import_normalize_box->isChecked()) {
     bar_temp_file.setName(import_tempwav_name);
   }
-  if((import_script_pid=fork())==0) {
-    if(system(cmd)!=0) {
-      unlink(import_dest_filename);
-    }
-    exit(0);
-  }
-  else {
     import_bar->setProgress(0);
+      if(import_finished_length)
+      {
     import_bar->setPercentageVisible(true);
     import_bar_timer->start(IMPORT_BAR_INTERVAL,true);
   }
+      else
+      {
+         import_bar->setPercentageVisible(false);
+         import_bar_timer->start(IMPORT_BAR_INTERVAL/20,true);
+      }
+   }
 }
 
 
 void RDImportAudio::ExportProgress()
 {
-  printf("ExportProgress()\n");
-  if(*import_running) {
-    if(import_multipass) {
+   if(proc->isRunning()) {
+      if(import_finished_length){
+         // Exporting currently alwasy two pass (decode infile to temp, encode temp to outfile).
       import_bar->
-	setProgress((int)(50.0*((double)bar_temp_file.
-				size()/(double)import_temp_length+
-				(double)GetFileSize(import_dest_filename)/
-				(double)import_finished_length)));
-    }
-    else {
-      import_bar->setProgress((int)(100.0*(double)GetFileSize(import_dest_filename)/
-				    (double)import_finished_length));
-    }
+            setProgress((int)(100.0*((double)(bar_temp_file.size() + GetFileSize(import_dest_filename))/(double)(import_temp_length+ import_finished_length))));
     import_bar_timer->start(IMPORT_BAR_INTERVAL,true);
   }
   else {
-    import_bar->setPercentageVisible(false);
-    import_bar->reset();
-    if(QFile::exists(import_dest_filename)) {
-      import_out_selector_button->setEnabled(true);
-      import_import_button->setEnabled(true);
-      import_cancel_button->setEnabled(true);
-      QMessageBox::information(this,tr("Export Complete"),
-			       tr("Export complete!"));
-    }
-    else {
-      if(import_import_aborted) {
-	QMessageBox::information(this,tr("Export Aborted"),
-				 tr("The export has been aborted."));
-      }
-      else {
-	QMessageBox::warning(this,tr("Export Failed"),
-			     tr("The Exporter encountered an error.\n\
-Please check your configuration and try again."));
-      }
+         static bool reverse_progress=false;
+         int currentPos = import_bar->progress();
+         if(currentPos == import_bar->totalSteps())
+            reverse_progress=true;
+         else if(currentPos == 0)
+            reverse_progress=false;
+         if(reverse_progress)
+            import_bar->setProgress(--currentPos);
+         else 
+            import_bar->setProgress(++currentPos);
+         import_bar_timer->start(IMPORT_BAR_INTERVAL/20,true);
     }
-    unlink(import_tempwav_name);
-    unlink(import_tempdat_name);
-    done(0);
+
   }
 }
 
@@ -1071,3 +966,143 @@
   }
   return stat_data.st_size;
 }
+
+void RDImportAudio::importProcessExitedSlot()
+{
+   QString cuts_sql;
+   QSqlQuery *q;
+   import_in_selector_button->setEnabled(import_wavedata!=NULL);
+   *import_import_metadata=import_in_metadata_box->isChecked();
+   import_import_button->setEnabled(true);
+   import_cancel_button->setEnabled(true);
+   import_bar->setPercentageVisible(false);
+   import_bar->reset();
+   unlink(import_tempwav_name);
+   unlink(import_tempdat_name);
+   if(proc->normalExit() && proc->exitStatus()==0 && QFile::exists(import_dest_filename)) {
+      chown(RDCut::pathName(import_cutname),import_config->uid(),
+            import_config->gid());
+      chmod(RDCut::pathName(import_cutname),
+            S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
+      RDCut *cut=new RDCut(import_cutname);
+      cut->reset();
+      cut->setOriginName(import_station->name());
+      if(import_autotrim_box->isChecked()) {
+         AutoTrim();
+      }
+
+      //
+      // Update Metadata
+      //
+      if(import_wavedata!=NULL) {
+         if(import_wavedata->title().isEmpty()) {
+            import_wavedata->
+               setTitle(QString().sprintf("Imported from %s",
+                        (const char *)RGetBasePart(import_in_filename_edit->text())));
+         }
+         if(import_in_metadata_box->isChecked()&&import_wavedata->metadataFound()) {
+            cuts_sql="update CUTS set ";
+            cuts_sql+=QString().sprintf("DESCRIPTION=\"%s\",",
+                  (const char *)import_wavedata->title());
+            if(!import_wavedata->outCue().isEmpty()) {
+               cuts_sql+=QString().sprintf("OUTCUE=\"%s\",",
+                     (const char *)import_wavedata->outCue());
+            }
+            else {
+               switch(import_wavedata->endType()) {
+                  case RWaveData::FadeEnd:
+                     cuts_sql+="OUTCUE=\"[music fades]\",";
+                     break;
+
+                  case RWaveData::ColdEnd:
+                     cuts_sql+="OUTCUE=\"[music ends cold]\",";
+                     break;
+
+                  case RWaveData::UnknownEnd:
+                     break;
+               }
+            }
+            if(!import_wavedata->isrc().isEmpty()) {
+               cuts_sql+=QString().sprintf("ISRC=\"%s\",",
+                     (const char *)import_wavedata->isrc());
+            }
+            if(import_wavedata->introLength()>0) {
+               cuts_sql+=QString().sprintf("TALK_START_POINT=%d,TALK_END_POINT=%d,",
+                     cut->startPoint(),
+                     import_wavedata->introLength());
+            }
+            if(import_wavedata->segueLength()>0) {
+               cuts_sql+=QString().sprintf("SEGUE_START_POINT=%d,SEGUE_END_POINT=%d,",
+                     import_wavedata->segueLength(),
+                     cut->endPoint());
+            }
+            if((!import_wavedata->startDate().isNull())&&
+                  (!import_wavedata->startTime().isNull())) {
+               cuts_sql+=QString().sprintf("START_DATETIME=\"%s %s\",",
+                     (const char *)import_wavedata->startDate().
+                     toString("yyyy-MM-dd"),
+                     (const char *)import_wavedata->startTime().
+                     toString("hh:mm:ss"));
+            }
+            if((!import_wavedata->endDate().isNull())&&
+                  (!import_wavedata->endTime().isNull())) {
+               cuts_sql+=QString().sprintf("END_DATETIME=\"%s %s\",",
+                     (const char *)import_wavedata->endDate().
+                     toString("yyyy-MM-dd"),
+                     (const char *)import_wavedata->endTime().
+                     toString("hh:mm:ss"));
+            }
+            cuts_sql=cuts_sql.left(cuts_sql.length()-1);
+            cuts_sql+=QString().
+               sprintf(" where CUT_NAME=\"%s\"",(const char *)import_cutname);
+            q=new QSqlQuery(cuts_sql);
+            delete q;
+         }
+      }
+      delete cut;
+      QMessageBox::information(this,tr("Import Complete"),
+            tr("Import complete!"));
+      done(0);
+   }
+   else if(import_import_aborted) {
+      QMessageBox::information(this,tr("Import Aborted"),
+            tr("The import has been aborted."));
+      unlink(import_dest_filename);
+   }
+   else {
+      QMessageBox::warning(this,tr("Import Failed"),
+            tr("The importer encountered an error.\n\
+               Please check your importer configuration and try again."));
+      unlink(import_dest_filename);
+   }
+   *import_running = false;
+}
+
+void RDImportAudio::exportProcessExitedSlot()
+{
+   import_bar->setPercentageVisible(false);
+   import_bar->reset();
+   unlink(import_tempwav_name);
+   unlink(import_tempdat_name);
+   if(proc->normalExit() && proc->exitStatus()==0 && QFile::exists(import_dest_filename)) {
+      import_out_selector_button->setEnabled(true);
+      import_import_button->setEnabled(true);
+      import_cancel_button->setEnabled(true);
+      QMessageBox::information(this,tr("Export Complete"),
+            tr("Export complete!"));
+      done (0);
+   }
+   else if(import_import_aborted) {
+      QMessageBox::information(this,tr("Export Aborted"),
+            tr("The export has been aborted."));
+      unlink(import_dest_filename);
+   }
+   else {
+      QMessageBox::warning(this,tr("Export Failed"),
+            tr("The Exporter encountered an error.\n\
+               Please check your configuration and try again."));
+      unlink(import_dest_filename);
+   }
+   *import_running = false;
+}
+
Index: lib/rdimport_audio.h
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdimport_audio.h,v
retrieving revision 1.5
diff -u -B -b -w -r1.5 rdimport_audio.h
--- lib/rdimport_audio.h	13 Oct 2006 21:55:42 -0000	1.5
+++ lib/rdimport_audio.h	26 Dec 2006 23:43:29 -0000
@@ -61,6 +61,7 @@
 #define IMPORT_BAR_INTERVAL 500
 #define IMPORT_TEMP_BASENAME "rdlib"
 
+class QProcess;
 
 class RDImportAudio : public QDialog
 {
@@ -89,6 +90,9 @@
   void importData();
   void cancelData();
 
+  void importProcessExitedSlot();
+  void exportProcessExitedSlot();
+
  protected:
   void paintEvent(QPaintEvent *e);
   void closeEvent(QCloseEvent *e);
@@ -153,6 +157,9 @@
   RWaveData *import_wavedata;
   QString import_tempwav_name;
   QString import_tempdat_name;
+
+  QProcess * proc;
+  QString import_in_filename;
 };
 
 
Index: lib/rdlibrary_conf.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdlibrary_conf.cpp,v
retrieving revision 1.17
diff -u -B -b -w -r1.17 rdlibrary_conf.cpp
--- lib/rdlibrary_conf.cpp	13 Oct 2006 21:55:42 -0000	1.17
+++ lib/rdlibrary_conf.cpp	26 Dec 2006 23:43:29 -0000
@@ -316,13 +316,25 @@
     s->setChannels(q->value(0).toUInt());
     s->setSampleRate(q->value(1).toUInt());
     switch(q->value(2).toInt()) {
-	case 0:
+       case RDSettings::Pcm16:
 	  s->setFormat(RDSettings::Pcm16);
 	  break;
 
-	case 1:
+       case RDSettings::MpegL1:
+	  s->setFormat(RDSettings::MpegL1);
+	  break;
+       case RDSettings::MpegL2:
 	  s->setFormat(RDSettings::MpegL2);
 	  break;
+       case RDSettings::MpegL3:
+	  s->setFormat(RDSettings::MpegL3);
+	  break;
+	case RDSettings::OggVorbis:
+	  s->setFormat(RDSettings::OggVorbis);
+	  break;
+	case RDSettings::Flac:
+	  s->setFormat(RDSettings::Flac);
+	  break;
     }
     s->setBitRate(q->value(3).toUInt());
     s->setNormalizationLevel(q->value(4).toUInt());
Index: lib/rdlogedit_conf.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/lib/rdlogedit_conf.cpp,v
retrieving revision 1.7
diff -u -B -b -w -r1.7 rdlogedit_conf.cpp
--- lib/rdlogedit_conf.cpp	13 Oct 2006 21:55:42 -0000	1.7
+++ lib/rdlogedit_conf.cpp	26 Dec 2006 23:43:30 -0000
@@ -293,13 +293,25 @@
     s->setChannels(q->value(0).toUInt());
     s->setSampleRate(q->value(1).toUInt());
     switch(q->value(2).toInt()) {
-	case 0:
+       case RDSettings::Pcm16:
 	  s->setFormat(RDSettings::Pcm16);
 	  break;
 
-	case 1:
+       case RDSettings::MpegL1:
+	  s->setFormat(RDSettings::MpegL1);
+	  break;
+       case RDSettings::MpegL2:
 	  s->setFormat(RDSettings::MpegL2);
 	  break;
+       case RDSettings::MpegL3:
+	  s->setFormat(RDSettings::MpegL3);
+	  break;
+	case RDSettings::OggVorbis:
+	  s->setFormat(RDSettings::OggVorbis);
+	  break;
+	case RDSettings::Flac:
+	  s->setFormat(RDSettings::Flac);
+	  break;
     }
     s->setBitRate(q->value(3).toUInt());
     s->setNormalizationLevel(q->value(4).toUInt());
Index: rdadmin/edit_decks.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdadmin/edit_decks.cpp,v
retrieving revision 1.24
diff -u -B -b -w -r1.24 edit_decks.cpp
--- rdadmin/edit_decks.cpp	13 Oct 2006 21:55:46 -0000	1.24
+++ rdadmin/edit_decks.cpp	26 Dec 2006 23:43:30 -0000
@@ -299,6 +299,8 @@
   edit_play_channel=edit_play_deck_box->currentItem()+129;
   edit_format_box->insertItem(tr("PCM16"));
   edit_format_box->insertItem(tr("MPEG Layer 2"));
+  edit_format_box->insertItem(tr("Ogg Vorbis"));
+  //edit_format_box->insertItem(tr("Flac"));
   edit_channels_box->insertItem("1");
   edit_channels_box->insertItem("2");
   edit_samprate_box->insertItem("32000");
@@ -567,8 +569,14 @@
 
 	case RDSettings::MpegL1:
 	case RDSettings::MpegL3:
+	  break;
 	case RDSettings::Flac:
+	  edit_format_box->setCurrentItem(3);
+	  edit_bitrate_box->setEnabled(true);
+	  break;
 	case RDSettings::OggVorbis:
+	  edit_format_box->setCurrentItem(2);
+	  edit_bitrate_box->setEnabled(true);
 	  break;
     }
     edit_channels_box->setCurrentItem(edit_record_deck->defaultChannels()-1);
@@ -689,6 +697,12 @@
 	case 1:
 	  edit_record_deck->setDefaultFormat(RDSettings::MpegL2);
 	  break;
+	case 2:
+	  edit_record_deck->setDefaultFormat(RDSettings::OggVorbis);
+	  break;
+	case 3:
+	  edit_record_deck->setDefaultFormat(RDSettings::Flac);
+	  break;
     }
     edit_record_deck->setDefaultChannels(edit_channels_box->currentItem()+1);
     sscanf((const char *)edit_samprate_box->currentText(),"%d",&temp);
Index: rdadmin/edit_rdlibrary.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdadmin/edit_rdlibrary.cpp,v
retrieving revision 1.25
diff -u -B -b -w -r1.25 edit_rdlibrary.cpp
--- rdadmin/edit_rdlibrary.cpp	13 Oct 2006 21:55:46 -0000	1.25
+++ rdadmin/edit_rdlibrary.cpp	26 Dec 2006 23:43:30 -0000
@@ -318,7 +318,27 @@
   lib_riplevel_spin->setValue(lib_lib->ripperLevel()/100);
   lib_format_box->insertItem(tr("PCM16"));
   lib_format_box->insertItem(tr("MPEG Layer 2"));
-  lib_format_box->setCurrentItem(lib_lib->defaultFormat());
+  lib_format_box->insertItem(tr("Ogg Vorbis"));
+  //lib_format_box->insertItem(tr("Flac"));
+    switch(lib_lib->defaultFormat()) {
+	case RDSettings::Pcm16:
+	  lib_format_box->setCurrentItem(0);
+	  break;
+
+	case RDSettings::MpegL2:
+	  lib_format_box->setCurrentItem(1);
+	  break;
+
+	case RDSettings::MpegL1:
+	case RDSettings::MpegL3:
+	  break;
+	case RDSettings::OggVorbis:
+	  lib_format_box->setCurrentItem(2);
+	  break;
+	case RDSettings::Flac:
+	  lib_format_box->setCurrentItem(3);
+	  break;
+    }
   lib_channels_box->insertItem("1");
   lib_channels_box->insertItem("2");
   lib_channels_box->setCurrentItem(lib_lib->defaultChannels()-1);
@@ -403,6 +423,20 @@
 
 void EditRDLibrary::formatData(int index)
 {
+   switch(index){
+      case 0:
+         index = RDSettings::Pcm16;
+         break;
+      case 1:
+         index = RDSettings::MpegL2;
+         break;
+      case 2:
+         index = RDSettings::OggVorbis;
+         break;
+      case 3:
+         index = RDSettings::Flac;
+         break;
+   }
   ShowBitRates(index,lib_lib->defaultBitrate());
 }
 
@@ -422,7 +456,21 @@
   lib_lib->setRipperDevice(lib_ripdev_edit->text());
   lib_lib->setParanoiaLevel(lib_paranoia_box->currentItem());
   lib_lib->setRipperLevel(lib_riplevel_spin->value()*100);
-  lib_lib->setDefaultFormat(lib_format_box->currentItem());
+  switch(lib_format_box->currentItem())
+  {
+	case 0:
+	  lib_lib->setDefaultFormat(RDSettings::Pcm16);
+	  break;
+	case 1:
+	  lib_lib->setDefaultFormat(RDSettings::MpegL2);
+	  break;
+	case 2:
+	  lib_lib->setDefaultFormat(RDSettings::OggVorbis);
+	  break;
+	case 3:
+	  lib_lib->setDefaultFormat(RDSettings::Flac);
+	  break;
+  }
   lib_lib->setDefaultChannels(lib_channels_box->currentItem()+1);
   sscanf(lib_samprate_box->currentText(),"%d",&rate);
   lib_lib->setDefaultSampleRate(rate);
@@ -464,11 +512,11 @@
 {
   lib_bitrate_box->clear();
   switch(layer) {
-      case 0:  // PCM16
+     case RDSettings::Pcm16:  // PCM16
 	lib_bitrate_box->setDisabled(true);
 	break;
 
-      case 1:  // MPEG-1 Layer 2
+     case RDSettings::MpegL1:  // MPEG-1 Layer 2
 	lib_bitrate_box->setEnabled(true);
 	lib_bitrate_box->insertItem(tr("32 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("48 kbps/chan"));
@@ -527,7 +575,10 @@
 	}
 	break;
 
-      case 2:  // MPEG-1 Layer 3
+     case RDSettings::MpegL2:  // MPEG-1 Layer 3
+     case RDSettings::MpegL3:
+      case RDSettings::Flac:
+      case RDSettings::OggVorbis:
 	lib_bitrate_box->setEnabled(true);
 	lib_bitrate_box->insertItem(tr("32 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("40 kbps/chan"));
@@ -543,7 +594,7 @@
 	lib_bitrate_box->insertItem(tr("224 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("256 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("320 kbps/chan"));
-	switch(lib_lib->defaultLayer()) {
+	switch(lib_lib->defaultBitrate()) {
 	    case 32000:
 	      lib_bitrate_box->setCurrentItem(0);
 	      break;
Index: rdadmin/edit_rdlogedit.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdadmin/edit_rdlogedit.cpp,v
retrieving revision 1.6
diff -u -B -b -w -r1.6 edit_rdlogedit.cpp
--- rdadmin/edit_rdlogedit.cpp	13 Oct 2006 21:55:46 -0000	1.6
+++ rdadmin/edit_rdlogedit.cpp	26 Dec 2006 23:43:30 -0000
@@ -328,7 +328,28 @@
   lib_preroll_spin->setValue(lib_lib->tailPreroll());
   lib_format_box->insertItem(tr("PCM16"));
   lib_format_box->insertItem(tr("MPEG Layer 2"));
-  lib_format_box->setCurrentItem(lib_lib->format());
+  lib_format_box->insertItem(tr("Ogg Vorbis"));
+  //lib_format_box->insertItem(tr("Flac"));
+  switch(lib_lib->format()) {
+        case RDSettings::Pcm16:
+ 	  lib_format_box->setCurrentItem(0);
+ 	  break;
+ 
+ 	case RDSettings::MpegL2:
+ 	  lib_format_box->setCurrentItem(1);
+ 	  break;
+ 
+ 	case RDSettings::MpegL1:
+ 	case RDSettings::MpegL3:
+ 	  break;
+ 	case RDSettings::OggVorbis:
+ 	  lib_format_box->setCurrentItem(2);
+ 	  break;
+ 	case RDSettings::Flac:
+ 	  lib_format_box->setCurrentItem(3);
+ 	  break;
+  }
+
   lib_channels_box->insertItem("1");
   lib_channels_box->insertItem("2");
   lib_channels_box->setCurrentItem(lib_lib->defaultChannels()-1);
@@ -394,6 +415,21 @@
 
 void EditRDLogedit::formatData(int index)
 {
+   switch(index){
+      case 0:
+         index=RDSettings::Pcm16;
+         break;
+      case 1:
+         index=RDSettings::MpegL2;
+         break;
+      case 2:
+         index=RDSettings::OggVorbis;
+         break;
+      case 3:
+         index=RDSettings::Flac;
+         break;
+
+   }
   ShowBitRates(index,lib_lib->bitrate());
 }
 
@@ -490,7 +526,22 @@
   else {
     lib_lib->setRecEndCart(lib_recendcart_edit->text().toUInt());
   }
-  lib_lib->setFormat(lib_format_box->currentItem());
+  switch(lib_format_box->currentItem())
+   {
+ 	case 0:
+ 	  lib_lib->setFormat(RDSettings::Pcm16);
+ 	  break;
+ 	case 1:
+ 	  lib_lib->setFormat(RDSettings::MpegL2);
+ 	  break;
+ 	case 2:
+ 	  lib_lib->setFormat(RDSettings::OggVorbis);
+ 	  break;
+ 	case 3:
+ 	  lib_lib->setFormat(RDSettings::Flac);
+ 	  break;
+  }
+
   lib_lib->setDefaultChannels(lib_channels_box->currentItem()+1);
   sscanf(lib_samprate_box->currentText(),"%d",&rate);
   lib_lib->setSampleRate(rate);
@@ -515,11 +566,11 @@
 {
   lib_bitrate_box->clear();
   switch(layer) {
-      case 0:  // PCM16
+     case RDSettings::Pcm16:  // PCM16
 	lib_bitrate_box->setDisabled(true);
 	break;
 
-      case 1:  // MPEG-1 Layer 2
+     case RDSettings::MpegL1:  // MPEG-1 Layer 2
 	lib_bitrate_box->setEnabled(true);
 	lib_bitrate_box->insertItem(tr("32 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("48 kbps/chan"));
@@ -578,7 +629,11 @@
 	}
 	break;
 
-      case 2:  // MPEG-1 Layer 3
+     case RDSettings::MpegL2:  // MPEG-1 Layer 3
+     case RDSettings::MpegL3:
+      case RDSettings::Flac:
+      case RDSettings::OggVorbis:
+
 	lib_bitrate_box->setEnabled(true);
 	lib_bitrate_box->insertItem(tr("32 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("40 kbps/chan"));
@@ -594,7 +649,7 @@
 	lib_bitrate_box->insertItem(tr("224 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("256 kbps/chan"));
 	lib_bitrate_box->insertItem(tr("320 kbps/chan"));
-	switch(lib_lib->layer()) {
+	switch(lib_lib->bitrate()) {
 	    case 32000:
 	      lib_bitrate_box->setCurrentItem(0);
 	      break;
Index: rdcatch/edit_download.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdcatch/edit_download.cpp,v
retrieving revision 1.9
diff -u -B -b -w -r1.9 edit_download.cpp
--- rdcatch/edit_download.cpp	13 Oct 2006 21:55:50 -0000	1.9
+++ rdcatch/edit_download.cpp	26 Dec 2006 23:43:30 -0000
@@ -474,8 +474,8 @@
 {
   QString str;
 
-  RDCutDialog *cut=new RDCutDialog(&edit_cutname,edit_filter,NULL,"",
-				   false,true);
+  RDCutDialog *cut=new RDCutDialog(&edit_cutname,edit_filter,NULL,
+				   catch_user->name(),false,true);
   switch(cut->exec()) {
       case 0:
 	edit_description_edit->setText(RDCutPath(edit_cutname));
Index: rdcatchd/rdcatchd.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdcatchd/rdcatchd.cpp,v
retrieving revision 1.104
diff -u -B -b -w -r1.104 rdcatchd.cpp
--- rdcatchd/rdcatchd.cpp	29 Nov 2006 21:20:32 -0000	1.104
+++ rdcatchd/rdcatchd.cpp	26 Dec 2006 23:43:30 -0000
@@ -1189,7 +1189,9 @@
   //
   RDCae::AudioCoding format=catch_events[event].format();
   QString cut_name;
-  if(catch_events[event].normalizeLevel()==0) {
+  
+  // Temp Kludge.  Recording OggVorbis doesn't support a user settable normalization level.
+  if(catch_events[event].normalizeLevel()==0 || catch_events[event].format() == RDSettings::OggVorbis) {
     cut_name=catch_events[event].cutName();
   }
   else {
@@ -1247,6 +1249,14 @@
 	cut->setCodingFormat(1);
 	break;
 
+      case RDSettings::OggVorbis:
+	cut->setCodingFormat(RDSettings::OggVorbis);
+	break;
+
+      case RDSettings::Flac:
+	cut->setCodingFormat(RDSettings::Flac);
+	break;
+
       default:
 	cut->setCodingFormat(0);
 	break;
@@ -2439,10 +2449,8 @@
 			      (const char *)catch_temp_dir,
 			      catch_events[event].id());
 
-  QString local_filename=
-    QString().sprintf("%s/%s.%s",RD_AUDIO_ROOT,
-		      (const char *)catch_events[event].cutName(),
-		      RD_AUDIO_EXTENSION);
+  QString local_filename= RDCut::pathName(catch_events[event].cutName());
+  
   QFile file(local_filename);
   if(!file.exists()) {
     return QString();
@@ -2453,20 +2461,45 @@
     return QString();
   }
   int samplerate=wave->getSamplesPerSec();
+  switch(wave->type()){
+     case RWaveFile::Atx:
+     case RWaveFile::Tmc:
+     case RWaveFile::Wave:
   switch(wave->getFormatTag()) {
       case WAVE_FORMAT_PCM:
-	format_in=0;
 	catch_events[event].
 	  setTempLength(wave->getSampleLength()*
 			wave->getChannels()*(wave->getBitsPerSample()/8));
+              format_in=RDSettings::Pcm16;
 	break;
 
       case WAVE_FORMAT_MPEG:
+              catch_events[event].
+                 setTempLength(wave->getSampleLength()*wave->getChannels()*2);
 	format_in=wave->getHeadLayer();
+              break;
+        }
+        break;
+     case RWaveFile::Mpeg:
 	catch_events[event].
 	  setTempLength(wave->getSampleLength()*wave->getChannels()*2);
+        format_in=wave->getHeadLayer();
+        break;
+     case RWaveFile::Flac:
+        format_in=RDSettings::Flac;
+        break;
+     case RWaveFile::Ogg:
+        format_in=RDSettings::OggVorbis;
+        break;
+     default:
+        wave->closeWave();
+        delete wave;
+        LogLine(QString().
+              sprintf("unrecognized format in temporary file %s, id=%d",
+                 (const char *)catch_events[event].tempName(),
+                 catch_events[event].id()));
+        return QString();
 	break;
-
   }
   wave->closeWave();
   delete wave;
@@ -2578,6 +2611,8 @@
   if(!file.exists()) {
     return QString();
   }
+  file.close();
+  
   RWaveFile *wave=new RWaveFile(catch_events[event].tempName());
   if(!wave->openWave()) {
     delete wave;
@@ -2587,58 +2622,73 @@
 		    catch_events[event].id()));
     return QString();
   }
-  if(wave->type()==RWaveFile::Unknown) {
-    wave->closeWave();
-    delete wave;
-    LogLine(QString().
-	    sprintf("unrecognized format in temporary file %s, id=%d",
-		    (const char *)catch_events[event].tempName(),
-		    catch_events[event].id()));
-    return QString();
-  }
+  
   int samplerate=wave->getSamplesPerSec();
+  switch(wave->type()){
+     case RWaveFile::Atx:
+     case RWaveFile::Tmc:
+     case RWaveFile::Wave:
   switch(wave->getFormatTag()) {
       case WAVE_FORMAT_PCM:
-	format_in=0;
+              format_in=RDSettings::Pcm16;
 	break;
 
       case WAVE_FORMAT_MPEG:
 	format_in=wave->getHeadLayer();
 	break;
   }
+        break;
+     case RWaveFile::Mpeg:
+        format_in=wave->getHeadLayer();
+        break;
+     case RWaveFile::Flac:
+        format_in=RDSettings::Flac;
+        break;
+     case RWaveFile::Ogg:
+        format_in=RDSettings::OggVorbis;
+        break;
+     default:
+        wave->closeWave();
+        delete wave;
+        LogLine(QString().
+              sprintf("unrecognized format in temporary file %s, id=%d",
+                 (const char *)catch_events[event].tempName(),
+                 catch_events[event].id()));
+        return QString();
+        break;
+  }
+  wave->closeWave();
   delete wave;
 
-  switch(catch_default_format) {
-      case 0:  // PCM16
+  switch(catch_events[event].format()) {
+     case RDSettings::Pcm16:  // PCM16
 	catch_events[event].
 	  setFinalLength((int)(((double)catch_events[event].tempLength()/2.0)*
 			    (double)catch_default_channels*
 			    (double)catch_default_samplerate/44100.0));
 	break;
-      case 1:  // MPEG-1 Layer 2
-      case 2:  // MPEG-1 Layer 3
+     case RDSettings::MpegL2:  // MPEG L2
 	catch_events[event].
 	  setFinalLength((int)((double)catch_events[event].tempLength()*
 			       (double)catch_default_channels*
 			       (double)catch_default_bitrate/1411200.0));
 	break;
-  }
-  file.close();
-  switch(catch_events[event].format()) {
-      case 0:  // PCM16
-	format_out=0;
-	break;
-
-      case 2:  // MPEG L2
-	format_out=1;
+     case RDSettings::Flac:  
+     case RDSettings::OggVorbis:  
+	catch_events[event].
+	  setFinalLength((int)((double)catch_events[event].tempLength()*
+			       (double)catch_default_channels*
+			       (double)catch_default_bitrate/1411200.0));
 	break;
 
       default:
 	LogLine(QString().sprintf("unknown output format %d, id=%d",
 				  catch_events[event].format(),
 				  catch_events[event].id()));
+        return QString();
 	break;
   }
+  format_out=catch_events[event].format();
   
   QString cmd;
   float normal=0.0;
Index: rdlibrary/audio_cart.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdlibrary/audio_cart.cpp,v
retrieving revision 1.43
diff -u -B -b -w -r1.43 audio_cart.cpp
--- rdlibrary/audio_cart.cpp	21 Nov 2006 21:03:29 -0000	1.43
+++ rdlibrary/audio_cart.cpp	26 Dec 2006 23:43:30 -0000
@@ -497,6 +497,8 @@
   cutname=item->text(11);
   RDSettings settings;
   rdlibrary_conf->getSettings(&settings);
+  // TODO: until there is a way to set the default quality
+  settings.setQuality(5);
   RDImportAudio *import=new RDImportAudio(cutname,rdcart_import_path,
 					  &settings,&rdcart_import_metadata,
 					  &wavedata,cut_clipboard,
Index: rdlibrary/cdripper.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdlibrary/cdripper.cpp,v
retrieving revision 1.32
diff -u -B -b -w -r1.32 cdripper.cpp
--- rdlibrary/cdripper.cpp	13 Oct 2006 21:55:52 -0000	1.32
+++ rdlibrary/cdripper.cpp	26 Dec 2006 23:43:30 -0000
@@ -412,14 +412,23 @@
     rip_temp_length=(int)((double)rip_cdrom->
 	    trackLength(rip_track_list->currentItem()->text(0).toInt())*176.4);
     switch(rip_conf->defaultFormat()) {
-	case 0:  // PCM16
+       case RDSettings::Pcm16:  // PCM16
 	  rip_finished_length=
 	    (int)(((double)rip_temp_length/2.0)*
 		  (double)(rip_channels_box->currentItem()+1.0)*
 		  (double)rip_conf->defaultSampleRate()/44100.0);
 	  break;
-	case 1:  // MPEG-1 Layer 2
-	case 2:  // MPEG-1 Layer 3
+       case RDSettings::MpegL1:  // MPEG-1 Layer 1
+       case RDSettings::MpegL2:  // MPEG-1 Layer 2
+       case RDSettings::MpegL3:  // MPEG-1 Layer 3
+	  rip_finished_length=
+	    (int)((double)rip_temp_length*
+		  (double)(rip_channels_box->currentItem()+1)*
+		  (double)rip_conf->defaultBitrate()/1411200.0);
+	  break;
+       case RDSettings::OggVorbis:  // MPEG-1 Layer 2
+       case RDSettings::Flac:  // MPEG-1 Layer 3
+          //TODO have no idea what this should be.
 	  rip_finished_length=
 	    (int)((double)rip_temp_length*
 		  (double)(rip_channels_box->currentItem()+1)*
Index: rdlibrary/disk_ripper.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdlibrary/disk_ripper.cpp,v
retrieving revision 1.17
diff -u -B -b -w -r1.17 disk_ripper.cpp
--- rdlibrary/disk_ripper.cpp	29 Nov 2006 15:30:28 -0000	1.17
+++ rdlibrary/disk_ripper.cpp	26 Dec 2006 23:43:31 -0000
@@ -815,14 +815,23 @@
 
   rip_temp_length=(int)((double)rip_cdrom->trackLength(track)*176.4);
   switch(rdlibrary_conf->defaultFormat()) {
-      case 0:  // PCM16
+       case RDSettings::Pcm16:  // PCM16
 	rip_finished_length=
 	  (int)(((double)rip_temp_length/2.0)*
 		(double)(rip_channels_box->currentItem()+1.0)*
 		(double)rdlibrary_conf->defaultSampleRate()/44100.0);
 	break;
-      case 1:  // MPEG-1 Layer 2
-      case 2:  // MPEG-1 Layer 3
+       case RDSettings::MpegL1:  // MPEG-1 Layer 1
+       case RDSettings::MpegL2:  // MPEG-1 Layer 2
+       case RDSettings::MpegL3:  // MPEG-1 Layer 3
+	  rip_finished_length=
+	    (int)((double)rip_temp_length*
+		  (double)(rip_channels_box->currentItem()+1)*
+		  (double)rdlibrary_conf->defaultBitrate()/1411200.0);
+	  break;
+       case RDSettings::OggVorbis:  // MPEG-1 Layer 2
+       case RDSettings::Flac:  // MPEG-1 Layer 3
+          //TODO have no idea what this should be.
 	rip_finished_length=
 	  (int)((double)rip_temp_length*
 		(double)(rip_channels_box->currentItem()+1)*
@@ -893,14 +902,22 @@
     raw_length=length;
   }
   switch(rdlibrary_conf->defaultFormat()) {
-      case 0:  // PCM16
+     case RDSettings::Pcm16:  // PCM16
 	return (int)(((double)length/2.0)*
 		     (double)(rip_channels_box->currentItem()+1.0)*
 		     (double)rdlibrary_conf->defaultSampleRate()/44100.0)+
 	  raw_length;
 	break;
-      case 1:  // MPEG-1 Layer 2
-      case 2:  // MPEG-1 Layer 3
+       case RDSettings::MpegL1:  // MPEG-1 Layer 1
+       case RDSettings::MpegL2:  // MPEG-1 Layer 2
+       case RDSettings::MpegL3:  // MPEG-1 Layer 3
+	return (int)((double)length*
+		     (double)(rip_channels_box->currentItem()+1)*
+		     (double)rdlibrary_conf->defaultBitrate()/1411200.0)+
+	  raw_length;
+	break;
+       case RDSettings::OggVorbis:  // MPEG-1 Layer 2
+       case RDSettings::Flac:  // MPEG-1 Layer 3
 	return (int)((double)length*
 		     (double)(rip_channels_box->currentItem()+1)*
 		     (double)rdlibrary_conf->defaultBitrate()/1411200.0)+
Index: rdlibrary/record_cut.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdlibrary/record_cut.cpp,v
retrieving revision 1.76
diff -u -B -b -w -r1.76 record_cut.cpp
--- rdlibrary/record_cut.cpp	29 Nov 2006 15:15:08 -0000	1.76
+++ rdlibrary/record_cut.cpp	26 Dec 2006 23:43:31 -0000
@@ -113,19 +113,6 @@
   rec_card_no[0]=rdlibrary_conf->inputCard();
   rec_card_no[1]=rdlibrary_conf->outputCard();
   rec_name=rec_cut->cutName();
-  switch(rec_cut->codingFormat()) {
-      case 0:
-	rec_format=RDCae::Pcm16;
-	break;
-	
-      case 1:
-	rec_format=RDCae::MpegL2;
-	break;
-
-      default:
-	rec_format=RDCae::Pcm16;
-	break;
-  }	
   rec_channels=rec_cut->channels();
   rec_samprate=rec_cut->sampleRate();
   rec_bitrate=rec_cut->bitRate();
@@ -723,22 +710,7 @@
       }
     }
     QFile(filename).remove();
-    switch(rdlibrary_conf->defaultFormat()) {
-	case 0:
-	  rec_cut->setCodingFormat(0);
-	  rec_format=RDCae::Pcm16;
-	  break;
-
-	case 1:
-	  rec_cut->setCodingFormat(1);
-	  rec_format=RDCae::MpegL2;
-	  break;
-
-	default:
-	  rec_cut->setCodingFormat(0);
-	  rec_format=RDCae::Pcm16;
-	  break;
-    }
+    rec_cut->setCodingFormat(rdlibrary_conf->defaultFormat());
     rec_samprate=rdlibrary_conf->defaultSampleRate();
     rec_cut->setSampleRate(rec_samprate);
     rec_bitrate=rdlibrary_conf->defaultBitrate();
@@ -751,7 +723,7 @@
     cut_origin_datetime=QDateTime::currentDateTime();
     cut_origin_edit->setText(cut_origin_name+" - "+
 			    cut_origin_datetime.toString("M/d/yyyy hh:mm:ss"));
-    rdcae->loadRecord(rec_card_no[0],rec_port_no[0],rec_name,rec_format,
+    rdcae->loadRecord(rec_card_no[0],rec_port_no[0],rec_name,(RDCae::AudioCoding)rec_cut->codingFormat(),
 			rec_channels,rec_samprate,rec_bitrate*rec_channels);
   }
 }
Index: rdlogedit/voice_tracker.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/rdlogedit/voice_tracker.cpp,v
retrieving revision 1.68
diff -u -B -b -w -r1.68 voice_tracker.cpp
--- rdlogedit/voice_tracker.cpp	15 Nov 2006 18:40:25 -0000	1.68
+++ rdlogedit/voice_tracker.cpp	26 Dec 2006 23:43:31 -0000
@@ -3068,22 +3068,29 @@
   if(edit_track_cut!=NULL) {
     delete edit_track_cut;
   }
-  edit_track_cut=new RDCut(edit_track_cart->number(),
-			   edit_track_cart->addCut(edit_format,edit_samprate,
-						   edit_bitrate,edit_chans));
+  
   switch(edit_format) {
-      case 0:
+     case RDSettings::Pcm16:
 	edit_coding=RDCae::Pcm16;
 	break;
-	
-      case 1:
+     case RDSettings::MpegL2:
 	edit_coding=RDCae::MpegL2;
 	break;
-	
-      default:
+     case RDSettings::OggVorbis:
+        edit_coding=RDCae::OggVorbis;
+        break;
+     case RDSettings::MpegL1:
+     case RDSettings::MpegL3:
+     case RDSettings::Flac:
 	edit_coding=RDCae::Pcm16;
 	break;
   }
+
+  // I would think the edit_format here should be the same as the edit_coding above.
+  edit_track_cut=new RDCut(edit_track_cart->number(),
+			   edit_track_cart->addCut(edit_coding,edit_samprate,
+						   edit_bitrate,edit_chans));
+
   edit_deck_state=VoiceTracker::DeckTrack1;
   edit_sliding=false;
   for(unsigned i=0;i<3;i++) {
Index: scripts/rd_export_file
===================================================================
RCS file: /home/cvs/srl/rivendell/scripts/rd_export_file,v
retrieving revision 1.5
diff -u -B -b -w -r1.5 rd_export_file
--- scripts/rd_export_file	13 Oct 2006 21:55:59 -0000	1.5
+++ scripts/rd_export_file	26 Dec 2006 23:43:31 -0000
@@ -26,7 +26,7 @@
 #
 #        <level> = Normalization level, expressed as linear ratio, 
 #                  0 = No normalization
-#    <in-format> = Input format, 0 = PCM16, 1 = MPEG Layer 2
+#    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 1, 2 = MPEG-1 Layer 2, 3 = MPEG-1 Layer 3, 4 = FLAC, 5 = ogg
 #  <in-samprate> = Input sample rate, in samples/sec
 #   <in-wavfile> = Source file for export.
 #   <out-format> = Output format, 0 = PCM16, 1 = MPEG Layer 1
@@ -44,10 +44,10 @@
     cat <<EOF 
 Usage: `basename $0` <level> <in-samprate> <in-wavfile> <out-format> <out-chans> <out-samprate> <out-bitrate> <out-wavfile> <datfile> <tmpfile>
     <level> = Normalization level, expressed as linear ratio (0 = No normalization)
-    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 2
+    <in-format> = Input format, 0 = PCM16, 2 = MPEG-1 Layer 2, 4 = FLAC, 5 = OggVorbis
     <in-samprate> = Input sample rate, in samples/sec
     <in-wavfile> = Source file for import.
-    <out-format> = Output format, 0 = PCM16, 2 = MPEG-1 Layer 2
+   <out-format> = Output format, 0 = PCM16, 2 = MPEG Layer 2, 3 = MPEG Layer 3, 4 = FLAC, 5 = OggVorbis
     <out-chans> = Output channels, 1 or 2
     <out-samprate> = Output sample rate, in samples/sec
     <out-bitrate> = MPEG Bitrate, in kbps, or 0 for PCM16
@@ -112,17 +112,29 @@
 #
 # Convert to PCM (if necessary)
 #
-if [ $FORMAT_IN = 0 ] ; then
+case "$FORMAT_IN" in
+  0)  # PCM16
   cp $FILE_IN $WORK
-else
+  ;;
+
+  1 | 2 | 3)  # MPEG Layer 1, 2, 3
   mpg321 -q -w $WORK $FILE_IN
-fi
+  ;;
+
+  4)  # FLAC
+   exit 1
+  ;;
+
+  5)  # OggVorbis
+      ogg123 -q -d wav -f $WORK $FILE_IN
+  ;;
+esac
 
 #
 # Get Peak Level
 #
 if [ $NORMAL_LEVEL != 0 ] ; then
-  PEAK_LEVEL=`sox $WORK -e stat -v 2>&1 | grep -v ^sox` 
+  PEAK_LEVEL=`sox $SOX_FORMAT_IN $WORK -e stat -v 2>&1 | grep -v ^sox` 
   SCALE=`echo "$NORMAL_LEVEL * $PEAK_LEVEL" | bc -l`
   if [ "$SCALE" == "1.00000000000000000000" ]; then
     SCALE="1"
@@ -133,7 +145,7 @@
 
 case "$FORMAT_OUT" in
   0)  # PCM16
-    sox $SOX_SCALE $WORK -r $SAMPRATE_OUT -c $CHANS_OUT $FILE_OUT $RESAMPLE_FLAG
+    sox $SOX_SCALE $SOX_FORMAT_IN $WORK -r $SAMPRATE_OUT -c $CHANS_OUT $FILE_OUT $RESAMPLE_FLAG
   ;;
 
   1)  # MPEG Layer 1
@@ -141,19 +153,19 @@
   ;;
 
   2)  # Mpeg Layer 2
-    sox $SOX_SCALE $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t wav - $RESAMPLE_FLAG | toolame -t 0 -s $TOOLAME_SAMPRATE -m $MPEG_MODE -b $BITRATE_OUT /dev/stdin $FILE_OUT
+    sox $SOX_SCALE $SOX_FORMAT_IN $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t wav - $RESAMPLE_FLAG | toolame -t 0 -s $TOOLAME_SAMPRATE -m $MPEG_MODE -b $BITRATE_OUT /dev/stdin $FILE_OUT
   ;;
 
   3)  # MPEG Layer 3
-    sox $SOX_SCALE $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | lame --silent -r -x -s $SAMPRATE_OUT -m $MPEG_MODE $LAME_RATE - $FILE_OUT
+    sox $SOX_SCALE $SOX_FORMAT_IN $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | lame --silent -r -x -s $SAMPRATE_OUT -m $MPEG_MODE $LAME_RATE - $FILE_OUT
   ;;
 
   4)  # FLAC
-    sox $SOX_SCALE $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | flac -f --silent --best --endian=little --sign=signed --bps=16 --channels=$CHANS_OUT --sample-rate=$SAMPRATE_OUT --force-raw-format -o $FILE_OUT -
+    sox $SOX_SCALE $SOX_FORMAT_IN $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | flac -f --silent --best --endian=little --sign=signed --bps=16 --channels=$CHANS_OUT --sample-rate=$SAMPRATE_OUT --force-raw-format -o $FILE_OUT -
   ;;
 
   5)  # OggVorbis
-    sox $SOX_SCALE $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | oggenc -r -B 16 -C $CHANS_OUT -R $SAMPRATE_OUT -q $QUALITY_OUT -o $FILE_OUT -
+    sox $SOX_SCALE $SOX_FORMAT_IN $WORK -r $SAMPRATE_OUT -c $CHANS_OUT -t raw - $RESAMPLE_FLAG | oggenc -Q -r -B 16 -C $CHANS_OUT -R $SAMPRATE_OUT -q $QUALITY_OUT -o $FILE_OUT -
   ;;
 esac
 
Index: scripts/rd_import_file
===================================================================
RCS file: /home/cvs/srl/rivendell/scripts/rd_import_file,v
retrieving revision 1.19
diff -u -B -b -w -r1.19 rd_import_file
--- scripts/rd_import_file	13 Oct 2006 21:55:59 -0000	1.19
+++ scripts/rd_import_file	26 Dec 2006 23:43:31 -0000
@@ -26,10 +26,10 @@
 #
 #        <level> = Normalization level, expressed as linear ratio, 
 #                  0 = No normalization
-#    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 2
+#    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 1, 2 = MPEG-1 Layer 2, 3 = MPEG-1 Layer 3, 4 = FLAC, 5 = ogg
 #  <in-samprate> = Input sample rate, in samples/sec
 #   <in-wavfile> = Source file for import.
-#   <out-format> = Output format, 0 = PCM16, 1 = MPEG-1 Layer 2
+#    <out-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 1, 2 = MPEG-1 Layer 2, 3 = MPEG-1 Layer 3, 4 = FLAC, 5 = ogg
 #    <out-chans> = Output channels, 1 or 2
 # <out-samprate> = Output sample rate, in samples/sec
 #  <out-bitrate> = MPEG Bitrate, in kbps, or 0 for PCM16
@@ -41,10 +41,10 @@
     cat <<EOF 
 Usage: `basename $0` <level> <in-samprate> <in-wavfile> <out-format> <out-chans> <out-samprate> <out-bitrate> <out-wavfile> <datfile> <tmpfile>
     <level> = Normalization level, expressed as linear ratio (0 = No normalization)
-    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 2
+    <in-format> = Input format, 0 = PCM16, 1 = MPEG-1 Layer 1, 2 = MPEG-1 Layer 2, 3 = MPEG-1 Layer 3, 4 = FLAC, 5 = ogg
     <in-samprate> = Input sample rate, in samples/sec
     <in-wavfile> = Source file for import.
-    <out-format> = Output format, 0 = PCM16, 1 = MPEG-1 Layer 2
+    <out-format> = Input format, 0 = PCM16, 2 = MPEG-1 Layer 2, 4 = FLAC, 5 = ogg
     <out-chans> = Output channels, 1 or 2
     <out-samprate> = Output sample rate, in samples/sec
     <out-bitrate> = MPEG Bitrate, in kbps, or 0 for PCM16
@@ -72,7 +72,9 @@
 
 set -e
 
-EXTENSION_IN=`echo $FILE_IN | sed 's/.*\.\([a-zA-Z0-9]\)/\1/'`
+# The sed function only handles ascii characters.
+#EXTENSION_IN=`echo $FILE_IN | sed 's/.*\.\([a-zA-Z0-9]\)/\1/'`
+EXTENSION_IN=`echo $FILE_IN | grep -o "atx$\|ATX$\|tmc$\|TMC$\|mp2$\|MP2$\|mp3$\|MP3$\|ogg$\|ogg$\|wav$\|flac$\|FLAC$\|wav$\|WAV$"`
 
 case "$EXTENSION_IN" in
     atx)
@@ -178,7 +180,7 @@
     sox $SOX_OPTIONS | rdfilewrite --channels=$4 --sample-rate=$5 $2
     }
     ;;
-    1)
+    2)
     function masterize() {
 	SOX_OPTIONS="$1 -w -c $CHANS_OUT -r $SAMPRATE_OUT -t raw"
 	if [ $3 != 1  ]; then
@@ -207,10 +209,73 @@
 		LAMERATE=48
             ;;
         esac
-        LAME_OPTIONS="-t 0 -m $MODE -s $LAMERATE -b $BITRATE_OUT"
-	sox $SOX_OPTIONS | toolame $LAME_OPTIONS /dev/stdin -W $2 > /dev/null 2> /dev/null
+        LAME_OPTIONS="-r -b $BITRATE_OUT"
+	sox $SOX_OPTIONS | toolame $LAME_OPTIONS /dev/stdin -o 
     }
     ;;
+4)
+# encode FLAC 
+function masterize() {
+   LAME_OPTIONS="--ogg  --endian=little --channels=2 --bps=16 --sign=signed --sample-rate=$SAMPRATE_OUT"
+	  if [ $3 != 1  ]; then
+		 SOX_OPTIONS="$1 -w -c $CHANS_OUT -r $SAMPRATE_OUT -t raw"
+		 SOX_OPTIONS="-v $3 $SOX_OPTIONS"
+		 SOX_OPTIONS="$SOX_OPTIONS -"
+
+		 if [ $SAMPRATE_OUT -ne $SAMPRATE_IN ]; then
+			SOX_OPTIONS="$SOX_OPTIONS resample"
+		 fi
+		 echo	"sox $SOX_OPTIONS | flac $LAME_OPTIONS /dev/stdin -o $2 > /dev/null 2> /dev/null"
+		 sox $SOX_OPTIONS | flac $LAME_OPTIONS - -o $2 
+	  else
+		 flac $LAME_OPTIONS $1 -o $2
+	  fi
+    }
+    ;;
+    5)
+# encode Ogg Vorbis
+    if [ "$EXTENSION_IN" = "ogg" ] || [ "$EXTENSION_IN" = "OGG" ] ; then 
+#    function masterize() {
+#       SOX_OPTIONS="$1 -w -c $CHANS_OUT -r $SAMPRATE_OUT -t raw"
+#       if [ $3 != 1  ]; then
+#          SOX_OPTIONS="-v $3 $SOX_OPTIONS"
+#       fi
+
+#      SOX_OPTIONS="$SOX_OPTIONS -"
+
+#       if [ $SAMPRATE_OUT -ne $SAMPRATE_IN ]; then
+#          SOX_OPTIONS="$SOX_OPTIONS resample"
+#       fi
+
+#       LAME_OPTIONS="-r -b $BITRATE_OUT"
+# Calculation of volume peak moved to libradio.  Calling rdfilewrite writes out the energy file and 
+# calculates the peak level which is scaled by the NORMAL_LEVEL passed here.
+       ogg123 -q -d raw -f - "$FILE_IN" | rdfilewrite --do-energy=1 --normalize=$NORMAL_LEVEL "$FILE_OUT" 
+       cp "$FILE_IN" "$FILE_OUT" 
+      exit 0
+ #   } 
+else   
+function masterize() {
+   SOX_OPTIONS="$1 -w -c $CHANS_OUT -r $SAMPRATE_OUT -t raw"
+   if [ $3 != 1  ]; then
+      SOX_OPTIONS="-v $3 $SOX_OPTIONS"
+   fi
+
+   SOX_OPTIONS="$SOX_OPTIONS -"
+
+#  SAMPRATE already covered above.
+#   if [ $SAMPRATE_OUT -ne $SAMPRATE_IN ]; then
+#      SOX_OPTIONS="$SOX_OPTIONS resample"
+#   fi
+
+   LAME_OPTIONS="-r -b $BITRATE_OUT -R $SAMPRATE_OUT"
+# Calculation of volume peak moved to libradio.  Calling rdfilewrite writes out the energy file and 
+# calculates the peak level which is scaled by the NORMAL_LEVEL passed here.
+      sox $SOX_OPTIONS | rdfilewrite --set-energy=1 --channels=$4 --sample-rate=$5 --out-format=$FORMAT_OUT --normalize=$NORMAL_LEVEL $2
+#   sox $SOX_OPTIONS | oggenc $LAME_OPTIONS /dev/stdin -o $2 > /dev/null 2> /dev/null
+}
+fi
+;;   
     *)
     echo "unsupported output format $FORMAT_OUT";
     ;;
Index: scripts/rd_rip_cd
===================================================================
RCS file: /home/cvs/srl/rivendell/scripts/rd_rip_cd,v
retrieving revision 1.13
diff -u -B -b -w -r1.13 rd_rip_cd
--- scripts/rd_rip_cd	29 Nov 2006 13:42:45 -0000	1.13
+++ scripts/rd_rip_cd	26 Dec 2006 23:43:31 -0000
@@ -28,7 +28,7 @@
 #   <paranoia> = Paranoia level. 0 = Normal, 1 = Low, 2 = None
 #      <level> = Normalization level, expressed as linear ratio, 
 #                0 = No normalization
-#     <format> = Output format, 0 = PCM16, 1 = MPEG-1 Layer 2
+#     <format> = Output format, 0 = PCM16, 2 = MPEG-1 Layer 2, 4 = Flac, 5 = ogg
 #      <chans> = Output channels, 1 or 2
 #   <samprate> = Output sample rate, in samples/sec
 #    <bitrate> = MPEG Bitrate, in kbps, or 0 for PCM16
@@ -55,7 +55,7 @@
 # Sanity Checks
 #
 set -e
-if [ $FORMAT = "2" ]; then    # MPEG Layer 3 not supported!
+if [ $FORMAT = "3" ]; then    # MPEG Layer 3 not supported!
    exit 1;
 fi 
 
@@ -120,7 +120,7 @@
 
 # ############################################################################
 # Encode to MPEG Layer 2
-if [ $FORMAT = 1 ]; then
+if [ $FORMAT = 2 ]; then
     if [ $CHANS = 1 ]; then
 	MODE="m"
     else
@@ -174,8 +174,34 @@
     fi
 
 fi
+# ############################################################################
+
+# ############################################################################
+# Encode to Ogg Vorbis
+if [ $FORMAT = 5 ]; then
+LAME_OPTIONS="-r -b $BITRATE"
+
+# Let libradio via rdfilewrite create energy data file and handle normalization. 
+# fixed rdfilewrite to handle ogg encoding too. 
+#
+# Phase One - Rip to 44.1 Stereo WAV, convert to proper sample rate and channels, create energy file 
+# and handle normalization. 
+#
+cdda2wav --quiet -D $RIPDEV -t $TRACK $PARANOIA_FLAG - | sox -t wav - -t raw -c $CHANS -r $SAMPRATE - $RESAMPLE_FLAG | rdfilewrite --set-energy=1 --channels=$CHANS --sample-rate=$SAMPRATE --normalize=$NORMAL_LEVEL --out-format=5 $WAVE
+
+#
+# Phase Two - Encode audio to final destination
+#
+#oggenc $LAME_OPTIONS $WORK -o $WAVE 
 
+#mv $WORK.energy $WAVE.energy
+#
+# Clean Up
+#
+rm -f $WORK
+# ############################################################################
 
+fi
 
 
 # End of rd_rip_cd
Index: utils/rdfilewrite/rdfilewrite.cpp
===================================================================
RCS file: /home/cvs/srl/rivendell/utils/rdfilewrite/rdfilewrite.cpp,v
retrieving revision 1.3
diff -u -B -b -w -r1.3 rdfilewrite.cpp
--- utils/rdfilewrite/rdfilewrite.cpp	13 Oct 2006 21:55:59 -0000	1.3
+++ utils/rdfilewrite/rdfilewrite.cpp	26 Dec 2006 23:43:31 -0000
@@ -30,17 +30,130 @@
 #include <rdcmd_switch.h>
 #include <rdfilewrite.h>
 
+#include <rdsettings.h>
+
 //
 // Globals
 //
 RDCmdSwitch *rdcmdswitch=NULL;
 
+vector<unsigned short> energy_data;
+unsigned short levl_block_ptr;
+unsigned levl_istate;
+short levl_accum;
+
+bool WriteEnergyFile(QString wave_file_name, double normalize_level)
+{
+  mode_t prev_mask;
+  bool rc;
+  QFile energy_file;
+  // Calculate peak amplitude.  
+  //
+  // The way sox does this:
+  // - Find the sample with the highest value.  
+  // Should be looking at minimum values too and take the absolute value.
+  double peak_level = 0;
+  for(unsigned i=0;i<energy_data.size();i++) {
+     if(energy_data[i] > peak_level) {
+        peak_level = energy_data[i]; 
+     }
+  }
+  // - Then we need a ratio to multiple all our samples by.  i.e.
+  // vol_scale * sample will never be greater then SIGNED_SHORT_MAX.
+  double vol_scale = 32768.0f/peak_level; 
+  // - Then we want to allow for adjusting the volume so it's not so full on loud.  
+  // Like set it 13db below the max.  This is where the user selectable level comes in.
+  normalize_level = normalize_level*vol_scale;
+  if(normalize_level==0){
+     normalize_level=1.0f;
+  }else{
+     for(unsigned i=0;i<energy_data.size();i++) {
+        energy_data[i] *= normalize_level;
+     }
+  }
+  // I Propose the normalize_level here is the same as sent to rd_import_file.
+  // i.e. normal=pow(10.0,(double)(library_conf->ripperLevel())/20.0);
+  // failing that change it to a int and set the normalize_level to ripperLevel() and 
+  // keep the gory details of converting that to double within this library.
+  QString str(QString().sprintf("%f\n",normalize_level));
+  energy_file.setName(wave_file_name+".energy");
+  energy_file.remove();
+  prev_mask = umask(0113);      // Set umask so files are user and group writable.
+  rc=energy_file.open(IO_ReadWrite);
+  umask(prev_mask);
+  if(rc) {
+     write(energy_file.handle(),(const char*)str,strlen(str));
+     write(energy_file.handle(),&(energy_data[0]),2*energy_data.size());
+     energy_file.close();
+  }
+}
+
+int getEnergy(void *buf,int count, int channels)
+   
+{
+   for(int i=0;i<count;i++) {
+      switch(levl_istate) {
+         case 0:   // Left Channel, LSB
+            levl_accum=((char *)buf)[i]&0xff;
+            levl_istate=1;
+            break;
+
+         case 1:   // Left Channel, MSB
+            levl_accum|=((((char *)buf)[i]&0xff)<<8);
+            switch(channels) {
+               case 1:
+                  if(levl_accum>energy_data[energy_data.size()-1]) {
+                     energy_data[energy_data.size()-1]=levl_accum;
+                  }
+                  if(++levl_block_ptr==1152) {
+                     energy_data.push_back(0);
+                     levl_block_ptr=0;
+                  }
+                  levl_istate=0;
+                  break;
+
+               case 2:
+                  if(levl_accum>energy_data[energy_data.size()-2]) {
+                     energy_data[energy_data.size()-2]=levl_accum;
+                  }
+                  levl_istate=2;
+                  break;
+            }
+            break;
+
+         case 2:   // Right Channel, LSB
+            levl_accum=((char *)buf)[i]&0xff;
+            levl_istate=3;
+            break;
+
+         case 3:   // Right Channel, MSB
+            levl_accum|=((((char *)buf)[i]&0xff)<<8);
+            if(levl_accum>energy_data[energy_data.size()-1]) {
+               energy_data[energy_data.size()-1]=levl_accum;
+            }
+            if(++levl_block_ptr==1152) {
+               energy_data.push_back(0);
+               energy_data.push_back(0);
+               levl_block_ptr=0;
+            }
+            levl_istate=0;
+            break;
+      }
+   }
+   return true;
+}
 
 MainObject::MainObject(QObject *parent,const char *name)
 {
-  unsigned sample_rate=0;
-  unsigned channels=0;
-  QString filename;
+   unsigned sample_rate=44100;
+   unsigned channels=2;
+   unsigned out_format=0;
+   unsigned set_energy=0;
+   unsigned do_energy=0;
+   QString in_filename("-"), out_filename;
+   double normalize_level=1.0;
+   int filename_pos=0;
+   int print_info=0;
   char buffer[RDFILEWRITE_BUFFER_SIZE];
   size_t n;
 
@@ -52,55 +165,186 @@
   for(unsigned i=0;i<cmd->keys();i++) {
     if(cmd->key(i)=="--channels") {
       channels=cmd->value(i).toUInt();
+         filename_pos++;
+      }
+      if(cmd->key(i)=="--print-info") {
+         print_info=cmd->value(i).toUInt();
+         filename_pos++;
     }
     if(cmd->key(i)=="--sample-rate") {
       sample_rate=cmd->value(i).toUInt();
+         filename_pos++;
     }
+      if(cmd->key(i)=="--out-format") {
+         out_format=cmd->value(i).toUInt();
+         filename_pos++;
+      }
+      if(cmd->key(i)=="--normalize") {
+         normalize_level=cmd->value(i).toDouble();
+         filename_pos++;
+      }
+      if(cmd->key(i)=="--set-energy") {
+         set_energy=true;
+         filename_pos++;
+      }
+      if(cmd->key(i)=="--do-energy") {
+         do_energy=true;
+         filename_pos++;
+      }
+      if(cmd->key(i)=="--in-file") {
+         in_filename=cmd->value(i);
+         filename_pos++;
   }
-  if(channels==0) {
-    fprintf(stderr,"rdfilewrite: missing/invalid --channels argument\n");
-    exit(256);
-  }
-  if(sample_rate==0) {
-    fprintf(stderr,"rdfilewrite: missing/invalid --sample-rate argument\n");
-    exit(256);
   }
-  if(cmd->keys()!=3) {
+
+   if(do_energy){
+      if(cmd->keys()!=(filename_pos+1)) {
     fprintf(stderr,"rdfilewrite: missing filename argument\n");
     exit(256);
   }
-  filename=cmd->key(2);
-  delete cmd;
+      out_filename=cmd->key(filename_pos);
+      levl_block_ptr=0;
+      levl_istate=0;
+      levl_accum=0;
+      energy_data.clear();
+      for(int i=0;i<channels;i++) {
+         energy_data.push_back(0);
+      }
+      //
+      // transfer data
+      //
+      while((n=read(0,buffer,RDFILEWRITE_BUFFER_SIZE))>0) {
+         getEnergy(buffer,n, channels);
+      }
+      WriteEnergyFile(out_filename,normalize_level);
 
+   } else {
   //
   // Create Output File
   //
-  RWaveFile *wavefile=new RWaveFile(filename);
-  wavefile->nameWave(filename);
-  wavefile->setFormatTag(WAVE_FORMAT_PCM);
-  wavefile->setBitsPerSample(16);
-  wavefile->setChannels(channels);
-  wavefile->setSamplesPerSec(sample_rate);
-  wavefile->setBextChunk(true);
-  wavefile->setLevlChunk(true);
-  if(!wavefile->createWave()) {
+      RWaveFile *in_wave = NULL;
+      RWaveData *in_data = NULL;
+      if(in_filename.length() && in_filename != "-"){
+         new RWaveFile(in_filename);
+         in_wave = new RWaveFile(in_filename);
+         in_data = new RWaveData();
+         if(!in_wave->openWave(in_data)) {
+            fprintf(stderr,"rdfilewrite: unable to open input file\n");
+            delete in_wave;
+            delete cmd;
+            exit(256);
+         }
+         if(print_info){
+            switch(in_wave->getFormatTag()){
+               case WAVE_FORMAT_PCM:
+                  printf("Type: WAVE_FORMAT_PCM\n");
+                  break;
+               case WAVE_FORMAT_VORBIS:
+                  printf("Type: WAVE_FORMAT_VORBIS\n");
+                  break;
+               case WAVE_FORMAT_MPEG:
+                  printf("Type: WAVE_FORMAT_MPEG\n");
+                  break;
+            }
+            switch(in_wave->encoding()){
+               case RWaveFile::Raw:
+                  printf("encoding: Raw\n");
+                  break;
+               case RWaveFile::Signed16Int:
+                  printf("encoding: Signed16Int\n");
+                  break;
+               case RWaveFile::Signed32Float:
+                  printf("encoding: Signed32Float\n");
+                  break;
+            }
+            switch(in_wave->type()){
+               case RWaveFile::Unknown:
+                  printf("encoding: Unknown\n");
+                  break;
+               case RWaveFile::Wave:
+                  printf("encoding: Wave\n");
+                  break;
+               case RWaveFile::Mpeg:
+                  printf("encoding: Mpeg\n");
+                  break;
+               case RWaveFile::Ogg:
+                  printf("encoding: Ogg\n");
+                  break;
+               case RWaveFile::Atx:
+                  printf("encoding: Atx\n");
+                  break;
+               case RWaveFile::Tmc:
+                  printf("encoding: Tmc\n");
+                  break;
+               case RWaveFile::Flac:
+                  printf("encoding: Flac\n");
+                  break;
+            }
+            printf("channels: %d\n",in_wave->getChannels());
+            printf("samples per sec: %d\n",in_wave->getSamplesPerSec());
+            delete in_wave;
+            exit(0);
+         }
+      }
+      if(cmd->keys()!=(filename_pos+1)) {
+         fprintf(stderr,"rdfilewrite: missing filename argument\n");
+         exit(256);
+      }
+      out_filename=cmd->key(filename_pos);
+      RWaveFile *out_wave=new RWaveFile(out_filename);
+      out_wave->setBitsPerSample(16);
+      out_wave->setChannels(channels);
+      out_wave->setSamplesPerSec(sample_rate);
+      out_wave->setEnergyTag(set_energy);
+      switch(out_format){
+         case RDSettings::OggVorbis:
+            out_wave->setFormatTag(WAVE_FORMAT_VORBIS);
+            break;
+         case RDSettings::Pcm16:
+         default:
+            out_wave->setFormatTag(WAVE_FORMAT_PCM);
+            break;
+
+      }
+      out_wave->setBextChunk(true);
+      out_wave->setLevlChunk(true);
+      out_wave->setNormalizeLevel(normalize_level);
+      if(!out_wave->createWave(in_data)) {
     fprintf(stderr,"rdfilewrite: unable to open output file\n");
-    delete wavefile;
+         delete in_wave;
+         delete out_wave;
+         delete cmd;
     exit(256);
   }
 
   //
-  // Transfer Data
+      // transfer data
+      //
+      if(in_wave){
+         while((n=in_wave->readWave(buffer,RDFILEWRITE_BUFFER_SIZE))>0) {
+            out_wave->writeWave(buffer,n);
+         }
+         //
+         // clean up and exit
   //
+         out_wave->closeWave();
+         in_wave->closeWave();
+         delete out_wave;
+         delete in_wave;
+      }
+      else{
   while((n=read(0,buffer,RDFILEWRITE_BUFFER_SIZE))>0) {
-    wavefile->writeWave(buffer,n);
+            out_wave->writeWave(buffer,n);
   }
-
   //
-  // Clean Up and Exit
+         // clean up and exit
   //
-  wavefile->closeWave();
-  delete wavefile;
+         out_wave->closeWave();
+         delete out_wave;
+      }
+
+   }
+   delete cmd;
   exit(0);
 }
 

© 2005 KDRT 101.5 FM • Davis, California