⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_volume.c

📁 bluelab的一个很好的例程
💻 C
📖 第 1 页 / 共 2 页
字号:
    3. Wait 100ms
    4. Ramp up the microphone gain from 0 to the desired value


RETURNS
    
*/
static void VolumeStartUnMuteMicrophone ( hsTaskData * pApp ) 
{
        /*1. Set mic gain to 0*/
    VolumeSetMicLevel ( pApp , 0 ) ;
        /*2. Set the mic bias to 1*/
    LEDManagerSetMicBias ( pApp , TRUE ) ;


    SOM_DEBUG(("SOM: StUnMuteMic\n")) ;
    
        /*post an internal Message to complete the Unmute*/
    MessageSendLater ( &pApp->task , EventDoCompleteUnMuteMic , 0 , VOLUME_MIC_UNMUTE_DELAY_MS ) ;

}
/****************************************************************************
NAME 
 VolumeCompleteUnmuteMicrophone

DESCRIPTION
 method to complete the unmute action - ramps the vol up to the desired level
    This should occur after the delay between setting the mic bias and beginning the #
    mic gain increase

RETURNS

*/
void VolumeCompleteUnmuteMicrophone ( hsTaskData * pApp )
{
    uint16 lMicLevel = pApp->theSoundTask.gVolMaps[pApp->theSoundTask.gSMVolumeLevel].Mic ;
    uint16 lRampLevel = 0 ;
    

    SOM_DEBUG(("SOM: ComUnMuteMic\n")) ;
    
/*4. Ramp up the microphone gain from 1 to the desired value*/
    for ( lRampLevel = 1; lRampLevel < (lMicLevel+1) ; lRampLevel++)
    {
        SOM_DEBUG(("SOM: Ramp Mic [%x]\n" , lRampLevel)) ;
        VolumeSetMicLevel ( pApp ,lRampLevel ) ;
    }
}

/****************************************************************************
NAME 
 VolumeSendAndSetHeadsetVolume

DESCRIPTION
 sets the vol to the level corresponding to the phone volume level
    In addition - send a response to the AG indicating new volume level

RETURNS
 void
    
*/
static void VolumeSendAndSetHeadsetVolume ( hsTaskData * pApp  ,uint16 pNewVolume , bool pPlayTone) 
{
        /*if there is a hfp attached - then send the vol change*/
    if ( stateManagerIsConnected() )
    {
           /*use correct profile instance*/
        if (pApp->profile_connected == hfp_handsfree_profile)
        {
           HfpSendSpeakerVolume ( pApp->hfp , pNewVolume ) ;
        }
        else
        {
           HfpSendSpeakerVolume ( pApp->hsp , pNewVolume ) ;
        }
    }
    
    SOM_DEBUG(("VOL: SEND and")) ;
    VolumeSetHeadsetVolume ( pApp , pNewVolume , pPlayTone ) ;
}
/****************************************************************************
NAME 
 VolumeSetHeadsetVolume

DESCRIPTION
 sets the internal speaker gain to the level corresponding to the phone volume level
    
RETURNS
 void
    
*/
static void VolumeSetHeadsetVolume ( hsTaskData * pApp  ,uint16 pNewVolume , bool pPlayTone) 
{    
    bool lMuted = (pApp->theSoundTask.gMuted == VOL_MUTED) ;
        
    bool lTonePlayed = FALSE ;


    bool lOverideMute = pApp->features.OverideMute ;
    bool lMuteLocalVolAction = pApp->features.MuteLocalVolAction ;

    SOM_DEBUG(("SET Vol [%x]\n" , pNewVolume)) ;
    
    SOM_DEBUG(("SOM : SetVol[%d][%d][%d]\n " , lMuted , lOverideMute , lMuteLocalVolAction)) ;
    
/*this should only occur if we are not muted*/
/*or if we are muted but wish to overide*/
    if ( (!lMuted ) || ( lOverideMute ) )
    {
        /*set the mic gain to the level specified at this corresponding profile volume level*/
        if ( lMuted ) /*if we were muted then unmute gently*/
        {
            MessageSend( &pApp->task , EventMuteOff , 0 ) ;
        }
        else
        {
            VolumeSetMicLevel ( pApp , pApp->theSoundTask.gVolMaps[pNewVolume].Mic) ;
        }

        VolumeScaleAndSetCodecs( pApp , pNewVolume) ;
        
        /*if there is a tone associated with this vol level  and we want to play it*/
        if ( soundManagerIsToneDefined ( pApp->theSoundTask.gVolMaps[pNewVolume].Tone ) )
        {
            if( (pPlayTone) )
            {
                lTonePlayed = TRUE ;
                SOM_DEBUG(("SOM: VolTn[%x]\n" , (int)pApp->theSoundTask.gVolMaps[pNewVolume].Tone)) ;
                soundManagerPlayTone ( pApp , pApp->theSoundTask.gVolMaps[pNewVolume].Tone  ) ;
            } 
        }
    }
    
/*this should be updated if we are not muted*/    
/*or if we are muted but wish to overide*/
/*or if we are muted , dont want to override but do want to take local mute vol action*/
        /*store the newly set profile volume*/
    if ( (!lMuted ) ||( lOverideMute ) || (lMuteLocalVolAction) )
    {
    
        pApp->theSoundTask.gSMVolumeLevel = pNewVolume ;
        VolumeScaleAndSetCodecs( pApp , pNewVolume) ;
        
            /*check that the tone is valid*/
        if ( soundManagerIsToneDefined ( pApp->theSoundTask.gVolMaps[pNewVolume].Tone ) )
        {
            if( (pPlayTone) )
            {
                    /*only attempt to play the tone if it has not yet been played*/
                if ( lTonePlayed == FALSE )
                {
                    SOM_DEBUG(("SOM: VolTn[%x]\n" , (int)pApp->theSoundTask.gVolMaps[pNewVolume].Tone)) ;
                    soundManagerPlayTone ( pApp , pApp->theSoundTask.gVolMaps[pNewVolume].Tone  ) ;
                }    
            } 
        }    
    }
}

