[xiph-commits] r9587 - in trunk/ghost: . libghost

jm at svn.xiph.org jm at svn.xiph.org
Mon Jul 18 20:04:00 PDT 2005


Author: jm
Date: 2005-07-18 20:03:57 -0700 (Mon, 18 Jul 2005)
New Revision: 9587

Added:
   trunk/ghost/libghost/ghost.h
   trunk/ghost/libghost/pitch.c
   trunk/ghost/libghost/sinusoids.h
   trunk/ghost/libghost/testghost.c
Modified:
   trunk/ghost/Ghost.kdevelop
   trunk/ghost/README
   trunk/ghost/libghost/Makefile.am
   trunk/ghost/libghost/ghost.c
   trunk/ghost/libghost/sinusoids.c
Log:
Some initial code


Modified: trunk/ghost/Ghost.kdevelop
===================================================================
--- trunk/ghost/Ghost.kdevelop	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/Ghost.kdevelop	2005-07-19 03:03:57 UTC (rev 9587)
@@ -1,22 +1,22 @@
-<?xml version="1.0"?>
+<?xml version = '1.0'?>
 <kdevelop>
- <general>
-  <author>Jean-Marc Valin</author>
-  <email>jean-marc.valin at usherbrooke.ca</email>
-  <version>$VERSION$</version>
-  <projectmanagement>KDevAutoProject</projectmanagement>
-  <primarylanguage>C</primarylanguage>
-  <ignoreparts>
-  </ignoreparts>
- </general>
- <kdevautoproject>
   <general>
-   <activetarget>src/Ghost</activetarget>
-   <useconfiguration>debug</useconfiguration>
+    <author>Jean-Marc Valin</author>
+    <email>jean-marc.valin at usherbrooke.ca</email>
+    <version>$VERSION$</version>
+    <projectmanagement>KDevAutoProject</projectmanagement>
+    <primarylanguage>C</primarylanguage>
+    <ignoreparts/>
   </general>
-  <run>
-   <mainprogram>src/Ghost</mainprogram>
-  </run>
+  <kdevautoproject>
+    <general>
+      <activetarget>src/Ghost</activetarget>
+      <useconfiguration>default</useconfiguration>
+    </general>
+    <run>
+      <mainprogram>src/Ghost</mainprogram>
+      <directoryradio>executable</directoryradio>
+    </run>
     <configurations>
       <optimized>
         <builddir>optimized</builddir>
@@ -34,13 +34,19 @@
         <cflags>-O0 -g3</cflags>
       </debug>
     </configurations>
- </kdevautoproject>
- <kdevdebugger>
-  <general>
-   <dbgshell>libtool</dbgshell>
-  </general>
- </kdevdebugger>
- <kdevdoctreeview>
+    <make>
+      <envvars>
+        <envvar value="1" name="WANT_AUTOCONF_2_5" />
+        <envvar value="1" name="WANT_AUTOMAKE_1_6" />
+      </envvars>
+    </make>
+  </kdevautoproject>
+  <kdevdebugger>
+    <general>
+      <dbgshell>libtool</dbgshell>
+    </general>
+  </kdevdebugger>
+  <kdevdoctreeview>
     <ignoretocs>
       <toc>ada</toc>
       <toc>ada_bugs_gcc</toc>
@@ -87,7 +93,7 @@
     <ignoredoxygen>
       <toc>KDE Libraries (Doxygen)</toc>
     </ignoredoxygen>
- </kdevdoctreeview>
+  </kdevdoctreeview>
   <kdevfilecreate>
     <filetypes/>
     <useglobaltypes>
@@ -95,4 +101,29 @@
       <type ext="h" />
     </useglobaltypes>
   </kdevfilecreate>
