Skip to content

Commit

Permalink
Better default window function
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Jan 22, 2020
1 parent 90242f9 commit 6979dbd
Show file tree
Hide file tree
Showing 37 changed files with 182 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## version 10.4.2 - 2020-01-22
Better sinc resampling.

## version 10.4.1 - 2020-01-21
Faster sinc resampling.

Expand Down
16 changes: 8 additions & 8 deletions dist/wavefile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/resampler/interpolator.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Interpolator {
* The sinc kernel.
* @type {Function}
*/
this.kernel_ = sincKernel_(details.sincWindow || gaussianWindow_);
this.kernel_ = sincKernel_(details.sincWindow || window_);
}

/**
Expand Down Expand Up @@ -187,8 +187,8 @@ export class Interpolator {
* @return {number}
* @private
*/
function gaussianWindow_(x) {
return Math.exp(-x * x);
function window_(x) {
return Math.exp(-x / 2 * x / 2);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wavefile",
"version": "10.4.1",
"version": "10.4.2",
"description": "Create, read and write wav files according to the specs.",
"homepage": "https://github.com/rochars/wavefile",
"author": "Rafael da Silva Rocha <[email protected]>",
Expand Down Expand Up @@ -73,7 +73,7 @@
"test-sr-point": "node ./node_modules/mocha/bin/_mocha test/resampler-full/point.js -R dot --timeout=1600000",
"test-sr-linear": "node ./node_modules/mocha/bin/_mocha test/resampler-full/linear.js -R dot --timeout=1600000",
"test-sr-cubic": "node ./node_modules/mocha/bin/_mocha test/resampler-full/cubic.js -R dot --timeout=1600000",
"test-sr-sinc": "node ./node_modules/mocha/bin/_mocha test/resampler-full/sinc.js test/resampler-full/sinc-IIR.js -R dot --timeout=1600000",
"test-sr-sinc": "node ./node_modules/mocha/bin/_mocha test/resampler-full/sinc.js test/resampler-full/sinc-IIR.js test/resampler-full/sinc-no-lpf.js -R dot --timeout=1600000",
"test-umd": "node ./node_modules/mocha/bin/_mocha test/resampler test/dist test/src --umd --recursive -R dot --timeout=240000",
"test-tsc": "tsc ./test/TypeScript/index.ts && node -r esm ./test/TypeScript/index.js",
"test-cli": "wavefile ./test/files/M1F1-int12WE-AFsp.wav --tag=ICMT",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/files/out/to-sample-rate/sinc-IIR-song1-16kHz.wav
Binary file not shown.
Binary file modified test/files/out/to-sample-rate/sinc-IIR-song1-96kHz.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/files/out/to-sample-rate/sinc-song1-16kHz.wav
Binary file not shown.
Binary file modified test/files/out/to-sample-rate/sinc-song1-96kHz.wav
Binary file not shown.
165 changes: 165 additions & 0 deletions test/resampler-full/sinc-no-lpf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* WaveFile: https://github.com/rochars/wavefile
* Copyright (c) 2017-2018 Rafael da Silva Rocha. MIT License.
*
* Tests for sample rate conversion, sinc method.
*
*/

const assert = require('assert');
const fs = require("fs");
const WaveFile = require("../../test/loader.js");
const path = "./test/files/";

console.log('sinc, no LPF');

let hrstart = process.hrtime();

// Chirps, FP

describe('Downsample a 32-bit 44.1kHz log sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "32fp-44100Hz-mono-chirp-1-22050-log.wav"));

// Convert to another sample rate
wav.toSampleRate(16000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-32fp-16000Hz-mono-chirp-1-22050-log.wav",
wav.toBuffer());
});

describe('Upsample a 32-bit 44.1kHz log sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "32fp-44100Hz-mono-chirp-1-22050-log.wav"));

// Convert to another sample rate
wav.toSampleRate(96000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-32fp-96000Hz-mono-chirp-1-22050-log.wav",
wav.toBuffer());
});

describe('Downsample a 32-bit 44.1kHz linear sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "32fp-44100Hz-mono-chirp-1-22050-linear.wav"));

// Convert to another sample rate
wav.toSampleRate(16000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-32fp-16000Hz-mono-chirp-1-22050-linear.wav",
wav.toBuffer());
});

describe('Upsample a 32-bit 44.1kHz linear sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "32fp-44100Hz-mono-chirp-1-22050-linear.wav"));

// Convert to another sample rate
wav.toSampleRate(96000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-32fp-96000Hz-mono-chirp-1-22050-linear.wav",
wav.toBuffer());
});

// Chirps, int

describe('Downsample a 16-bit 44.1kHz log sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "16bit-44100Hz-mono-chirp-1-22050-log.wav"));

// Convert to another sample rate
wav.toSampleRate(16000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-16bit-16000Hz-mono-chirp-1-22050-log.wav",
wav.toBuffer());
});

describe('Upsample a 16-bit 44.1kHz log sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "16bit-44100Hz-mono-chirp-1-22050-log.wav"));

// Convert to another sample rate
wav.toSampleRate(96000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-16bit-96000Hz-mono-chirp-1-22050-log.wav",
wav.toBuffer());
});

describe('Downsample a 16-bit 44.1kHz linear sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "16bit-44100Hz-mono-chirp-1-22050-linear.wav"));

// Convert to another sample rate
wav.toSampleRate(16000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-16bit-16000Hz-mono-chirp-1-22050-linear.wav",
wav.toBuffer());
});

describe('Upsample a 16-bit 44.1kHz linear sine sweep', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "16bit-44100Hz-mono-chirp-1-22050-linear.wav"));

// Convert to another sample rate
wav.toSampleRate(96000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-16bit-96000Hz-mono-chirp-1-22050-linear.wav",
wav.toBuffer());
});

// Songs

describe('Downsample a 16bit 44.1kHz file', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "song1.wav"));

// Convert to another sample rate
wav.toSampleRate(16000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-song1-16kHz.wav",
wav.toBuffer());
});

describe('Upsample a 16bit 44.1kHz file', function() {
// Read a 8kHz wav
let wav = new WaveFile(
fs.readFileSync(path + "song1.wav"));

// Convert to another sample rate
wav.toSampleRate(96000, {method: 'sinc', LPF: false});

// Write the file
fs.writeFileSync(
path + "/out/to-sample-rate/sinc-no-LPF-song1-96kHz.wav",
wav.toBuffer());
});

hrend = process.hrtime(hrstart);
console.info('%ds %dms', hrend[0], hrend[1] / 1000000);

0 comments on commit 6979dbd

Please sign in to comment.