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 CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by