+  <kdevcppsupport>
+    <references/>
+    <codecompletion>
+      <includeGlobalFunctions>true</includeGlobalFunctions>
+      <includeTypes>true</includeTypes>
+      <includeEnums>true</includeEnums>
+      <includeTypedefs>false</includeTypedefs>
+      <automaticCodeCompletion>true</automaticCodeCompletion>
+      <automaticArgumentsHint>true</automaticArgumentsHint>
+      <automaticHeaderCompletion>true</automaticHeaderCompletion>
+      <codeCompletionDelay>250</codeCompletionDelay>
+      <argumentsHintDelay>400</argumentsHintDelay>
+      <headerCompletionDelay>250</headerCompletionDelay>
+    </codecompletion>
+  </kdevcppsupport>
+  <kdevfileview>
+    <groups>
+      <hidenonprojectfiles>false</hidenonprojectfiles>
+      <hidenonlocation>false</hidenonlocation>
+    </groups>
+    <tree>
+      <hidepatterns>*.o,*.lo,CVS</hidepatterns>
+      <hidenonprojectfiles>false</hidenonprojectfiles>
+    </tree>
+  </kdevfileview>
 </kdevelop>

Modified: trunk/ghost/README
===================================================================
--- trunk/ghost/README	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/README	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,3 @@
+This is an attempt at a better audio codec. Don't bother with this unless
+you're interested in codec development. Certainly don't expect this to
+be ready any time soon.

Modified: trunk/ghost/libghost/Makefile.am
===================================================================
--- trunk/ghost/libghost/Makefile.am	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/Makefile.am	2005-07-19 03:03:57 UTC (rev 9587)
@@ -9,10 +9,10 @@
 lib_LTLIBRARIES = libghost.la
 
 # Sources for compilation in the library
-libghost_la_SOURCES = ghost.c \
-			sinusoids.c
+libghost_la_SOURCES = ghost.c 			sinusoids.c pitch.c
 
 #noinst_HEADERS =
 
 libghost_la_LDFLAGS = -version-info @GHOST_LT_CURRENT@:@GHOST_LT_REVISION@:@GHOST_LT_AGE@
 
+noinst_HEADERS = ghost.h pitch.h

Modified: trunk/ghost/libghost/ghost.c
===================================================================
--- trunk/ghost/libghost/ghost.c	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/ghost.c	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,66 @@
+/* Copyright (C) 2005 */
+/**
+   @file ghost.c
+   @brief Main codec file
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdlib.h>
+#include "ghost.h"
+#include "pitch.h"
+#include "sinusoids.h"
+
+#define PCM_BUF_SIZE 2048
+
+GhostEncState *ghost_encoder_state_new(int sampling_rate)
+{
+   GhostEncState *st = calloc(1,sizeof(GhostEncState));
+   st->pcm_buf = calloc(PCM_BUF_SIZE,sizeof(float));
+   st->current_pcm = st->pcm_buf + PCM_BUF_SIZE - 256;
+   return st;
+}
+
+void ghost_encoder_state_destroy(GhostEncState *st)
+{
+   free(st);
+}
+
+void ghost_encode(GhostEncState *st, float *pcm)
+{
+   int i;
+   float gain;
+   int pitch;
+   for (i=0;i<PCM_BUF_SIZE-st->frame_size;i++)
+      st->pcm_buf[i] = st->current_pcm[i+st->frame_size];
+   for (i=0;i<st->frame_size;i++)
+      st->current_pcm[i]=pcm[i];
+   find_pitch(st->current_pcm, &gain, &pitch, 100, 768, st->frame_size);
+   printf ("%d %f\n", pitch, gain);
+}

Added: trunk/ghost/libghost/ghost.h
===================================================================
--- trunk/ghost/libghost/ghost.h	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/ghost.h	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,46 @@
+/* Copyright (C) 2005 */
+/**
+   @file ghost.h
+   @brief Main codec file
+ */
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+typedef struct {
+   float *pcm_buf;
+   float *current_pcm;
+   int frame_size;
+} GhostEncState;
+
+GhostEncState *ghost_encoder_state_new(int sampling_rate);
+
+void ghost_encoder_state_destroy(GhostEncState *st);
+
+void ghost_encode(GhostEncState *st, float *pcm);

