Fadein fadeout in a wav file

조회 수: 12 (최근 30일)
AngelsaAtWar
AngelsaAtWar 2013년 3월 24일
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);

채택된 답변

Image Analyst
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
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.
AngelsaAtWar
AngelsaAtWar 2013년 3월 25일
I want to apologize again for not seeing it the first time, now I do understand it better... thank you very much :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by