Page 178 - Hacking Roomba
P. 178

Chapter 8 — Making Roomba Sing                159




                               Listing 8-3 Continued

                                 if( note >= 0 ) {
                                   octave = (octave < 2) ? 2 : (octave > 9) ? 9 : octave;
                                   note = note + ((octave+1)*12);
                                   roombacomm.playNote(note, 10);
                                   println(“playing note: “+note+” (octave:”+octave+”)”);
                                 }
                               }





                     Roomba Ringtones

                             The Roomba piezo beeper sounds a lot like the ringer of older mobile phones. Many of these
                             phones enable you to customize the ringtone by inputting a string of text that describes the
                             melody. This text is standardized and called the ungainly acronym RTTTL (Ringing Tones
                             Text Transfer Language), also known as Nokring since Nokia was the first phone maker to
                             provide it.
                             An example RTTTL format ringtone looks like this:
                             simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,
                             2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6

                             The format has three parts: a name, a set of defaults, and the list of notes, all separated by
                             colons. The defaults specify the duration of the notes, a default octave, and a speed in bpm
                             (beats per minute). The note list is a comma-separated list of notes, or p for a rest (pause). A
                             note letter can be preceded by a duration value and/or followed by an octave, if either differs
                             from the default. The format isn’t that interesting and its specification can be looked up
                             online at www.mxtelecom.com/tech/sms/ringtone. In the RoombaComm API, there is
                             a roombacomm.RTTTLParser class that parses the ringtone into a usable note list.
                             The important aspect of the RTTTL format is that there are thousands of free ringtones avail-
                             able on the Net. Do a search for monophonic ringtones or RTTTL ringtones to find them. Go
                             out and find a handful of melodies you’d like your Roomba to play. Most of the sites enable you
                             to audition them so you can get an idea of what they sound like.

                             The RTTTLParser class expects no whitespace in the RTTTL string, so be sure to delete any
                             spaces or tabs in the ringtone.




                             Many RTTTL ringtones have speeds that are too fast for Roomba to play. The “b=” part in the
                             default section specifies the beats per minute. Usually you should halve the original number. So
                             if the original ringtone has “b=200”, change it to “b=100”.
   173   174   175   176   177   178   179   180   181   182   183