|
"Ashwini Deshpande" <vd.ashwini@mathworks.com> wrote in message <gh813i$22c$1@fred.mathworks.com>...
> Hi,
>
> I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so.
>
> But the problem is when a sound file is running and at the same time if i get an input from user, the sound which is running currently has to be stopped and new file has to be run as per the input.
>
> How do i do this ?
> Any help in this regards would be appreciated .
>
> Thanks !
> Ashwini
Hello.
I think you are currently using 'waveplay'?
Did you investigate how to use 'analogoutput'? I would propose to use the analogobject and put data into your soundcard.
On the fly:
(we need 3 m files)
- main.m (gui) for handling userinputs <- this is your part
- init.m to initialize objects, routines etc. <- i will try to give help
- analogoutput.m <- i will try to give help
INIT.M
--------
function handles = init(handles)
handles.Samprate = 44100;
handles.N = 2^12;
handles.step = 1; %used in update_plot
handles.Track = wavread('my_nice_sound_file'); % get the track
% we have to calculate the splits of the track
handles.L = length(handles.Track);
handles.N; %this is our framelength
handles.Nframes = floor(handles.L / handles.N);
% create output object %
handles.ao = analogoutput('winsound');
addchannel(handles.ao, 1);
% configure your soundcard %
set(handles.ao, 'SampleRate', handles.SampRate);
set(handles.ao, 'TriggerType', 'Manuel');
set(handles.ao, 'ManualTriggerHwOn', 'Trigger');
set(handles.ao, 'SamplesAcquiredFcnCount', handles.N); % how many samples should be packed into the object
set(handles.ao, 'SamplesAcquiredFcn', {@update_plot_out, handles});
% the last line is very important! here we set into our analogobject that if the amount
% of data is gone, call our function (update_plot_out)
% it is like I would say "fill that hole, and there (update_plot) you can find (rolling) stones
setappdata(gcf, 'apphandles', handles);
UPDATE_PLOT_OUT
-----------------------------
function handles = update_plot_out(hObject, eventdata, handles)
% small problem: if your pc is to slow and data is gone without refilling, the object will be automatically deleted. to avoid that we do following:
if strcmp( get(handles.ao, 'Running'), 'Off')
data = zeros(15000, 1);
putdata(handles.ao, data);
start(handles.ao);
trigger(handles.ao);
end
% defined in init
handles.step = handles.step + 1;
handles.ind_out = handles.k * handles.N;
handles.ind_in = handles.ind_out - handles.N + 1;
% reset or go on
if handles.ind_out > handles.L
handles.k = 1;
else
putdata(handles.ao, handles.Track(handles.ind_in:handles.ind_out);
end
guidata(handles.figure1, handles);
MAIN.M (GUI)
--------------------
%define a start, stop button
%inside gui in the beginning
handles = init(handles);
%startbutton
start(handles.ao);
trigger(handles.ao);
%stopbutton
stop(handles.ao)
%closebutton
%check if stopped
delete(handles.ao)
|