saving/loading FFT amplitude and phase data from/to buffer~

ffomezolam's icon

I'm working with the pfft phase vocoder tutorial patch, in which amplitude and phase data from the FFT input (after cartopol~/phasewrap~ etc.) are saved into a two-channel buffer in the FFT, and then index~ is used within the FFT to select and play back a frame from that buffer through the FFT output. What I'm trying to do is write that buffer to disk so it can be restored into the FFT. The goal here is to quickly load samples into the FFT for time-shifting purposes.

When doing this, however, I notice that the restored data when played back is (very) distorted, and on further analysis noticed that saving the buffer data to a file clips it between -1 and 1, thereby not preserving amplitude and phase values exceeding +/- 1 (tested by peek~ing into the restored buffer). Doing a capture~ on the FFT amplitude and phase data being recorded shows values exceeding +/- 1. I believe this clipping is what causes the output distortion. I've saved the buffer data as AIF and WAV to no avail, and my attempt at re-headering the RAW file just introduced the same clipping. I don't know whether the clipping is introduced on write or on restore.

Before I delve into entirely new (to me) ways of doing this, I'm wondering if there is any solution to the buffer data clipping issue. Or maybe there are ideas as to other reasons for the garbled restored output? Or other tests to run? Any help is appreciated. Thanks in advance.

Jean-Francois Charles's icon

Well, there is a limit to the amplitude and phase difference values. For phase, obviously, -pi to pi, for amplitude, not obvious, it depends on the window shape and lots of factors, but you can experiment and find out something correct.
Bottom line is: you could use a /~ 1000. before saving, then *~ 1000. to solve your potential clipping problem.
By the way, I personally prefer to work with jitter matrices, 2D, like a sonogram (with 2 planes, one for amplitude, one for phase differences).

AlexHarker's icon

The best solution is to make sure you save the file in 32 bit floating point format (I can't remember the exact message - check the ref file for buffer~) This way when you reopen the buffer from disk the contents is *exactly* the same.

If you use any other format you'll see this clipping at -1 and 1. - the data will also be rounded to the available values in the format, so you will lose accuracy.

HTH

A.

ffomezolam's icon

Oh the format message worked perfectly, thanks!

I considered scaling the input between -1 and 1 but was sure that a more efficient solution existed. If I was any good with Jitter, I might try that route. Some day, perhaps.