Implementing the Chorus Effect
35 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(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 个评论
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!