Playing a sound and then stopping it

4 vues (au cours des 30 derniers jours)
Jack Walker
Jack Walker le 26 Avr 2016
Modifié(e) : Jack Walker le 28 Avr 2016
Hello everybody ! I am new to Matlab, but i tried some things out and it is really nice. But now to my question. I am generating a sine by playing it through the function sound. While i am generating a sine, the ampltidue is increasing. This means, we perceive the sound louder over time. The duration is about 20 seconds. Now i want to play the sound and then , for example, stop it at 5 seconds. Is it possible ? I (Btw english is not my mother language, sry about that...)
fs=44100; %Sample Frequency
samples=1/fs;
d=20; %Duration
t=0:samples:(d-samples); % time
amp=linspace(0.0001,2,882000); %Increasing the amplitude
input('Please press enter to go on ')
a = true;
while a
disp('')
Enter = input('Chose 1 and press enter to play sound: ');
switch Enter
case 1 %Generating sound with a frequency of 125 Hz
f = 125;
s1 = sin(2*pi*f*t);
y= amp.*s1;
sound(y,fs);
end
end

Réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by