📄 headset_tones.c
字号:
AUDIO_TEMPO(1200), AUDIO_VOLUME(64), AUDIO_TIMBRE(sine),
AUDIO_NOTE(B6 , CROTCHET),
AUDIO_END
};
/*series of 5 high beeps with pause*/
static const audio_note tone_S4[] =
{
AUDIO_TEMPO(1200), AUDIO_VOLUME(64), AUDIO_TIMBRE(sine),
AUDIO_NOTE(A6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(A6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(A6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(A6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(A6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_END
};
/*Low / High beep */
static const audio_note tone_S5[] =
{
AUDIO_TEMPO(1200), AUDIO_VOLUME(64), AUDIO_TIMBRE(sine),
AUDIO_NOTE(B6 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(DS8 , CROTCHET),
AUDIO_END
};
/* High / Low beep */
static const audio_note tone_S6[] =
{
AUDIO_TEMPO(1200), AUDIO_VOLUME(64), AUDIO_TIMBRE(sine),
AUDIO_NOTE(DS8 , CROTCHET),
AUDIO_NOTE(REST , CROTCHET),
AUDIO_NOTE(B6 , CROTCHET),
AUDIO_END
};
/***************************************************************************/
/*
The Tone Array
*/
/*************************************************************************/
#define NUM_FIXED_TONES (56)
/* This must make use of all of the defined tones - requires the extra space first */
static const audio_note * const gFixedTones [ NUM_FIXED_TONES ] =
{
/*1*/ tone_B , /*Vol 0*/
/*2*/ tone_C , /*Vol 1*/
/*3*/ tone_D , /*Vol 2*/
/*4*/ tone_E , /*Vol 3*/
/*5*/ tone_F , /*Vol 4*/
/*6*/ tone_G , /*Vol 5*/
/*7*/ tone_H , /*Vol 6*/
/*8*/ tone_I , /*Vol 7*/
/*9*/ tone_J , /*Vol 8*/
/*A*/ tone_K , /*Vol 9*/
/*b*/ tone_L , /*Vol 10*/
/*c*/ tone_M , /*4 note rise*/
/*d*/ tone_N , /*2 note ris*/
/*e*/ tone_O , /*2 note fall*/
/*f*/ tone_P , /*long low short high*/
/*10*/ tone_Q , /*conn */
/*11*/ tone_R , /*power*/
/*12*/ tone_S , /*error*/
/*13*/ tone_T , /*short cfm*/
/*14*/ tone_U , /*long CFM*/
/*15*/ tone_V , /*Low Batt*/
/*16*/ tone_W , /*pair removal*/
/*17*/ tone_X , /*spare*/
/*18*/ battery_low_tone ,
/*19*/ low_500ms_tone ,
/*1a*/ mute_reminder_tone ,
/*1b*/ ring_twilight ,
/*1c*/ ring_g_s_t_q ,
/*1d*/ ring_valkyries ,
/*1e*/ ring_greensleeves ,
/*1f*/ ring_two_beeps ,
/*20*/ ring_fairground ,
/*21*/ ring_counterpoint ,
/*22*/ ring_major_arp ,
/*23*/ ring_major_scale ,
/*24*/ ring_minor_arp ,
/*25*/ ring_harmonic_minor_scale,
/*26*/ ring_more_than_a_feeling ,
/*27*/ ring_eight_beeps ,
/*28*/ ring_four_beeps ,
/*29*/ ring_bumble_bee ,
/*2a*/ ring_aug_scale ,
/*2b*/ ring_dim_scale ,
/*2c*/ CustomRingTone , /*this is a custom ring tone that can be defined if required.*/
/*2d*/ tone_A1 , /*4 low to high 38ms*/
/*2e*/ tone_A2 , /*4 high to low 38ms*/
/*2f*/ tone_A3 , /*short high low 25ms**/
/*30*/ tone_A4 , /*series of 5 high tones 94 ms*/
/*31*/ tone_A5 , /*low to high 100ms tones 50ms pause*/
/*32*/ tone_A6 , /*high to low 100ms tones 50ms pause*/
/*33*/ tone_S1 , /*short v high 2400hz**/
/*34*/ tone_S2 , /*series(12) of high / higher beeps*/
/*35*/ tone_S3 , /*short middle (987) **/
/*36*/ tone_S4 , /*series of 5 high beeps with pause*/
/*37*/ tone_S5 , /*Low High*/
/*38*/ tone_S6 , /*High Low*/
} ;
static bool gToneIsPlaying = FALSE ;
/****************************************************************************
Local Functions
*/
static void TonesHandler( Task task, MessageId id, Message message ) ;
/****************************************************************************
FUNCTIONS
*/
/****************************************************************************
NAME
TonesInit
DESCRIPTION
Initialise the tones functions
RETURNS
void
*/
void TonesInit ( hsTaskData * pApp )
{
/*set up the callback message handler*/
pApp->theSoundTask.task.handler = TonesHandler ;
/*init the tone Q*/
pApp->theSoundTask.gToneQueue.Tone1 = 0x00 ;
pApp->theSoundTask.gToneQueue.Tone2 = 0x00 ;
pApp->theSoundTask.gToneQueue.Tone3 = 0x00 ;
pApp->theSoundTask.gToneQueue.Tone4 = 0x00 ;
}
/****************************************************************************
NAME
TonesConfigureEvent
DESCRIPTION
Configures a tones event mapping - used to playback a tone
RETURNS
void
*/
void TonesConfigureEvent ( hsTaskData * pApp ,headsetEvents_t pEvent , HeadsetTone_t pTone )
{
uint16 lEventIndex = pEvent - EVENTS_EVENT_BASE ;
/* gEventTones is an array of indexes to the tones*/
SOM_DEBUG(("Add Tone[%x][%x]\n" , pEvent , pTone ));
pApp->theSoundTask.gEventTones [ lEventIndex ] = pTone ;
SOM_DEBUG(("SOM; Add Ev[%x][%x]Tone[%x][%x]\n", pEvent
, lEventIndex
, pTone
, (int) pApp->theSoundTask.gEventTones [ lEventIndex]
)) ;
}
/****************************************************************************
NAME
TonesPlayTone
DESCRIPTION
Playsback the tone given by the heasdsetTone_t index
RETURNS
void
*/
void TonesPlayTone ( hsTaskData * pApp , HeadsetTone_t pTone )
{
bool ring_success = FALSE;
Source stream_source;
/*if a tone was not currently being played*/
if ( gToneIsPlaying ==FALSE )
{
/* Set volume to zero before disconnecting stream to mask out any clicks */
VolumeZero(pApp);
/* Disconnect anything already connected to PCM slot 0 i.e a sco */
StreamDisconnect(StreamPcmSource(0), StreamPcmSink(0));
/* Restore volume */
VolumeRestoreAfterTonePlayback(pApp);
/* Stream the tone*/
if ( ToneIsDefined (pTone ) )
{
/* Change the volume if required to do so*/
if (pApp->features.PlayTonesAtFixedVolume)
{
VolumeSetForTonePlayback ( pApp , TONES_VOL_PLAYBACK_LEVEL ) ;
}
/* As the index HeadsetTone_t first element is TONE_NOT_DEFINED then we have to offset into the
fixed array of tones here having first checked that the tone is ok to be played (-1) */
stream_source = StreamAudioSource( gFixedTones[ (pTone - 1) ]);
/* Connect*/
ring_success = StreamConnect(stream_source, StreamPcmSink(0));
gToneIsPlaying = TRUE ;
/* Send a message to indicate when the PCM connect disconnects */
MessageSinkTask ( StreamPcmSink(0) , &pApp->theSoundTask.task ) ;
}
}
else
{
if (pApp->features.QueueToneEvents)
{
if (pApp->theSoundTask.gToneQueue.Tone1 == 0 )
{
SOM_DEBUG(("SOM: Queue 1 [ %x]\n", pTone)) ;
pApp->theSoundTask.gToneQueue.Tone1 = (uint8)pTone ;
}
else if (pApp->theSoundTask.gToneQueue.Tone2 == 0 )
{
SOM_DEBUG(("SOM: Queue 2 [ %x]\n", pTone)) ;
pApp->theSoundTask.gToneQueue.Tone2 = (uint8)pTone ;
}
else if (pApp->theSoundTask.gToneQueue.Tone3 == 0 )
{
SOM_DEBUG(("SOM: Queue 3 [ %x]\n", pTone)) ;
pApp->theSoundTask.gToneQueue.Tone3 = (uint8)pTone ;
}
else if (pApp->theSoundTask.gToneQueue.Tone4 == 0 )
{
SOM_DEBUG(("SOM: Queue 4 [ %x]\n", pTone)) ;
pApp->theSoundTask.gToneQueue.Tone4 = (uint8)pTone ;
}
else
{
SOM_DEBUG(("SOM: Queue Full\n")) ;
}
}
}
SOM_DEBUG(("SOM: play=%d\n", ring_success));
}
/****************************************************************************
NAME
TonesHandler
DESCRIPTION
Message handler - arrived at on completion of a tone playback - deletes any queued messages
and attempts to reconnect the last sco link if there was one
RETURNS
void
*/
static void TonesHandler ( Task task, MessageId id, Message message )
{
hsTaskData * lApp = (hsTaskData *) getAppTask() ;
uint16 lNumCancelledMsgs = 0 ;
/* Set volume to zero before disconnecting stream to mask out any clicks */
VolumeZero(lApp);
/* Disconnect whatever is connected to the PCM*/
StreamDisconnect(StreamPcmSource(0), StreamPcmSink(0));
/* Restore volume */
VolumeRestoreAfterTonePlayback(lApp);
/* Attempt to reconnect the sco*/
if ( lApp->sco_sink)
{
audioConnectScoToPcm ( lApp, 0 ) ;
}
/* Now cancel any outstanding messages*/
lNumCancelledMsgs = MessageFlushTask ( &lApp->theSoundTask.task ) ;
/* Indicate that a tone is not currently playing*/
gToneIsPlaying = FALSE ;
/* Change the volume if required to do so*/
if (lApp->features.PlayTonesAtFixedVolume)
{
VolumeRestoreAfterTonePlayback ( lApp ) ;
}
if (lApp->features.QueueToneEvents)
{
if ( lApp->theSoundTask.gToneQueue.Tone1 )
{
/*then there is a tone in the Q*/
SOM_DEBUG(("SOM: Play Q'd Tone [%x]\n", lApp->theSoundTask.gToneQueue.Tone1)) ;
soundManagerPlayTone ( lApp, lApp->theSoundTask.gToneQueue.Tone1 ) ;
/*shuffle the Queue*/
lApp->theSoundTask.gToneQueue.Tone1 = lApp->theSoundTask.gToneQueue.Tone2 ;
lApp->theSoundTask.gToneQueue.Tone2 = lApp->theSoundTask.gToneQueue.Tone3 ;
lApp->theSoundTask.gToneQueue.Tone3 = lApp->theSoundTask.gToneQueue.Tone4 ;
lApp->theSoundTask.gToneQueue.Tone4 = 0x00 ;
}
}
SOM_DEBUG(("SOM: MSG[%x]c[%x]\n", id , lNumCancelledMsgs )) ;
}
/****************************************************************************
NAME
ToneIsDefined
DESCRIPTION
Helper fn to determine if a tone has been defined or not
RETURNS
bool
*/
bool ToneIsDefined ( HeadsetTone_t pTone )
{
bool lResult = TRUE ;
if ( pTone == TONE_NOT_DEFINED )
{
lResult = FALSE ;
}
if ( ! gFixedTones [ (pTone - 1) ] )
{
/*the tone is also not defined if no entry exists for it*/
lResult = FALSE ;
}
return lResult ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -