Playsound and CPU overload (Problem & Solution)

Hello everybody, this is the PROBLEM and SOLUTION regarding the CPU overload due to the Playsound command execution. Many thanks to JIM "How does it work?" PROUTY for his help and solution!

PROBLEM

I am using Igor 4 in order to generate a sine wave by means of my sound card, executing the Playsound command. I have just tried to use the default example, increasing the number of points to 10000 and then to 100000:

Make/B/O/N=10000 sineSound // 8 bit samples
SetScale/P x,0,1e-4,sineSound // Set sample rate to 10Khz
sineSound= 100*sin(2*Pi*1000*x) // Create 1Khz sinewave tone
PlaySound sineSound


but my computer completely freezes, I mean it executes the command and generates the wave, I can hear the sound without problem, but it asks for 100% CPU power and this means that meanwhile I execute this command I am unable to execute other commands. I have tried to use this example also on other computers with different hardware configuration (all of them Windows XP equipped) and also using Igor 6, but the problem stays there. Moreover I want that if, for instance, Igor creates a wave with 1000 points, the Playsound command executes just the first 500 points.

SOLUTION by JIM "How does it work?" PROUTY

Using the Playsound/A command, Igor creates the wave and just after plays it, following the asynchronous command instruction and avoiding the CPU overload problem. Moreover using the flag option /A=2, it is possible to stop playing any sound. You can use this with a tiny silent sound wave to cause the current sound to stop, this is a very useful tip if you want use a Stop Button in order to play just a portion of the generated wave and not the whole wave.

Many thanks Jim

Alessandro Sepe