Fadein fadeout in a wav file
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi there, I have a problem I am stuck with...
1. The WAV file will have the first Hallelujah repeated twice (and no other sound),
The initial allelujah will gradually increase in volume, the second Hallelujah will gradually
decrease in volume.
so far I have this as my code, I cannot find out how to fade in or out the sound,** Thanks
load handel.mat;
hfile= 'handel.wav';
wavwrite(y, Fs, hfile);
nsamples= 2.5*Fs;
[t,Fs]= wavread(hfile, nsamples);
v= [ t'/5 t'];
sound(v);
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 24 Mär. 2013
Bearbeitet: Image Analyst
am 25 Mär. 2013
Try this:
clc;
close all;
fontSize = 22;
% Load sound file.
load handel.mat;
hfile= 'handel.wav';
% Plot original signal.
sound(y);
subplot(4,1,1);
plot(y);
grid on;
title('Original Wave File', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Write out wave to a file.
wavwrite(y, Fs, hfile);
promptMessage = sprintf('Wait until the sound finishes.\nDo you want to Continue processing,\nor Cancel processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Read it back in.
nsamples= 2.5*Fs;
[t,Fs]= wavread(hfile, nsamples);
% Construct attenuated portion next to original portion
v= [ t'/5 t'];
subplot(4,1,2);
plot(v);
title('Two Choruses', 'FontSize', fontSize);
grid on;
sound(v);
promptMessage = sprintf('Wait until the sound finishes.\nDo you want to Continue processing,\nor Cancel processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Construct ramps
amplitudeEnvelope = [linspace(0, 1, length(t)), linspace(1, 0, length(t))];
subplot(4,1,3);
plot(amplitudeEnvelope);
grid on;
title('Amplitude Ramp', 'FontSize', fontSize);
% ------ MAIN PART OF THE PROGRAM --------
% Multiply the amplitude envelope by the original waveform
% to produce the signal where the volume ramps up then down.
wave2 = [t' t'] .* amplitudeEnvelope;
%-------------------------------------------
subplot(4,1,4);
plot(wave2);
grid on;
sound(wave2);
title('Ramped Sound', 'FontSize', fontSize);
5 Kommentare
Image Analyst
am 25 Mär. 2013
Bearbeitet: Image Analyst
am 26 Mär. 2013
I added a comment to make it more obvious where the main part of the program is.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!