Create an audio replay in slider callback
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!