[xiph-commits] r7363 - icecast/trunk/ices0/src

brendan at dactyl.lonelymoon.com brendan
Mon Jul 26 21:42:09 PDT 2004


Author: brendan
Date: Mon Jul 26 21:42:09 2004
New Revision: 7363

Added:
icecast/trunk/ices0/src/crossfade.c
icecast/trunk/ices0/src/plugin.h
Modified:
icecast/trunk/ices0/src/Makefile.am
icecast/trunk/ices0/src/definitions.h
icecast/trunk/ices0/src/icestypes.h
icecast/trunk/ices0/src/setup.c
icecast/trunk/ices0/src/stream.c
Log:
Crossfade plugin. Disabled for now - it seems to have a glitchy ring buffer.
Also, I have to tie it into the config file.


Modified: icecast/trunk/ices0/src/Makefile.am
===================================================================
--- icecast/trunk/ices0/src/Makefile.am	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/Makefile.am	2004-07-27 04:42:08 UTC (rev 7363)
@@ -6,10 +6,10 @@

noinst_HEADERS = icestypes.h definitions.h setup.h log.h stream.h util.h \
cue.h metadata.h in_vorbis.h mp3.h id3.h signals.h reencode.h \
-	ices_config.h
+	ices_config.h plugin.h

ices_SOURCES = ices.c log.c setup.c stream.c util.c mp3.c cue.c metadata.c \
-	id3.c signals.c
+	id3.c signals.c crossfade.c

EXTRA_ices_SOURCES = ices_config.c reencode.c in_vorbis.c


Added: icecast/trunk/ices0/src/crossfade.c
===================================================================
--- icecast/trunk/ices0/src/crossfade.c	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/crossfade.c	2004-07-27 04:42:08 UTC (rev 7363)
@@ -0,0 +1,102 @@
+/* crossfade.c
+ * Crossfader plugin
+ * Copyright (c) 2004 Brendan Cully
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+#include "definitions.h"
+#include "plugin.h"
+
+static void cf_new_track(void);
+static int cf_process(int ilen, int16_t* il, int16_t* ir, int16_t* ol, int16_t* or);
+
+static ices_plugin_t Crossfader = {
+  "crossfade",
+  cf_new_track,
+  cf_process
+};
+
+static int NewTrack = 0;
+static int FadeSecs = 4;
+static int FadeSamples;
+static int16_t* FL;
+static int16_t* FR;
+static int fpos = 0;
+static int flen = 0;
+
+/* public functions */
+ices_plugin_t *crossfade_plugin(void) {
+  FadeSamples = FadeSecs * 44100;
+  FL = malloc(FadeSamples * 2);
+  FR = malloc(FadeSamples * 2);
+  return &Crossfader;
+}
+
+/* private functions */
+static void cf_new_track(void) {
+  NewTrack = FadeSamples;
+}
+
+static int cf_process(int ilen, int16_t* il, int16_t* ir, int16_t* ol, int16_t* or)
+{
+  int i, j;
+  float weight;
+
+  i = 0;
+  /* if the buffer is not full, don't attempt to crossfade, just fill it */
+  if (flen < FadeSamples)
+    NewTrack = 0;
+
+  while (ilen && NewTrack > 0) {
+    weight = (float)NewTrack / FadeSamples;
+
+    ol[i] = FL[fpos] * weight + il[i] * (1 - weight);
+    or[i] = FR[fpos] * weight + ir[i] * (1 - weight);
+    i++;
+    fpos++;
+    fpos = fpos % FadeSamples;
+    ilen--;
+    NewTrack--;
+    if (!NewTrack)
+      flen = 0;
+  }
+
+  j = i;
+  while (ilen && flen < FadeSamples) {
+    FL[fpos] = il[j];
+    FR[fpos] = ir[j];
+    j++;
+    fpos++;
+    fpos = fpos % FadeSamples;
+    flen++;
+    ilen--;
+  }
+
+  while (ilen) {
+    ol[i] = FL[fpos];
+    or[i] = FR[fpos];
+    FL[fpos] = il[j];
+    FR[fpos] = ir[j];
+    i++;
+    j++;
+    fpos++;
+    fpos = fpos % FadeSamples;
+    ilen--;
+  }
+
+  return i;
+}

Modified: icecast/trunk/ices0/src/definitions.h
===================================================================
--- icecast/trunk/ices0/src/definitions.h	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/definitions.h	2004-07-27 04:42:08 UTC (rev 7363)
@@ -109,6 +109,7 @@
#include "reencode.h"
#include "ices_config.h"
#include "playlist/playlist.h"
+#include "plugin.h"

#define BUFSIZE 8192
#define ICES_DEFAULT_HOST "127.0.0.1"

