How to fade sound gradually

11 vues (au cours des 30 derniers jours)
Lady Black
Lady Black le 15 Déc 2020
hello all
please can ou help me out adding attenuation of sound from the middle to the end of the track to my system
>> [y,Fs] = audioread('1.mp3');
>> N=length(y);
>> T=N/Fs;
>> n1=T/2*Fs;
...
>> audiowrite('2.wav' ,y,Fs);
Thank you so much

Réponses (1)

Image Analyst
Image Analyst le 16 Déc 2020
Try this:
% Read in audio file.
folder = 'C:\Users\LadyBlack\Music\My Albums\Led Zeppelin\Early Days- The Best of Led Zeppelin, Vol. 1\';
baseFileName = '13 Stairway to Heaven.mp3';
fullFileName = fullfile(folder, baseFileName);
[y,Fs] = audioread(fullFileName);
% Plot original signal.
subplot(3, 1, 1);
plot(y, '-', 'LineWidth', 2);
title(baseFileName, 'FontSize', fontSize);
grid on;
% Create a fading envelope signal.
numSamples = length(y)
midIndex = round(numSamples/2);
T=numSamples/Fs % Seconds.
% Create a fading envelope
fadeSignal = [ones(1, midIndex), linspace(1, 0, numSamples - midIndex)]';
% If stereo, make another column
if size(y, 2) > 1
fadeSignal = [fadeSignal, fadeSignal];
end
% Plot fading signal.
subplot(3, 1, 2);
plot(fadeSignal, '-', 'LineWidth', 2);
title('Fading Envelope Signal', 'FontSize', fontSize);
grid on;
% Apply the fading by multiplying
yFaded = y .* fadeSignal;
% Plot fading signal.
subplot(3, 1, 3);
plot(yFaded, '-', 'LineWidth', 2);
title('Faded Waveform', 'FontSize', fontSize);
grid on;
% audiowrite('2.wav' ,y,Fs);
fprintf('Done running %s.m.\n', mfilename);

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!

Translated by