summaryrefslogtreecommitdiff
path: root/libav/audio.c
diff options
context:
space:
mode:
authorPhilip Gladstone <philipjsg@users.sourceforge.net>2002-05-09 01:15:21 +0000
committerPhilip Gladstone <philipjsg@users.sourceforge.net>2002-05-09 01:15:21 +0000
commit1de1cce27d52c0dbb37e58976762812122c5a8c9 (patch)
treeb09fb1d321d8911f6fce91b2e06fb8e448701ef9 /libav/audio.c
parentf80c1ac01b0961137ea3f6fe064c04d549c657fa (diff)
* 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
Diffstat (limited to 'libav/audio.c')
-rw-r--r--libav/audio.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libav/audio.c b/libav/audio.c
index 1091f6bc95..ddbe382d60 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;
}