Implementing the Chorus Effect
显示 更早的评论
I have implemented a code for flanging. Flanging uses a delay of 0-10ms (in this case 0-3ms) to produce the desired output. Now, I want to implement this same code for creating a chorus effect, which uses a delay of 25-30 or 30-50ms. Please suggest what I should do
clear all;
close all;
infile='acoustic.wav';
outfile='out_chorus.wav';
% current sample is 11kHz so 0-3 ms is 0 - 33 samples
% read the sample waveform
[x,Fs] = audioread(infile);
% parameters to vary the effect %
min_time_delay=0.010; % 10ms min delay in seconds
max_time_delay=0.025; % 25ms max delay in seconds
rate=1; %rate of flange in Hz
index=1:length(x);
% sin reference to create oscillating delay
sin_ref = (sin(2*pi*index*(rate/Fs)))'; % sin(2pi*fa/fs);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
min_samp_delay=round(min_time_delay*Fs); %convert delay in ms to min delay in samples
max_samp_delay=round(max_time_delay*Fs); %convert delay in ms to max delay in samples
y = zeros(length(x),1); % create empty out vector
y(1:max_samp_delay)=x(1:max_samp_delay); % to avoid referencing of negative samples
amp=0.7; % suggested coefficient from page 71 DAFX
% for each sample
for i = (max_samp_delay+1):length(x)
cur_sin=abs(sin_ref(i)); %abs of current sin val 0-1
cur_delay=ceil(cur_sin*max_samp_delay); % generate delay from 1-max_samp_delay and ensure whole number
y(i) = (amp*x(i)) + amp*(x(i-cur_delay)); % add delayed sample
end
% write output
audiowrite(outfile, y, Fs);
figure(1)
hold on
plot(x,'r');
plot(y,'b');
title('Flanger and original Signal');
6 个评论
Mathieu NOE
2020-11-19
hello
have you tried the examples given in matlab :
Mathieu NOE
2020-11-19
also available info's here :
http://users.cs.cf.ac.uk/Dave.Marshall/Multimedia/PDF/07_Audio_Effects.pdf
Vincent Abraham
2020-11-19
Vincent Abraham
2020-11-19
Mathieu NOE
2020-11-19
and you don't have Simulink ?
Vincent Abraham
2020-11-19
回答(1 个)
Mathieu NOE
2020-11-19
hello again
so this could be considered as a vectorized version of the original code. You can add multiple delayed versions of the original signal
just make sure the dimensions of rate and amp are consistent
hope it matches your musical expectations...
infile='DirectGuitar.wav';
outfile='out_chorus.wav';
% current sample is 11kHz so 0-3 ms is 0 - 33 samples
% read the sample waveform
[x,Fs] = audioread(infile);
% normalize x to +/- 1 amplitude
x = x ./ (max(abs(x)));
samples = length(x);
% parameters to vary the effect %
min_time_delay=0.010; % 10ms min delay in seconds
max_time_delay=0.025; % 25ms max delay in seconds
% nb_effects = 4; % assume we do 4 delayed versions of the signal that will be summed
rate=[1 0.9 0.8 0.7] ; %rate of flange in Hz (as many as chorus effects)
nb_effects = length(rate); % assume we do 4 delayed versions of the signal that will be summed in the final section
% amplitude is now a vector
amp=[0.7 0.6 0.5 0.4 0.3];; % suggested coefficient from page 71 DAFX;
% Nb the first value applies to x and the remaining values apply to the 4
% delayed versions of x) so make sure this vector has length = nb_effects +1
index=(1:samples)';
% sin reference to create oscillating delay
sin_ref = (sin(2*pi*index*(rate/Fs)))'; % sin(2pi*fa/fs); % make sure this is a matrix dimensins = (nb_effects , samples)
% sin_ref = 0.5*(1+sin(2*pi*index*(rate/Fs)))'; % sin(2pi*fa/fs); % make sure this is a matrix dimensins = (nb_effects , samples)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
min_samp_delay=round(min_time_delay*Fs); %convert delay in ms to min delay in samples
max_samp_delay=round(max_time_delay*Fs); %convert delay in ms to max delay in samples
y = zeros(samples,1); % create empty out vector
y(1:max_samp_delay)=x(1:max_samp_delay); % to avoid referencing of negative samples
% amp=0.7; % suggested coefficient from page 71 DAFX
% for each sample
for i = (max_samp_delay+1):length(x)
cur_sin=abs(sin_ref(:,i)); %abs of current sin val 0-1
cur_delay=ceil(cur_sin*max_samp_delay); % generate delay from 1-max_samp_delay and ensure whole number
% add the amp weigthed multiple delayed x values
y(i) = amp(1)*x(i) + sum(amp(2:nb_effects+1)'.*x(i-cur_delay)); % add all 4 delayed sample (in one shot !)
end
% write output
% normalize y to +/- 1 amplitude
y = y ./ (max(abs(y)));
audiowrite(outfile, y, Fs);
figure(1)
hold on
plot(x,'r');
plot(y,'b');
title('Chorus and original Signal');
19 个评论
Vincent Abraham
2020-11-19
Mathieu NOE
2020-11-19
ok - I'll modify the code - see you soon
Mathieu NOE
2020-11-19
so this is it
I must admit the listening of the effect is strange
Now you have plenty of parameters to play with :
- nb of effects : 4 (now)
- amplitudes of delayed signals : amp = [0.7 0.3 0.3 0.3 0.3];
- initial randon signal amplitude (0.2) : rand_ref = 0.2*rand(nb_effects , samples);
- you can apply a low pass filter effct on this "brute" random values to get a LP filtered random. This is driven by : b = 0.2; % coefficient for 1st order IIR low pass filter
- you can see the effect of this LP filter on figure (2). at the beginning there is no filtering (no worry as it is not applyed yet on the signal), then when i = max_samp_delay+1 at the beginning of the for loop , we have the LP effect coming into play
infile='DirectGuitar.wav';
outfile='out_chorus.wav';
% current sample is 11kHz so 0-3 ms is 0 - 33 samples
% read the sample waveform
[x,Fs] = audioread(infile);
% normalize x to +/- 1 amplitude
x = x ./ (max(abs(x)));
samples = length(x);
% parameters to vary the effect %
min_time_delay=0.010; % 10ms min delay in seconds
max_time_delay=0.025; % 25ms max delay in seconds
nb_effects = 4; % assume we do 4 delayed versions of the signal that will be summed
% amplitude is now a vector
amp = [0.7 0.3 0.3 0.3 0.3]; % suggested coefficient from page 71 DAFX;
% Nb the first value applies to x and the remaining values apply to the 4
% delayed versions of x) so make sure this vector has length = nb_effects +1
index=(1:samples)';
% rand reference to create delay
rand_ref = 0.2*rand(nb_effects , samples); % rand returns a single uniformly distributed random number in the interval (0,1).
% make sure this is a matrix dimensins = (nb_effects , samples)
b = 0.2; % coefficient for 1st order IIR low pass filtering or rand modulation amplitude
% b = 1 => no LP filter, b = 0.01 very slow filtering
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rand_ref_filtered = rand_ref; % init
min_samp_delay=round(min_time_delay*Fs); %convert delay in ms to min delay in samples
max_samp_delay=round(max_time_delay*Fs); %convert delay in ms to max delay in samples
y = zeros(samples,1); % create empty out vector
y(1:max_samp_delay)=x(1:max_samp_delay); % to avoid referencing of negative samples
% amp=0.7; % suggested coefficient from page 71 DAFX
% for each sample
for i = (max_samp_delay+1):samples
rand_ref_filtered(:,i) = (1-b)*rand_ref_filtered(:,i-1) + b*rand_ref(:,i); % IIR low pass filtering of rand_ref
cur_delay=ceil(rand_ref_filtered(:,i)*max_samp_delay); % generate delay from 1-max_samp_delay and ensure whole number
% cur_delay=ceil(rand_ref(:,i)*max_samp_delay); % generate delay from 1-max_samp_delay and ensure whole number
% add the amp weigthed multiple delayed x values
y(i) = amp(1)*x(i) + sum(amp(2:nb_effects+1)'.*x(i-cur_delay)); % add all 4 delayed sample (in one shot !)
end
% write output
% normalize y to +/- 1 amplitude
y = y ./ (max(abs(y)));
audiowrite(outfile, y, Fs);
figure(1)
hold on
plot(x,'r');
plot(y,'b');
title('Chorus and original Signal');
figure(2),plot(1:1000,rand_ref_filtered(:,1:1000));grid
sound(y,Fs);
Vincent Abraham
2020-11-19
Mathieu NOE
2020-11-19
hmm
i wonder if the code implementation is truly what we were looking for.
I tried the chorus effect on a separate application, and it sounds very different, without the this unpleasant grainy sound that we get with the matlab implementation.
I followed what the pdf says and triple checked the code. So it is doing what we asked for, but I'm surprised by the result.
Vincent Abraham
2020-11-19
Vincent Abraham
2020-11-19
Mathieu NOE
2020-11-19
I simply used Goldwave freeware that has almost everything you need to play with wav files.
just for fun, I will try waht the Simulink version gives and maybe find the reason behind that not 100% satisfying result
that's for tomorrow when I'm done with my official work....
Vincent Abraham
2020-11-19
Mathieu NOE
2020-11-20
forgot that I don't have the audio toolbox
in the matlab doc about audio effects with simulink
the chorus effect is implemented with sinus LFO and not random as the pdf says; so our first implementation with sinus (and not random) modulation is better ?

Vincent Abraham
2020-11-20
Vincent Abraham
2020-11-20
Mathieu NOE
2020-11-20
why two ? you're talking about the picture ? there is only one common reference
Vincent Abraham
2020-11-20
Mathieu NOE
2020-11-20
funny
I tested again the basic sine flanger file
when the dealy is fixed the output sound is clean, not so grainy
when the delay are variable , the sound quality is poor; there must be somewhere a problem but I don't see it yet;
Vincent Abraham
2020-11-20
Vincent Abraham
2020-11-20
Mathieu NOE
2020-11-23
hello
yes , for the fixed dealy (4 effects) the sound is good
as soon as we make the delay variable, it's horrible... don't know what we are doing wrong here
Mathieu NOE
2020-11-23
so what do we do next ??
类别
在 帮助中心 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!