Skip to content

Commit

Permalink
upgrade to soundworks#v5
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Feb 4, 2025
1 parent 94b8828 commit aae326f
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 1,066 deletions.
4 changes: 2 additions & 2 deletions .soundworks
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"eslint": true,
"language": "js",
"configFormat": "yaml",
"createVersion": "1.0.0-alpha.23"
}
"createVersion": "5.0.1"
}
6 changes: 3 additions & 3 deletions config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: simone-v2
author: ""
clients:
controller:
target: browser
runtime: browser
default: true
satellite:
target: node
runtime: node
recorder:
target: browser
runtime: browser
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,32 @@
"postinstall": "soundworks-build -C",
"start": "node .build/server/index.js",
"watch": "soundworks-build -p",
"watch:inspect": "soundworks-build -d -p",
"watch:inspect": "soundworks-build -i -p",
"watch:sass": "sass --watch src/clients/styles:.build/public/css",
"lint": "eslint ."
},
"dependencies": {
"@ircam/sc-components": "^3.0.0-alpha.60",
"@ircam/sc-loader": "^1.0.0-alpha.1",
"@ircam/sc-scheduling": "^0.1.6",
"@ircam/sc-utils": "^1.3.3",
"@soundworks/core": "^4.0.0-alpha.23",
"@soundworks/helpers": "^1.0.0-alpha.2",
"@soundworks/max": "^1.1.1",
"@soundworks/plugin-filesystem": "^2.0.0-alpha.6",
"@soundworks/plugin-platform-init": "^1.0.0-alpha.5",
"@soundworks/plugin-sync": "^2.0.0-alpha.3",
"@ircam/sc-components": "^3.2.5",
"@ircam/sc-loader": "^1.1.0",
"@ircam/sc-scheduling": "^1.0.0",
"@ircam/sc-utils": "^1.9.0",
"@soundworks/core": "^5.0.0",
"@soundworks/helpers": "^5.0.0",
"@soundworks/plugin-filesystem": "^5.0.0",
"@soundworks/plugin-platform-init": "^5.0.0",
"@soundworks/plugin-sync": "^5.0.0",
"audiobuffer-to-wav": "^1.0.0",
"json5": "^2.2.2",
"lit": "^3.0.2",
"node-web-audio-api": "^0.21.1",
"node-web-audio-api": "^1.0.1",
"static-kdtree": "^1.0.2"
},
"devDependencies": {
"@ircam/eslint-config": "^1.2.1",
"@soundworks/build": "^1.0.0-alpha.2",
"@soundworks/create": "^1.0.0-alpha.19",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"@ircam/eslint-config": "^2.0.1",
"@soundworks/build": "^5.0.0",
"@soundworks/create": "^5.0.0",
"concurrently": "^9.1.2",
"eslint": "^9.19.0",
"sass": "^1.57.1"
}
}
61 changes: 8 additions & 53 deletions src/clients/utils/mfcc.worker.js → public/Mfcc.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,4 @@
addEventListener('message', e => {
const {type, data} = e.data;
if (type === 'message') {
postMessage({
type: 'message',
data,
});
}
if (type === 'analyze-calibration') {
console.log('begin analysis');
const init = data.analysisInitData;
const analyzer = new Mfcc(init.mfccBands, init.mfccCoefs, init.mfccMinFreq, init.mfccMaxFreq, init.frameSize, init.sampleRate);
const [mfccFrames, times, means, std, minRms, maxRms] = analyzer.computeBufferMfcc(data.buffer, init.hopSize);
postMessage({
type,
data: {
means,
std,
minRms,
maxRms,
}
});
}
if (type === 'analyze-recording') {
console.log('begin analysis');
const init = data.analysisInitData;
const analyzer = new Mfcc(init.mfccBands, init.mfccCoefs, init.mfccMinFreq, init.mfccMaxFreq, init.frameSize, init.sampleRate);
const [mfccFrames, times, means, std, minRms, maxRms] = analyzer.computeBufferMfcc(data.buffer, init.hopSize);
postMessage({
type,
data: {
means,
std,
minRms,
maxRms,
bufferParams: data.bufferParams,
buffer: data.buffer,
},
});

}
});


