[mythtv] [PATCH] Revisied mp3 audio options patch

David Zanetti dave2 at wetstring.net
Sun Dec 7 20:39:03 EST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attached patch is a revision of the mp3 codec option expansion patch I
posted a few days ago.

It now switches UI elements as suggested, so you only get the widgets
appropriate for the mode. Not 100% happy with the resulting look, but it
appears to be the same way the hardware MPEG audio option switching is
implemented.

CBR bitrates 32 and 64 have been commented out, as the encoder appeared to
produce a large number of 0-length chunks which caused all sorts of
playback problems. All other modes have been tried and appear to work as
expected.

This patch also uses the label "Performance" for the mp3quality
(lame_set_quality()) param with three options (Fast, Medium, Slow; with
quality indication afterwards). To be honest, I think it's more accurate,
but if it gets applied labelled something else I don't mind. :) The rest
of the changes are the meat of it anyway.

Not yet tested: directshow nuv playback.

Feedback very welcome :)

- -- 
David Zanetti           |  (__)             
#include <geek/unix.h>  |  ( oo    Mooooooo 
http://hairy.geek.nz/   |  /(_O ./         
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Made with pgp4pine 1.75-6

iD8DBQE/09Y5T21+qRy4P+QRAtTtAJ0ZbTUqKHPDNN1pxY5MYZ66lN0tSACgxL1/
7/uAMMaCZ2uFTDVtIfMTOlE=
=ak5L
-----END PGP SIGNATURE-----

-------------- next part --------------
diff -u mythtv-orig/libs/libmythtv/NuppelVideoRecorder.cpp mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
--- mythtv-orig/libs/libmythtv/NuppelVideoRecorder.cpp	2003-11-24 05:28:54.000000000 +1300
+++ mythtv/libs/libmythtv/NuppelVideoRecorder.cpp	2003-12-06 20:30:08.000000000 +1300
@@ -65,6 +65,11 @@
     height_multiplier = 1.0;
 
     mp3quality = 3;
+    mp3bitrate = 128;
+    mp3bitrateabr = 128;
+    mp3vbrqual = 4;
+    mp3encodingtype = 0;
+    mp3stereomode = 0;
     gf = NULL;
     rtjc = NULL;
     strm = NULL;   
@@ -256,6 +261,16 @@
         compressaudio = value;
     else if (opt == "mp3quality")
         mp3quality = value;
+    else if (opt == "mp3bitrate")
+        mp3bitrate = value;
+    else if (opt == "mp3bitrateabr")
+	mp3bitrateabr = value;
+    else if (opt == "mp3vbrqual")
+        mp3vbrqual = value;
+    else if (opt == "mp3stereomode")
+        mp3stereomode = value;
+    else if (opt == "mp3encodingtype")
+        mp3encodingtype = value;
     else if (opt == "samplerate")
         audio_samplerate = value;
     else if (opt == "audioframesize")
@@ -533,12 +548,45 @@
     if (compressaudio)
     {
         gf = lame_init();
+        lame_set_in_samplerate(gf, audio_samplerate);
+        lame_set_num_channels(gf, audio_channels);
         lame_set_bWriteVbrTag(gf, 0);
         lame_set_quality(gf, mp3quality);
-        lame_set_compression_ratio(gf, 11);
-        lame_set_mode(gf, audio_channels == 2 ? STEREO : MONO);
-        lame_set_num_channels(gf, audio_channels);
-        lame_set_in_samplerate(gf, audio_samplerate);
+        if (audio_channels == 2) {
+               /* only bother setting this for stereo audio, since
+                * lame will automatically use mono when set to one
+                * channel */
+        	switch (mp3stereomode) {
+                  case 0: /* Auto */
+                         /* do nothing */
+                        break;
+                  case 1: /* Joint Stereo */
+                        lame_set_mode(gf,JOINT_STEREO);
+                        break;
+                  case 2: /* Stereo */
+                        lame_set_mode(gf,STEREO);
+                        break;
+                  case 3: /* Mono */
+                        lame_set_mode(gf,MONO);
+                        break;
+        	} 
+        } 
+        switch (mp3encodingtype) {
+          case 0: /* CBR */
+		lame_set_brate(gf,mp3bitrate);
+                lame_set_VBR(gf,vbr_off);
+                break;
+          case 1: /* VBR */
+                lame_set_VBR(gf,vbr_mtrh); /* "New" VBR code */
+                lame_set_VBR_q(gf,mp3vbrqual);
+                break;
+          case 2: /* ABR */
+                lame_set_brate(gf, mp3bitrateabr);
+                lame_set_VBR(gf,vbr_abr);
+                lame_set_VBR_mean_bitrate_kbps(gf, mp3bitrateabr);
+                break;
+        }
+
         if((tmp = lame_init_params(gf)) != 0)
         {
             cerr << "lame_init_params error " << tmp << "\n";
diff -u mythtv-orig/libs/libmythtv/NuppelVideoRecorder.h mythtv/libs/libmythtv/NuppelVideoRecorder.h
--- mythtv-orig/libs/libmythtv/NuppelVideoRecorder.h	2003-11-23 18:44:16.000000000 +1300
+++ mythtv/libs/libmythtv/NuppelVideoRecorder.h	2003-12-06 20:10:49.000000000 +1300
@@ -142,6 +142,11 @@
     CommDetect *commDetect;
 
     int mp3quality;
+    int mp3bitrate;
+    int mp3bitrateabr;
+    int mp3vbrqual;
+    int mp3stereomode;
+    int mp3encodingtype;
     char *mp3buf;
     int mp3buf_size;
     lame_global_flags *gf;
diff -u mythtv-orig/libs/libmythtv/recordingprofile.cpp mythtv/libs/libmythtv/recordingprofile.cpp
--- mythtv-orig/libs/libmythtv/recordingprofile.cpp	2003-11-02 07:08:35.000000000 +1300
+++ mythtv/libs/libmythtv/recordingprofile.cpp	2003-12-08 13:57:40.000000000 +1300
@@ -44,19 +44,101 @@
     };
 };
 
