Apologies if this makes no sense or seems rather simple, I'm a Matlab newbie.

Basically, I've got a .wav audio waveform which I am resampling to various different frequencies and then trimming the length to a second (44100 samples). However, when resampling to certain tones, such as the note C3 or A5, I'm not left with enough samples to trim the note to an acceptable length.

Obviously this means that the sample needs extending, which I've worked out can be done taking a sample period s1 to s2 and adding that onto the end as many times as is necessary.

extendedSignal = x(1:s1-1);

for i = 1:4
    extendedSignal = vertcat(extendedSignal, x(s1:s2));

extendedSignal = vertcat(extendedSignal, x(s2:44100));

However, when it comes to finding a continuous period in which to sample, I cannot seem to find one for any note which does not sound like it is being repeated. Am I missing something really obvious?

  • $\begingroup$ It's not clear to me what you mean by "resampling to a note". You can resample an audio recording to different sampling frequencies, but the sampling frequency needs to be more than twice as large as the basic frequency of the note in order to capture it at all, and even higher if you want to preserve the harmonics (encoding the "sound" of the note). $\endgroup$ – A. Donda Dec 2 '14 at 20:42

Although it's not entirely clear to what you try to do (maybe there are better ways to accomplish your goal), I'll try to give some hints.

There exist "time stretching" techniques that can slow down a sample without changing its pitch, but they are not trivial to implement yourself. Some audio editors have plugins that support this.

As a poor man's implementation, if the sound has a single pitch, you can try something like the following (I've successfully used this in the past to extend a long, sung, single note):

First I cut the sound in three parts:

Sound -> | Begin | Middle | End |

Always cut at zero crossings.

Then, if you make "Middle" short enough, like around 0.1 seconds or so, you can repeat it a number of times times to stretch your sound a bit:

| Begin | Middle | Middle | Middle | Middle | Middle | Middle | End |

  • $\begingroup$ If you make the "middle" 0.2 second in length, but repeat them at a period of 0.1 second, crossfading each segment by applying a triangular envelope on each segment, it's easier to get smooth sounding results. As you decrease the period of repetition relative to the length of the segment, the result sounds increasingly smooth but gains a "phasy" quality that you might find objectionable. The best results come when the frequency of the repetition evenly divides the frequency of the sound's pitch. $\endgroup$ – MackTuesday Jan 4 '15 at 22:35

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.