[xiph-cvs] cvs commit: ices/src audio.c audio.h reencode.c reencode.h

Michael Smith msmith at xiph.org
Sat Aug 3 07:41:11 PDT 2002



msmith      02/08/03 07:41:11

  Modified:    src      audio.c audio.h reencode.c reencode.h
  Log:
  Working downmixing and resampling for reencoding as well, now.

Revision  Changes    Path
1.2       +18 -2     ices/src/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/audio.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio.c	2002/08/03 08:21:33	1.1
+++ audio.c	2002/08/03 14:41:10	1.2
@@ -2,7 +2,7 @@
  * stereo->mono downmixing
  * resampling
  *
- * $Id: audio.c,v 1.1 2002/08/03 08:21:33 msmith Exp $
+ * $Id: audio.c,v 1.2 2002/08/03 14:41:10 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -27,7 +27,7 @@
 downmix_state *downmix_initialise(void) {
     downmix_state *state = calloc(1, sizeof(downmix_state));
 
-    LOG_INFO0("Enabling mono->stereo downmixing");
+    LOG_INFO0("Enabling stereo->mono downmixing");
 
     return state;
 }
@@ -38,6 +38,22 @@
         free(s);
     }
 }
+
+void downmix_buffer_float(downmix_state *s, float **buf, int samples)
+{
+    int i;
+
+    if(samples > s->buflen) {
+        s->buffer = realloc(s->buffer, samples * sizeof(float));
+        s->buflen = samples;
+    }
+
+    for(i=0; i < samples; i++) {
+        s->buffer[i] = (buf[0][i] + buf[1][i])*0.5;
+    }
+    
+}
+
 
 void downmix_buffer(downmix_state *s, signed char *buf, int len, int be)
 {

<p><p>1.2       +2 -1      ices/src/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/audio.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio.h	2002/08/03 08:21:33	1.1
+++ audio.h	2002/08/03 14:41:10	1.2
@@ -2,7 +2,7 @@
  * - stereo->mono downmixing
  * - resampling
  *
- * $Id: audio.h,v 1.1 2002/08/03 08:21:33 msmith Exp $
+ * $Id: audio.h,v 1.2 2002/08/03 14:41:10 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -37,6 +37,7 @@
 downmix_state *downmix_initialise(void);
 void downmix_clear(downmix_state *s);
 void downmix_buffer(downmix_state *s, signed char *buf, int len, int be);
+void downmix_buffer_float(downmix_state *s, float **buf, int samples);
 
 resample_state *resample_initialise(int channels, int infreq, int outfreq);
 void resample_clear(resample_state *s);

<p><p>1.6       +50 -12    ices/src/reencode.c

Index: reencode.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- reencode.c	2002/08/03 12:11:57	1.5
+++ reencode.c	2002/08/03 14:41:10	1.6
@@ -1,7 +1,7 @@
 /* reencode.c
  * - runtime reencoding of vorbis audio (usually to lower bitrates).
  *
- * $Id: reencode.c,v 1.5 2002/08/03 12:11:57 msmith Exp $
+ * $Id: reencode.c,v 1.6 2002/08/03 14:41:10 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "stream.h"
 #include "encode.h"
+#include "audio.h"
 
 #define MODULE "reencode/"
 #include "logging.h"
@@ -83,6 +84,11 @@
 
                 if(s->encoder)
                 {
+            if(s->resamp) {
+                resample_finish(s->resamp);
+                encode_data_float(s->encoder, s->resamp->buffers, 
+                        s->resamp->buffill);
+            }
                         encode_finish(s->encoder);
                         while(encode_flush(s->encoder, &encog) != 0)
                         {
@@ -96,6 +102,10 @@
                 }
                 encode_clear(s->encoder);
         s->encoder = NULL;
+        resample_clear(s->resamp);
+        s->resamp = NULL;
+        downmix_clear(s->downmix);
+        s->downmix = NULL;
 
                 ogg_stream_clear(&s->os);
                 ogg_stream_init(&s->os, s->current_serial);
@@ -137,25 +147,35 @@
                                 {
                                         vorbis_block_init(&s->vd, &s->vb);
                                         vorbis_synthesis_init(&s->vd, &s->vi);
-					if(s->vi.channels != s->out_channels
-						|| s->vi.rate != s->out_samplerate)
-					{
-						/* FIXME: Implement this. In the shorter term, at
-						 * least free all the memory that's lying around.
-						 */
-						LOG_ERROR0("Converting channels or sample rate NOT "
-								"currently supported.");
-						return -1;
-					}
                                         
                                         s->encoder = encode_initialise(s->out_channels, 
                                                         s->out_samplerate, s->managed, 
                             s->out_min_br, s->out_nom_br, s->out_max_br,
                                                         s->quality, s->current_serial, &s->vc);
+
                     if(!s->encoder) {
                         LOG_ERROR0("Failed to configure encoder for reencoding");
                         return -1;
                     }
+                    if(s->vi.rate != s->out_samplerate) {
+                        s->resamp = resample_initialise(s->out_channels,
+                                s->vi.rate, s->out_samplerate);
+                    }
+                    else
+                        s->resamp = NULL;
+
+                    if(s->vi.channels != s->out_channels) {
+                        if(s->vi.channels == 2 && s->out_channels == 1)
+                            s->downmix = downmix_initialise();
+                        else {
+                            LOG_ERROR2("Converting from %d to %d channels is not"
+                                    " currently supported", s->vi.channels,
+                                    s->out_channels);
+                            return -1;
+                        }
+                    }
+                    else
+                        s->downmix = NULL;
                                 }
                         }
                         else
@@ -171,7 +191,25 @@
 
                                 while((samples = vorbis_synthesis_pcmout(&s->vd, &pcm))>0)
                                 {
-					encode_data_float(s->encoder, pcm, samples);
+                    if(s->downmix) {
+                        downmix_buffer_float(s->downmix, pcm, samples);
+                        if(s->resamp) {
+                            resample_buffer_float(s->resamp, &s->downmix->buffer,
+                                    samples);
+                            encode_data_float(s->encoder, s->resamp->buffers,
+                                    s->resamp->buffill);
+                        }
+                        else 
+                            encode_data_float(s->encoder, &s->downmix->buffer,
+                                    samples);
+                    }
+                    else if(s->resamp) {
+                        resample_buffer_float(s->resamp, pcm, samples);
+                        encode_data_float(s->encoder, s->resamp->buffers,
+                                s->resamp->buffill);
+                    }
+                    else
+					    encode_data_float(s->encoder, pcm, samples);
                                         vorbis_synthesis_read(&s->vd, samples);
                                 }
 

<p><p>1.4       +4 -1      ices/src/reencode.h

Index: reencode.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/reencode.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- reencode.h	2002/01/28 00:19:15	1.3
+++ reencode.h	2002/08/03 14:41:10	1.4
@@ -1,7 +1,7 @@
 /* reencode.h
  * - reencoding functions
  *
- * $Id: reencode.h,v 1.3 2002/01/28 00:19:15 msmith Exp $
+ * $Id: reencode.h,v 1.4 2002/08/03 14:41:10 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "stream.h"
 #include "encode.h"
+#include "audio.h"
 
 typedef struct {
         int out_min_br;
@@ -44,6 +45,8 @@
         vorbis_block vb;
 
         encoder_state *encoder;
+    downmix_state *downmix;
+    resample_state *resamp;
 
 } reencode_state;
 

<p><p><p><p>--- >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