[mythtv] [PATCH] mono support
Jim Radford
mythtv-dev@snowman.net
Wed, 13 Nov 2002 17:33:19 -0800
So far I haven't been able to get my cheap AverTV Stereo card to
actually work in stereo, so I needed this patch to kill the chipmunks.
The audio is still out of sync though. Isaac, can you think of any
other places that need to be updated? I don't understand how the
audio is synced yet.
-Jim
Index: libs/libNuppelVideo/NuppelVideoPlayer.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libNuppelVideo/NuppelVideoPlayer.cpp,v
retrieving revision 1.95
diff -u -r1.95 NuppelVideoPlayer.cpp
--- libs/libNuppelVideo/NuppelVideoPlayer.cpp 17 Nov 2002 11:51:26 -0000 1.95
+++ libs/libNuppelVideo/NuppelVideoPlayer.cpp 17 Nov 2002 23:30:23 -0000
@@ -75,6 +75,7 @@
weMadeBuffer = false;
osd = NULL;
+ audio_channels = 2;
audio_samplerate = 44100;
editmode = false;
advancevideo = resetvideo = advancedecoder = false;
@@ -171,12 +172,12 @@
void NuppelVideoPlayer::InitSound(void)
{
- int bits = 16, stereo = 1, speed = audio_samplerate, caps;
+ int bits = 16, channels = audio_channels, speed = audio_samplerate, caps;
if (usingextradata)
{
bits = extradata.audio_bits_per_sample;
- stereo = (extradata.audio_channels == 2);
+ channels = extradata.audio_channels;
speed = extradata.audio_sample_rate;
}
@@ -202,11 +203,18 @@
return;
}
- if (ioctl(audiofd, SNDCTL_DSP_STEREO, &stereo) < 0)
+ cout << "setting channels to " << channels << endl;
+ if (ioctl(audiofd, SNDCTL_DSP_CHANNELS, &channels) < 0)
{
cerr << "problem setting to stereo, exiting\n";
close(audiofd);
audiofd = -1;
return;
}
+ cout << "actually set channels to " << channels << endl;
+ if(channels != audio_channels) {
+ cout << "output forced to use " << channels
+ << " instead of " << audio_channels << endl;
+ audio_channels = channels;
+ }
@@ -479,8 +488,10 @@
foundit = 0;
effdsp = audio_samplerate;
- if (usingextradata)
+ if (usingextradata) {
effdsp = extradata.audio_sample_rate;
+ audio_channels = extradata.audio_channels;
+ }
while (!foundit)
{
@@ -856,7 +867,7 @@
ioctl(audiofd, SNDCTL_DSP_GETODELAY, &soundcard_buffer); // bytes
totalbuffer = audiolen(false) + soundcard_buffer;
- audiotime = audbuf_timecode - (int)((double)totalbuffer * 25000.0 /
+ audiotime = audbuf_timecode - (int)((double)totalbuffer * 50000.0 / audio_channels /
(double)effdsp);
gettimeofday(&audiotime_updated, NULL);
Index: libs/libNuppelVideo/NuppelVideoPlayer.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libNuppelVideo/NuppelVideoPlayer.h,v
retrieving revision 1.48
diff -u -r1.48 NuppelVideoPlayer.h
--- libs/libNuppelVideo/NuppelVideoPlayer.h 15 Nov 2002 00:12:07 -0000 1.48
+++ libs/libNuppelVideo/NuppelVideoPlayer.h 17 Nov 2002 23:30:23 -0000
@@ -183,6 +183,7 @@
unsigned char *buf2;
char lastct;
int effdsp; // from the recorded stream
+ int audio_channels; // from the recorded stream
int audio_samplerate; // rate to tell the output device
int filesize;
int startpos;
Index: libs/libNuppelVideo/NuppelVideoRecorder.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libNuppelVideo/NuppelVideoRecorder.cpp,v
retrieving revision 1.61
diff -u -r1.61 NuppelVideoRecorder.cpp
--- libs/libNuppelVideo/NuppelVideoRecorder.cpp 16 Nov 2002 20:08:08 -0000 1.61
+++ libs/libNuppelVideo/NuppelVideoRecorder.cpp 17 Nov 2002 23:30:25 -0000
@@ -71,6 +71,7 @@
keyframedist = KEYFRAMEDIST;
audiobytes = 0;
+ audio_channels = 2;
audio_samplerate = 44100;
picture_format = PIX_FMT_YUV420P;
@@ -331,11 +333,19 @@
if (afmt != AFMT_S16_LE)
{
cerr << "Can't get 16 bit DSP, exiting\n";
- return(1);
+ return 1;
}
- channels = 2;
- ioctl(afd, SNDCTL_DSP_CHANNELS, &channels);
+ channels = audio_channels;
+ if(ioctl(afd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+ cerr << "setting sample channels failed, exiting\n";
+ return 1;
+ }
+ if(channels != audio_channels) {
+ cout << "input forced to use " << channels
+ << " instead of " << audio_channels << endl;
+ audio_channels = channels;
+ }
/* sample rate */
rate = audio_samplerate;
@@ -354,7 +385,7 @@
if (-1 == ioctl(afd, SNDCTL_DSP_GETBLKSIZE, &blocksize))
{
cerr << "Can't get DSP blocksize, exiting\n";
- return(1);
+ return 1;
}
blocksize *= 4;
@@ -1107,7 +1138,7 @@
}
moredata.audio_sample_rate = audio_samplerate;
- moredata.audio_channels = 2;
+ moredata.audio_channels = audio_channels;
moredata.audio_bits_per_sample = 16;
extendeddataOffset = ringBuffer->GetFileWritePosition();
@@ -1264,12 +1295,25 @@
return;
}
- channels = 2;
- ioctl(afd, SNDCTL_DSP_CHANNELS, &channels);
+ channels = audio_channels;
+ if(ioctl(afd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+ cerr << "Can't set DSP channels, exiting";
+ close(afd);
+ return;
+ }
+ if(channels != audio_channels) {
+ cout << "input forced to use " << channels
+ << " instead of " << audio_channels << endl;
+ audio_channels = channels;
+ }
/* sample rate */
rate = audio_samplerate;
- ioctl(afd, SNDCTL_DSP_SPEED, &rate);
+ if(ioctl(afd, SNDCTL_DSP_SPEED, &rate) < 0) {
+ cerr << "Can't set DSP sample rate, exiting";
+ close(afd);
+ return;
+ }
if (-1 == ioctl(afd, SNDCTL_DSP_GETBLKSIZE, &blocksize))
{
Index: libs/libNuppelVideo/NuppelVideoRecorder.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libNuppelVideo/NuppelVideoRecorder.h,v
retrieving revision 1.24
diff -u -r1.24 NuppelVideoRecorder.h
--- libs/libNuppelVideo/NuppelVideoRecorder.h 15 Nov 2002 21:40:21 -0000 1.24
+++ libs/libNuppelVideo/NuppelVideoRecorder.h 17 Nov 2002 23:30:25 -0000
@@ -126,6 +126,7 @@
int compression;
int compressaudio;
unsigned long long audiobytes;
+ int audio_channels; // channels to request from sounddevice
int audio_samplerate; // rate we request from sounddevice
int effectivedsp; // actual measured rate