Skip to content

Commit

Permalink
fix tabledesign
Browse files Browse the repository at this point in the history
  • Loading branch information
n64 committed Aug 25, 2019
1 parent 89e8690 commit b333dd0
Show file tree
Hide file tree
Showing 8 changed files with 868 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ aifc_decode_CFLAGS := -O2 # both runs and compiles faster than -O3

aiff_extract_codebook_SOURCES := aiff_extract_codebook.c

tabledesign_SOURCES := sdk-tools/tabledesign/codebook.c sdk-tools/tabledesign/estimate.c sdk-tools/tabledesign/print.c sdk-tools/tabledesign/tabledesign.c
tabledesign_SOURCES := sdk-tools/tabledesign_src/codebook.c sdk-tools/tabledesign_src/estimate.c sdk-tools/tabledesign_src/print.c sdk-tools/tabledesign_src/tabledesign.c
tabledesign_CFLAGS := -Wno-uninitialized -laudiofile

vadpcm_enc_SOURCES := sdk-tools/adpcm/vadpcm_enc.c sdk-tools/adpcm/vpredictor.c sdk-tools/adpcm/quant.c sdk-tools/adpcm/util.c sdk-tools/adpcm/vencode.c
Expand Down
9 changes: 9 additions & 0 deletions tools/sdk-tools/tabledesign_src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.o
*.s
*.dump
*.aiff
*.aifc
*.table
/tabledesign_irix
/tabledesign_native
/tabledesign_orig
31 changes: 31 additions & 0 deletions tools/sdk-tools/tabledesign_src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Makefile for building tabledesign for either IRIX or natively.
# For an IRIX build, the env variable IRIX_ROOT should point to the root of an
# IRIX filesystem, and QEMU_IRIX should point to the qemu-irix binary.

IRIX_CC := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
IRIX_CFLAGS := -fullwarn -Wab,-r4300_mul -Xcpluscomm -mips1 -O2

NATIVE_CC := gcc
NATIVE_CFLAGS := -Wall -Wno-uninitialized -O2

LDFLAGS := -lm -laudiofile

default: native
all: irix native

irix: tabledesign_irix
native: tabledesign_native

clean:
$(RM) *.o tabledesign_irix tabledesign_native

%.o: %.c
$(IRIX_CC) -c $(IRIX_CFLAGS) $< -o $@

tabledesign_irix: tabledesign.o codebook.o estimate.o print.o
$(IRIX_CC) $^ -o $@ $(LDFLAGS)

tabledesign_native: tabledesign.c codebook.c estimate.c print.c
$(NATIVE_CC) $(NATIVE_CFLAGS) $^ -o $@ $(LDFLAGS)

.PHONY: default all irix native clean
104 changes: 104 additions & 0 deletions tools/sdk-tools/tabledesign_src/codebook.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <stdlib.h>
#include "tabledesign.h"

void split(double **table, double *delta, int order, int npredictors, double scale)
{
int i, j;

for (i = 0; i < npredictors; i++)
{
for (j = 0; j <= order; j++)
{
table[i + npredictors][j] = table[i][j] + delta[j] * scale;
}
}
}

void refine(double **table, int order, int npredictors, double **data, int dataSize, int refineIters, UNUSED double unused)
{
int iter; // spD8
double **rsums;
int *counts; // spD0
double *temp_s7;
double dist;
double dummy; // spC0
double bestValue;
int bestIndex;
int i, j;

rsums = malloc(npredictors * sizeof(double*));
for (i = 0; i < npredictors; i++)
{
rsums[i] = malloc((order + 1) * sizeof(double));
}

counts = malloc(npredictors * sizeof(int));
temp_s7 = malloc((order + 1) * sizeof(double));

for (iter = 0; iter < refineIters; iter++)
{
for (i = 0; i < npredictors; i++)
{
counts[i] = 0;
for (j = 0; j <= order; j++)
{
rsums[i][j] = 0.0;
}
}

for (i = 0; i < dataSize; i++)
{
bestValue = 1e30;
bestIndex = 0;

for (j = 0; j < npredictors; j++)
{
dist = model_dist(table[j], data[i], order);
if (dist < bestValue)
{
bestValue = dist;
bestIndex = j;
}
}

counts[bestIndex]++;
rfroma(data[i], order, temp_s7);
for (j = 0; j <= order; j++)
{
rsums[bestIndex][j] += temp_s7[j];
}
}

for (i = 0; i < npredictors; i++)
{
if (counts[i] > 0)
{
for (j = 0; j <= order; j++)
{
rsums[i][j] /= counts[i];
}
}
}

for (i = 0; i < npredictors; i++)
{
durbin(rsums[i], order, temp_s7, table[i], &dummy);

for (j = 1; j <= order; j++)
{
if (temp_s7[j] >= 1.0) temp_s7[j] = 0.9999999999;
if (temp_s7[j] <= -1.0) temp_s7[j] = -0.9999999999;
}

afromk(temp_s7, table[i], order);
}
}

free(counts);
for (i = 0; i < npredictors; i++)
{
free(rsums[i]);
}
free(rsums);
free(temp_s7);
}
Loading

0 comments on commit b333dd0

Please sign in to comment.