| |||||||||||
| |||||||||||
Send a sound... Posted by dje76 (dje76), 19 August 2004 Hello,I've a problem: ![]() i'ld like to send a song (like sinus wave frequency, or beep...) only when i have a key press (and so the sound stop when i release the key). I want do that for build a perl programm for learn the morse (and so for learn perl). i've tryed with Audio: ![]() ![]() Do you have an idea? Thanks a lot for your idees and your answer... ![]() Posted by admin (Graham Ellis), 19 August 2004 You have two very unusual requirements in your applicationa) You want to produce sound output b) You want to read keys as they are pressed rather than wait for an end of line. Both of these things are possible, but they're advanced, system dependent and not the sort of exercise I would choose to learn Perl with. I would suggest that you learn some Perl on other projects first, and add in your two requirements one by one when you're a bit more confident. Certainly, your first experiements with the sound module should NOT be tied to the reading os whether a key is up or down ... for the simple reason that if it doesn't work first time it's going to be near impossible to work out where the faults lie. Posted by dje76 (dje76), 21 August 2004 Hello,Thank's a lot for your answer... ![]() So, i've found the way to have a press/release key event with "bind" in the Perl/Tk extention. But i've not the solution about the sound... (i'm trying this way: when the key is pressing, an event is on, and call an external command (as calling a lower level language code... C perhaps) who can send a sound while a flag (with ref in a scalar...?...) is up.... when the event of key release is turning up, the same command will be calling with the flag's shutting down... and the sound off). And so i think it's impossible to learn a language without having problem... and my idea is to keep the final open code in the web to have a look of the evolution of the code... (and see how doing better with the other experiences). PS: it has to be long because i don't know how to program with C... ( ![]() .... I'll send you my way to do it when i found it. ![]() Posted by admin (Graham Ellis), 22 August 2004 I have to admire that you'ver managed to find the Tk module and its ability to read "key down" and "key up". Still wouldn't be my first project (and I would personally write a separate test program to work with sounds before I merge the two), but if you can pull it off ... good luck to you.For sound - have a look at http://search.cpan.org/~acalpini/Win32-Sound-0.45/Sound.pm, http://search.cpan.org/~djhd/Audio-OSS-0.0501/OSS.pm and similar ... it depends very much on your operating system and sound device. Search the Cpan for sound if you need - start at http://search.cpan.org Posted by dje76 (dje76), 31 August 2004 hello, ![]() i'm happy to send you my answer... it's possible to send morse code with real time playing sound with threads ans module Audio: ![]() ![]() my way (but peraps not the only way) is: (a part of the code): use threads; use Thread::Queue; use Audio: ![]() use Audio: ![]() use (all that you want... like TK...)... $audio = Audio::play->new(); $audio->tone('1000','0.001','50'); # it's important to have a good relation between frequency (1000) and time duration (0.001) and ... see the next mark $svr = Audio: ![]() $Q = Thread::Queue->new(); sub beep { while (1) { my $in = $Q->dequeue_nb; $var = $in if defined($in); if ($var eq "stop") { nop } if ($var eq "beep") { $svr->play($audio); nop x 50000; }# mark: that depend of your processor but it's a good way to have no bounce or no suplement duration threads->yield; } } my $thread1 = threads->new(\&beep); $main = Tk::MainWindow->new(); . . . $main->bind("<ButtonPress-1>", sub { $Q->enqueue("beep") }; $main->bind("<ButtonRelease-1>", sub { $Q->enqueue("stop") }; . . . MainLoop(); $thread1->detach; and thanks for your help ( a lot of inspiration... ) when i finished my progs, i want to send the open code for have a possibility to view how to do better (because i'm beginner since 3 month ago ) ![]() Posted by admin (Graham Ellis), 1 September 2004 My pleasure to help ... glad you've got it worked out, thank you for posting and welcome to the fantastic world of Perl!This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |