Fadein fadeout in a wav file
12 ビュー (過去 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!