Playing a sound and then stopping it

4 Ansichten (letzte 30 Tage)
Jack Walker
Jack Walker am 26 Apr. 2016
Bearbeitet: Jack Walker am 28 Apr. 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

Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by