From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

interrupt sound output

Solved!
Go to solution

I am writing a one minute sound file to the sound card using the Labview 2011 Sound Output Write vi.  The sound starts to play and there doesn't appear to be any way to stop it until the entire file has played.  Not even the Abort Execution button will stop it.  I have looked at the KB article called Stopping a Sound File during Playback, but it was written a long time ago before Sound Output Write became available.

 

I have tried using an event structure with Sound Output Stop and Sound Output Clear but it doesn't work.  In fact the event never fires.  It is as if Sound File writes lock out everything until the complete. Example is attached.

 

David

 

0 Kudos
Message 1 of 6
(4,234 Views)

Hi David,

 

did you do some basic debugging with highlighting?

You would have recognized your DATAFLOW problem: your while loop containing the event structure can only start after PlaySound has finished!

 

But then: your sound output goes into a DLL call (CLFN) - I doubt you will be able to break that call once it started...

 

Maybe you should consider playing your wav file in small pieces when you need to stop playing in between!?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(4,225 Views)

Gerd,

 

Thanks for taking an interest in my problem.  But you miss the point entirely.

 

Here is what labview help says about Sound Output Stop:

 

"Stops the device from playing sound from the buffer. Use the Sound Output Clear VI to clear the data in the buffer."

 

Well.  It doesn't.  In fact it doesn't do anything.  It is totally useless.  I posted my query in the hope that I was missing something and that someone could show me what it was. 

 

I think you will agree that Sound Output Clear.vi doesn't work.  I think that is a bug, don't you? 

 

You state that Sound Output Write VI uses an uninterruptible system DLL call.  Bug number 2?

 

You suggest breaking up the sound output file into a series of very short writes so that I can stop where I want.  I agree that that will work.  But shouldn't Sound Output Write do that for me if Labview is to provide an interruptible sound output capability?

 

Now as far as violating Labview data flow niceties, yes, I was in a hurry and I was just trying to create something which would demonstrate the problem.  If you want, move the Sound Output Write into the loop and you will see the exact same result.

 

I have an old PC with Labview 7.1.  I'm going to fire it up and see if the old sound VI's have the same problem. 

 

Regards,

 

David

 

0 Kudos
Message 3 of 6
(4,201 Views)
Solution
Accepted by topic author David_Lieberman

No bugs here.

 

In order to get the Sound Output Stop.vi to act as you want, the sound device needs to be configured correctly. Try this:

 

1. On Sound Output Configure.vi, create a constant for the sample mode enum and set it to Finite Samples. It wouldn't hurt to wire a constant set to 0 to the device ID if you have more than one sound device on your computer.


2. On Play Sound.vi, wire a numerical constant to timeout(sec) and set the timeout(sec) constant to 0. Otherwise the VI waits for the sound operation to complete and Sound Output Stop.vi has no effect.

 

You can check LabVIEW Help for these two VIs to see the full explanation.

 

In your present configuration, hitting the stop button while the sound is still playing will generate a buffer overwrite error on Sound Output Write.vi since you are aborting the operation while data remains in the sound output buffer. You could ignore the error which usually is not a good idea. Otherwise, as suggested previously,  you could set the buffer size with the number of samples/ch control in Sound Output Configure.vi and with Play Sound.vi in loop send the data to the sound device in small chunks.

 

An easier way to do this is to look at the SoundPlayer.vi in the examples which does the same job using Play Sound File.vi.

 

JohnCS



 

0 Kudos
Message 4 of 6
(4,191 Views)

As I suspected, the program works fine using the Labview 7.1 sound VI's.

 

See the attached.

 

david

 

Download All
0 Kudos
Message 5 of 6
(4,184 Views)

John,

 

It works.  No need to send the data in small chunks.  I sent the entire one minute file to the Write to Sound Card VI.  The keys were the timeout setting on the Write which causes the VI to return immediately and thus free up the front panel controls (the stop button).

 

Thanks.

 

David

 

0 Kudos
Message 6 of 6
(4,169 Views)