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

Not accurate waveform #5

Closed
NPetrovs opened this issue Oct 13, 2017 · 15 comments
Closed

Not accurate waveform #5

NPetrovs opened this issue Oct 13, 2017 · 15 comments

Comments

@NPetrovs
Copy link

NPetrovs commented Oct 13, 2017

Hey,
From what I can see, if I upload any audio file, both sides (left/right) of the waveform, they are identical.
Mirror of the waveform should be different and they should not be identical.

Is it possible to fix?

@enjikaka
Copy link
Owner

enjikaka commented Oct 13, 2017 via email

@NPetrovs
Copy link
Author

NPetrovs commented Oct 13, 2017

A) This this the waveform your code is generating:
screen shot 2017-10-13 at 19 28 18

B) This is waveform of the same track, but just a bit stretched:
screen shot 2017-10-13 at 19 29 37

If you look at the image on the B case, left and right channels are different, but when generating it with your code, they are exactly the same, which is a wrong interpretation of the track.

screen shot 2017-10-13 at 19 28 18

screen shot 2017-10-13 at 19 29 37

@NPetrovs
Copy link
Author

NPetrovs commented Oct 13, 2017

Hope, that you understand what I mean.
You can compare with http://convert.ing-now.com/
From what I can see, their generated waveforms are pretty much correct

@enjikaka
Copy link
Owner

enjikaka commented Oct 13, 2017 via email

@enjikaka
Copy link
Owner

I've started experimenting with it in this branch; https://github.com/enjikaka/WaveformGenerator.js/tree/feature/stereo-waveform

@NPetrovs
Copy link
Author

NPetrovs commented Oct 13, 2017 via email

@NPetrovs
Copy link
Author

NPetrovs commented Oct 13, 2017 via email

@NPetrovs
Copy link
Author

NPetrovs commented Oct 13, 2017

screen shot 2017-10-14 at 01 19 31

This is a stereo track. If you do buffer.getChannelData(0) and buffer.getChannelData(1) You will be joining them together and result still won't be correct

@NPetrovs
Copy link
Author

screen shot 2017-10-14 at 01 19 31

@enjikaka
Copy link
Owner

The result in the branch for an example stereo track, I used this https://www.youtube.com/watch?v=kh8akNfMRa0

Isn't that what you want?

@NPetrovs
Copy link
Author

NPetrovs commented Oct 14, 2017

Correct waveform for this track would be this:

d6d0d3fa6a9c913cee1e7c54b3749a45

What you are doing, you are taking the stereo channel buffer.getChannelData(1) and applying it as a mirror of the track, which is not correct. You have to draw correct image just using buffer.getChannelData(0). Like it is done in this code example: https://codepen.io/ronanhigg/pen/gmFaq

@enjikaka
Copy link
Owner

Only using channel 0 (L) is what is done today.

What I've done there in the branch is that I've that I've taken channel 0 (L) on the top, and channel 1 (R) on the bottom. Like you explained. That gives a waveform like in my last picture.

It's either that or using L+R to make a combined bar height.

@NPetrovs
Copy link
Author

NPetrovs commented Oct 14, 2017

Could you explain how this code is drawing different L/R if I pass only buffer.getChannelData(0) in data argument?

function drawBuffer( width, height, context, data ) { var step = Math.ceil( data.length / width ); var amp = height / 2; context.fillStyle = "silver"; context.clearRect(0,0,width,height); for(var i=0; i < width; i++){ var min = 1.0; var max = -1.0; for (j=0; j<step; j++) { var datum = data[(i*step)+j]; if (datum < min) min = datum; if (datum > max) max = datum; } context.fillRect(i,(1+min)*amp,1,Math.max(1,(max-min)*amp)); } }

@enjikaka
Copy link
Owner

@NPetrovs If you pass buffer.getChannelData(0) into that you'd only get L channel.

buffer.getChannelData(0) = left channel
buffer.getChannelData(1) = right channel

@NPetrovs
Copy link
Author

NPetrovs commented Oct 16, 2017 via email

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

No branches or pull requests

2 participants