?? headset_volume.c
字號(hào):
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release
FILE NAME
headset_volume.c
DESCRIPTION
Controls the volume of the headset.
*/
/****************************************************************************
Header files
*/
#include "headset_private.h"
#include "av_stream_control.h"
#include "headset_tones.h"
#include "headset_volume.h"
#include <codec.h>
#include <panic.h>
#include <pcm.h>
#include <pio.h>
#include <ps.h>
#include <stdlib.h>
#include <audio.h>
#include <string.h>
#define VOLUME_MIC_UNMUTE_DELAY_MS 100
#define APP_MUTE_REMINDER_TIME_INT 5000
#ifdef DEBUG_VOLUME
#define VOLUME_DEBUG(x) DEBUG(x)
#else
#define VOLUME_DEBUG(x)
#endif
static const uint8 vgsToCodecGain[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
static void playVolLimitTone(headsetTaskData* app)
{
headsetPlayTone(app, tone_type_vol_limit);
}
/**************************************************************************/
void initialiseVolume(headsetTaskData* app)
{
/* Read the volume from PS. The volume is stored as:
HF Volume | AV volume
---------------------------------
|15| | | | | | |8|7| | | | | | |0|
---------------------------------
*/
if (!PsRetrieve(VOLUME_LEVEL, &app->speaker_volume, sizeof(app->speaker_volume)))
{
/* set the headset gain to a reasonable value */
app->speaker_volume.hfp_volume = 0x0A;
app->speaker_volume.av_volume = 0x0A;
}
AudioSetVolume( app->speaker_volume.hfp_volume , app->codec_task ) ;
#ifdef DEV_1645
/* Set the microphone bias voltage level: */
PioSetMicBiasHwVoltage(11); /* 11 = 2.71v */
#endif
}
/**************************************************************************/
void headsetHandleAvVolUp(headsetTaskData* app)
{
if (app->speaker_volume.av_volume < 15)
{
app->speaker_volume.av_volume++;
headsetUpdateVolume(app->codec_task, app->speaker_volume.av_volume);
}
else
{
playVolLimitTone(app);
}
}
/**************************************************************************/
void headsetHandleAvVolDown(headsetTaskData* app)
{
if (app->speaker_volume.av_volume > 0)
{
app->speaker_volume.av_volume--;
headsetUpdateVolume(app->codec_task, app->speaker_volume.av_volume);
}
else
{
playVolLimitTone(app);
}
}
/**************************************************************************/
void headsetHandleHfVolUp(headsetTaskData* app)
{
if (app->speaker_volume.hfp_volume < 15)
{
app->speaker_volume.hfp_volume++;
AudioSetVolume (app->speaker_volume.hfp_volume , app->codec_task ) ;
}
else
{
playVolLimitTone(app);
}
}
/**************************************************************************/
void headsetHandleHfVolDown(headsetTaskData* app)
{
if (app->speaker_volume.hfp_volume > 0)
{
app->speaker_volume.hfp_volume--;
AudioSetVolume( app->speaker_volume.hfp_volume , app->codec_task ) ;
}
else
{
playVolLimitTone(app);
}
}
/**************************************************************************/
void headsetCheckHfVolLimits(headsetTaskData* app)
{
if ((app->speaker_volume.hfp_volume == 15) || (app->speaker_volume.hfp_volume == 0))
playVolLimitTone(app);
}
/**************************************************************************/
void headsetUpdateVolume(Task codec_task, uint8 gain)
{
if (gain <= 15)
CodecSetOutputGainNow(codec_task, vgsToCodecGain[gain], left_and_right_ch);
VOLUME_DEBUG(("VOLUME: New volume: %d\n",gain));
}
/***************************************************************************/
void headsetMicrophoneMuteToggle(headsetTaskData *app)
{
if(app->mic_mute_on)
{
headsetMicrophoneMuteOff(app);
}
else
{
headsetMicrophoneMuteOn(app);
}
}
/***************************************************************************/
void headsetMicrophoneMuteOn(headsetTaskData *app)
{
AudioSetMode (AUDIO_MODE_MUTE_SPEAKER , NULL) ;
/* Start mute reminder operation */
MessageSendLater( &app->task , APP_MUTE_REMINDER , 0 , 1000) ;
app->mic_mute_on = TRUE;
}
/***************************************************************************/
void headsetMicrophoneMuteOff(headsetTaskData *app)
{
if ((app->hfp_state == headsetActiveCall) && app->sco_sink)
{
VOLUME_DEBUG(("VOLUME: Mic mute off\n"));
app->mic_mute_on = FALSE;
MessageCancelAll( &app->task , APP_MUTE_REMINDER) ;
/* Reconnect the microphone */
AudioSetMode(AUDIO_MODE_CONNECTED , NULL);
/* Send a message to complete the unmute a short time later */
MessageSendLater ( &app->task , APP_UNMUTE_MIC , 0 , VOLUME_MIC_UNMUTE_DELAY_MS ) ;
}
}
/***************************************************************************/
void headsetVolumeSetMicLevel (headsetTaskData *app , uint16 micGain)
{
#ifndef INCLUDE_CVC
uint16 codecVal = 0;
/*scale the codec gain accordingly*/
codecVal = vgsToCodecGain[micGain] ;
if (app->profile_connected == hfp_handsfree_profile)
{
HfpSendMicrophoneVolume(app->hfp , micGain);
}
else
{
HfpSendMicrophoneVolume(app->hsp , micGain);
}
/*set the mic gain as requested*/
CodecSetInputGainNow(app->codec_task, codecVal, left_and_right_ch);
#endif
}
/****************************************************************************
NAME
headsetVolumeCompleteUnmuteMicrophone
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 headsetVolumeCompleteUnmuteMicrophone (headsetTaskData *app)
{
#ifndef INCLUDE_CVC
uint16 micLevel = app->mic_volume;
uint16 rampLevel = 0 ;
/*4. Ramp up the microphone gain from 1 to the desired value*/
for ( rampLevel = 1; rampLevel < (micLevel+1) ; rampLevel++)
{
headsetVolumeSetMicLevel ( app ,rampLevel ) ;
}
#endif
}
/********************************************************************************
NAME
VolumeMuteRemind
DESCRIPTION
Plays a beep every 5 seconds to indicate that the Mute button has been pressed
RETURNS
*/
void VolumeMuteRemind (headsetTaskData *app)
{
MessageSendLater( &app->task , APP_MUTE_REMINDER , 0 , APP_MUTE_REMINDER_TIME_INT) ;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -