[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123.c
Jack Moffitt
jack at xiph.org
Fri Dec 7 12:47:41 PST 2001
jack 01/12/07 12:47:41
Modified: ogg123 Tag: volsung_kc_20011011 ogg123.c
Log:
Some cards don't do mono2stereo conversion. Some cards are broken. Some
drivers are broken. We'll help them all out by doing the conversion
ourselves.
Revision Changes Path
No revision
No revision
1.39.2.30.2.11 +41 -7 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.30.2.10
retrieving revision 1.39.2.30.2.11
diff -u -r1.39.2.30.2.10 -r1.39.2.30.2.11
--- ogg123.c 2001/11/23 05:15:29 1.39.2.30.2.10
+++ ogg123.c 2001/12/07 20:47:39 1.39.2.30.2.11
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.39.2.30.2.10 2001/11/23 05:15:29 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.30.2.11 2001/12/07 20:47:39 jack Exp $
********************************************************************/
@@ -40,6 +40,7 @@
/* take buffer out of the data segment, not the stack */
#define BUFFER_CHUNK_SIZE 4096
unsigned char convbuffer[BUFFER_CHUNK_SIZE];
+unsigned char convbuffer2[BUFFER_CHUNK_SIZE];
int convsize = BUFFER_CHUNK_SIZE;
/* take big options structure from the data segment */
@@ -713,6 +714,10 @@
double realseekpos = Options.playOpts.seekpos;
int nthc = 0, ntimesc = 0;
long bitrate;
+ int mono2stereo = 0;
+ ogg_int16_t *src, *dest;
+ int c;
+ int count;
ov_callbacks VorbisfileCallbacks;
/* Setup callbacks and data structures for HTTP stream or file */
@@ -789,6 +794,11 @@
Options.outputOpts.rate = vi->rate;
Options.outputOpts.channels = vi->channels;
+ if (Options.outputOpts.channels == 1) {
+ mono2stereo = 1;
+ Options.outputOpts.channels = 2;
+ }
+
/* Open audio device before we read and output comments. We have
to do this inside the loop in order to deal with chained
bitstreams with different sample rates */
@@ -889,9 +899,15 @@
/* Read another block of audio data */
old_section = current_section;
- ret =
- ov_read(&vf, (char *) convbuffer, sizeof(convbuffer), is_big_endian,
- 2, 1, ¤t_section);
+ if (mono2stereo)
+ ret =
+ ov_read(&vf, (char *) convbuffer, sizeof(convbuffer) / 2, is_big_endian,
+ 2, 1, ¤t_section);
+ else
+ ret =
+ ov_read(&vf, (char *) convbuffer, sizeof(convbuffer), is_big_endian,
+ 2, 1, ¤t_section);
+
if (ret == 0)
{
/* End of file */
@@ -933,18 +949,36 @@
as needed */
if (ret > 0)
{
+ if (mono2stereo) {
+ count = sizeof(convbuffer) / 4;
+ src = (ogg_int16_t *)convbuffer;
+ dest = (ogg_int16_t *)convbuffer2;
+ for (c = 0; c < count; c++) {
+ *dest++ = *src;
+ *dest++ = *src++;
+ }
+ memcpy(convbuffer, convbuffer2, sizeof(convbuffer));
+ }
+
do
{
if (nthc-- == 0)
{
if (Options.outputOpts.buffer)
{
- buffer_submit_data (Options.outputOpts.buffer,
- convbuffer, ret, 1);
+ if (mono2stereo)
+ buffer_submit_data (Options.outputOpts.buffer,
+ convbuffer, ret*2, 1);
+ else
+ buffer_submit_data (Options.outputOpts.buffer,
+ convbuffer, ret, 1);
UpdateStats();
}
else
- OutBufferWrite (convbuffer, ret, 1, &Options, 0);
+ if (mono2stereo)
+ OutBufferWrite (convbuffer, ret*2, 1, &Options, 0);
+ else
+ OutBufferWrite (convbuffer, ret, 1, &Options, 0);
nthc = Options.playOpts.nth - 1;
}
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list