Fadein fadeout in a wav file

5 visualizzazioni (ultimi 30 giorni)
AngelsaAtWar
AngelsaAtWar il 24 Mar 2013
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);

Risposta accettata

Image Analyst
Image Analyst il 24 Mar 2013
Modificato: Image Analyst il 25 Mar 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 Commenti
Image Analyst
Image Analyst il 25 Mar 2013
Modificato: Image Analyst il 26 Mar 2013
I added a comment to make it more obvious where the main part of the program is.
AngelsaAtWar
AngelsaAtWar il 25 Mar 2013
I want to apologize again for not seeing it the first time, now I do understand it better... thank you very much :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by