[xiph-commits] r10711 - trunk/ghost/libghost

jm at svn.xiph.org jm at svn.xiph.org
Sun Jan 8 19:47:40 PST 2006


Author: jm
Date: 2006-01-08 19:47:36 -0800 (Sun, 08 Jan 2006)
New Revision: 10711

Modified:
   trunk/ghost/libghost/ghost.c
   trunk/ghost/libghost/ghost.h
   trunk/ghost/libghost/pitch.c
   trunk/ghost/libghost/sinusoids.c
   trunk/ghost/libghost/sinusoids.h
   trunk/ghost/libghost/testghost.c
Log:
works on overlapped frames now (with windowing)


Modified: trunk/ghost/libghost/ghost.c
===================================================================
--- trunk/ghost/libghost/ghost.c	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/ghost.c	2006-01-09 03:47:36 UTC (rev 10711)
@@ -28,14 +28,27 @@
 #include "ghost.h"
 #include "pitch.h"
 #include "sinusoids.h"
+
 #define PCM_BUF_SIZE 2048
 
 GhostEncState *ghost_encoder_state_new(int sampling_rate)
 {
+   int i;
    GhostEncState *st = calloc(1,sizeof(GhostEncState));
-   st->frame_size = 256;
+   st->length = 256;
+   st->advance = 192;
+   st->overlap = 64;
    st->pcm_buf = calloc(PCM_BUF_SIZE,sizeof(float));
-   st->current_pcm = st->pcm_buf + PCM_BUF_SIZE - st->frame_size;
+   st->window = calloc(st->length,sizeof(float));
+   st->syn_memory = calloc(st->overlap,sizeof(float));
+   st->current_pcm = st->pcm_buf + PCM_BUF_SIZE - st->length;
+   for (i=0;i<st->length;i++)
+      st->window[i] = 1;
+   for (i=0;i<st->overlap;i++)
+   {
+      st->window[i] = .5-.5*cos(M_PI*i/st->overlap);
+      st->window[st->length-i] = .5-.5*cos(M_PI*(i+1)/st->overlap);
+   }
    return st;
 }
 
@@ -50,25 +63,34 @@
    float gain;
    float pitch;
    float w;
-   for (i=0;i<PCM_BUF_SIZE-st->frame_size;i++)
-      st->pcm_buf[i] = st->pcm_buf[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);
-   //pitch = 256;
-   //printf ("%d %f\n", pitch, gain);
+   for (i=0;i<PCM_BUF_SIZE-st->advance;i++)
+      st->pcm_buf[i] = st->pcm_buf[i+st->advance];
+   for (i=0;i<st->advance;i++)
+      st->current_pcm[i+st->overlap]=pcm[i];
+   find_pitch(st->current_pcm, &gain, &pitch, 100, 1024, st->length);
+   //fprintf (stderr,"%f %f\n", pitch, gain);
+   pitch = 256;
    w = 2*M_PI/pitch;
    {
       float wi[45];
-      float y[256];
+      float x[st->length];
+      float y[st->length];
       float ai[45], bi[45];
       for (i=0;i<45;i++)
          wi[i] = w*(i+1);
-      extract_sinusoids(st->current_pcm, wi, ai, bi, y, 20, 256);
-      short out[256];
-      for (i=0;i<256;i++)
+      for (i=0;i<st->length;i++)
+         x[i] = st->window[i]*st->current_pcm[i];
+      extract_sinusoids(x, wi, st->window, ai, bi, y, 20, st->length);
+      /*for (i=0;i<st->length;i++)
+      y[i] = x[i];*/
+      short out[st->advance];
+      for (i=0;i<st->overlap;i++)
+         out[i] = st->syn_memory[i]+y[i];
+      for (i=st->overlap;i<st->advance;i++)
          out[i] = y[i];
-      fwrite(out, sizeof(short), 256, stdout);
+      for (i=st->advance;i<st->length;i++)
+         st->syn_memory[i-st->advance]=y[i];
+      fwrite(out, sizeof(short), st->advance, stdout);
    }
    
 }

