From 1de1cce27d52c0dbb37e58976762812122c5a8c9 Mon Sep 17 00:00:00 2001 From: Philip Gladstone Date: Thu, 9 May 2002 01:15:21 +0000 Subject: [PATCH] * Make it work with sound cards (like mine) that can only capture in stereo. * Add a kludge to allow the left channel to be inverted -- my tv card/sound card ends up with the left channel = minus right channel. Converting to mono by adding the channels doesn't work well. Originally committed as revision 458 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libav/audio.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libav/audio.c b/libav/audio.c index 1091f6b..ddbe382 100644 --- a/libav/audio.c +++ b/libav/audio.c @@ -38,6 +38,7 @@ typedef struct { int channels; int frame_size; /* in bytes ! */ int codec_id; + int flip_left : 1; UINT8 buffer[AUDIO_BLOCK_SIZE]; int buffer_ptr; } AudioData; @@ -46,6 +47,7 @@ static int audio_open(AudioData *s, int is_output) { int audio_fd; int tmp, err; + char *flip = getenv("AUDIO_FLIP_LEFT"); /* open linux audio device */ if (is_output) @@ -57,6 +59,10 @@ static int audio_open(AudioData *s, int is_output) return -EIO; } + if (flip && *flip == '1') { + s->flip_left = 1; + } + /* non blocking mode */ fcntl(audio_fd, F_SETFL, O_NONBLOCK); @@ -114,6 +120,8 @@ static int audio_open(AudioData *s, int is_output) perror("SNDCTL_DSP_STEREO"); goto fail; } + if (tmp) + s->channels = 2; tmp = s->sample_rate; err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp); @@ -259,6 +267,15 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) } } pkt->size = ret; + if (s->flip_left && s->channels == 2) { + int i; + short *p = (short *) pkt->data; + + for (i = 0; i < ret; i += 4) { + *p = ~*p; + p += 2; + } + } return 0; } -- 2.7.4