Fadein fadeout in a wav file
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2013-3-24
编辑:Image Analyst
2013-3-25
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 个评论
Image Analyst
2013-3-25
编辑:Image Analyst
2013-3-26
I added a comment to make it more obvious where the main part of the program is.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!