Spectogram plugin cuts out half of the canvas
See original GitHub issueI noticed it when working with 44.1kHz files (in your examples you are using 22k ones and it works just fine).
This is what I get:
this is the same file in audacity (notice the 0-11k range):
this is the same file in audacity with range 0-22k
I changed line 46 in wavesurfer-js/plugins/wavesurfer/spectogram.js (granted this breaks things for 22k files and most likely in other cases)
from: this.height = this.fftSamples/2;
to:
this.height = this.fftSamples;'
and I got as a result:
my code:
<head>
<script src="wavesurfer.js/dist/wavesurfer.min.js"></script>
<script src="wavesurfer.js/plugin/wavesurfer.spectrogram.js"></script>
</head>
<body>
<div id="waveform"></div>
<div id="wave-spectrogram"></div>
<script type="text/javascript">
var wavesurfer = WaveSurfer.create({
container: '#waveform',
});
wavesurfer.on('ready', function () {
var spectrogram = Object.create(WaveSurfer.Spectrogram);
spectrogram.init({
wavesurfer: wavesurfer,
container: "#wave-spectrogram",
});
});
wavesurfer.load('music_file.mp3')
</script>
</body>
</html>
music file that I used: https://github.com/arirusso/d3-audio-spectrum/blob/master/public/media/sweep.mp3
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (7 by maintainers)
Top Results From Across the Web
1 Panes and Layers - Sonic Visualiser: A Brief Reference
The plain spectrogram option creates a spectrogram that displays the full frequency range up to half of the audio file's sampling rate, with...
Read more >Alchemy spectral edit window in Logic Pro - Apple Support
Spectral editor window. Spectral data is displayed as follows in the Spectral edit window, or “canvas”. Time, expressed in seconds, is represented ...
Read more >Should I try to fill the whole frequency spectrum at any part of a ...
I know that a producer should try to make the spectrum as wide as ... of not filling the spectrum 100% of the...
Read more >Plugins - ImageJ
Plugins. Contents Acquisition Analysis Collections Color Filters Segmentation Graphics Input/Output Programming Examples Scripting Stacks Tools Toolsets
Read more >Write an audio visualizer from scratch with vanilla JavaScript
CORS prevents accessing resources from outside of its domain. ... This is where we'll be holding our canvas and audio elements.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My coworker came across this bug report when he searched around after we discovered that the spectrogram frequency content was mislabeled and half of what we expected it to be. To demonstrate what I was seeing, we replaced the demo.wav file with a file that contains a 4kHz square wav (wav file with 16kHz sampling rate) and this is what I saw:
Notice that the fundamental frequency is incorrectly labeled at 8kHz. Changing the heightFactor = 1 fixed things. I also specified an audioContext with “audioContext: new AudioContext({sampleRate: 16000})”. This proved important when displaying waveforms with more frequency content if their sampleRate was low since the default audioContext seems to resample things pretty high (44.1 or 48kHz) and this results in a lot of black space at the top of the spectrogram. This is the result with the changes:
Notice that the original demo.wav file has a sample rate of 22050hz and yet the demo implies there is frequency content above nyquist.
The issue appears not to be with the FFT/spectrogram but with that heightFactor. Does anybody know why it was originally set to something other than 1?
In an ideal world the spectrogram plugin could determine the original sampling rate and so something with that information (such as create an audioContext with the same sampling rate) so that it doesn’t resample and create that empty space, but I guess in the case of compressed audio this might be trickier.
Without understanding what the heightFactor is for, I wonder if it can be removed. I guess that would change the look of everyone’s spectrograms if they’re used to seeing only half of the spectrogram Thoughts? Alternatively, assuming heightFactor has a useful purpose, could we make it explicitly programmable in the Spectrogram’s params?
maybe we should use an external spectrogram library for this plugin instead, e.g. https://github.com/vlandham/spectrogramJS