-class MP3Quality: public CodecParam, public SliderSetting {
+class MP3Quality: public CodecParam, public ComboBoxSetting {
 public:
     MP3Quality(const RecordingProfile& parent):
-        CodecParam(parent, "mp3quality"),
-        SliderSetting(1,9,1) {
-        setLabel(QObject::tr("MP3 Quality"));
-        setValue(7);
-	setHelpText(QObject::tr("The higher the slider number, the lower the "
-                    "quality of the audio.  Better quality audio (lower "
-                    "numbers) requires more CPU."));
+        CodecParam(parent, "mp3quality") {
+        setLabel(QObject::tr("Performance"));
+        addSelection("Slow (High Quality)","2");
+        addSelection("Medium (Good Quality)","5");
+        addSelection("Fast (Okay Quality)","7");
+        setValue(2);
+        setHelpText(QObject::tr("How intensive should the encoder operate. This affects quality at the cost of CPU load, but bitrate is more important. Selecting \"Slow\" with low bitrates will still result in bad audio, so increase bitrate before trying this. If unsure, select \"Fast\"."));
+    };
+};
+
+class MP3BitrateABR: public CodecParam, public ComboBoxSetting {
+public:
+    MP3BitrateABR(const RecordingProfile& parent):
+	CodecParam(parent, "mp3bitrateabr") {
+	setLabel(QObject::tr("Average Bitrate"));
+
+// Although it works with all settings listed (and ABR accepts int values
+// between 8 and 310kps, disabling for consistancy
+//	addSelection("32 kbps", "32");
+//	addSelection("64 kbps", "64");
+	addSelection("96 kbps", "96");
+	addSelection("112 kbps", "112");
+	addSelection("128 kbps", "128");
+	addSelection("160 kbps", "160");
+	addSelection("192 kbps", "192");
+	addSelection("224 kbps", "224");
+	addSelection("256 kbps", "256");
+	addSelection("288 kbps", "288");
+	
+	setValue(2);
+	setHelpText(QObject::tr("Higher bitrates result in better quality, but at the cost of larger files. If unsure, select 128 kbps"));
+    };
+};
+
+class MP3Bitrate: public CodecParam, public ComboBoxSetting {
+public:
+    MP3Bitrate(const RecordingProfile& parent):
+	CodecParam(parent, "mp3bitrate") {
+	setLabel(QObject::tr("Bitrate"));
+
+// 32 and 64 seem to produce lots of zero-sized blocks in CBR
+//        addSelection("32 kbps", "32");
+//        addSelection("64 kbps", "64");
+        addSelection("96 kbps", "96");
+	addSelection("112 kbps", "112");
+        addSelection("128 kbps", "128");
+        addSelection("160 kbps", "160");
+        addSelection("192 kbps", "192");
+        addSelection("224 kbps", "224");
+        addSelection("256 kbps", "256");
+        addSelection("320 kbps", "320");
+
+        setValue(2);
+        setHelpText("Higher bitrates result in better quality, but at the cost of larger files. If unsure, select 128 kbps.");
     };
 };
 
+class MP3VBRQual: public CodecParam, public SliderSetting {
+public:
+     MP3VBRQual(const RecordingProfile& parent):
+        CodecParam(parent, "mp3vbrqual"),
+        SliderSetting(0,9,1) {
+        setLabel(QObject::tr("VBR Quality"));
+        setValue(4);
+        setHelpText("VBR quality desired. Lower numbers are higher quality, at the cost of larger files. If unsure, select 4.");
+     };
+};
+
+class MP3EncodingType: public CodecParam, public ComboBoxSetting {
+public:
+     MP3EncodingType(const RecordingProfile& parent):
+        CodecParam(parent, "mp3encodingtype") {
+        setLabel(QObject::tr("Encoding Type"));
+        setHelpText("CBR produces fixed size audio at the bitrate given regardless of input. VBR and ABR float the bitrate used as needed based on the input audio, VBR chooses by desired quality, ABR chooses by desired bitrate. If unsure, select CBR.");
+     };
+};
+
+class MP3StereoMode: public CodecParam, public ComboBoxSetting {
+public:
+     MP3StereoMode(const RecordingProfile& parent):
+        CodecParam(parent, "mp3stereomode") {
+        setLabel(QObject::tr("Stereo mode"));
+        addSelection("Auto","0");
+        addSelection("Joint-Stereo","1");
+        addSelection("Stereo","2");
+        addSelection("Mono","3");
+ 
+        setValue(0);
+        setHelpText("Joint-Stereo may produce better quality audio in lower bitrates than Stereo, but Stereo will have more correct stereo seperation at the cost of needing more bitrate. Mono will downmix audio to one channel. If unsure, select Auto.");
+     };
+};
+
 class SampleRate: public CodecParam, public ComboBoxSetting {
 public:
     SampleRate(const RecordingProfile& parent, bool analog = true):
@@ -74,12 +156,46 @@
             //addSelection("44100");
             //addSelection("32000");
         }
-	setHelpText(QObject::tr("Sets the audio sampling rate for your DSP. "
+        setHelpText(QObject::tr("Sets the audio sampling rate for your DSP. "
                     "Ensure that you choose a sampling rate appropriate "
                     "for your device.  btaudio may only allow 32000."));
     };
 };
 
+class MP3BitrateSettings: public VerticalConfigurationGroup,
+	public TriggeredConfigurationGroup {
+public:
+    MP3BitrateSettings(const RecordingProfile& parent)
+	    : VerticalConfigurationGroup(false)
+    {
+	setLabel(QObject::tr("Encoding Type"));
+	setUseLabel(false);
+	MP3EncodingType* encType = new MP3EncodingType(parent);
+	addChild(encType);
+	setTrigger(encType);
+
+	ConfigurationGroup* encOpt = new VerticalConfigurationGroup(false);
+	encOpt->addChild(new MP3Bitrate(parent));
+	encOpt->setLabel("CBR (Constant Bitrate)");
+	addTarget("0",encOpt);
+	encType->addSelection("CBR (Constant Bitrate)","0");
+
+	encOpt = new VerticalConfigurationGroup(false);
+	encOpt->addChild(new MP3BitrateABR(parent));
+	encOpt->setLabel("ABR (Average Bitrate)");
+	addTarget("1",encOpt);
+	encType->addSelection("ABR (Average Bitrate)","1");
+	
+	encOpt = new VerticalConfigurationGroup(false);
+	encOpt->addChild(new MP3VBRQual(parent));
+	encOpt->setLabel("VBR (Variable Bitrate)");
+	addTarget("2",encOpt);
+	encType->addSelection("VBR (Variable Bitrate)","2");
+
+	encType->setValue(0);
+    };
+};
+
 class MPEG2audType: public CodecParam, public ComboBoxSetting {
 public:
    MPEG2audType(const RecordingProfile& parent):
@@ -198,8 +314,10 @@
 
         ConfigurationGroup* params = new VerticalConfigurationGroup(false);
         params->setLabel("MP3");
-        params->addChild(new SampleRate(parent));
+        params->addChild(new MP3BitrateSettings(parent));
+        params->addChild(new MP3StereoMode(parent));
         params->addChild(new MP3Quality(parent));
+        params->addChild(new SampleRate(parent));
         addTarget("MP3", params);
 
         params = new VerticalConfigurationGroup(false);
diff -u mythtv-orig/libs/libmythtv/tv_rec.cpp mythtv/libs/libmythtv/tv_rec.cpp
--- mythtv-orig/libs/libmythtv/tv_rec.cpp	2003-11-12 21:45:47.000000000 +1300
+++ mythtv/libs/libmythtv/tv_rec.cpp	2003-12-06 20:23:12.000000000 +1300
@@ -622,6 +622,11 @@
     {
         nvr->SetOption("audiocompression", 1);
         SetOption(profile, "mp3quality");
+        SetOption(profile, "mp3vbrqual");
+        SetOption(profile, "mp3stereomode");
+        SetOption(profile, "mp3bitrate");
+        SetOption(profile, "mp3bitrateabr");
+        SetOption(profile, "mp3encodingtype");
         SetOption(profile, "samplerate");
     } 
     else if (setting == "Uncompressed") 


More information about the mythtv-dev mailing list