<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412</link>
    <title>MATLAB Central Newsreader - running and stopping wave files</title>
    <description>Feed for thread: running and stopping wave files</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 04 Dec 2008 07:33:06 -0500</pubDate>
      <title>running and stopping wave files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412#614962</link>
      <author>Ashwini Deshpande</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so. &lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
How do i do this ?&lt;br&gt;
Any help in this regards would be appreciated .&lt;br&gt;
&lt;br&gt;
Thanks !&lt;br&gt;
Ashwini</description>
    </item>
    <item>
      <pubDate>Thu, 04 Dec 2008 10:07:01 -0500</pubDate>
      <title>Re: running and stopping wave files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412#614978</link>
      <author>Denis </author>
      <description>&quot;Ashwini Deshpande&quot; &amp;lt;vd.ashwini@mathworks.com&amp;gt; wrote in message &amp;lt;gh813i$22c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How do i do this ?&lt;br&gt;
&amp;gt; Any help in this regards would be appreciated .&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks !&lt;br&gt;
&amp;gt; Ashwini&lt;br&gt;
&lt;br&gt;
Hello.&lt;br&gt;
&lt;br&gt;
I think you are currently using 'waveplay'?&lt;br&gt;
&lt;br&gt;
Did you investigate how to use 'analogoutput'? I would propose to use the analogobject and put data into your soundcard.&lt;br&gt;
&lt;br&gt;
On the fly:&lt;br&gt;
&lt;br&gt;
(we need 3 m files)&lt;br&gt;
- main.m (gui) for handling userinputs &amp;lt;- this is your part&lt;br&gt;
- init.m to initialize objects, routines etc. &amp;lt;- i will try to give help&lt;br&gt;
- analogoutput.m &amp;lt;- i will try to give help&lt;br&gt;
&lt;br&gt;
INIT.M&lt;br&gt;
--------&lt;br&gt;
function handles = init(handles)&lt;br&gt;
&lt;br&gt;
handles.Samprate = 44100;&lt;br&gt;
handles.N = 2^12;&lt;br&gt;
handles.step = 1; %used in update_plot&lt;br&gt;
handles.Track = wavread('my_nice_sound_file'); % get the track&lt;br&gt;
&lt;br&gt;
% we have to calculate the splits of the track&lt;br&gt;
handles.L = length(handles.Track);&lt;br&gt;
handles.N; %this is our framelength&lt;br&gt;
handles.Nframes = floor(handles.L / handles.N);&lt;br&gt;
&lt;br&gt;
% create output object %&lt;br&gt;
handles.ao = analogoutput('winsound');&lt;br&gt;
addchannel(handles.ao, 1);&lt;br&gt;
&lt;br&gt;
% configure your soundcard %&lt;br&gt;
set(handles.ao, 'SampleRate', handles.SampRate);&lt;br&gt;
set(handles.ao, 'TriggerType', 'Manuel');&lt;br&gt;
set(handles.ao, 'ManualTriggerHwOn', 'Trigger');&lt;br&gt;
set(handles.ao, 'SamplesAcquiredFcnCount', handles.N); % how many samples should be packed into the object&lt;br&gt;
set(handles.ao, 'SamplesAcquiredFcn', {@update_plot_out, handles});&lt;br&gt;
% the last line is very important! here we set into our analogobject that if the amount &lt;br&gt;
% of data is gone, call our function (update_plot_out)&lt;br&gt;
% it is like I would say &quot;fill that hole, and there (update_plot) you can find (rolling) stones&lt;br&gt;
&lt;br&gt;
setappdata(gcf, 'apphandles', handles);&lt;br&gt;
&lt;br&gt;
UPDATE_PLOT_OUT&lt;br&gt;
-----------------------------&lt;br&gt;
function handles = update_plot_out(hObject, eventdata, handles)&lt;br&gt;
&lt;br&gt;
% 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:&lt;br&gt;
if strcmp( get(handles.ao, 'Running'), 'Off')&lt;br&gt;
data = zeros(15000, 1);&lt;br&gt;
putdata(handles.ao, data);&lt;br&gt;
start(handles.ao);&lt;br&gt;
trigger(handles.ao);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% defined in init&lt;br&gt;
handles.step = handles.step + 1;&lt;br&gt;
handles.ind_out = handles.k * handles.N;&lt;br&gt;
handles.ind_in = handles.ind_out - handles.N + 1;&lt;br&gt;
&lt;br&gt;
% reset or go on&lt;br&gt;
if handles.ind_out &amp;gt; handles.L&lt;br&gt;
handles.k = 1;&lt;br&gt;
else&lt;br&gt;
putdata(handles.ao, handles.Track(handles.ind_in:handles.ind_out);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
guidata(handles.figure1, handles);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
MAIN.M (GUI)&lt;br&gt;
--------------------&lt;br&gt;
%define a start, stop button&lt;br&gt;
&lt;br&gt;
%inside gui in the beginning&lt;br&gt;
handles = init(handles);&lt;br&gt;
&lt;br&gt;
%startbutton&lt;br&gt;
start(handles.ao);&lt;br&gt;
trigger(handles.ao);&lt;br&gt;
&lt;br&gt;
%stopbutton&lt;br&gt;
stop(handles.ao)&lt;br&gt;
&lt;br&gt;
%closebutton&lt;br&gt;
%check if stopped&lt;br&gt;
delete(handles.ao)</description>
    </item>
    <item>
      <pubDate>Thu, 04 Dec 2008 10:20:17 -0500</pubDate>
      <title>Re: running and stopping wave files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412#614988</link>
      <author>Dave Brackett</author>
      <description>&quot;Ashwini Deshpande&quot; &amp;lt;vd.ashwini@mathworks.com&amp;gt; wrote in message &amp;lt;gh813i$22c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How do i do this ?&lt;br&gt;
&amp;gt; Any help in this regards would be appreciated .&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks !&lt;br&gt;
&amp;gt; Ashwini&lt;br&gt;
&lt;br&gt;
won't just 'clear playsnd' do the job of stopping the wav file playing?</description>
    </item>
    <item>
      <pubDate>Thu, 04 Dec 2008 10:26:01 -0500</pubDate>
      <title>Re: running and stopping wave files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412#614991</link>
      <author>Denis </author>
      <description>&quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;gh8at1$77t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Ashwini Deshpande&quot; &amp;lt;vd.ashwini@mathworks.com&amp;gt; wrote in message &amp;lt;gh813i$22c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; How do i do this ?&lt;br&gt;
&amp;gt; &amp;gt; Any help in this regards would be appreciated .&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks !&lt;br&gt;
&amp;gt; &amp;gt; Ashwini&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; won't just 'clear playsnd' do the job of stopping the wav file playing?&lt;br&gt;
&lt;br&gt;
hm. never used this. maybe this (yours) is easier to implement =)&lt;br&gt;
&lt;br&gt;
Denis</description>
    </item>
    <item>
      <pubDate>Thu, 04 Dec 2008 10:45:04 -0500</pubDate>
      <title>Re: running and stopping wave files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240412#614998</link>
      <author>Ashwini Deshpande</author>
      <description>&quot;Denis &quot; &amp;lt;dzone@gmx.de&amp;gt; wrote in message &amp;lt;gh8b7p$aj4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;gh8at1$77t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Ashwini Deshpande&quot; &amp;lt;vd.ashwini@mathworks.com&amp;gt; wrote in message &amp;lt;gh813i$22c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I am doing sound simulation. Here i need to run a wave file corresponding to user input. THere is no problem in doing so. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; How do i do this ?&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Any help in this regards would be appreciated .&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Thanks !&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Ashwini&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; won't just 'clear playsnd' do the job of stopping the wav file playing?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; hm. never used this. maybe this (yours) is easier to implement =)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Denis&lt;br&gt;
&lt;br&gt;
Thanks a lotttt !!!&lt;br&gt;
&lt;br&gt;
Dave's answer is short and sweet ...&lt;br&gt;
&lt;br&gt;
Denis's answer is also very much helpful to me .......&lt;br&gt;
&lt;br&gt;
Again thanks u both ....... &lt;br&gt;
&lt;br&gt;
Ashwini.  :-))</description>
    </item>
  </channel>
</rss>

