Sound, Music and Vibration


Defines

#define CK_NO   0
#define CK_BEEP   1
#define CK_BEEP_SHORT   2
#define BEEP_OK   0
#define BEEP_INFO   1
#define BEEP_QUESTION   2
#define BEEP_ERROR   3

Functions

bool get_sounds_enabled (void)
void enable_sounds (bool enable)
void beep (int beep_type)
bool is_tone_playing (void)
void play_tone (int index)
void play_raw (int divisor)
void stop_tone (void)
void enable_vibration (bool enable)
void vibrate (int index)


Compounds

     struct   MSequenceThe music sequence object


Detailed Description

These structures are used to control sound, music and vibration in the Cybiko computer. Most music control methods can be found within the description of the MSequence structure.


Define Documentation

#define BEEP_ERROR   3
 

The beep function argument for the ERROR dialog.

#define BEEP_INFO   1
 

The beep function argument for the INFO dialog.

#define BEEP_OK   0
 

The beep function argument for the OK dialog.

#define BEEP_QUESTION   2
 

The beep function argument for the QUESTION dialog.

#define CK_BEEP   1
 

Normal click sound.

#define CK_BEEP_SHORT   2
 

Short click sound.

#define CK_NO   0
 

No click sound.


Function Documentation

void beep ( int beep_type )
 

Produces a beep tone.

Parameters:
beep_type   Is one of the following: BEEP_OK, BEEP_INFO, BEEP_QUESTION or BEEP_ERROR.
Returns:
None.
       #include <cybiko.h>
       ...
       beep( BEEP_QUESTION );
       ...
See also:
BEEP_OK, BEEP_INFO, BEEP_QUESTION, BEEP_ERROR.

void enable_sounds ( bool enable )
 

Enables or disables tone generation.
When tone generation is disabled, play_tone() has no effect (the device's speaker keeps silent). Tone generation is enabled on startup.

Parameters:
enable   - If TRUE, tone generation is enabled, otherwise it is disabled.
Returns:
None.
       #include <cybiko.h>
       ...
       if ( !get_sounds_enabled() )
             enable_sounds( TRUE );
       ...

void enable_vibration ( bool enable )
 

Enables or disables vibration.

Parameters:
enable   If TRUE, vibration will be enabled, else one will be disabled.
Returns:
None.
       #include <cybiko.h>
       ...
       struct module_t main_module;
       ...
       init_module( &main_module );
       ...
       enable_vibration( TRUE );
       ...
       vibrate( 255 );
       cWinApp_pause( main_module.m_process, 250 );
       vibrate( 0 );
       ...
See also:
vibrate.

bool get_sounds_enabled ( void )
 

Returns a sounds-enabled flag state.

Returns:
Sounds-enabled flag state.
       #include <cybiko.h>
       ...
       if ( !get_sounds_enabled() )
             enable_sounds( TRUE );
       ...
See also:
enable_sounds.

bool is_tone_playing ( void )
 

Allows the device to determine whether or not a tone is being played.

Returns:
TRUE if a tone is being played, FALSE if no tone is being played.
       #include <cybiko.h>
       ...
       if ( !is_tone_playing() )
             beep( BEEP_ERROR );
       ...

void play_raw ( int divisor )
 

Starts playing a tone.
This function works the same way as the play_tone function. The difference is that, instead of the musical tone index, you provide the divisor for the timer so you can get any kind of sound this hardware can generate.

Parameters:
divisor   Value from the range [6505 - 1356] (or 85Hz - 4075Hz )
Returns:
None.
       #include <cybiko.h>
       ...
       int index;
       int count = 0;
       ...
       // Here is a simple example that screams like a crazy cat:
       for( index = 0; index < 0xFFF; index++ )
       {
         count = ( count + 1 ) % 64;
         if( count < 32 )
             play_raw( count * 10 + 1000 );
         else
             play_raw( ( 64 - count ) * 10 + 1000 );
       }
       stop_tone();
See also:
play_tone.

void play_tone ( int index )
 

Starts tone generation.
The range of valid values is from 0 (85Hz) to 67 (about 4075Hz) inclusive. If the index is negative, calling play_tone() is the same as calling stop_tone().

Parameters:
index   Specifies the frequency of the generated sound.
Returns:
None.
       #include <cybiko.h>
       ...
       struct module_t main_module;
       ...
       init_module( &main_module );
       ...
       play_tone(30);
       cWinApp_pause(main_module.m_process, 200);
       play_tone(-1);
       ...
See also:
play_raw.

void stop_tone ( void )
 

Stops tone playing (turns the sound off).
It's safe to call it even if no tone is being played.

Returns:
None.
       #include <cybiko.h>
       ...
       int index;
       int count = 0;
       ...
       // Here is a simple example that screams like a crazy cat:
       for( index = 0; index < 0xFFF; index++ )
       {
         count = ( count + 1 ) % 64;
         if( count < 32 )
             play_raw( count * 10 + 1000 );
         else
             play_raw( ( 64 - count ) * 10 + 1000 );
       }
       stop_tone();
See also:
play_tone.

void vibrate ( int index )
 

Turns the vibrator on (if index > 0) or off (if index is 0).
The greater the index (0 .. 255), the stronger the vibrations.

Parameters:
index   Strength of the vibration (0 .. 255). If index is 0, vibration will stop.
Returns:
None.
       #include <cybiko.h>
       ...
       struct module_t main_module;
       ...
       init_module( &main_module );
       ...
       enable_vibration( TRUE );
       ...
       vibrate( 255 );
       cWinApp_pause( main_module.m_process, 250 );
       vibrate( 0 );
       ...
See also:
enable_vibration.