class Mfcc {
export default class Mfcc {
constructor(nbrBands, nbrCoefs, minFreq, maxFreq, frameSize, sampleRate) {
this.nbrBands = nbrBands;
this.nbrCoefs = nbrCoefs;
Expand All @@ -65,7 +21,7 @@ class Mfcc {
}

computeBufferMfcc(channelData, hopSize) {
console.log("analysing file");
console.log("analyzing file");
const mfccFrames = [];
const times = [];
const means = new Float32Array(this.nbrCoefs);
Expand Down Expand Up @@ -93,10 +49,10 @@ class Mfcc {
frameRms = Math.sqrt(frameRms/frame.length);
if (frameRms > maxRms) {
maxRms = frameRms;
}
}
if (frameRms < minRms) {
minRms = frameRms;
}
}
}
for (let j = 0; j < this.nbrCoefs; j++) {
means[j] /= mfccFrames.length;
Expand Down Expand Up @@ -204,7 +160,7 @@ class Mel {

for (var j = 0; j < weights.length; j++) {
value += weights[j] * data[startIndex + j];
}
}
if (scale !== 1) value *= scale;

if (this.log) {
Expand Down Expand Up @@ -286,6 +242,7 @@ function getMelBandWeights(nbrBins, nbrBands, sampleRate, minFreq, maxFreq) {

class Fft {
constructor(mode, frameSize, fftSize, windowSize) {
console.log(mode, frameSize, fftSize, windowSize);
this.mode = mode;
this.frameSize = frameSize;
this.fftSize = fftSize;
Expand Down Expand Up @@ -349,7 +306,7 @@ class Fft {
var _imagNy = this.imag[this.fftSize / 2];
outData[this.fftSize / 2] = (_realNy * _realNy + _imagNy * _imagNy) * _norm;


for (var _i3 = 1, _j = this.fftSize - 1; _i3 < this.fftSize / 2; _i3++, _j--) {
var _real = 0.5 * (this.real[_i3] + this.real[_j]);
var _imag = 0.5 * (this.imag[_i3] - this.imag[_j]);
Expand All @@ -369,7 +326,7 @@ class FftNayuki {

for (var i = 0; i < 32; i++) {
if (1 << i == n) {
this.levels = i;
this.levels = i;
}
}

Expand Down Expand Up @@ -453,5 +410,3 @@ function hannWindow(buffer, size, normCoefs) {
normCoefs.linear = size / linSum;
normCoefs.power = Math.sqrt(size / powSum);
}


51 changes: 51 additions & 0 deletions public/mfcc.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Mfcc from './Mfcc.js';

addEventListener('message', e => {
const {type, data} = e.data;

switch (type) {
case 'message': {
// ping / pong message to ensure initialization
postMessage({ type: 'message', data });
break;
}
case 'analyze-calibration': {
console.log('begin analysis');
const init = data.analysisInitData;
const analyzer = new Mfcc(init.mfccBands, init.mfccCoefs, init.mfccMinFreq, init.mfccMaxFreq, init.frameSize, init.sampleRate);
const [mfccFrames, times, means, std, minRms, maxRms] = analyzer.computeBufferMfcc(data.buffer, init.hopSize);
postMessage({
type,
data: {
means,
std,
minRms,
maxRms,
}
});
break;
}
case 'analyze-recording': {
console.log('begin analysis');
const init = data.analysisInitData;
const analyzer = new Mfcc(init.mfccBands, init.mfccCoefs, init.mfccMinFreq, init.mfccMaxFreq, init.frameSize, init.sampleRate);
const [mfccFrames, times, means, std, minRms, maxRms] = analyzer.computeBufferMfcc(data.buffer, init.hopSize);
postMessage({
type,
data: {
means,
std,
minRms,
maxRms,
bufferParams: data.bufferParams,
buffer: data.buffer,
},
});
break;
}
default: {
console.log('mfcc.worker: Unhandled message type', type);
break;
}
}
});
Loading

0 comments on commit aae326f

Please sign in to comment.