
How to fade sound gradually
29 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 16 Dec 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);

0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!