Implementing the Chorus Effect

조회 수: 50 (최근 30일)
Vincent Abraham
Vincent Abraham 2020년 11월 18일
댓글: Mathieu NOE 2020년 11월 23일
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
Mathieu NOE 2020년 11월 19일
and you don't have Simulink ?
Vincent Abraham
Vincent Abraham 2020년 11월 19일
I do. But i need to implement this in code

댓글을 달려면 로그인하십시오.

답변 (1개)

Mathieu NOE
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
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
Mathieu NOE 2020년 11월 23일
so what do we do next ??

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by