/****************************************************************************
NAME 
 VolumeScaleVolume

DESCRIPTION
 helper function to scale the volume for the codecs
    
RETURNS
 void
    
*/
static uint16 VolumeScaleVolume ( uint16 pVolume , uint16 pRange )
{    
    uint16 lCodecVal = 0 ;
 
       /*scale and set the actual headset volume*/
    if (pVolume == 0 )
    {
        lCodecVal = 0 ;
    }
    else
    {
            /*calc the range = we have 16 vol settings 0-15 hence - 1*/
            /*pRange - we can only use settings in the range 0 to (pRange - 1) */
        lCodecVal = (pVolume  * (pRange - 1) ) / (SOM_NUM_VOL_SETTINGS - 1) ;
    }
    
    SOM_DEBUG(("SOM: Cod[%d]/%d*[%d] = [%d]\n", pVolume, SOM_NUM_VOL_SETTINGS, pRange , lCodecVal)) ;
 
    return lCodecVal ;
    
}
/****************************************************************************
NAME 
 VolumeScaleAndSetCodecs

DESCRIPTION
 Sets the Speaker Gain to the New scaled value
 
RETURNS
    
*/

static void VolumeScaleAndSetCodecs ( hsTaskData * pApp , uint16 pNewVolume ) 
{  
    uint16 lCodecVal = 0 ;
       /*scale the output value*/
    if (pApp->features.ScaleSpeakerCodec)
    {

        lCodecVal = VolumeScaleVolume ( pNewVolume , CodecOutputGainRange() ) ; 
    }
    else
    {
           /*only provide a non-zero volume */
        if (pNewVolume)
        {
            lCodecVal = pNewVolume + VOLUME_SPEAKER_CODEC_OFFSET ;
        }
        
        SOM_DEBUG(("SOM: LinCodScale[%x][%x]\n" , pNewVolume , lCodecVal)) ;
        
    }
    

        /*user defined codec gains take priority*/
    if (pApp->features.UseUserDefinedCodecGains)
    {
        SOM_DEBUG(("SOM: User Codec\n")) ;
        
        lCodecVal = pApp->theSoundTask.gVolMaps[pNewVolume].VolGain;
    }
    SOM_DEBUG(("SOM: Vol Codec [%d]\n" , lCodecVal)) ;
    
        /*and set the codecs  with the new value*/
    CodecSetOutputGainA(lCodecVal);
    CodecSetOutputGainB(lCodecVal);
}

/****************************************************************************
NAME 
 SetSpeakerVolumeForTonePlayback

DESCRIPTION
 Sets a VOlume Level to be used for the Tone playback. This level is just set to the
    codecs and notused as an internal volume level. This can be restored once the tone 
    playback is complete
 
RETURNS
    
*/
void VolumeSetForTonePlayback (hsTaskData * pApp , uint16 pNewVolume )
{
    VolumeScaleAndSetCodecs ( pApp , pNewVolume )  ;
}
/****************************************************************************
NAME 
 RestoreVolumeAfterTonePlayback

DESCRIPTION
 After the tone has been played - this restores the volume to the internal level used
 
RETURNS
    
*/
void VolumeRestoreAfterTonePlayback ( hsTaskData * pApp  ) 
{
        /*if we are currently muted and mutre controls the speaker gain then return to mute*/
    if ( (pApp->theSoundTask.gMuted == VOL_MUTED ) && (pApp->features.MuteSpeakerAndMic) )
    {
        VolumeScaleAndSetCodecs ( pApp , 0 )  ;    
    }
    else
    {
        VolumeScaleAndSetCodecs ( pApp , pApp->theSoundTask.gSMVolumeLevel )  ;    
    }
}

/****************************************************************************
NAME 
 VolumeGetStoredAGVolumeLevel

DESCRIPTION
 Get the stored volume level of the device with the specified bdaddr
 
RETURNS
   
*/
void VolumeGetStoredAGVolumeLevel(const bdaddr* bd_addr)
{
 ConnectionSmGetAttribute(SOM_VOLUME_PSKEY_BASE, bd_addr, sizeof(uint16));
}


/****************************************************************************
NAME 
 VolumeSetStoredAGVolumeLevel

DESCRIPTION
 Set the stored volume level of the device with the specified bdaddr
 
RETURNS
 
*/
void VolumeSetStoredAGVolumeLevel(const bdaddr* bd_addr, uint16 level)
{
 ConnectionSmPutAttribute(SOM_VOLUME_PSKEY_BASE, bd_addr, sizeof(uint16), (uint8*)&level);  
}

/****************************************************************************
NAME 
 VolumeMuteRemind

DESCRIPTION
 Sends a mute reminder message
 
RETURNS
 
*/
void VolumeMuteRemind ( hsTaskData * pApp )
{
        /*start the mute reminder event*/
    MessageSendLater( &pApp->task , EventMuteReminder , 0 ,D_SEC(pApp->theSoundTask.gSMMuteRemindTimeSec ) ) ;
}

/****************************************************************************
NAME 
 VolumeZero

DESCRIPTION
 Set the volume to zero
 
RETURNS
    
*/
void VolumeZero ( hsTaskData * pApp  ) 
{
	VolumeScaleAndSetCodecs ( pApp , 0 )  ;    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -