creating the chorus effect without using a loop

okay so I made some progress but I am still lost and im not sure what sound I am suppose to hear back. There are not any helpful youtube videos about this topic.. but now I am hearing a static noise for about 3 seconds. Please if anyone can look at my updated code and help me out so I can see what I am doing wrong. Do it for a veteran :)
[x,Fs]=audioread('slowguitar.wav');
sound(x, Fs);
n=44100;
D=round(Fs*40e-3);
x=rand(1,n);
y=zeros(1,n);
y(1)=x(1);
y(2:n) =x(2:n)+x(n-D);
sound(y(2:n), Fs);

2 comentarios

Paul
Paul el 15 de Nov. de 2022
Hi Damien,
I don't know what the chorus effect is, so don't know how it should be implemented. If it can be explained, preferably in mathematical terms, it's likely someone could help implement it in Matlab.
In the above code, the variable x is an output from audioread, but four lines later it's overwritten with random numbers. Is that correct?
Damien
Damien el 15 de Nov. de 2022
Thank you, I fixed this but still no luck in obtaining the desired result.

Iniciar sesión para comentar.

 Respuesta aceptada

Mathieu NOE
Mathieu NOE el 15 de Nov. de 2022
hello
the chorus effect is basically a multiple echo effect ; the echo by itself is a delayed version of the original signal , added to it with a given amplitude (therefore you can tweak the delay and amount of the echo)
when you have understood the echo principle , apply it multiple times and here you have a chorus effect (like many people singing at different distance from the listening point, causing different delays and amplitudes)
the code below is for a wav file (attached if you want to try it) but you can easily modify it at your convenience
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);
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.7 0.7 0.7]; % suggested coefficient from page 71 DAFX; the values apply to the 4 delayed versions of x
cur_delay = [134;248;422;13]; % fixed delay case
max_samp_delay=max(cur_delay);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y = x; % init y
for i = (max_samp_delay+1):samples
% add the amp weigthed multiple delayed x values
y(i) = x(i) + sum(amp(1:nb_effects)'.*x(i-cur_delay)); % add all 4 delayed sample (in one line !)
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');
legend('Original','Chorus');
sound(y,Fs);

10 comentarios

Damien
Damien el 15 de Nov. de 2022
How would this work without the "for " loop? Im sorry if i didnt state that in the question but I am trying to acomplish this effect without using a loop
Ok why not...
the price to pay is that you have to manually create as many variables as there are delayed versions of the signal
here y1 , y2 , y3 and y 4 are the four delayed versions of the input signal. Each one has individual delay and amplitude.
code with zero for loop :
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);
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.7 0.7 0.7]; % suggested coefficient from page 71 DAFX; the values apply to the 4 delayed versions of x
cur_delay = [134;248;422;13]; % fixed delay case
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% y1, y2 , y3, y4 are the four delayed version of x (and scaled with
% "amp" amplitude);
y1 = zeros(size(x)); % init
y1(cur_delay(1)+1:samples) = amp(1)*x(1:samples-cur_delay(1));
y2 = zeros(size(x)); % init
y2(cur_delay(2)+1:samples) = amp(2)*x(1:samples-cur_delay(2));
y3 = zeros(size(x)); % init
y3(cur_delay(3)+1:samples) = amp(3)*x(1:samples-cur_delay(3));
y4 = zeros(size(x)); % init
y4(cur_delay(4)+1:samples) = amp(4)*x(1:samples-cur_delay(4));
y = x + y1 + y2 + y3 + y4; % sum all signals
% normalize y to +/- 1 amplitude for wav export
y = y ./ (max(abs(y)));
audiowrite(outfile, y, Fs);
figure(1)
hold on
plot(x,'r');
plot(y,'b');
title('Chorus and Original Signal');
legend('Original','Chorus');
sound(y,Fs);
Paul
Paul el 16 de Nov. de 2022
Editada: Paul el 16 de Nov. de 2022
Why not just use a filter of the form:
H(z) = 1 + amp1*z^(-(curdelay1-1)) + amp2*z^(-(curdelay2-1) ....
Mathieu NOE
Mathieu NOE el 16 de Nov. de 2022
yes if you have the signal processing toolbox , you can use filter with your defined FIR delay filter
Damien
Damien el 16 de Nov. de 2022
Thank you both gentlemen, I have finally understood this and I got the results. Again Huge thank you to you Mathieu.
BLas
BLas el 16 de Nov. de 2022
Damien can you explain how you firgured it out I have the same problem.
i had to manually create multiple y variables since I did not use a loop my data is different from the examples given but in my case, I did not have coefficients or "amps" to begin with. Here is my updated code for you to examine.
%% sound x
[x,Fs]=audioread('slowguitar.wav');
x = x ./ (max(abs(x)));
sound(x,Fs);
%% vectorize
n = length(x);
D=round(Fs*40e-3); % our delay
a = rand(1,n);
y1 = zeros(size(x)); % initialize y1
y1(D+1:n) = a(1)*x(1:n-D);
y2 = zeros(size(x)); % initialize y2
y2(D+1:n) = a(2)*x(1:n-D);
y3 = zeros(size(x)); % initialize y3
y3(D+1:n) = a(3)*x(1:n-D);
y4 = zeros(size(x)); % initialize y4
y4(D+1:n) = a(4)*x(1:n-D);
y = x + y1 + y2 + y3 + y4; % sum all signals
y = y ./ (max(abs(y))); % initialize y
%% sound y
sound(y,Fs);
BLas
BLas el 16 de Nov. de 2022
Im pretty sure we in the same class and I dont know if thats the way she wanted it but here you go.
[x,Fs]=audioread('slowguitar.wav');
sound(x, Fs);
n=length(x);
D=round(Fs*40e-3);
y=zeros(1,n);
y(1:n) =x(1:n)+x(n-D);
sound(y(1:n), Fs);
This is how you do it
Source: Bryann Acorns 2301 second Street 78852 Apt12 Eagle Pass Tx
Damien
Damien el 17 de Nov. de 2022
Thanks Bryann!
Mathieu NOE
Mathieu NOE el 17 de Nov. de 2022
as always, my pleasure !

Iniciar sesión para comentar.

Más respuestas (1)

jibrahim
jibrahim el 15 de Nov. de 2022
Damien, Audio Toolbox has a Chorus object that might be helpful. See audiopluginexample.Chorus here.
It is used in this example.

1 comentario

Damien
Damien el 15 de Nov. de 2022
Thank you I understand the concept now and what I am suppose to hear, still working how to process the audio vector x and generate a new vector

Iniciar sesión para comentar.

Categorías

Más información sobre Audio I/O and Waveform Generation en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Preguntada:

el 14 de Nov. de 2022

Comentada:

el 17 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by