Added: trunk/ghost/libghost/pitch.c
===================================================================
--- trunk/ghost/libghost/pitch.c	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/pitch.c	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,66 @@
+/* Copyright (C) 2005 */
+/**
+   @file pitch.c
+   @brief Pitch analysis
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+float inner_prod(float *x, float *y, int len)
+{
+   float sum=0;
+   int i;
+   for (i=0;i<len;i++)
+   {
+      sum += x[i]*y[i];
+   }
+   return sum;
+}
+
+void find_pitch(float *x, float *gain, int *pitch, int start, int end, int len)
+{
+   int i;
+   float max_score = -1;
+   for (i=start;i<end;i++)
+   {
+      float corr, score, E;
+      corr = inner_prod(x,x-i,len);
+      E = inner_prod(x-i,x-i,len);
+      score = corr*corr/(1+E);
+      if (score > max_score)
+      {
+         *pitch = i;
+         max_score = score;
+         *gain = corr/(1+E);
+      }
+   }
+}
+
+
+

Modified: trunk/ghost/libghost/sinusoids.c
===================================================================
--- trunk/ghost/libghost/sinusoids.c	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/sinusoids.c	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,83 @@
+/* Copyright (C) 2005 */
+/**
+   @file sinusoids.c
+   @brief Sinusoid extraction/synthesis
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <math.h>
+#include "sinusoids.h"
+
+void extract_sinusoids(float *x, float *w, float *ai, float *bi, float *y, int N, int len)
+{
+   float cos_table[N][len];
+   float sin_table[N][len];
+   float cosE[N], sinE[N];
+   int i,j, iter;
+   for (i=0;i<N;i++)
+   {
+      float tmp1=0, tmp2=0;
+      for (j=0;j<len;j++)
+      {
+         cos_table[i][j] = cos(w[i]*j);
+         sin_table[i][j] = sin(w[i]*j);
+         tmp1 += cos_table[i][j]*cos_table[i][j];
+         tmp2 += sin_table[i][j]*sin_table[i][j];
+      }
+      cosE[i] = tmp1;
+      sinE[i] = tmp2;
+   }
+   for (j=0;j<len;j++)
+      y[j] = 0;
+   for (i=0;i<N;i++)
+      ai[i] = bi[i] = 0;
+
+   for (iter=0;iter<3;iter++)
+   {
+      for (i=0;i<N;i++)
+      {
+         float tmp1=0, tmp2=0;
+         for (j=0;j<len;j++)
+         {
+            tmp1 += (x[j]-y[j])*cos_table[i][j];
+            tmp2 += (x[j]-y[j])*sin_table[i][j];
+         }
+         tmp1 /= cosE[i];
+         tmp2 /= sinE[i];
+         for (j=0;j<len;j++)
+         {
+            y[j] += tmp1*cos_table[i][j] + tmp2*sin_table[i][j];
+         }
+         ai[i] += tmp1;
+         bi[i] += tmp2;
+      }
+   }
+}
+

Added: trunk/ghost/libghost/sinusoids.h
===================================================================
--- trunk/ghost/libghost/sinusoids.h	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/sinusoids.h	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,36 @@
+/* Copyright (C) 2005 */
+/**
+   @file sinusoids.h
+   @brief Sinusoid extraction/synthesis
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+void extract_sinusoids(float *x, float *w, float *ai, float *bi, float *y, int N, int len);
+

Added: trunk/ghost/libghost/testghost.c
===================================================================
--- trunk/ghost/libghost/testghost.c	2005-07-19 01:38:18 UTC (rev 9586)
+++ trunk/ghost/libghost/testghost.c	2005-07-19 03:03:57 UTC (rev 9587)
@@ -0,0 +1,58 @@
+/* Copyright (C) 2005 */
+/**
+   @file ghost.c
+   @brief Sinusoid extraction/synthesis
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <math.h>
+#include "sinusoids.h"
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+   float x[256];
+   float y[256];
+   float w[2] = {.05, .2};
+   float ai[2], bi[2];
+   int i;
+   for (i=0;i<256;i++)
+   {
+      x[i] = cos(.05*i+2) + .2*cos(.2*i+1.1);
+   }
+   extract_sinusoids(x, w, ai, bi, y, 2, 256);
+   printf ("%f %f\n", ai[0], bi[0]);
+   printf ("%f %f\n", ai[1], bi[1]);
+   
+   /*for (i=0;i<256;i++)
+      printf ("%f %f\n", x[i], y[i]);*/
+   return 0;
+}
+



More information about the commits mailing list