1

I understand to find the length of the grain I need to perform an FFT over the source to find the fundamental harmonic, I can do that and find an accurate grain length, but now I need to find a start and end point of each grain and I'm not sure how to decide how to do it.

From what I can think of I have the following options

  • Always cut at the zero cross over point, ignoring the accurate grain length.
  • Cut the first grain at zero, from then on rely on the FFT information to cut accurate grain lengths and hope each start and end will be close to zero.
  • Find the centre of each grain using an average of amplitude, then use the accurate grain length (this would put duplicate data in grains next to each other, as each grain would not care where the last grain ended, this doesn't seem right)
  • The above but guarantee each grain starts where the other ended, and sacrifice both zero crossover AND grain length
  • Nothing, just use grain length and not care about zero crossings or being anywhere near them.
cool mr croc
  • 111
  • 2
  • 1
    uhm, this looks a lot like it's about Lent's algorithm (also credited to Hamon) for shifting pitch without shifting the spectral envelope.

    back in 1995, i had a paper about this. Lent's original paper is 1989 in Computer Music Journal.

    you want to window off two adjacent periods and use a complementary window (like Hann) to define the grain. you likely also want to position the center of the window around where, in the waveform, there is maximum energy.

    – robert bristow-johnson Aug 11 '19 at 21:35
  • 1
    and i wouldn't bother with an FFT. use a time-domain pitch detection technique and isolate your overlapping and adjacent grains from that information. – robert bristow-johnson Aug 11 '19 at 21:36
  • I see. I've inherited this project that uses FFT, but I think I can still do what you've suggested, look for the maximum energy in two grains and slice inbetween. I'm feeling confident now, thanks. – cool mr croc Aug 12 '19 at 19:22
  • i have a pretty good description of a time domain pitch detection alg here which will help you parse the boundaries or "epochs" of each cycle. remember that two adjacent cycles windowed with a Hann window makes a grain. And here you can get a copy of an old paper of mine describing the algorithm i call "grains" little "wavelets". – robert bristow-johnson Aug 12 '19 at 20:21
  • and you might be able to read Lent's paper here. – robert bristow-johnson Aug 12 '19 at 20:24
  • I started to read Lent's paper but it details pitch shifting. What I'm doing is taking an original recording that already increases in pitch, cutting grains, and playing them back depending on what pitch I need. – cool mr croc Aug 13 '19 at 12:04
  • //" ... cutting grains, and playing them back depending on what pitch I need."// - - - and how is that different than pitch shifting? – robert bristow-johnson Aug 13 '19 at 18:45
  • Pitch shifting as I understand it will take the source and resample so as to increase or decrease pitch. What I'm doing is picking grains based on what fundamental frequency the grain composes. I have a source with an ascending pitch, cut the grains, then select and playback the based on a controlling input. – cool mr croc Aug 15 '19 at 08:57
  • The pitch shifting that you refer to can be compared to the pitch shifting that you're doing except in your case, you do not stretch or scrunch the grains for downshifting or upshifting respectively. But in the resampled buffer case, it's like the grain length increases for down shifting or decreases for up shifting. then the spectral envelope (or "formants") is shifted up or down with pitch. but for vocals, to avoid "munchkinization" of the shifted voice, you want to parse into overlapping grains and launch the grains at a faster or slower rate for pitch shifting. – robert bristow-johnson Aug 15 '19 at 09:08

0 Answers0