Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
400da27
Added firefox compablity changes
Sean1572 Aug 18, 2021
e7be805
created system to dynamically take in sample rate value from backend
Sean1572 Aug 18, 2021
dd4257c
manual sampling rate changer
Sean1572 Aug 18, 2021
46ba477
added zoom component but more work is still need debugging
Sean1572 Aug 24, 2021
9fe3086
test
Sean1572 Aug 25, 2021
5c73a68
added horizontal zoom back - todo: add feature form stuff
Sean1572 Aug 25, 2021
edacdcd
feature form
Sean1572 Aug 25, 2021
f812bfe
got a slider for frequency calucation
Sean1572 Aug 25, 2021
6dd0ad5
Update sampleRateChanger.js
Sean1572 Aug 25, 2021
547cd58
Merge branch 'main' into frequency-scale-changer
Sean1572 Aug 25, 2021
71f8452
Merge branch 'zoom_horizontal' into frequency-scale-changer
Sean1572 Aug 25, 2021
1999ca1
Update sampleRateChanger.js
Sean1572 Aug 25, 2021
51003cf
new attempt at image data scaling
Sean1572 Aug 27, 2021
dc6ae68
next attempt
Sean1572 Aug 27, 2021
134337c
Got scaling working, just need to rotate it
Sean1572 Sep 1, 2021
e2c5642
Vertical scale completed, just need to fix up some stuff with the sta…
Sean1572 Sep 1, 2021
e9803f6
attempt at fixing regions when scaling
Sean1572 Sep 1, 2021
da56cb0
set up init scaling
Sean1572 Sep 2, 2021
7b76d05
Merge branch 'main' into frequency-scale-changer
Sean1572 Sep 2, 2021
fffe4bf
fixed merge bugs
Sean1572 Sep 2, 2021
6619c1f
disable region scaling code till later demo
Sean1572 Sep 7, 2021
338333f
added low freq limit
Sean1572 Sep 8, 2021
09030e8
added low freq input
Sean1572 Sep 8, 2021
ecf9982
fixed next button bug and cleaned up input text
Sean1572 Sep 8, 2021
16161c0
Fixed desync bug
Sean1572 Sep 14, 2021
111335e
Merge branch 'main' into frequency-scale-changer
Sean1572 Dec 22, 2021
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
3 changes: 2 additions & 1 deletion audino/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
"popper.js": "^1.16.1",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-bootstrap": "^1.0.1",
"react-bootstrap": "^1.6.3",
"react-dom": "^16.13.1",
"react-helmet": "^6.0.0",
"react-redux": "^7.2.6",
"react-router": "^5.2.0",
"react-router-dom": "^5.3.0",
"react-scripts": "3.4.1",
"resize-image-data": "^0.3.0",
"redux": "^4.1.2",
"uuid": "^8.3.2",
"wavesurfer.js": "^5.2.0"
Expand Down
1 change: 1 addition & 0 deletions audino/frontend/scripts/run-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ echo "npm install"
cd "${app}" && npm install
cd "${app}" && npm install jszip
cd "${app}" && npm install file-saver
cd "${app}" && npm i resize-image-data
} || {
echo "package update broke install, deleting node_modules"
cd "${app}" && rm -rf node_modules
Expand Down
3 changes: 2 additions & 1 deletion audino/frontend/src/components/annotate/navbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const NavButton = props => {
previous_pages[num_of_prev] = dataId;
localStorage.setItem('previous_links', JSON.stringify(previous_pages));
localStorage.setItem('count', JSON.stringify(next_page_num));

console.log("configed browser settings")
if (noMore) {
window.location.href = `${path}/projects/${projectId}/data`;
} else {
Expand Down Expand Up @@ -69,6 +69,7 @@ const NavButton = props => {
})
.then(response => {
const { data_id } = response.data;
console.log("successfully prepared next data point")
loadNextPage(response.status === 202, data_id);
})
.catch(e => {
Expand Down
58 changes: 58 additions & 0 deletions audino/frontend/src/components/annotate/sampleRateChanger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { Button } from '../button';

const SampleRateChanger = props => {
const {annotate, state} = props
const {wavesurfer, filename, spectrogram} = state
const [text, setText] = React.useState("")
const [hz, setHz] = React.useState(0)
const [hz2, setHz2] = React.useState(Number(wavesurfer.backend.offlineAc.sampleRate/1000))

const handleSubmit = () => {
const int = parseInt(text, 10)

const newState = annotate.initalState;
newState["sampleRate"] = int || 44100
wavesurfer.load(`/audios/${filename}`, null, null, null, int );
}

const inputText = e => {
setText(e.target.value)
}

const ChangeColorChange = e => {
setHz(e.target.value)
wavesurfer.empty()
wavesurfer.load(`/audios/${filename}`, null, null, null, e.target.value * 1000);
}

return (
<div className="sideMenuItem">
<input
type="range"
min="0"
max={`${Number(wavesurfer.backend.offlineAc.sampleRate/1000) - 1}`}
value={hz}
onChange={e => {
setHz(e.target.value)
spectrogram.scale(e.target.value, hz2, wavesurfer.backend.offlineAc.sampleRate/1000)
}} />
<input
type="range"
min="1"
max={`${Number(wavesurfer.backend.offlineAc.sampleRate/1000)}`}
value={hz2}
onChange={e => {
setHz2(e.target.value);
spectrogram.scale(0, e.target.value, Math.ceil(wavesurfer.backend.offlineAc.sampleRate/1000))
/*Object.values(wavesurfer.regions.list).forEach(segment => {
segment.scale(e.target.value * 1000)
})*/
}}
/>
{hz/2 + " - " + hz2/2 + " khz"}
</div>
)
};

export default SampleRateChanger;
39 changes: 39 additions & 0 deletions audino/frontend/src/components/annotate/zoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import StickySlider from '../stickySlider';
const Zoom = props => {
const {annotate} = props
const {state} = annotate;
const {isRendering, wavesurfer, zoomOn} = state

/*wavesurfer.on('zoom', pxPerSec => {
wavesurfer.spectrogram._onUpdate(pxPerSec * wavesurfer.getDuration());
})*/

const handleZoom = value => {
console.log("hello", wavesurfer, state, annotate, props)
wavesurfer.zoom(value);
wavesurfer.spectrogram._onUpdate()
}

return (
<div>
{zoomOn ?
<div
style={{ display: isRendering ? 'none' : '' }}
>
<StickySlider
min="1"
max="200"
finalChangeCallback={value => handleZoom(value)}
stickyPos={[0, 200]}
threshold={5}
/>
</div>
: null}

</div>

);
};

export default Zoom;
5 changes: 4 additions & 1 deletion audino/frontend/src/components/sideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Button, IconButton } from './button';
import SpectroChanger from './annotate/spectroChanger';
import ChangePlayback from './annotate/extraFeatures/changePlayback';
import PreviousAnnotationButton from './annotate/extraFeatures/previousAnnotationButton';

import SampleRateChanger from './annotate/sampleRateChanger';
import Zoom from './annotate/zoom';
const SideMenuTab = props => {
const { tab, icon, tabOpen, setTab } = props;
const swapTabs = tab => {
Expand Down Expand Up @@ -100,6 +101,8 @@ const SideMenu = props => {
<ChangePlayback annotate={annotate} />
<PreviousAnnotationButton annotate={annotate} />
{toUnsavedClipOn && annotate.UnsavedButton ? annotate.UnsavedButton.render() : null}
<SampleRateChanger state={state} annotate={annotate}/>
<Zoom annotate={annotate} />

<br />
<Button
Expand Down
4 changes: 3 additions & 1 deletion audino/frontend/src/components/stickySlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const StickySlider = ({
hasLabels = true,
threshold = 10,
stickyPos = [],
changeCallback = noop
changeCallback = noop,
finalChangeCallback = noop
}) => {
const [value, setValue] = React.useState(Math.floor((max - min) / 2));

Expand All @@ -25,6 +26,7 @@ const StickySlider = ({
if (Math.abs(pos - finalValue) < threshold) finalValue = pos;
});
changeCallback(finalValue);
finalChangeCallback(finalValue)
setValue(finalValue);
};

Expand Down
3 changes: 2 additions & 1 deletion audino/frontend/src/containers/forms/featureForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class FeatureForm extends React.Component {
'2D Labels': false,
'to unsaved cliped': false,
playbackOn: false,
'spectrogram demo': false
'spectrogram demo': false,
'zoom': true,
}
};

Expand Down
8 changes: 8 additions & 0 deletions audino/frontend/src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ body,
float: left;
}

#wavegraph-fliped {
width: 200%;
top: 256px;
position: relative;
float: left;
transform: scaleY(-1);
}

#waveform-labels {
width: 100%;
position: relative;
Expand Down
26 changes: 18 additions & 8 deletions audino/frontend/src/pages/annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Annotate extends React.Component {
toUnsavedClipOn: response.data.features_list['to unsaved cliped'],
referenceWindowOn: response.data.features_list['reference window'],
playbackOn: response.data.features_list.playbackOn,
spectrogramDemoOn: response.data.features_list['spectrogram demo']
spectrogramDemoOn: response.data.features_list['spectrogram demo'],
zoomOn: response.data.features_list['zoom']
});

const wavesurferMethods = new WavesurferMethods({
Expand Down Expand Up @@ -146,13 +147,19 @@ class Annotate extends React.Component {
}

loadFileMetadata(response, boundingBox, wavesurfer, wavesurferMethods) {
console.log("hello?????????????????????????")
this.setState({
isDataLoading: false,
labels: response[0].data
labels: response[0].data,
wavesurfer,
wavesurferMethods
});

const { is_marked_for_review, segmentations, filename, original_filename } = response[1].data;

const { is_marked_for_review, segmentations, filename, original_filename, sampling_rate } = response[1].data;
let {sampleRate} = this.state
if (!sampleRate) {
sampleRate = sampling_rate
}
const regions = segmentations.map(segmentation => {
if (boundingBox) {
return {
Expand Down Expand Up @@ -180,18 +187,20 @@ class Annotate extends React.Component {
boundingBox
};
});

console.log("hello?????????????????????????", this.state.wavesurfer)
this.setState({
isDataLoading: false,
isMarkedForReview: is_marked_for_review,
original_filename
});
console.log("hello?????????????????????????")

wavesurfer.load(`/audios/${filename}`);
console.log("start load", sampleRate)
wavesurfer.load(`/audios/${filename}`, null, null, null, sampleRate);
const { zoom } = this.state;
wavesurfer.zoom(zoom);

this.setState({ wavesurfer, wavesurferMethods });
this.setState({ wavesurfer, wavesurferMethods, filename });
this.loadRegions(regions);
}

Expand All @@ -203,8 +212,9 @@ class Annotate extends React.Component {
newState.segmentationUrl = `/api/projects/${projectId}/data/${nextDataId}/segmentations`;
newState.dataId = nextDataId;
newState.wavesurfer = null;

console.log("configed new state")
wavesurfer.destroy();
console.log("wavesurfer destroied")
this.setState(newState, () => {
this.componentDidMount();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ class WavesurferMethods {
wavesurfer.skipBackward(5);
}

handleZoom(e) {
const { wavesurfer } = this.state;
const zoom = Number(e.target.value);
wavesurfer.zoom(zoom);
this.setState({ zoom });
}

styleRegionColor(region, color) {
region.style(region.element, {
backgroundColor: color
Expand Down
11 changes: 11 additions & 0 deletions audino/frontend/src/wavesurfer.js/src/plugin/regions/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ export default class Region {
};
}

async scale(newMaxFrequency) {

const freqRatio = newMaxFrequency / this.maxFrequency
console.log(this.maxFrequency, newMaxFrequency, freqRatio )
this.maxFrequency = newMaxFrequency
console.log(this.top, this.top / freqRatio )
this.top = this.top * freqRatio
this.bot = this.bot * freqRatio
this.update({})
}

/* Update region params. */
update(params) {
if (params.start != null) {
Expand Down
37 changes: 32 additions & 5 deletions audino/frontend/src/wavesurfer.js/src/plugin/spectrogram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ export default class SpectrogramPlugin {
}

render(zoom = false) {
this.loadLabels(
'rgba(68,68,68,0.5)',
'12px',
'10px',
'',
'#fff',
'#f7f7f7',
'center',
'#specLabels'
);
this.updateCanvasStyle(zoom);

if (this.frequenciesDataUrl) {
Expand Down Expand Up @@ -334,7 +344,7 @@ export default class SpectrogramPlugin {
}
spectrCc.putImageData(imageData, 0, 0);
try {
const test = new Spectrogram(my.wavesurfer, spectrCc, imageData, pixels, heightFactor);
const test = new Spectrogram(my.wavesurfer, spectrCc, imageData, pixels, heightFactor, my);
} catch (e) {
console.error(e);
}
Expand All @@ -349,7 +359,9 @@ export default class SpectrogramPlugin {
const { buffer } = this;
const channelOne = buffer.getChannelData(0);
// const bufferLength = buffer.length;
const { sampleRate } = buffer;
let { sampleRate } = buffer;
//sampleRate = 18000 * 2
console.log(sampleRate)
const frequencies = [];

if (!buffer) {
Expand Down Expand Up @@ -405,7 +417,9 @@ export default class SpectrogramPlugin {
textColorFreq,
textColorUnit,
textAlign,
container
container,
sampleRateParam=null,
sampleRateMin=null
) {
const frequenciesHeight = this.height;
bgFill = bgFill || 'rgba(68,68,68,0)';
Expand All @@ -419,8 +433,21 @@ export default class SpectrogramPlugin {
const bgWidth = 55;
const getMaxY = frequenciesHeight || 512;
const labelIndex = 5 * (getMaxY / 256);
const freqStart = 0;
const step = (this.wavesurfer.backend.ac.sampleRate / 2 - freqStart) / labelIndex;
const freqStart = sampleRateMin || 0;

let sampleRate = sampleRateParam
if (sampleRate === null) {
if (this.wavesurfer.backend.offlineAc.sampleRate) {
sampleRate = this.wavesurfer.backend.offlineAc.sampleRate
} else if (this.wavesurfer.backend.ac.sampleRate) {
sampleRate = this.wavesurfer.backend.ac.sampleRate
}
} else {
sampleRate = sampleRateParam
}


const step = (sampleRate / 2 - freqStart) / labelIndex;

// prepare canvas element for labels
const ctx = this.labelsEl.getContext('2d');
Expand Down
Loading