Modified: icecast/trunk/ices0/src/icestypes.h
===================================================================
--- icecast/trunk/ices0/src/icestypes.h	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/icestypes.h	2004-07-27 04:42:08 UTC (rev 7363)
@@ -1,7 +1,7 @@
/* icestypes.h
* - Datatypes for ices
* Copyright (c) 2000 Alexander Haväng
- * Copyright (c) 2001-3 Brendan Cully <brendan at icecast.org>
+ * Copyright (c) 2001-4 Brendan Cully <brendan at xiph.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,6 +22,8 @@
#ifndef _ICES_ICESTYPES_H
#define _ICES_ICESTYPES_H

+#include "plugin.h"
+
typedef enum {
icy_protocol_e,
xaudiocast_protocol_e,
@@ -85,6 +87,7 @@

ices_stream_t* streams;
playlist_module_t pm;
+  ices_plugin_t *plugin;
} ices_config_t;

/* -- input stream types -- */

Added: icecast/trunk/ices0/src/plugin.h
===================================================================
--- icecast/trunk/ices0/src/plugin.h	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/plugin.h	2004-07-27 04:42:08 UTC (rev 7363)
@@ -0,0 +1,32 @@
+/* plugin.h
+ * Audio plugin API
+ * Copyright (c) 2004 Brendan Cully <brendan at xiph.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+#ifndef _ICES_PLUGIN_H_
+#define _ICES_PLUGIN_H_ 1
+
+typedef struct {
+  const char *name;
+  void (*new_track)(void);
+  int (*process)(int ilen, int16_t *il, int16_t *ir, int16_t *ol, int16_t *or);
+} ices_plugin_t;
+
+ices_plugin_t *crossfade_plugin(void);
+
+#endif

Modified: icecast/trunk/ices0/src/setup.c
===================================================================
--- icecast/trunk/ices0/src/setup.c	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/setup.c	2004-07-27 04:42:08 UTC (rev 7363)
@@ -1,7 +1,7 @@
/* setup.c
* - Functions for initialization in ices
* Copyright (c) 2000 Alexander Haväng
- * Copyright (c) 2002-3 Brendan Cully <brendan at xiph.org>
+ * Copyright (c) 2002-4 Brendan Cully <brendan at xiph.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -79,6 +79,9 @@
#ifdef HAVE_LIBLAME
/* Initialize liblame for reeencoding */
ices_reencode_initialize ();
+  /*
+  ices_config.plugin = crossfade_plugin();
+  */
#endif
}


Modified: icecast/trunk/ices0/src/stream.c
===================================================================
--- icecast/trunk/ices0/src/stream.c	2004-07-27 03:21:41 UTC (rev 7362)
+++ icecast/trunk/ices0/src/stream.c	2004-07-27 04:42:08 UTC (rev 7363)
@@ -1,7 +1,7 @@
/* stream.c
* - Functions for streaming in ices
* Copyright (c) 2000 Alexander Haväng
- * Copyright (c) 2001-3 Brendan Cully
+ * Copyright (c) 2001-4 Brendan Cully <brendan at xiph.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -153,6 +153,9 @@
/* worst case decode: 22050 Hz at 8kbs = 44.1 samples/byte */
static int16_t left[INPUT_BUFSIZ * 45];
static int16_t right[INPUT_BUFSIZ * 45];
+  static int16_t ol[INPUT_BUFSIZ * 45];
+  static int16_t or[INPUT_BUFSIZ * 45];
+  int i;
static int16_t* rightp;
#endif

@@ -162,11 +165,15 @@

if (config->reencode) {
ices_reencode_reset (source);
-    for (stream = config->streams; stream; stream = stream->next)
-      if (stream->reencode && stream_needs_reencoding (source, stream)) {
-        decode = 1;
-        break;
-      }
+    if (config->plugin) {
+      decode = 1;
+      config->plugin->new_track();
+    } else
+      for (stream = config->streams; stream; stream = stream->next)
+	if (stream->reencode && stream_needs_reencoding (source, stream)) {
+	  decode = 1;
+	  break;
+	}
}

if (decode) {
@@ -199,6 +206,17 @@
#endif
}

+#ifdef HAVE_LIBLAME
+    /* run output through plugin */
+    if (samples && config->plugin) {
+      samples = config->plugin->process(samples, left, right, ol, or);
+      for (i = 0; i < samples; i++) {
+	left[i] = ol[i];
+	right[i] = or[i];
+      }
+    }
+#endif
+
if (len == 0) {
ices_log_debug ("Done sending");
break;
@@ -214,7 +232,7 @@
for (stream = config->streams; stream; stream = stream->next) {
/* don't reencode if the source is MP3 and the same bitrate */
#ifdef HAVE_LIBLAME
-        if (stream->reencode && stream_needs_reencoding (source, stream)) {
+        if (stream->reencode && (config->plugin || stream_needs_reencoding (source, stream))) {
if (samples > 0) {
/* for some reason we have to manually duplicate right from left to get
* LAME to output stereo from a mono source */



More information about the commits mailing list