Skip to content
Snippets Groups Projects
Commit a3db6ff2 authored by CARNEIRO--GILLET Alexandre's avatar CARNEIRO--GILLET Alexandre
Browse files

modifs mineures et ajout karplus_strong

parent 29759c5b
No related branches found
No related tags found
No related merge requests found
function y = effet_delay_filtre(x, delay_time, g, K, Fs)
% effet_delay : applique un effet de délai amorti sur un signal
% Entrées :
% x : signal d'entrée (vecteur ligne ou colonne)
% delay_time : délai en secondes
% g : coefficient d'amortissement
% Fs : fréquence d'échantillonnage en Hz
%
% Sortie :
% y : signal filtré
% Calcul du délai en nombre d'échantillons
tau = round(delay_time * Fs);
% Construction des coefficients du filtre
% Equation : y[n] + g * y[n - tau] = x[n]
a = [1 zeros(1, tau - 1 + K) -(g/K)*ones(1, K)];
b = [1 zeros(1, tau)];
% Application du filtre
y = filter(b, a, x);
end
......@@ -14,8 +14,8 @@ function y = effet_delay_filtre(x, delay_time, g, K, Fs)
% Construction des coefficients du filtre
% Equation : y[n] + g * y[n - tau] = x[n]
a = [1 zeros(1, tau - 1 - K) -(g/K)*ones(1, K)];
b = [1 zeros(1, tau)];
a = [1 zeros(1, tau + 1 - K) -(g/K)*ones(1, K)];
b = [1 zeros(1, tau - 1 + K)];
% Application du filtre
y = filter(b, a, x);
......
function y = karplus_strong(x, N, g, alpha)
% Construction des coefficients du filtre
b = [zeros(1, N) 1 0];
a = [1 zeros(1, N-1) g*alpha g*(1-alpha)];
% Application du filtre
y = filter(b, a, x);
% === Enveloppe ADSR avec pourcentages ===
attackPct = 0.1;
decayPct = 0.1;
sustainPct = 0.6;
releasePct = 0.2;
sustainLevel = 0.5;
% Longueur totale du signal
totalLen = length(y);
% Calcul des longueurs en échantillons
aLen = round(attackPct * totalLen);
dLen = round(decayPct * totalLen);
sLen = round(sustainPct * totalLen);
rLen = totalLen - aLen - dLen - sLen; % ajustement final
% Génération de l'enveloppe
attackEnv = linspace(0, 1, aLen);
decayEnv = linspace(1, sustainLevel, dLen);
sustainEnv = sustainLevel * ones(1, sLen);
releaseEnv = linspace(sustainLevel, 0, rLen);
adsr = [attackEnv, decayEnv, sustainEnv, releaseEnv];
% Ajustement si la longueur ne colle pas parfaitement
adsr = adsr(1:min(length(adsr), totalLen));
if length(adsr) < totalLen
adsr = [adsr, zeros(1, totalLen - length(adsr))];
end
% Application de l'enveloppe
y = y .* adsr;
end
audio_path = "Files - SAR Audio - signal\student_pack\src\wav\single_tone_";
audio_path = "..\wav\single_tone_";
instrument = "piano1"
instrument = "piano1";
[x,fe]=audioread(audio_path + instrument +".wav");
soundsc(x,fe);
fft_ = 1*(abs(fftshift(fft(x))));
......
......@@ -5,7 +5,7 @@ x=square(2*pi*(1/T)*t);
a = [1 0];
b = [1/2 1/2];
d = designfilt('lowpassiir','FilterOrder',1,'HalfPowerFrequency',0.25);
d = designfilt('lowpassfir','FilterOrder',2,'HalfPowerFrequency',0.25);
y=filter(d.Denominator,d.Numerator,x);
......
audio_path = "Files - SAR Audio - signal\student_pack\src\wav\";
audio_path = "..\wav\";
instrument = "piano_chord";
......
Fe = 44100; % Hz
f1 = 440; % Hz
N = round(Fe/f1);
g = 0.998;
alpha = 0.5;
T_note = 10.5; % sec, temps d'excitation de la corde
T_sil = 2; % sec, temps de silence après
x_randn = [randn(1, round(T_note*Fe)) zeros(1,T_t*Fe)];
y_randn = karplus_strong(x_randn, N, g, alpha);
soundsc(y_randn, Fe);
[x_guitar, Fe_guitar] = audioread("..\wav\single_tone_guitar_nylon_string_a2.wav");
y_guitar = karplus_strong(x_guitar, N, g, alpha);
% soundsc(y_guitar, Fe_guitar);
Fe = 44100; % Hz
f1 = 440; % Hz
N = round(Fe/f1);
g = 0.998;
alpha = 0.5;
T_note = 0.005; % sec, temps d'excitation de la corde
T_sil = 2; % sec, temps de silence après
x_randn = [randn(1, round(T_note*Fe)) zeros(1,T_sil*Fe)];
y_randn = karplus_strong(x_randn, N, g, alpha);
soundsc(y_randn, Fe);
[x_guitar, Fe_guitar] = audioread("..\wav\single_tone_guitar_nylon_string_a2.wav");
y_guitar = karplus_strong(x_guitar, N, g, alpha);
% soundsc(y_guitar, Fe_guitar);
% Affichage
figure;
plot(y);
title('Signal Karplus-Strong avec enveloppe ADSR');
xlabel('Échantillons');
ylabel('Amplitude');
\ No newline at end of file
Fe = 44100; % Fréquence d’échantillonnage
f0 = 440; % Note à jouer (La4)
N = round(Fe / f0); % Délai du filtre
g = 0.998; % Facteur d’amortissement
alpha = 0.5; % Filtrage du signal
% Signal d'excitation : bruit binaire de taille N
x = 2 * (rand(1, N) > 0.5) - 1;
% Durée du son généré (en secondes)
duration = 2; % secondes
samples = round(duration * Fe);
x = [x, zeros(1, samples - length(x))]; % padding à la bonne durée
% Appel de la fonction
y = karplus_strong(x, N, g, alpha);
% Écoute
soundsc(y, Fe);
% Affichage
figure;
plot(y);
title('Signal Karplus-Strong avec enveloppe ADSR');
xlabel('Échantillons');
ylabel('Amplitude');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment