|
10-25-01
REALbasic Phone Home by
Erick Tejkowsi
This week we'll create a fun REALbasic project that spits out audio files. These audio files will
play a tone like your telephone produces when you press the number keys.
Background
Telephones keypads in the United States produce tones in a unique manner called "DTMF". DMTF stands for Dual-Tone Multi-Frequency. There's no need
to sweat the terminology if you're a technophobe. All it really means is that each row and column on a telephone keypad produces a unique tone.
In other words, The 1, 4, 7, and * keys all share a common tone, and keys 1, 2, 3 produce a common tone. When you press a key, it sounds
two simultaneous tones (hence the Dual in DTMF). If you'd like to hear the tone for a particular row or column, pick up your telephone
and press two keys in the same row or column. The tone you hear is the frequency that the row or column shares. For the technically inclined out
there, these tones are pure sine waves. So, in our code, we will produce audio files that contain sine waves of the two tones
for any particular telephone key. If you'd like to know more about how DTMF and phones work, there's lots of info on the web. Try
this site or do a search on Google for DTMF.
The good news is that I (along with some help from Cubie award winner Wade) have taken care of the hard part
of creating the tones for you and put them in a RB class.
You just have to "wire up" the class in your own project to take advantage of it. So, let's get started.
Build the Interface
Launch REALbasic and open Window1. To the window add 12 PushButtons and rename the "1" key, giving it a name like "NumKey" and change its
Index property to a value of 0 (zero). Then copy the "NumKey" name to the clipboard and select the "2" key and paste the name in for this key.
When you press return, you should notice that the Index property will automatically increment to the next available number. Continue in this fashion
for each key. When you're finished, you should have twelve PushButtons that share the same name, but each with a unique index number between 0 and 11 inclusive.
Next, add a checkbox to the window and give it some descriptive text. We will use this checkbox to decide if we want the two tones played together as
we do on a phone, or separated between the stereo field, with one tone in the left speaker and one in the right. This is just so you can
hear the tones separated like the example above where you pressed two keys on the phone at once.
Finally, add a ChasingArrow control to the window and make it invisible by unchecking its Visible property.
It takes a little while to produce an audio file, so we will use this to show the user that we are hard at work producing the file. You may arrange the
interface however you want, but it might look something like this.
Add the Code
To create phone tones, you'll need to either download the phone tone class or download the completed
project listed at the end of this tutorial. If you choose to download the class, drag it into your project window. If you download the completed
project, it already contains the class.
Next, enter the following code in the Action event of any of the Window1 PushButtons (they share the same code since they
are an array of controls):
First, this code turns on the ChasingArrows to show that a process is taking place.
Then the code asks for a file where the user may save the audio. If one is chosen, the code then creates a new object based on
the phone tone class (named "System7Creator"). Once the object is created, we send it the following messages:
- SFILCreatePhoneNumberWave - creates the audio sine wave data based on which key was pressed
- SetOutputFile - hopefully self-explanatory
- MakeFile - make the sucker!
When the code has done its thing, hide the ChasingArrows again.
Conclusion
Well, that's it! Run the project and when you're happy with the results, build it. This project should work just fine on Carbon as well.
If you'd like to download this week's example instead of typing it in, you can download the completed project.
Oh, and if you've made it this far... look at the first and last initials in my name versus the title of this project to see if you can figure out my poor excuse for humor. Honest, there's
a joke in there somewhere. See you next week!
10-16-01
REALbasic News
by Erick Tejkowsi
Slap a few Frogs
Frogslapper is another fine product from Stimpsoft, Made with
REALbasic - fully OS X ready, totally rewritten. Frogslapper is a light, free POP3 email checker.
Search plugin
Thomas Reed has released the first
alpha of a plugin entitled MSSearch.
The MSSearch Plugin provides a search class capable of searching for
multiple search terms in one pass. It's free including the source code.
REAL Control Strip
INTELLI INNOVATIONS has posted REAL Control Strip free-of-charge for inclusion with any
application (commercial or non-commercial). Additionally, the complete
source code is now bundled with the software for public use and
modification.
iScreenSaver
iScreensaver Designer for Windows and Macintosh version 2.0beta11 is available:
Game Code
Looking for some good REALbasic gaming code? Don't miss iDevGames.
They specialize in Mac programming, with particular focus to gaming. Source code is included for many languages, including REALbasic.
|