Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectrogram's canvas does not full fill the container of it #3140

Open
KrazyPhish opened this issue Aug 25, 2023 · 17 comments
Open

Spectrogram's canvas does not full fill the container of it #3140

KrazyPhish opened this issue Aug 25, 2023 · 17 comments

Comments

@KrazyPhish
Copy link

Bug description

I was doing a Vue2 to Vue3 project, found that spectrogram's canvas cannot full fill its parent element.
But it works well in my Vue2 project.
Infomation of the versions:
my Vue2 project: wavesurfer.js 6.2.0 (2022-05-16)
my Vue3 project: wavesurfer.js latest

Environment

  • Dev: VSCode, TypeScript, Vue3
  • Browser: Chrome - version 116.0.5845.97
  • OS: windows 11

Minimal code snippet

In Vue2:
plugins.push(
spectrogram.create({
container: this.$refs.waveSpectrogramRef,
labels: true,
height: height * this.verticalZoom.value,
colorMap
})
)

In Vue3:
const spectrogram: SpectrogramPlugin = SpectrogramPlugin.create({
container: waveSpectrogramRef.value as HTMLElement,
labels: true,
height: height * state.verticalZoom,
colorMap
})

The value height equals its parent's clientHeight, it's a constant value, so is the verticalZoom value.

Expected result

Like wavesurfer works in my Vue2 project, spectrogram's canvas fully fill its parent element.

Obtained result

Same as Expected result

Screenshots

The parent element div.
image
The left side label canvas, this means spectrogram tried to fill the element, I guess.
image
The style attributes show that the canvas has fully filled its parent element, there must be some problems with canvas while the plugin working with canvas.
image

@KrazyPhish KrazyPhish added the bug label Aug 25, 2023
@katspaugh
Copy link
Owner

You might need to increase the sampleRate for it to have the data to fill the chart. Try passing 22050 or 44100 like here: https://wavesurfer-js.org/examples/?spectrogram.js

@KrazyPhish
Copy link
Author

Attribute sampleRate 22050 works the same as my last try, 44100 makes a little diffrence but still didn't solve the problem, here's the pic in 44100 samepleRate, it seems that only expanded the label values:
image

@katspaugh
Copy link
Owner

I see, thanks for checking this. Looks like a regression in v7, since you said it worked well in v6. 🐞

@KrazyPhish
Copy link
Author

Yep, the version of 6.2.0 worked well, but the problem above was found while using the version of 7.1.5. Hope this can help.

@Richard-2-4-2
Copy link

hi all, is there the same isuue?
image

@katspaugh
Copy link
Owner

Try decreasing your sample rate

Screenshot 2023-10-16 at 11 20 22

@Richard-2-4-2
Copy link

Richard-2-4-2 commented Oct 16, 2023

thanks for your answer. no changes (on left). on right, image of audacity for comparison. seems that frequencies beyond 4000hz are not drawn . sorry i pasted wrong image
image

@KrazyPhish
Copy link
Author

It looks like decreasing the sampleRate value solved your problem in some way? I've tried it too, but makes no diffrence in my case

@katspaugh
Copy link
Owner

Try also adjusting the min and max frequency accordingly.

https://wavesurfer.xyz/docs/types/plugins_spectrogram.SpectrogramPluginOptions

frequencyMax?: number
Max frequency to scale spectrogram. Set this to samplerate/2 to draw whole range of spectrogram.

@Richard-2-4-2
Copy link

my sample is 44100 hz. i can give a value up to 11050hz or i must use these value ?

@Richard-2-4-2
Copy link

It looks like decreasing the sampleRate value solved your problem in some way? I've tried it too, but makes no diffrence in my case
sorry, i copy only one layer of photoshop. the two graphes are for comparison to audacity ( i want to have similar appearence)

@katspaugh
Copy link
Owner

You can set any value down to 8000 for sampleRate. In Chrome down to 3000.

@Richard-2-4-2
Copy link

for spectrogram :
if i define height: 500 : 181 pixels drawn
height: 2000 : 185 pixels drawn
is it normal?
i dont understand the samplerate option. the value is given by the file, non ?
something special to chrome compared to others?

@KrazyPhish
Copy link
Author

image
I am very glad to see this to solve my problem, temporarily. I guess that setting the sampleRate and frequencyMax may cut the canvas, however, didn't like the docs said to set the frequencyMax to sampleRate/2 but the sampleRate/4.

@Richard-2-4-2
Copy link

KrazyPhish, how is the samplerate of your audio file? wich values are you using for sampleRate and frequencyMax ?

@KrazyPhish
Copy link
Author

I am not sure about my files sample rate range cause the file was somehow just use to test, 22050 for the sampleRate and 5512.5 for the frequencyMax are my settings.

@Richard-2-4-2
Copy link

Richard-2-4-2 commented Oct 18, 2023

my sample is Mono, 44100Hz, 32bits.
sorry, i was wrong tried to setting sampleRate: 44100 for spectrogram and not wave surfer.
in the previous version, it was not necessary to specify samplerate and i was confused because the wav file have is own samplerate. it works as expected, now :
image
next steps : zoom and scrolling according to waveform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants