write function that generates an echo to audio.Why am i getting this error
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function output = echo_gen(input, fs, delay, amp);
% Load the 'gong' sound
% Define the range of samples you want to read from the original audio
% startSample = 3;
% endSample = 5 * Fs;
% Create a delay effect by shifting the audio signal
delaySamples = round(delay.* fs); % Adjust the delay time as needed
delayedSignal = [zeros(delaySamples, 1); input];
% % Determine the length of the combined audio
combinedLength = max(length(input), length(delayedSignal));
%
% % Pad the delayed signal if needed
% if length(delayedSignal) < combinedLength
% delayedSignal = [delayedSignal; zeros(combinedLength - length(delayedSignal), 1)];
% end
%
% Pad the original signal if needed
if length(input) < combinedLength
input = [input; zeros(combinedLength - length(input), 1)];
end
% Combine the audio signals
output1 = input + delayedSignal;
%for amplification
output=amp.*output1;
% Normalize the combined audio to prevent clipping
output = output / max(abs(output));
% Write the combined audio to a new file
audiowrite('combined_audio.wav', output, fs);
% Play the combined audio
sound(output, fs);
end

0 commentaires
Réponses (1)
Mathieu NOE
le 30 Août 2023
hello
you code can be simplified . Also an echoed signal means you add to the original a fraction (in amplitude) of the delayed version of it. The amount (amplitude) of the delayed signal is given by the factor "amp" , now correctly used in this code :
%%%%%%%%%%%%%
% Load the 'gong' sound
load gong.mat
input = y;
fs = Fs;
%%%%%%%%%%%%%
delay = 0.1;
amp = 0.1;
% Define the range of samples you want to read from the original audio
% startSample = 3;
% endSample = 5 * Fs;
% Create a delay effect by shifting the audio signal
delaySamples = round(delay.* fs); % Adjust the delay time as needed
delayedSignal = [zeros(delaySamples, 1); input];
% Pad the original signal
input = [input; zeros(delaySamples, 1)];
% Combine the audio signals
output = input + amp*delayedSignal; % correction here
% Normalize the combined audio to prevent clipping
output = output / max(abs(output));
% Write the combined audio to a new file
audiowrite('combined_audio.wav', output, fs);
% Play the combined audio
sound(output, fs);
0 commentaires
Voir également
Catégories
En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!