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

rsShiftForBestMatch not working for whole waveforms #304

Open
elanhickler opened this issue Jun 11, 2020 · 6 comments
Open

rsShiftForBestMatch not working for whole waveforms #304

elanhickler opened this issue Jun 11, 2020 · 6 comments

Comments

@elanhickler
Copy link
Contributor

elanhickler commented Jun 11, 2020

For some reason, I don't think rsShiftForBestMatch is working to align waveforms on a macro level. Instead, it seems to give a small shift value just to get the cycles in phase.

unaligned:
image

aligned:
image

comparison:
image

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Jun 11, 2020

in which file is this rsShiftForBestMatch function? the search function of visual studio gives me no results.

edit: ahh ok - i see - it's called rsGetShiftForBestMatch in MiscAudio.h/cpp.

edit2: haha - just reading my old comment there, what else could be done "blablabla...it's a mess..."

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Jun 11, 2020

so - what shift-value does the function actually produce in this case? can you show me a pic of that? i assume, the "aligned" and "comparison" pics are the desired results?

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Jun 11, 2020

i have an idea: apparently, the function was made for aligning some signal chunks taken somewhere from the middle of two signals...right? i don't remember - what was the original use-case? anyway - as i see it, the function rsMaxCorrelationLag that is called inside it, applies a Hamming window to both incoming signals before computing the cross-correlation. this is very likely the reason - i'd expect an effect like that from that. for chunks taken from the middle of signals, such a windowing seems a sensible thing to do (although i'm not sure, if hamming is the best choice - maybe we could experiment with other windows for this, too - edit: oh, in some other comment, i have said that i tried Hann and Blackman, too and than Hamming was indeed better - for alignment but not for cycle-marks - so more flexibility for this choice would indeed be nice).

however - for whole signals, we should perhaps use no window at all (i.e. rectangular). or, if only initial sections of samples are used, maybe a one-sided window that tapers off only to the right. hmmm...looks like we need a more flexible interface that allows client code to specify the window function to be used. ...maybe about time to consider, if a class is more appropriate than a function for this

@elanhickler
Copy link
Contributor Author

elanhickler commented Jun 11, 2020

I don't think I need this functionality after all, but I'd be willing to test if you want to work on it.

here are two files you can use to attempt to align them

two guitar samples.zip

@elanhickler
Copy link
Contributor Author

mm actually I might still need it

@RobinSchmidt
Copy link
Owner

RobinSchmidt commented Jun 12, 2020

hmm - ok - allowing other windows is not a big change algorithm-wise, but i may need to rethink the API for that functionality...maybe a class rsCorrelator and/or rsSampleAligner or something would be convenient...

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