0
$\begingroup$

For example, I would like to do like in this video: https://www.youtube.com/watch?v=YBhneZuAb5k

We have for example a goat yelling sample and from this sample, we can change the pitch according to the pressed piano key. I would like to make a script that will, from one input sample, generate all samples for each pitch/note (do re mi...). What is the algorithm for doing that?

$\endgroup$
  • $\begingroup$ What speaks against using your ears to identify the pitch (and if there's even something like pitch)? $\endgroup$ – Jazzmaniac Jan 20 '16 at 10:17
  • $\begingroup$ sorry, I misread your question. The pitch change is done by resampling the signal. However you need to identify the pitch first as resampling changes the pitch relative to the root. $\endgroup$ – Jazzmaniac Jan 20 '16 at 10:21
  • $\begingroup$ and ZouBi might need to do 1. looping, in case the note play is held longer than the original sample (scaled in time by the pitch transposition). and/or 2. an envelope going to zero to truncate the note if the key is held shorter. he/she doesn't have to do either, in which case each note is a "one-shot" sample and make them overlap. sorta like hitting vibes or tubular bells or a piano without the damping pedal. $\endgroup$ – robert bristow-johnson Jan 20 '16 at 19:56
1
$\begingroup$

One generic term for the class of libraries and algorithms that do this, make a set of music keyboard notes from random (psuedo-periodic) pitched sounds, is "time pitch modification". This is sometimes accomplished by frequency domain phase vocoder analysis-resynthesis or by time domain synchronized overlap-add, followed by filtered resampling. One example library might be Apple's OS X AVAudioUnitTimePitch effect unit. Here's a wikipedia page on the topic: https://en.wikipedia.org/wiki/Audio_time-scale/pitch_modification

First, you might have to use a pitch estimation algorithm to determine a perceived pitch for the original sound sample. Here's a wikipedia page summarizing some of these methods: https://en.wikipedia.org/wiki/Pitch_detection_algorithm

$\endgroup$
  • $\begingroup$ Thank you for your answer. I will have a lot to learn. I am very good at programming but much less in signal processing so everything seems new for me. I will do my best and thank you! I also find this SDK that does the job I need I guess. Take a look: littleendian.com/developers/spectrumworx-melodify-sdk $\endgroup$ – ZouBi Jan 21 '16 at 10:17
0
$\begingroup$

I would like to make a script that will, from one input sample, generate all samples for each pitch/note (do re mi...). What is the algorithm for doing that?

There's different algorithms that can do what you want.

So, let's say, you got a got that emits a known pitch, C.

C has a certain frequency on the usual tone scales, 261.626Hz. You want to pitch it up one octave? sure, just double that frequency. You can do that rather easily by multiplying your goat sample with a 261....Hz tone. Now, downside of that is that, for example, a low-frequency hum at 50Hz present in the original sample will suddenly be present as a 311Hz tone -- and clearly disturbing your audio perception. Also, for pitches, not only the fundamental tone, but also the harmonics, i.e. the multiples of the fundamental, are important. Now, the harmonics of 261.6Hz are $2\cdot,3\cdot,4\cdot,\dots\cdot 261.6Hz$, whereas the harmonics of 623.2Hz (=c) are $2\cdot,3\cdot,4\cdot,\dots\cdot 523.2Hz$. However, by shifting both the fundamental and its harmonics up by 261.6Hz, you end up with $1.5\cdot,2\cdot,2.5\cdot,3\cdot,3.5\cdot,\dots\cdot 523.2Hz$, which will sound strange. So that's not really a solution.

Another solution that "doubles" all the frequencies is just what happens when you play an LP record at twice the speed it should be played; digitally, you can achieve that by decimation of the original signal. Now, if you play that goat record at twice the speed, it will only be half as long. So that's not the whole solution either. Notice how when you listen to heavily autotuned songs like Dayum you seem to be able to hear some kind of "vibrato" in the longer-stretched high pitched tones?

My guess is that autotune algorithms try to first convert the tone to the desired frequency (possibly through frequency, or cepstrum transformations), and then match the original tone duration, which leads to periodicity of $\frac{\text{original length}}{\text{in/out frequency ration}}$.

So, this is a complex topic, and there's not a single solution to the problem -- after all, music is art, and to me all the autotune pop/house sounds terrible exactly because of this "mechanical" vibrato. Other folks really like that; it's a question of taste and preference. I'd say: get a well-trained goat. Make it emit a few different sounds. Analyze the sounds. Understand how a goat sound works: What's its start/cadence? How does the signal look like if the goat gives you a long C, compared with a short C? Can you manually make the C longer by copy&pasting without sounding awkward? Then, you might have a chance of making an aesthetically pleasing goatophone.

$\endgroup$
  • $\begingroup$ Hello and thank you for your answer. I don't need something sophisticated. All your questions at the end is not something I will care of at the beginning. Programming is not a problem and I think I found a good SDK that does everything I need. Check here: littleendian.com/developers/spectrumworx-melodify-sdk $\endgroup$ – ZouBi Jan 21 '16 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.