Skip to content

Commit

Permalink
aligned fetchaudiobuffer to getpredictbuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Mar 28, 2024
1 parent 16c19ad commit fc360b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion js/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class State {
this.list = 'everything',
this.customList = undefined,
this.local = true,
this.incrementor = 250,
this.incrementor = 1,
this.UUID = 0,
this.track = true
}
Expand Down
20 changes: 10 additions & 10 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@ const fetchAudioBuffer = async ({
file = '', start = 0, end = metadata[file].duration
}) => {
//if (end - start < 0.1) return // prevents dataset creation barfing with v. short buffer
const stream = new PassThrough();
const data = [];
const stream = new PassThrough({end: false});
let concatenatedBuffer = Buffer.alloc(0);
// Use ffmpeg to extract the specified audio segment
return new Promise((resolve, reject) => {
let command = ffmpeg(file)
Expand Down Expand Up @@ -1409,16 +1409,17 @@ const fetchAudioBuffer = async ({
})

stream.on('data', chunk => {
chunk.byteLength > 1 && data.push(chunk);
try {
concatenatedBuffer = concatenatedBuffer.length ? Buffer.concat([concatenatedBuffer, chunk]) : chunk;
} catch (error) {
console.warn(error)
}
});

stream.on('end', async () => {
if (data.length === 0) return;
//Add the audio header
data.unshift(CHIRPITY_HEADER)
// Concatenate the data chunks into a single Buffer
const audio = Buffer.concat(data);
// Native CHIRPITY_HEADER (24kHz) here for UI
if (concatenatedBuffer.length <= 1) return;
//Add the audio header for the UI
const audio = Buffer.concat([CHIRPITY_HEADER, concatenatedBuffer]);
const offlineCtx = await setupCtx(audio, sampleRate, 'UI').catch( (error) => {console.error(error.message)});
if (offlineCtx){
offlineCtx.startRendering().then(resampled => {
Expand All @@ -1428,7 +1429,6 @@ const fetchAudioBuffer = async ({
});
}
});

command.run();
});
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "chirpity",
"version": "1.6.3",
"version": "1.6.4",
"description": "Chirpity Nocmig",
"main": "main.js",
"scripts": {
"start": "electron .",
"prebuild": "node prebuild.js",
"minify": "node minify.js",
"export": "electron-builder build --linux",
"export": "electron-builder build --m",
"build": "electron-builder --win --x64 -p always"
},
"repository": {
Expand Down

0 comments on commit fc360b4

Please sign in to comment.