Create an audio replay in slider callback

1 回表示 (過去 30 日間)
Tomtom
Tomtom 2019 年 9 月 19 日
編集済み: Tomtom 2019 年 9 月 19 日
Hey,
I have a GUI where I want to instantly hear my changes that I do via a slider. In this example I have a amplitude-modulation of a simple sine sound that I change via the slider. But the audioplayer doesn't work inside a callback "loop". Do you have any good suggestions?
Also I can't pass any variables to the callback "plotstuff" function like the variable "t". Is there a better solution to this than globel variables?
global Fs = 1000; %Samplingrate
t_min = 0;
t_max = 3;
global t = linspace(t_min,t_max,t_max*Fs); %Timevector
sld1 = uicontrol ( ...
'style', 'slider', ...
'Units', 'normalized', ...
'position', [0.1, 0.9, 0.8, 0.1], ...
'SliderStep', [1/6 1/3], ...
'min', 0, ...
'max', 3, ...
'value', 3, ...
'callback', {@plotstuff} ...
);
function plotstuff (h, event)
amp = get (h, 'value');
global t;
global Fs;
f = 200; % Frequency of sound
y = amp * sin(2*pi*f*t); % Amplitudemodulation depending on slidervalue
%Plot
plot(t,y)
grid on
ylim([-3 3])
%Play
player = audioplayer(y,Fs);
play(player)
end
Thank you very much!

回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by