Being somewhat bored and such again, I figured out a way to use the PC Speaker to play sounds with C#. It's actually pretty simple, just use the winapi Beep() function. Of course that's not all! I made a small class which can be used to play songs (or annoying beeps) with the PC speaker and a console app which uses it. The notation is simple enough: , Frequency is a number between 37 and 32 767 (the highest frequencies might not play on all PC speakers) and time is the time the beep should play in milliseconds. So for example to play a few beeps for half a second you could write.. 2500,500 1200,500 400,500 You can also define a range of frequencies... 2500-3000,1 The above would play 2500,2501,2502... and so on up to 3000, each frequency for 1 ms. The cool thing is that, being a console application, you can use the piping operator < to direct a file to the input of the app! That way you could write your magnificent song into a file and just use beepage.exe < mysong.txt to play it. Neat huh? =)Download You can download the exe or source-code for the project Try installing this to someone elses computer and use the windows timed tasks feature to have it make some intresting noises a while later when he/she is back for a good laugh. If you use the beepage.exe -all parameter, it will play every frequency which causes a pretty freaky sound... ;)Labels: C# , sample , sound
1 Comments:
Really cool.like I said in:
http://my.opera.com/zomg/blog/2007/04/13/having-fun-with-the-pc-speaker
:-)
By Anonymous, at 9:41 PM
Post a Comment
<< Home