[mythtv] [patch] for reencoding with resampling

Craig Longman craigl at begeek.com
Mon May 19 02:04:47 EDT 2003


Isaac Richards wrote:

>It completely ignores the audio settings for the hardware encoding for now.  
>It's recorded at a 48kHz, it's in the file as 48kHz, it gets played back at 
>48kHz.  The transcoding process, however, doesn't pay any attention to that 
>whatsoever, and just assumes that it's at 32kHz because you said it was.  It 
>needs to resample the audio down to 32kHz.
>
>The annoying whine, on the other hand, is an ivtv driver bug (in the msp3400) 
>module).
>
ok, the whine i was hearing was simply an artifact of the 48K input and 
32K output.  thought i'd stumbled into something there.  should've 
looked harder before opening my mouth.

attached is a patch for review that allows the ReencodeFile() method to 
specify separate in & out sample rates to NuppelVideoRecorder.  its 
reasonably simple.  and seems to resample the audio as requested.

however, i have one trouble with it.  when i select the output audio as 
mp3, the audio is slightly delayed, and it seems to be consistently 
delayed (ie, it starts off behind ~.1-.25 seconds and stays there, it 
doesn't walk around) but if i choose uncompressed, the audio is pretty 
much bang on.  i haven't been able to figure out what is causing this 
yet, so i'd appreciate any suggestions.

i created this patch with the following command (while in the libmythtv 
directory):

     cvs -z3 -Q diff -ud > transcode.patch

if there was some extra cleaning up i should do to the output of that 
before submitting it, please lemme know.

cheers,

    CraigL->Thx();

-------------- next part --------------
Index: NuppelVideoPlayer.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp,v
retrieving revision 1.197
diff -u -d -r1.197 NuppelVideoPlayer.cpp
--- NuppelVideoPlayer.cpp 17 May 2003 20:50:57 -0000  1.197
+++ NuppelVideoPlayer.cpp 19 May 2003 04:53:43 -0000
@@ -2730,6 +2730,7 @@
         nvr->SetOption("audiocompression", 1);
         SetProfileOption(profile, "mp3quality");
         SetProfileOption(profile, "samplerate");
+        nvr->SetOption( "insamplerate", audio_samplerate );
         decoder->SetRawFrameState(true);
     }
     else if (setting == "Uncompressed")
@@ -2807,6 +2808,7 @@
                 int starttime = audbuf_timecode -
                                 (int)((audioframesize * 100000.0)
                                 / (audio_bytes_per_sample * effdsp));
+
                 nvr->WriteAudio(audiobuffer + raud, audioFrame++, starttime);
                 /* update raud */
                 raud = (raud + audioframesize) % AUDBUFSIZE;
Index: NuppelVideoRecorder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp,v
retrieving revision 1.113
diff -u -d -r1.113 NuppelVideoRecorder.cpp
--- NuppelVideoRecorder.cpp 18 May 2003 14:07:13 -0000  1.113
+++ NuppelVideoRecorder.cpp 19 May 2003 04:53:44 -0000
@@ -95,7 +95,8 @@
     audiobytes = 0;
     audio_bits = 16;
     audio_channels = 2;
-    audio_samplerate = 44100;
+    audio_out_samplerate = 44100;
+    audio_in_samplerate = 32000;
     audio_bytes_per_sample = audio_channels * audio_bits / 8;

     picture_format = PIX_FMT_YUV420P;
@@ -249,7 +250,9 @@
     else if (opt == "mp3quality")
         mp3quality = value;
     else if (opt == "samplerate")
-        audio_samplerate = value;
+        audio_out_samplerate = value;
+    else if (opt == "insamplerate")
+        audio_in_samplerate = value;
     else if (opt == "audioframesize")
         audio_buffer_size = value;
     else
@@ -492,11 +495,11 @@

         if (ioctl(afd, SNDCTL_DSP_SAMPLESIZE, &audio_bits) < 0 ||
             ioctl(afd, SNDCTL_DSP_CHANNELS, &audio_channels) < 0 ||
-            ioctl(afd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0)
+            ioctl(afd, SNDCTL_DSP_SPEED, &audio_out_samplerate) < 0)
         {
             cerr << "recorder: " << audiodevice
                  << ": error setting audio input device to "
-                 << audio_samplerate << "kHz/"
+                 << audio_out_samplerate << "kHz/"
                  << audio_bits << "bits/"
                  << audio_channels << "channel\n";
             return 1;
@@ -524,8 +527,8 @@
         lame_set_compression_ratio(gf, 11);
         lame_set_mode(gf, audio_channels == 2 ? STEREO : MONO);
         lame_set_num_channels(gf, audio_channels);
-        lame_set_out_samplerate(gf, audio_samplerate);
-        lame_set_in_samplerate(gf, audio_samplerate);
+        lame_set_out_samplerate(gf, audio_out_samplerate);
+        lame_set_in_samplerate(gf, audio_in_samplerate);
         lame_init_params(gf);

         if (audio_bits != 16)
@@ -1423,7 +1426,7 @@
         moredata.audio_fourcc = MKTAG('R', 'A', 'W', 'A');
     }

-    moredata.audio_sample_rate = audio_samplerate;
+    moredata.audio_sample_rate = audio_out_samplerate;
     moredata.audio_channels = audio_channels;
     moredata.audio_bits_per_sample = audio_bits;

@@ -1605,11 +1608,11 @@

     if (ioctl(afd, SNDCTL_DSP_SAMPLESIZE, &audio_bits) < 0 ||
         ioctl(afd, SNDCTL_DSP_CHANNELS, &audio_channels) < 0 ||
-        ioctl(afd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0)
+        ioctl(afd, SNDCTL_DSP_SPEED, &audio_out_samplerate) < 0)
     {
         cerr << "recorder: " << audiodevice
              << ": error setting audio input device to "
-             << audio_samplerate << "kHz/"
+             << audio_out_samplerate << "kHz/"
              << audio_bits << "bits/"
              << audio_channels << "channel\n";
         close(afd);
@@ -1688,7 +1691,7 @@
            and the length of audio still in the capture buffer. */
         audiobuffer[act]->timecode -= (int)(
                 (ispace.fragments * ispace.fragsize + audio_buffer_size)
-                 * 1000.0 / (audio_samplerate * audio_bytes_per_sample));
+                 * 1000.0 / (audio_out_samplerate * audio_bytes_per_sample));

         memcpy(audiobuffer[act]->buffer, buffer, audio_buffer_size);

Index: NuppelVideoRecorder.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoRecorder.h,v
retrieving revision 1.47
diff -u -d -r1.47 NuppelVideoRecorder.h
--- NuppelVideoRecorder.h 14 May 2003 02:43:29 -0000  1.47
+++ NuppelVideoRecorder.h 19 May 2003 04:53:44 -0000
@@ -137,7 +137,8 @@
     int audio_channels;
     int audio_bits;
     int audio_bytes_per_sample;
-    int audio_samplerate; // rate we request from sounddevice
+    int audio_out_samplerate; // rate we request from sounddevice
+    int audio_in_samplerate; // rate we will be receiving
     int effectivedsp; // actual measured rate

     int quiet;


More information about the mythtv-dev mailing list