C/C++ tone sequence / screensaver in Linux

Hi, I'm looking for a way of playing a tone sequence in C/C++ on a Linux operating system. There's an easy way of going this for J2ME devices where a tone sequence is defined as in this<http://download.oracle.com/javame/config/cldc/opt-pkgs/api/mm/jsr135/javax/microedition/media/control/ToneControl.html#tone_sequence_format> case. However, in my case, I want this in C/C++. I've tried projects like beep but without much success. Second one, what's the best way to detect "idle time" in C/C++ using pwrap/pwrap2 as the GUI library, how can you start an event if a user not interacting with the particular program say for 5 minutes? Somewhat like what you would do to activate a screensaver prefferably without using hooks and working in Linux. Please give me any leads on this. Thanks. -- Regards, Mike Muraguri Skype: mickie.mic M: + 254 722 799445

Playing the tone might be a hardware issue more than programming. J2ME devices have the tone generator in hardware. 2nd: An interacting user would be using keyboard or mouse (or whatever else input device). Always store the time for an I/O event (im assuming you can capture I/O events in some callback function). Have a separate thread running that takes the difference btwn the I/O time with the current time (sleep this thread according to how frequently u want to check e.g. sleep for like 1 minute...), if no I/O has taken place in >= 5 mins then u can launch u're screen saver, wash a dog or do whatever else u wish. Hope tht helps. ________________________________ From: Mike Muraguri <mickie.mic@gmail.com> To: Skunkworks Mailing List <skunkworks@lists.my.co.ke> Sent: Tuesday, September 13, 2011 11:06 AM Subject: [Skunkworks] C/C++ tone sequence / screensaver in Linux Hi, I'm looking for a way of playing a tone sequence in C/C++ on a Linux operating system. There's an easy way of going this for J2ME devices where a tone sequence is defined as in this case. However, in my case, I want this in C/C++. I've tried projects like beep but without much success. Second one, what's the best way to detect "idle time" in C/C++ using pwrap/pwrap2 as the GUI library, how can you start an event if a user not interacting with the particular program say for 5 minutes? Somewhat like what you would do to activate a screensaver prefferably without using hooks and working in Linux. Please give me any leads on this. Thanks. -- Regards, Mike Muraguri Skype: mickie.mic M: + 254 722 799445 _______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke

Wesley, This helps alot. But think of the situation where yo want to play the tone in an ordinary Linux box using C/C++ as the programming language, from there we can start moving to smaller devices. There's a project called beep<http://www.developer.com/open/article.php/631191/Simple-Sounds-for-Linux.htm> as shown here which is said to solve the problem. I however haven't had a lot of success with it. Funny enough, when I try to play sounds even using some methods as described there, I hear sounds much later and cannot see how to actually play a wav equivalent continuous sound using this. The IO idea is great, the only hitch is - how do you separate IO mean'n for program X from other IO? Thanks alot. -- Regards, Mike Muraguri Skype: mickie.mic M: + 254 722 799445

Mike, Yup, u're right. Someone else also pointed out to me that the old games used to have a variety of beep sounds so it should be possible to do it on the PC(linux). The Beep program also shows it can work. Can you post the code you're using to play the beep? Perhaps the reason you're hearing it latter is coz there is something slow in the code. Off the top of my head, I would look at the following: 1. If you're passing all the tones you want to play in one go then the program plays them after a long delay, then the problem could be that the sound system is being initialized and that's what causes the long delay. If that's the case, u can initalize the sound system much earlier in the code and re-use it with each call to the function. 2. If you're passing all the tones you want to play in one go BUT the program delays playing EACH tone then you may need to post you're code so that we can have a better look. 3. If you're passing each tone at a go, then you may need to look for a function that allows you to pass them all at a go. If you cant find one, then post your code as well. You've also mentioned wav. I think playing wav files is different from playing tones. A wav file stores different kind of data somtimes 0s and 1s to indicate 'peaks' and 'drops' in sound. Wav will also contain the frequency (sample rate) in which to play the WHOLE sound, so that when the machine plays the 0s and 1s in that frequency then the right sound is produced. However for tones, you define the frequency of EACH tone and the duration to play it. Perhaps you can store that in a custom file and read it as u play the tones. (AFAIK my explanation is right but feel free to google it) Regarding the IO, what I suggested for you was for program X, not all programs. Just to clarify, does pwrap have a callback function that receives IO events for your program? I've never used pwrap but I'm thinking the principles are the same with other UI libraries. ________________________________ From: Mike Muraguri <mickie.mic@gmail.com> To: wesley kirinya <kiriinya2000@yahoo.com>; Skunkworks Mailing List <skunkworks@lists.my.co.ke> Sent: Wednesday, September 14, 2011 5:29 PM Subject: Re: [Skunkworks] C/C++ tone sequence / screensaver in Linux Wesley, This helps alot. But think of the situation where yo want to play the tone in an ordinary Linux box using C/C++ as the programming language, from there we can start moving to smaller devices. There's a project called beep as shown here which is said to solve the problem. I however haven't had a lot of success with it. Funny enough, when I try to play sounds even using some methods as described there, I hear sounds much later and cannot see how to actually play a wav equivalent continuous sound using this. The IO idea is great, the only hitch is - how do you separate IO mean'n for program X from other IO? Thanks alot. -- Regards, Mike Muraguri Skype: mickie.mic M: + 254 722 799445
participants (2)
-
Mike Muraguri
-
wesley kirinya