Modified: trunk/ghost/libghost/ghost.h
===================================================================
--- trunk/ghost/libghost/ghost.h	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/ghost.h	2006-01-09 03:47:36 UTC (rev 10711)
@@ -26,7 +26,11 @@
 typedef struct {
    float *pcm_buf;
    float *current_pcm;
-   int frame_size;
+   float *window;
+   float *syn_memory;
+   int length;
+   int advance;
+   int overlap;
 } GhostEncState;
 
 GhostEncState *ghost_encoder_state_new(int sampling_rate);

Modified: trunk/ghost/libghost/pitch.c
===================================================================
--- trunk/ghost/libghost/pitch.c	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/pitch.c	2006-01-09 03:47:36 UTC (rev 10711)
@@ -50,7 +50,7 @@
       //printf ("%f ", E);
       score = corr*fabs(corr)/(1e4+E);
       sc[i] = score;
-      if (score > max_score)
+      if (score > max_score || i==start)
       {
          p = i;
          max_score = score;

Modified: trunk/ghost/libghost/sinusoids.c
===================================================================
--- trunk/ghost/libghost/sinusoids.c	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/sinusoids.c	2006-01-09 03:47:36 UTC (rev 10711)
@@ -24,7 +24,7 @@
 #include <math.h>
 #include "sinusoids.h"
 
-void extract_sinusoids(float *x, float *w, float *ai, float *bi, float *y, int N, int len)
+void extract_sinusoids(float *x, float *w, float *window, float *ai, float *bi, float *y, int N, int len)
 {
    float cos_table[N][len];
    float sin_table[N][len];
@@ -35,8 +35,8 @@
       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);
+         cos_table[i][j] = cos(w[i]*j)*window[j];
+         sin_table[i][j] = sin(w[i]*j)*window[j];
          tmp1 += cos_table[i][j]*cos_table[i][j];
          tmp2 += sin_table[i][j]*sin_table[i][j];
       }

Modified: trunk/ghost/libghost/sinusoids.h
===================================================================
--- trunk/ghost/libghost/sinusoids.h	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/sinusoids.h	2006-01-09 03:47:36 UTC (rev 10711)
@@ -23,6 +23,6 @@
 #ifndef _SINUSOIDS_H
 #define _SINUSOIDS_H
 
-void extract_sinusoids(float *x, float *w, float *ai, float *bi, float *y, int N, int len);
+void extract_sinusoids(float *x, float *w, float *window, float *ai, float *bi, float *y, int N, int len);
 
 #endif

Modified: trunk/ghost/libghost/testghost.c
===================================================================
--- trunk/ghost/libghost/testghost.c	2006-01-09 02:10:04 UTC (rev 10710)
+++ trunk/ghost/libghost/testghost.c	2006-01-09 03:47:36 UTC (rev 10711)
@@ -32,6 +32,7 @@
 const float predict[11] = {-0.00499385545085393, 0.0110380571786845, -0.018414597815401, 0.0275862067026581, -0.0393646739536688, 0.055303264488734, -0.0787612707745417, 0.118522526792966, -0.29689, 0.80484, 0.4211};
 const float update[11] = {-0.000749078317628089, 0.00165570857680267, -0.00276218967231015, 0.00413793100539871, -0.00590470109305032, 0.0082954896733101, -0.0118141906161813, 0.0226, -0.07844, 0.34242, 0.221};
 
+#define BLOCK_SIZE 192
 
 int main(int argc, char **argv)
 {
@@ -53,6 +54,7 @@
    printf ("%f %f\n", ai[0], bi[0]);
    printf ("%f %f\n", ai[1], bi[1]);
    */
+#if 0
    bas.predict_delay=1;
    bas.predict_length=11;
    bas.update_delay=1;
@@ -76,19 +78,20 @@
       printf ("%f ", x[i+30]);
    printf ("\n");
    return 0;
+#endif
    fin = fopen("test.sw", "r");
    state = ghost_encoder_state_new(48000);
    while (1)
    {
       int i;
-      float float_in[256];
-      short short_in[256];
-      fread(short_in, sizeof(short), 256, fin);
+      float float_in[BLOCK_SIZE];
+      short short_in[BLOCK_SIZE];
+      fread(short_in, sizeof(short), BLOCK_SIZE, fin);
       //printf ("%d ", short_in[0]);
 
       if (feof(fin))
          break;
-      for (i=0;i<256;i++)
+      for (i=0;i<BLOCK_SIZE;i++)
          float_in[i] = short_in[i];
       ghost_encode(state, float_in);
       



More information about the commits mailing list