Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to the newest Xwax Library #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions libs/xwax/lut.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Mark Hills <[email protected]>
* Copyright (C) 2012 Mark Hills <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -34,25 +34,25 @@
/* Initialise an empty hash lookup table to store the given number
* of timecode -> position lookups */

int lut_init(struct lut_t *lut, int nslots)
int lut_init(struct lut *lut, int nslots)
{
int n, hashes;
size_t bytes;

hashes = 1 << HASH_BITS;
bytes = sizeof(struct slot_t) * nslots + sizeof(slot_no_t) * hashes;
bytes = sizeof(struct slot) * nslots + sizeof(slot_no_t) * hashes;

fprintf(stderr, "Lookup table has %d hashes to %d slots"
" (%d slots per hash, %zuKb)\n",
hashes, nslots, nslots / hashes, bytes / 1024);

lut->slot = (struct slot_t*)malloc(sizeof(struct slot_t) * nslots);
lut->slot = malloc(sizeof(struct slot) * nslots);
if (lut->slot == NULL) {
perror("malloc");
return -1;
}

lut->table = (slot_no_t*)malloc(sizeof(slot_no_t) * hashes);
lut->table = malloc(sizeof(slot_no_t) * hashes);
if (lut->table == NULL) {
perror("malloc");
return -1;
Expand All @@ -67,17 +67,18 @@ int lut_init(struct lut_t *lut, int nslots)
}


void lut_clear(struct lut_t *lut)
void lut_clear(struct lut *lut)
{
free(lut->table);
free(lut->slot);
}


void lut_push(struct lut_t *lut, unsigned int timecode)
void lut_push(struct lut *lut, unsigned int timecode)
{
unsigned int hash;
slot_no_t slot_no;
struct slot_t *slot;
struct slot *slot;

slot_no = lut->avail++; /* take the next available slot */

Expand All @@ -90,11 +91,11 @@ void lut_push(struct lut_t *lut, unsigned int timecode)
}


unsigned int lut_lookup(struct lut_t *lut, unsigned int timecode)
unsigned int lut_lookup(struct lut *lut, unsigned int timecode)
{
unsigned int hash;
slot_no_t slot_no;
struct slot_t *slot;
struct slot *slot;

hash = HASH(timecode);
slot_no = lut->table[hash];
Expand Down
110 changes: 0 additions & 110 deletions libs/xwax/lut.cpp

This file was deleted.

16 changes: 8 additions & 8 deletions libs/xwax/lut.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009 Mark Hills <[email protected]>
* Copyright (C) 2012 Mark Hills <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -22,21 +22,21 @@

typedef unsigned int slot_no_t;

struct slot_t {
struct slot {
unsigned int timecode;
slot_no_t next; /* next slot with the same hash */
};

struct lut_t {
struct slot_t *slot;
struct lut {
struct slot *slot;
slot_no_t *table, /* hash -> slot lookup */
avail; /* next available slot */
};

int lut_init(struct lut_t *lut, int nslots);
void lut_clear(struct lut_t *lut);
int lut_init(struct lut *lut, int nslots);
void lut_clear(struct lut *lut);

void lut_push(struct lut_t *lut, unsigned int timecode);
unsigned int lut_lookup(struct lut_t *lut, unsigned int timecode);
void lut_push(struct lut *lut, unsigned int timecode);
unsigned int lut_lookup(struct lut *lut, unsigned int timecode);

#endif
16 changes: 8 additions & 8 deletions libs/xwax/pitch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Mark Hills <[email protected]>
* Copyright (C) 2012 Mark Hills <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -23,17 +23,17 @@
/* Values for the filter concluded experimentally */

#define ALPHA (1.0/512)
#define BETA (ALPHA/1024)
#define BETA (ALPHA/256)

/* State of the pitch calculation filter */

struct pitch_t {
float dt, x, v;
struct pitch {
double dt, x, v;
};

/* Prepare the filter for observations every dt seconds */

static inline void pitch_init(struct pitch_t *p, float dt)
static inline void pitch_init(struct pitch *p, double dt)
{
p->dt = dt;
p->x = 0.0;
Expand All @@ -46,9 +46,9 @@ static inline void pitch_init(struct pitch_t *p, float dt)
* Because the vinyl uses timestamps, the values for dx are discrete
* rather than smooth. */

static inline void pitch_dt_observation(struct pitch_t *p, float dx)
static inline void pitch_dt_observation(struct pitch *p, double dx)
{
float predicted_x, predicted_v, residual_x;
double predicted_x, predicted_v, residual_x;

predicted_x = p->x + p->v * p->dt;
predicted_v = p->v;
Expand All @@ -63,7 +63,7 @@ static inline void pitch_dt_observation(struct pitch_t *p, float dx)

/* Get the pitch after filtering */

static inline float pitch_current(struct pitch_t *p)
static inline double pitch_current(struct pitch *p)
{
return p->v;
}
Expand Down
Loading