Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

I've got a rather large Perl/Tk script that I want to incorporate sound into. The Win32::Sound::WaveOut package does what I need and sounds great in short test programs, including those that use Tk. But when I incorporate it into the big script, the sound quality goes to hell. There seems to be some low-frequency modulation going on, resulting a buzz or warble, depending on the frequency I'm trying to produce. This happens even when the Tk event loop is blocked. I checked CPU usage with the Windows task manager, and in both cases (good and bad), the usage was 100% while sound was playing. Has anyone had a similar experience? Were you able to work around it?

BTW: Modules used by the big script and not by the test programs include Carp, POSIX, and Tie:IxHash.

Update: Solved it. I was also using

use encoding 'cp1252';
In my quest for brevity, I used chr($value) to pack the sound bytes into the sound buffer instead of pack("C", $value). 'Works fine with ASCII -- not so great with Unicode!

Replies are listed 'Best First'.
Re: Perl/Tk and Sound
by zentara (Cardinal) on Feb 18, 2005 at 21:27 UTC
    I don't use Win32, and you show no code, but you are probably trying to play your sound with a system call? That will cause havoc with the event loop. Try the SDL module, this demo works on windows -> Tk Game Sound demo

    I'm not really a human, but I play one on earth. flash japh
      Even though I've solved this in the short run, your pointer to SDL may be a godsend! I had looked in vain for a cross platform sound solution. SDL may just be the ticket. Thanks!