ericlyon / pd-fftease

FFTease 3.0 for Pd
Other
18 stars 4 forks source link

Question about copyArray function in mindwarp~ #34

Closed ericlyon closed 3 years ago

ericlyon commented 3 years ago

I just noticed that a new function was introduced, "copyArray." Looks like it's copying the array, and attempts to zero-pad. Not sure why zero pad values are set to 1.0, rather than 0.0 - looks like a bug.

In any case, I advise against using this function callout, as opposed to keeping the code within do_mindwarp(), since there may be a loss of efficiency in the function call. For improving efficiency, block operator functions memcpy() and memset() might be considered. Any thoughts?

static void copyArray(t_floatsrc, t_floatdst, size_t size, size_t zerosize) { size_t i; for(i=0; i<size; i++) dst++=src++; for(i=0; i<zerosize; i++) *dst++=1.; }

Lucarda commented 3 years ago

I think this question is directed to @umlaeute . (@ericlyon we have mention someone so the he/she gets email notification. Otherwise only people that read this are the "Watchers")

umlaeute commented 3 years ago

thanks @Lucarda :-) @erikd you probably should read a bit on markdown in order to format the code in a way that makes it fun to read :-)

about the problem at hand:

however, i agree that the current fix for the crash-problem is suboptimal. to recap:

the solution is bad insofar, as it doesn't address the actual problem, it just sweeps it under the carpet.

the real solution would be to just not access the arrays at invalid positions. there is absolutely no need to write any data into the extended portions of both the channelOne and the newChannel arrays.

we are repeatedly doing N operations on data that is never used (and should be always zero anyhow).

so my advise is to get rid of these extra operations:

thanks for bringing the issue up: i wanted to write that 2nd part anyhow, but forgot about it...

erikd commented 3 years ago

@umlaeute You probably should ping @ericlyon rather than me.

ericlyon commented 3 years ago

Thanks @umlaeute for the clarification. My concern was less about optimization (I wasn't actually planning to do anything about it), but more about complexifying the code unnecessarily for anyone who's trying to understand how it works by adding a function call, rather than doing relatively simple work inside the do_mindwarp() function. That may be a matter of programming style preference - I like to jump around as little as possible when trying to understand an algorithm. I'll fix the bug with an inline solution, unless there are any concerns about that approach.

Regarding the other point about the unnecessary calculations - I'll have to think about that. As I understand it, the algorithm stretches or shrinks the spectrum dynamically, and when it stretches, then some of the spectrum goes above the Nyquist, but without causing aliasing; in this case the above-Nyquist spectrum is just ignored. At least I think that's what's going on, such that it might actually be simplest to allow the algorithm to stand as is.

Thanks for the other advice about formatting code in github comments. That will probably come in handy for the future!

ericlyon commented 3 years ago

The code has now been updated. Thank you @umlaeute for discovering the bug and providing the initial fixes.

umlaeute commented 3 years ago

@erikd oops indeed. so many eriqs around :facepalm: sorry for the noise