[xiph-cvs] cvs commit: ices/src downmix.c downmix.h Makefile.am config.c config.h input.h metadata.c stream.c stream_shared.c

Michael Smith msmith at xiph.org
Sat Jul 20 05:52:08 PDT 2002



msmith      02/07/20 05:52:07

  Modified:    .        TODO
               conf     ices-live.xml
               src      Makefile.am config.c config.h input.h metadata.c
                        stream.c stream_shared.c
  Added:       src      downmix.c downmix.h
  Log:
  Stereo->mono downmixing. Currently only on live encode, not on reencoding.

Revision  Changes    Path
1.2       +3 -0      ices/TODO

Index: TODO
===================================================================
RCS file: /usr/local/cvsroot/ices/TODO,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TODO	2001/09/10 02:30:48	1.1
+++ TODO	2002/07/20 12:52:05	1.2
@@ -1,6 +1,9 @@
 - playlist scripting
 - cue files?
 - stream rewriting for serial number increment, etc.
+- DOCUMENTATION!
+- resampling.
+
 
 
 

<p><p>1.4       +5 -2      ices/conf/ices-live.xml

Index: ices-live.xml
===================================================================
RCS file: /usr/local/cvsroot/ices/conf/ices-live.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ices-live.xml	2002/01/29 09:20:26	1.3
+++ ices-live.xml	2002/07/20 12:52:05	1.4
@@ -23,7 +23,7 @@
                 <input>
                         <module>oss</module>
                         <param name="rate">22050</param> <!-- samplerate -->
-			<param name="channels">1</param> <!-- number of channels -->
+			<param name="channels">2</param> <!-- number of channels -->
                         <param name="device">/dev/dsp</param> <!-- audio device -->
                         <param name="metadata">1</param> <!-- Read metadata (from stdin by default, or filename defined below (if the latter, only on SIGUSR1) -->
                         <param name="metadatafilename">test</param>
@@ -60,8 +60,11 @@
                         <encode>  
                                 <quality>3</quality>
                                 <samplerate>22050</samplerate>
-				<channels>1</channels>
+				<channels>2</channels>
                         </encode>
+
+            <!-- stereo->mono downmixing, enabled by setting this to 1 -->
+            <downmix>0</downmix>
                 </instance>
 
         </stream>

<p><p>1.7       +2 -2      ices/src/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/ices/src/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.am	2002/06/29 15:22:33	1.6
+++ Makefile.am	2002/07/20 12:52:06	1.7
@@ -20,8 +20,8 @@
 
 bin_PROGRAMS = ices
 
-noinst_HEADERS = config.h input.h inputmodule.h im_playlist.h signals.h stream.h reencode.h encode.h playlist_basic.h logging.h im_stdinpcm.h $(ossheaders) $(sunheaders) event.h stream_shared.h metadata.h
-ices_SOURCES = input.c config.c stream.c ices.c signals.c im_playlist.c reencode.c encode.c playlist_basic.c im_stdinpcm.c $(osssources) $(sunsources) stream_shared.c savefile.c metadata.c stream_rewrite.c playlist_script.c
+noinst_HEADERS = config.h input.h inputmodule.h im_playlist.h signals.h stream.h reencode.h encode.h playlist_basic.h logging.h im_stdinpcm.h $(ossheaders) $(sunheaders) event.h stream_shared.h metadata.h downmix.h
+ices_SOURCES = input.c config.c stream.c ices.c signals.c im_playlist.c reencode.c encode.c playlist_basic.c im_stdinpcm.c $(osssources) $(sunsources) stream_shared.c savefile.c metadata.c stream_rewrite.c playlist_script.c downmix.c
 
 ices_LDADD = net/libicenet.la thread/libicethread.la log/libicelog.la\
         avl/libiceavl.la timing/libicetiming.la

<p><p>1.9       +5 -1      ices/src/config.c

Index: config.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- config.c	2002/07/05 07:55:02	1.8
+++ config.c	2002/07/20 12:52:06	1.9
@@ -1,7 +1,7 @@
 /* config.c
  * - config file reading code, plus default settings.
  *
- * $Id: config.c,v 1.8 2002/07/05 07:55:02 msmith Exp $
+ * $Id: config.c,v 1.9 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -45,6 +45,7 @@
 #define DEFAULT_MAX_BITRATE -1
 #define DEFAULT_QUALITY 3
 #define DEFAULT_REENCODE 0
+#define DEFAULT_DOWNMIX 0
 #define DEFAULT_RECONN_DELAY 2
 #define DEFAULT_RECONN_ATTEMPTS 10
 #define DEFAULT_MAXQUEUELENGTH 100 /* Make it _BIG_ by default */
@@ -124,6 +125,7 @@
         instance->max_br = DEFAULT_MAX_BITRATE;
     instance->quality = DEFAULT_QUALITY;
         instance->encode = DEFAULT_REENCODE;
+    instance->downmix = DEFAULT_DOWNMIX;
         instance->reconnect_delay = DEFAULT_RECONN_DELAY;
         instance->reconnect_attempts = DEFAULT_RECONN_ATTEMPTS;
         instance->max_queue_length = DEFAULT_MAXQUEUELENGTH;
@@ -190,6 +192,8 @@
                         SET_INT(instance->reconnect_attempts);
                 else if(strcmp(node->name, "maxqueuelength") == 0)
                         SET_INT(instance->max_queue_length);
+        else if(strcmp(node->name, "downmix") == 0)
+            SET_INT(instance->downmix);
                 else if (strcmp(node->name, "encode") == 0)
                         _parse_encode(instance, doc, node->xmlChildrenNode);
         } while ((node = node->next));

<p><p>1.11      +2 -1      ices/src/config.h

Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- config.h	2002/01/29 09:20:27	1.10
+++ config.h	2002/07/20 12:52:06	1.11
@@ -1,7 +1,7 @@
 /* config.h
  * - configuration, and global structures built from config
  *
- * $Id: config.h,v 1.10 2002/01/29 09:20:27 msmith Exp $
+ * $Id: config.h,v 1.11 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -37,6 +37,7 @@
         int reconnect_delay;
         int reconnect_attempts;
         int encode;
+    int downmix;
         int max_queue_length;
         char *savefilename;
 

<p><p>1.5       +3 -1      ices/src/input.h

Index: input.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/input.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- input.h	2002/01/23 03:40:28	1.4
+++ input.h	2002/07/20 12:52:06	1.5
@@ -1,7 +1,7 @@
 /* input.h
  * - Input functions
  *
- * $Id: input.h,v 1.4 2002/01/23 03:40:28 jack Exp $
+ * $Id: input.h,v 1.5 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -22,12 +22,14 @@
 #include "stream.h"
 #include "reencode.h"
 #include "encode.h"
+#include "downmix.h"
 
 typedef struct {
         instance_t *stream;
         input_module_t *input;
     reencode_state *reenc;
     encoder_state *enc;
+    downmix_state *downmix;
     shout_t *shout;
     vorbis_comment vc;
 } stream_description;

<p><p>1.6       +3 -2      ices/src/metadata.c

Index: metadata.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/metadata.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- metadata.c	2001/09/25 12:04:22	1.5
+++ metadata.c	2002/07/20 12:52:06	1.6
@@ -1,7 +1,7 @@
 /* metadata.c
  * - Metadata manipulation
  *
- * $Id: metadata.c,v 1.5 2001/09/25 12:04:22 msmith Exp $
+ * $Id: metadata.c,v 1.6 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -76,8 +76,9 @@
                 int comments = 0;
         FILE *file;
 
-        while(metadata_update_signalled == 0)
+        while(metadata_update_signalled == 0){
             thread_cond_wait(&ices_config->event_pending_cond);
+        }
 
         metadata_update_signalled = 0;
 

<p><p>1.12      +9 -1      ices/src/stream.c

Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- stream.c	2002/01/28 00:19:15	1.11
+++ stream.c	2002/07/20 12:52:06	1.12
@@ -1,7 +1,7 @@
 /* stream.c
  * - Core streaming functions/main loop.
  *
- * $Id: stream.c,v 1.11 2002/01/28 00:19:15 msmith Exp $
+ * $Id: stream.c,v 1.12 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -28,6 +28,7 @@
 #include "thread/thread.h"
 #include "reencode.h"
 #include "encode.h"
+#include "downmix.h"
 #include "inputmodule.h"
 #include "stream_shared.h"
 #include "stream.h"
@@ -118,6 +119,12 @@
                         return NULL;
                 }
 
+    /* FIXME: For now, only on encoding, not reencoding */
+    if(stream->downmix && encoding && stream->channels == 2) {
+        stream->channels = 1;
+        sdsc->downmix = downmix_initialise();
+    }
+
         if(encoding)
         {
                 if(inmod->metadata_update)
@@ -267,6 +274,7 @@
             shout_free(sdsc->shout);
         encode_clear(sdsc->enc);
         reencode_clear(sdsc->reenc);
+    downmix_clear(sdsc->downmix);
         vorbis_comment_clear(&sdsc->vc);
 
         stream->died = 1;

<p><p>1.8       +9 -2      ices/src/stream_shared.c

Index: stream_shared.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/stream_shared.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- stream_shared.c	2002/01/28 12:52:59	1.7
+++ stream_shared.c	2002/07/20 12:52:06	1.8
@@ -1,7 +1,7 @@
 /* stream_shared.c
  * - Stream utility functions.
  *
- * $Id: stream_shared.c,v 1.7 2002/01/28 12:52:59 msmith Exp $
+ * $Id: stream_shared.c,v 1.8 2002/07/20 12:52:06 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -23,6 +23,7 @@
 #include "stream.h"
 #include "reencode.h"
 #include "encode.h"
+#include "downmix.h"
 
 #define MODULE "stream-shared/"
 #include "logging.h"
@@ -154,7 +155,13 @@
                     sdsc->stream->serial++, &sdsc->vc);
                 }
 
-		encode_data(sdsc->enc, (signed char *)(buffer->buf), buffer->len, be);
+        if(sdsc->downmix) {
+            downmix_buffer(sdsc->downmix, buffer->buf, buffer->len, be);
+            encode_data_float(sdsc->enc, &sdsc->downmix->buffer, buffer->len/4);
+        }
+        else
+		    encode_data(sdsc->enc, (signed char *)(buffer->buf), 
+                    buffer->len, be);
 
                 while(encode_dataout(sdsc->enc, &og) > 0)
                 {

<p><p>1.1                  ices/src/downmix.c

Index: downmix.c
===================================================================
/* downmix.c
 * stereo->mono downmixing
 *
 * $Id: downmix.c,v 1.1 2002/07/20 12:52:06 msmith Exp $
 *
 * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
 *
 * This program is distributed under the terms of the GNU General
 * Public License, version 2. You may use, modify, and redistribute
 * it under the terms of this license. A copy should be included
 * with this source.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "downmix.h"

#define MODULE "downmix/"
#include "logging.h"

downmix_state *downmix_initialise(void) {
    downmix_state *state = calloc(1, sizeof(downmix_state));

    LOG_INFO0("Enabling mono->stereo downmixing");

    return state;
}

void downmix_clear(downmix_state *s) {
    if(s) {
        free(s->buffer);
        free(s);
    }
}

void downmix_buffer(downmix_state *s, signed char *buf, int len, int be)
{
    int samples = len/4;
    int i;

    if(samples > s->buflen) {
        s->buffer = realloc(s->buffer, samples * sizeof(float));
        s->buflen = samples;
    }

    if(be) {
        for(i=0; i < samples; i++) {
            s->buffer[i] = (((buf[4*i]<<8) | (buf[4*i + 1]&0xff)) +
                           ((buf[4*i + 2]<<8) | (buf[4*i + 3]&0xff)))/65536.f;
        }
    }
    else {
        for(i=0; i < samples; i++) {
            s->buffer[i] = (((buf[4*i + 1]<<8) | (buf[4*i]&0xff)) +
                           ((buf[4*i + 3]<<8) | (buf[4*i + 2]&0xff)))/65536.f;
        }
    }
}

<p><p><p><p><p>1.1                  ices/src/downmix.h

Index: downmix.h
===================================================================
/* downmix.h
 * - stereo->mono downmixing
 *
 * $Id: downmix.h,v 1.1 2002/07/20 12:52:06 msmith Exp $
 *
 * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
 *
 * This program is distributed under the terms of the GNU General
 * Public License, version 2. You may use, modify, and redistribute
 * it under the terms of this license. A copy should be included
 * with this source.
 */

#ifndef __DOWNMIX_H
#define __DOWNMIX_H

typedef struct {
    float *buffer;
    int buflen;
} downmix_state;

downmix_state *downmix_initialise(void);
void downmix_clear(downmix_state *s);
void downmix_buffer(downmix_state *s, signed char *buf, int len, int be);

#endif

<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