Thread Subject: running and stopping wave files

Subject: running and stopping wave files

From: Ashwini Deshpande

Date: 4 Dec, 2008 07:33:06

Message: 1 of 5

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

Subject: running and stopping wave files

From: Denis

Date: 4 Dec, 2008 10:07:01

Message: 2 of 5

"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)

Subject: running and stopping wave files

From: Dave Brackett

Date: 4 Dec, 2008 10:20:17

Message: 3 of 5

"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

won't just 'clear playsnd' do the job of stopping the wav file playing?

Subject: running and stopping wave files

From: Denis

Date: 4 Dec, 2008 10:26:01

Message: 4 of 5

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <gh8at1$77t$1@fred.mathworks.com>...
> "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
>
> won't just 'clear playsnd' do the job of stopping the wav file playing?

hm. never used this. maybe this (yours) is easier to implement =)

Denis

Subject: running and stopping wave files

From: Ashwini Deshpande

Date: 4 Dec, 2008 10:45:04

Message: 5 of 5

"Denis " <dzone@gmx.de> wrote in message <gh8b7p$aj4$1@fred.mathworks.com>...
> "Dave Brackett" <davebrackett@hotmail.com> wrote in message <gh8at1$77t$1@fred.mathworks.com>...
> > "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
> >
> > won't just 'clear playsnd' do the job of stopping the wav file playing?
>
> hm. never used this. maybe this (yours) is easier to implement =)
>
> Denis

Thanks a lotttt !!!

Dave's answer is short and sweet ...

Denis's answer is also very much helpful to me .......

Again thanks u both .......

Ashwini. :-))

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
soundcard Denis 4 Dec, 2008 05:10:21
gui Denis 4 Dec, 2008 05:10:21
analogobject Denis 4 Dec, 2008 05:10:21
wav Denis 4 Dec, 2008 05:10:21
winsound Denis 4 Dec, 2008 05:10:21
trigger Denis 4 Dec, 2008 05:10:21
sound Ashwini Deshpande 4 Dec, 2008 02:35:10
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com