The sms.m program can be extended by adding transformations. In the sms.m file locate the line "Transformations". This is the place where the sinusoidal plus residual data can be transformed before a sound is synthesized.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%===== Transformations =====
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
The variable iloc holds an array of peak positions, whereas the variable ival holds the corresponding amplitude values. We can use these two arrays in order to fill syniloc and synival, the corresponding arrays that get synthesized.
We can implement a band-pass filter defined by (x, y) points where x is the frequency value in Hertz and y is the amplitude factor to apply. In the example code given below, we define a band pass filter which suppresses frequencies not included in the range [2100 3000].
Download functions interp1.m and lookup.m.
Implement a function
function [syniloc synival] = transform(iloc,ival,mode)If the mode parameter is 1, the function uses the following code in order to filter the sinosoidal part of the input sound:
%===== Filtering with arbitrary resolution =====
Filter=[ 0 2099 2100 3000 3001 22050 ;
0 0 1 1 0 0 ];
[syniloc,ind] = sort(iloc);
FilterEnvelope = interp1(Filter(1,:)',Filter(2,:)',syniloc/N*SR);
synival = ival(ind)+(20*log10(max(FilterEnvelope,10^-9)));
synival(ind)=synival;
syniloc(ind)=syniloc;
%=== voice to clarinet ===
syniloc = iloc;
synival = ival;
if (isHarm == 1)
pitchvalue
for i=1:nSines
harmNum = round(((iloc(i)-1)/w1Length*SR/2)/pitchvalue);
if (mod(harmNum,2)==0) % case of an even harmonic number
synival(i) = -100;
end
end
end
In a similar way, we can apply a frequency scaling to the sinusoidal components of our modeled sound. In that way, we can transpose all the partials in the spectrum or reproduce pseudo-inharmonicities like the higher partials frequency stretching characteristical in a piano sound. In this first example we introduce a frequency shift factor to all the partials of our sound. Note, though, that if a constant is added to every partial of a harmonic spectrum, the resulting sound will be inharmonic. Implement this as mode 3 of the transform function.
%==== Frequency Shift =====Mode 4 is frequency stretch, where the fundamental stays the same but the sound gets inharmonic.
fstretch = 100; % frequency shift in Hz
syniloc = iloc + round(fstretch/SR*N);
syniloc = syniloc.*(syniloc<=N/2);
synival = ival;
%===== Frequency Stretch =====
fstretch = 1.1;
[syniloc,ind] = sort(iloc);
syniloc = syniloc.*((fstretch).^[0:nSines-1]');
syniloc = syniloc.*(syniloc<=N/2);
synival = ival;
Finally mode 5 is frequency scaling, where the pitch of the sound is changed, while the duration stays the same.
%==== Frequency Scale =====
fscale = 1.2; % frequency scaling factor
syniloc = iloc * fscale;
syniloc = syniloc.*(syniloc<=N/2);
synival = ival;
Add the function transform to the sms.m file and make a plot of the magnitude values of a significant frame of DAFx_outresynth, the resynthesized sound, and the same frame of DAFx_in, the input sound sax.wav. (In one plot, you can use the "hold on" function).
Make one plot for each of the five modes.Pitch transposition is the scaling of all the
partials of a sound by the same multiplying factor. Here we introduce
the concept of timbre preservation by leaving the spectral shape
unmodified. For that reason we scale the frequency of each partial
applying the original spectral shape.
where PitchTransposition is the following function:
a.
Use the function with the sound file elvis.wav and apply different transposition factors (for example: 0.2, 0.5, 2, 3, …).
Make sure that the output sound equals the original sound when no
transposition is applied (change analysis parameters if necessary).
b.
Compare the effect of applying pitch transposition with and without timbre preservation. Describe what is the difference.
c.
Plot
a magnitude spectrum of the input file (at a meaningful place) and one
magnitude spectrum for a few pitch transpositions. Explain the results.
Vibrato
and tremolo are common effects used with different kinds of acoustical
instruments, including the human voice. Both are low frequency
modulations: vibrato is applied to the frequency and tremolo to the
amplitude of the partials. Note, though, that in this particular
implementation, both effects share the same modulation frequency.
%===== vibrato and tremolo =====
if (isHarm == 1)
vtf = 5; % vibrato-tremolo frequency in Hz
va = 10; % vibrato depth in percentil
td = 3; % tremolo depth in dB
synival = ival + td*sin(2*pi*vtf*pin/SR); % tremolo
pt = 1 + va/200*sin(2*pi*vtf*pin/SR); % pitch transposition factor
[spectralShape, shapePos] = CalculateSpectralShape(iloc, ival, MinMag, N);
[syniloc, synival] = PitchTransposition(iloc, ival, spectralShape, shapePos, pt, N);
%--- comb filtering the residual
CombCoef = 1;
resfft = combFilter(resfft, N, SR/(pitchvalue*pt), CombCoef);
end
a.
Use the function with the sound file Trumpet-01-mf-A3.wav
and apply different vibrato and tremolo values. Make sure that the
output sound equals the original sound when no vibrato is applied
(change analysis parameters if necessary).
b.
Increase
the vibrato frequency to values higher than 50 Hz and the depth to
values higher than 200. Describe and explain what happens.
c.
Increase
the tremolo frequency to values higher than 50 Hz and the depth to
values higher than 50 dB. Describe and explain what happens. What is
the difference with the effect of the question (b).