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

Train rnn with microsoft SNSD #161

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4787439
Modularizing the RNN model
GregorR Aug 28, 2018
931e946
Fix some warnings
GregorR Aug 28, 2018
2809066
Made dump_rnn output in nu format.
GregorR Aug 28, 2018
b13c533
Neural network model files
GregorR Aug 29, 2018
56701ea
Since the library itself is incompatible, reset the versioning.
GregorR Aug 29, 2018
473e872
Trimming some fat.
GregorR Aug 29, 2018
bbeb920
Adding the 'cb' model, and some fixes to make model files work.
GregorR Aug 29, 2018
6f257df
Corrected a buggy lack of allocation.
GregorR Aug 30, 2018
76d0821
Added parameterizable maximum attenuation.
GregorR Aug 30, 2018
60a8fa7
Trimming more fat
GregorR Aug 30, 2018
63ee148
Merge branch 'master' of github.com:GregorR/rnnoise-nu
GregorR Aug 30, 2018
8a81924
Adding marathon-prescription model.
GregorR Aug 30, 2018
81ce39d
Updated README
GregorR Aug 30, 2018
c384577
Adding instructions on training.
GregorR Aug 30, 2018
0093ba9
Adding my own copyright lines would be wise...
GregorR Sep 1, 2018
c7e342c
More neural network models
GregorR Sep 1, 2018
8fb77f3
Merge branch 'master' of github.com:GregorR/rnnoise-nu
GregorR Sep 1, 2018
53f34de
Made sample rate a changeable parameter.
GregorR Sep 2, 2018
b049de3
Adding somnolent-hogwash model
GregorR Sep 2, 2018
6fc4199
Whoops, forgot to add sh to the Makefile!
GregorR Sep 2, 2018
da55528
Fixing !SMOOTH_BANDS mode
GregorR Sep 3, 2018
6c45a6d
Let's scale our maximum attenuation correctly...
GregorR Sep 3, 2018
925c2ba
Less ridiculous inter-band interpolation.
GregorR Sep 4, 2018
877bb95
Switching the default model to 'cb'
GregorR Sep 10, 2018
2626930
Backing out bad interpolation change.
GregorR Sep 16, 2018
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
75 changes: 23 additions & 52 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ACLOCAL_AMFLAGS = -I m4

AM_CFLAGS = -I$(top_srcdir)/include $(DEPS_CFLAGS)
AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(DEPS_CFLAGS)

dist_doc_DATA = COPYING AUTHORS README

include_HEADERS = include/rnnoise.h
include_HEADERS = include/rnnoise-nu.h

lib_LTLIBRARIES = librnnoise.la
lib_LTLIBRARIES = librnnoise-nu.la
noinst_HEADERS = src/arch.h \
src/celt_lpc.h \
src/common.h \
Expand All @@ -18,42 +18,49 @@ noinst_HEADERS = src/arch.h \
src/rnn.h \
src/tansig_table.h

librnnoise_la_SOURCES = \
librnnoise_nu_la_SOURCES = \
src/denoise.c \
src/rnn.c \
src/rnn_data.c \
src/models/cb.c \
src/models/mp.c \
src/models/bd.c \
src/models/lq.c \
src/models/sh.c \
src/rnn_reader.c \
src/models.c \
src/pitch.c \
src/kiss_fft.c \
src/celt_lpc.c

librnnoise_la_LIBADD = $(DEPS_LIBS) $(lrintf_lib) $(LIBM)
librnnoise_la_LDFLAGS = -no-undefined \
librnnoise_nu_la_LIBADD = $(DEPS_LIBS) $(lrintf_lib) $(LIBM)
librnnoise_nu_la_LDFLAGS = -no-undefined \
-version-info @OP_LT_CURRENT@:@OP_LT_REVISION@:@OP_LT_AGE@

if OP_ENABLE_EXAMPLES
noinst_PROGRAMS = examples/rnnoise_demo
noinst_PROGRAMS = examples/rnnoise_nu_demo
endif

examples_rnnoise_demo_SOURCES = examples/rnnoise_demo.c
examples_rnnoise_demo_LDADD = librnnoise.la
examples_rnnoise_nu_demo_SOURCES = examples/rnnoise_demo.c
examples_rnnoise_nu_demo_LDADD = librnnoise-nu.la $(LIBM)

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = rnnoise.pc
pkgconfig_DATA = rnnoise-nu.pc

debug:
$(MAKE) CFLAGS="${CFLAGS} -O0 -ggdb -DOP_ENABLE_ASSERTIONS" all

EXTRA_DIST = \
rnnoise.pc.in \
rnnoise-uninstalled.pc.in \
rnnoise-nu.pc.in \
rnnoise-nu-uninstalled.pc.in \
doc/Doxyfile.in \
doc/Makefile

# Targets to build and install just the library without the docs
librnnoise install-librnnoise: NO_DOXYGEN = 1
librnnoise-nu install-librnnoise-nu: NO_DOXYGEN = 1

rnnoise: all
install-rnnoise: install
rnnoise-nu: all
install-rnnoise-nu: install

# Or just the docs
docs: doc/doxygen-build.stamp
Expand Down Expand Up @@ -90,40 +97,4 @@ uninstall-local:

endif

# We check this every time make is run, with configure.ac being touched to
# trigger an update of the build system files if update_version changes the
# current PACKAGE_VERSION (or if package_version was modified manually by a
# user with either AUTO_UPDATE=no or no update_version script present - the
# latter being the normal case for tarball releases).
#
# We can't just add the package_version file to CONFIGURE_DEPENDENCIES since
# simply running autoconf will not actually regenerate configure for us when
# the content of that file changes (due to autoconf dependency checking not
# knowing about that without us creating yet another file for it to include).
#
# The MAKECMDGOALS check is a gnu-make'ism, but will degrade 'gracefully' for
# makes that don't support it. The only loss of functionality is not forcing
# an update of package_version for `make dist` if AUTO_UPDATE=no, but that is
# unlikely to be a real problem for any real user.
$(top_srcdir)/configure.ac: force
@case "$(MAKECMDGOALS)" in \
dist-hook) exit 0 ;; \
dist-* | dist | distcheck | distclean) _arg=release ;; \
esac; \
if ! $(top_srcdir)/update_version $$_arg 2> /dev/null; then \
if [ ! -e $(top_srcdir)/package_version ]; then \
echo 'PACKAGE_VERSION="unknown"' > $(top_srcdir)/package_version; \
fi; \
. $(top_srcdir)/package_version || exit 1; \
[ "$(PACKAGE_VERSION)" != "$$PACKAGE_VERSION" ] || exit 0; \
fi; \
touch $@

force:

# Create a minimal package_version file when make dist is run.
dist-hook:
echo 'PACKAGE_VERSION="$(PACKAGE_VERSION)"' > $(top_distdir)/package_version


.PHONY: rnnoise install-rnnoise docs install-docs
.PHONY: rnnoise-nu install-rnnoise-nu docs install-docs
11 changes: 8 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
RNNoise is a noise suppression library based on a recurrent neural network
RNNoise is a noise suppression library based on a recurrent neural network.
RNNoise-nu is a modified version of RNNoise aimed to be a bit more general
purpose.

To compile, just type:
% ./autogen.sh
% autoreconf -i
% ./configure
% make

Expand All @@ -12,6 +14,9 @@ While it is meant to be used as a library, a simple command-line tool is
provided as an example. It operates on RAW 16-bit (machine endian) mono
PCM files sampled at 48 kHz. It can be used as:

./examples/rnnoise_demo input.pcm output.pcm
./examples/rnnoise_demo <number of channels> <maximum attenuation> [model to use] < input.raw > output.raw

The output is also a 16-bit raw PCM file.

For information on the neural network models available, see
https://github.com/GregorR/rnnoise-models
11 changes: 11 additions & 0 deletions TRAINING
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(1) cd src ; ./compile.sh

(2) ./denoise_training signal.raw noise.raw count > training.f32

(note the matrix size and replace 500000 87 below)

(3) cd training ; ./bin2hdf5.py ../src/training.f32 500000 87 training.h5

(4) ./rnn_train.py

(5) ./dump_rnn.py weights.hdf5 rnn_data.c rnn_data.rnnn name
56 changes: 13 additions & 43 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
# autoconf source script for generating configure

dnl The package_version file will be automatically synced to the git revision
dnl by the update_version script when configured in the repository, but will
dnl remain constant in tarball releases unless it is manually edited.
m4_define([CURRENT_VERSION],
m4_esyscmd([ ./update_version 2>/dev/null || true
if test -e package_version; then
. ./package_version
printf "$PACKAGE_VERSION"
else
printf "unknown"
fi ]))

AC_INIT([rnnoise],[CURRENT_VERSION],[[email protected]])
AC_INIT([rnnoise-nu],[1.0],[[email protected]])
AC_CONFIG_SRCDIR([src/denoise.c])
AC_CONFIG_AUX_DIR([scripts])
AC_CONFIG_MACRO_DIR([m4])

AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE

m4_include([m4/lean.m4])

AM_INIT_AUTOMAKE([1.11 foreign no-define dist-zip subdir-objects])
AM_MAINTAINER_MODE([enable])

Expand All @@ -31,40 +22,19 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_DEFINE([RNNOISE_BUILD], [], [This is a build of the library])

dnl Library versioning for libtool.
dnl Please update these for releases.
dnl CURRENT, REVISION, AGE
dnl - library source changed -> increment REVISION
dnl - interfaces added/removed/changed -> increment CURRENT, REVISION = 0
dnl - interfaces added -> increment AGE
dnl - interfaces removed -> AGE = 0
dnl For some inane reason, in .so.major.minor.revision:
dnl - major = CURRENT-AGE
dnl - minor = AGE
dnl - revision = REVISION
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am relatively sure this is not how libtool versioning works. These do not correspond to major, minor, revision, see the libtool documentation. So I believe this change is wrong.


OP_LT_CURRENT=4
OP_LT_REVISION=1
OP_LT_AGE=4
OP_LT_CURRENT=1
OP_LT_REVISION=0
OP_LT_AGE=0

AC_SUBST(OP_LT_CURRENT)
AC_SUBST(OP_LT_REVISION)
AC_SUBST(OP_LT_AGE)

CC_CHECK_CFLAGS_APPEND(
[-pedantic -Wall -Wextra -Wno-sign-compare -Wno-parentheses -Wno-long-long])

# Platform-specific tweaks
case $host in
*-mingw*)
# -std=c89 causes some warnings under mingw.
CC_CHECK_CFLAGS_APPEND([-U__STRICT_ANSI__])
# We need WINNT>=0x501 (WindowsXP) for getaddrinfo/freeaddrinfo.
# It's okay to define this even when HTTP support is disabled, as it only
# affects header declarations, not linking (unless we actually use some
# XP-only functions).
AC_DEFINE_UNQUOTED(_WIN32_WINNT,0x501,
[We need at least WindowsXP for getaddrinfo/freeaddrinfo])
host_mingw=true
;;
esac
AM_CONDITIONAL(OP_WIN32, test "$host_mingw" = "true")

AC_ARG_ENABLE([assertions],
AS_HELP_STRING([--enable-assertions], [Enable assertions in code]),,
enable_assertions=no)
Expand Down Expand Up @@ -108,8 +78,8 @@ AM_CONDITIONAL([HAVE_DOXYGEN], [test "$HAVE_DOXYGEN" = "yes"])

AC_CONFIG_FILES([
Makefile
rnnoise.pc
rnnoise-uninstalled.pc
rnnoise-nu.pc
rnnoise-nu-uninstalled.pc
doc/Doxyfile
])
AC_CONFIG_HEADERS([config.h])
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PROJECT_NAME = @PACKAGE_NAME@
PROJECT_NUMBER = @PACKAGE_VERSION@
PROJECT_BRIEF = "RNN-based noise suppressor."
INPUT = @top_srcdir@/include/rnnoise.h
INPUT = @top_srcdir@/include/rnnoise-nu.h
OPTIMIZE_OUTPUT_FOR_C = YES

QUIET = YES
Expand Down
81 changes: 61 additions & 20 deletions examples/rnnoise_demo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2017 Mozilla */
/* Copyright (c) 2018 Gregor Richards
* Copyright (c) 2017 Mozilla */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand All @@ -24,36 +25,76 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <math.h>
#include <stdio.h>
#include "rnnoise.h"
#include <stdlib.h>
#include <sys/types.h>
#include "rnnoise-nu.h"

#define FRAME_SIZE 480

int main(int argc, char **argv) {
int i;
int i, ci;
int first = 1;
int channels;
float x[FRAME_SIZE];
FILE *f1, *fout;
DenoiseState *st;
st = rnnoise_create();
if (argc!=3) {
fprintf(stderr, "usage: %s <noisy speech> <output denoised>\n", argv[0]);
short *tmp;
int sample_rate;
RNNModel *model = NULL;
DenoiseState **sts;
float max_attenuation;
if (argc < 4) {
fprintf(stderr, "usage: %s <sample rate> <channels> <max attenuation dB> [model]\n", argv[0]);
return 1;
}
f1 = fopen(argv[1], "r");
fout = fopen(argv[2], "w");

sample_rate = atoi(argv[1]);
if (sample_rate <= 0) sample_rate = 48000;
channels = atoi(argv[2]);
if (channels < 1) channels = 1;
max_attenuation = pow(10, -atof(argv[3])/10);

if (argc >= 5) {
model = rnnoise_get_model(argv[4]);
if (!model) {
fprintf(stderr, "Model not found!\n");
return 1;
}
}

sts = malloc(channels * sizeof(DenoiseState *));
if (!sts) {
perror("malloc");
return 1;
}
tmp = malloc(channels * FRAME_SIZE * sizeof(short));
if (!tmp) {
perror("malloc");
return 1;
}
for (i = 0; i < channels; i++) {
sts[i] = rnnoise_create(model);
rnnoise_set_param(sts[i], RNNOISE_PARAM_MAX_ATTENUATION, max_attenuation);
rnnoise_set_param(sts[i], RNNOISE_PARAM_SAMPLE_RATE, sample_rate);
}

while (1) {
short tmp[FRAME_SIZE];
fread(tmp, sizeof(short), FRAME_SIZE, f1);
if (feof(f1)) break;
for (i=0;i<FRAME_SIZE;i++) x[i] = tmp[i];
rnnoise_process_frame(st, x, x);
for (i=0;i<FRAME_SIZE;i++) tmp[i] = x[i];
if (!first) fwrite(tmp, sizeof(short), FRAME_SIZE, fout);
fread(tmp, sizeof(short), channels * FRAME_SIZE, stdin);
if (feof(stdin)) break;

for (ci = 0; ci < channels; ci++) {
for (i=0;i<FRAME_SIZE;i++) x[i] = tmp[i*channels+ci];
rnnoise_process_frame(sts[ci], x, x);
for (i=0;i<FRAME_SIZE;i++) tmp[i*channels+ci] = x[i];
}

if (!first) fwrite(tmp, sizeof(short), channels * FRAME_SIZE, stdout);
first = 0;
}
rnnoise_destroy(st);
fclose(f1);
fclose(fout);

for (i = 0; i < channels; i++)
rnnoise_destroy(sts[i]);
free(tmp);
free(sts);
return 0;
}
Loading