[xiph-commits] r9588 - trunk/ghost/libghost
jm at svn.xiph.org
jm at svn.xiph.org
Mon Jul 18 22:56:34 PDT 2005
Author: jm
Date: 2005-07-18 22:56:31 -0700 (Mon, 18 Jul 2005)
New Revision: 9588
Modified:
trunk/ghost/libghost/Makefile.am
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:
experimenting with sinusoidal model
Modified: trunk/ghost/libghost/Makefile.am
===================================================================
--- trunk/ghost/libghost/Makefile.am 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/Makefile.am 2005-07-19 05:56:31 UTC (rev 9588)
@@ -16,3 +16,6 @@
libghost_la_LDFLAGS = -version-info @GHOST_LT_CURRENT@:@GHOST_LT_REVISION@:@GHOST_LT_AGE@
noinst_HEADERS = ghost.h pitch.h
+noinst_PROGRAMS = testghost
+testghost_SOURCES = testghost.c
+testghost_LDADD = $(top_builddir)/libghost/libghost.la
Modified: trunk/ghost/libghost/ghost.c
===================================================================
--- trunk/ghost/libghost/ghost.c 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/ghost.c 2005-07-19 05:56:31 UTC (rev 9588)
@@ -32,18 +32,21 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdio.h>
#include <stdlib.h>
+#include <math.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->frame_size = 256;
st->pcm_buf = calloc(PCM_BUF_SIZE,sizeof(float));
- st->current_pcm = st->pcm_buf + PCM_BUF_SIZE - 256;
+ st->current_pcm = st->pcm_buf + PCM_BUF_SIZE - st->frame_size;
return st;
}
@@ -56,11 +59,26 @@
{
int i;
float gain;
- int pitch;
+ float pitch;
+ float w;
for (i=0;i<PCM_BUF_SIZE-st->frame_size;i++)
- st->pcm_buf[i] = st->current_pcm[i+st->frame_size];
+ 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);
- printf ("%d %f\n", pitch, gain);
+ //printf ("%d %f\n", pitch, gain);
+ w = 2*M_PI/pitch;
+ {
+ float wi[45];
+ float y[256];
+ 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++)
+ out[i] = y[i];
+ fwrite(out, sizeof(short), 256, stdout);
+ }
+
}
Modified: trunk/ghost/libghost/ghost.h
===================================================================
--- trunk/ghost/libghost/ghost.h 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/ghost.h 2005-07-19 05:56:31 UTC (rev 9588)
@@ -32,6 +32,8 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _GHOST_H
+#define _GHOST_H
typedef struct {
float *pcm_buf;
@@ -44,3 +46,5 @@
void ghost_encoder_state_destroy(GhostEncState *st);
void ghost_encode(GhostEncState *st, float *pcm);
+
+#endif
Modified: trunk/ghost/libghost/pitch.c
===================================================================
--- trunk/ghost/libghost/pitch.c 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/pitch.c 2005-07-19 05:56:31 UTC (rev 9588)
@@ -32,6 +32,9 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdio.h>
+#include <math.h>
+
float inner_prod(float *x, float *y, int len)
{
float sum=0;
@@ -43,23 +46,34 @@
return sum;
}
-void find_pitch(float *x, float *gain, int *pitch, int start, int end, int len)
+void find_pitch(float *x, float *gain, float *pitch, int start, int end, int len)
{
int i;
float max_score = -1;
- for (i=start;i<end;i++)
+ float sc[end+1];
+ int p=0;
+ 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);
+ //E = inner_prod(x,x,len);
+ //printf ("%f ", E);
+ score = corr*fabs(corr)/(1e4+E);
+ sc[i] = score;
if (score > max_score)
{
- *pitch = i;
+ p = i;
max_score = score;
*gain = corr/(1+E);
}
}
+ if (p == start || p == end)
+ {
+ *pitch = p;
+ } else {
+ *pitch = p+.5*(sc[p+1]-sc[p-1])/(2*sc[p]-sc[p-1]-sc[p+1]);
+ }
}
Modified: trunk/ghost/libghost/sinusoids.c
===================================================================
--- trunk/ghost/libghost/sinusoids.c 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/sinusoids.c 2005-07-19 05:56:31 UTC (rev 9588)
@@ -59,7 +59,7 @@
for (i=0;i<N;i++)
ai[i] = bi[i] = 0;
- for (iter=0;iter<3;iter++)
+ for (iter=0;iter<5;iter++)
{
for (i=0;i<N;i++)
{
Modified: trunk/ghost/libghost/sinusoids.h
===================================================================
--- trunk/ghost/libghost/sinusoids.h 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/sinusoids.h 2005-07-19 05:56:31 UTC (rev 9588)
@@ -32,5 +32,9 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef _SINUSOIDS_H
+#define _SINUSOIDS_H
+
void extract_sinusoids(float *x, float *w, float *ai, float *bi, float *y, int N, int len);
+#endif
Modified: trunk/ghost/libghost/testghost.c
===================================================================
--- trunk/ghost/libghost/testghost.c 2005-07-19 03:03:57 UTC (rev 9587)
+++ trunk/ghost/libghost/testghost.c 2005-07-19 05:56:31 UTC (rev 9588)
@@ -33,12 +33,16 @@
*/
#include <math.h>
+#include <stdio.h>
#include "sinusoids.h"
-#include <stdio.h>
+#include "ghost.h"
+#include "pitch.h"
int main(int argc, char **argv)
{
- float x[256];
+ GhostEncState *state;
+ FILE *fin;
+ /*float x[256];
float y[256];
float w[2] = {.05, .2};
float ai[2], bi[2];
@@ -50,6 +54,25 @@
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]);
+ */
+ 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);
+ //printf ("%d ", short_in[0]);
+
+ if (feof(fin))
+ break;
+ for (i=0;i<256;i++)
+ float_in[i] = short_in[i];
+ ghost_encode(state, float_in);
+
+ }
+ ghost_encoder_state_destroy(state);
/*for (i=0;i<256;i++)
printf ("%f %f\n", x[i], y[i]);*/
More information about the commits
mailing list