Skip to content

Commit

Permalink
Long file spectrogram support. Fixed excessive memory use with long f…
Browse files Browse the repository at this point in the history
…iles. Page down and Page up buttons now page through a file. Play button for detections - seeks timecode and plays detection region.
  • Loading branch information
Mattk70 committed Jan 31, 2022
1 parent 750174d commit 423cd55
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 78 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Chirpity-Electron

Electron app for sound file analysis with Chirpity.
Electron app for sound file analysis with Chirpity.

Author: Matthew Kirkland

Expand Down Expand Up @@ -64,14 +64,12 @@ Install Bootstrap and its dependencies:
```
npm install bootstrap
npm install jquery
npm install popper.js
npm install popper
```

This app also needs some additional packages that we have to install.
This app also needs an additional package that we have to install.

```
npm install audio-loader
npm install audio-resampler
npm install colormap
```

Expand All @@ -96,5 +94,6 @@ After that, we can export the app with:
npm run export
```

The resulting application will be saves in the "packages" folder.


6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


<!-- App title -->
<title>Chirpity Sound Analysis</title>
<title>Chirpity Bird Call Detection</title>

</head>
<body>
Expand Down Expand Up @@ -110,6 +110,7 @@
</button -->

</div>
<div id="filename" class="align-bottom"></div>
<div class="progressDiv" style="width: 20%;display: none"> Working...<br>
<div class="progress" style="width: 100%">
<div class="progress-bar progress-bar-striped active" role="progressbar"
Expand All @@ -134,7 +135,8 @@
<th scope="col">Common name</th>
<th scope="col">Scientific name</th>
<th scope="col">Confidence</th>
<th scope="col"></th>
<th scope="col">Play</th>
<th scope="col"> View Alternates</th>
</tr>
</thead>
<tbody class="text-dark" id="resultTableBody">
Expand Down
48 changes: 48 additions & 0 deletions js/AudioBufferSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const audioContext = new (window.AudioContext || window.webkitAudioContext);

function AudioBufferSlice(buffer, begin, end, callback) {
if (!(this instanceof AudioBufferSlice)) {
return new AudioBufferSlice(buffer, begin, end, callback);
}

let error = null;

const duration = buffer.duration;
const channels = buffer.numberOfChannels;
const rate = buffer.sampleRate;

if (typeof end === 'function') {
callback = end;
end = duration;
}

// handle short clips and beginning /end of files
if (end > duration) end = duration;
if (begin < 0) begin = 0;

if (typeof callback !== 'function') {
error = new TypeError('callback must be a function');
}

const startOffset = rate * begin;
const endOffset = rate * end;
const frameCount = endOffset - startOffset;
let newArrayBuffer;

try {
newArrayBuffer = audioContext.createBuffer(channels, endOffset - startOffset, rate);
const anotherArray = new Float32Array(frameCount);
const offset = 0;

for (let channel = 0; channel < channels; channel++) {
buffer.copyFromChannel(anotherArray, channel, startOffset);
newArrayBuffer.copyToChannel(anotherArray, channel, offset);
}
} catch (e) {
error = e;
}

callback(error, newArrayBuffer);
}

module.exports = AudioBufferSlice;
14 changes: 7 additions & 7 deletions js/model.js

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

Loading

0 comments on commit 423cd55

Please sign in to comment.