Create an audio replay in slider callback
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!