home | |||||||||||||||||||||||||||||||||||
links |
|
||||||||||||||||||||||||||||||||||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
5 - Tone DurationDetermining duration can be somewhat trickier. The SDK documentation lets you calculate the duration for the structure's values of 'man' and 'exp' (mantissa and exponent) via the following equation:Interval in seconds = ( (man) * 4 ^ (15-(exp)) ) / 1,000,000 In practice, however, most of the values are uninteresting for general tones, being either extremely short or extremely long - the more practical values for 'exp' are:
The 'man' value is simply multiplied by the time value generated for each exponent. For example, a tone duration of about one second would be man=1, exp=5 (1 by 1 sec), or man=4, exp=6 (4 by 1/4 sec). According to the SDK, just the lower four bits of 'man' are valid, meaning that only 0 through 15 are usable. Taken together, these values should take care of most audio needs. As an example to wrap this all up, if we wanted to play a Middle C note for 1/2 second, we would set the following: struct piezo_tone info; info.tone =62; // approximately middle c info man =2; // 2 times 1/4 sec for exp, or 1/2 sec info.exp =6; // 1/4 sec info.unused=0; // always set to zero! piezo_play_1tone(info,0); // simple tone-no flags The sample code accompanying this article includes a button 'keyboard', allowing you to play one octave of notes in this manner. Previous Section Next Section |
||||||||||||||||||||||||||||||||||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |