📄 headset_volume.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.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 "cvc_headset.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 <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, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 19};
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;
}
headsetUpdateVolume(app->codec_task, app->speaker_volume.hfp_volume);
}
/**************************************************************************/
void headsetHandleAvVolUp(headsetTaskData* app)
{
if (app->speaker_volume.av_volume < 15)
{
app->speaker_volume.av_volume++;
if (app->pcm_audio_state == pcm_av)
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--;
if (app->pcm_audio_state == pcm_av)
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++;
#ifdef INCLUDE_CVC
CvcHeadsetVolume(app);
#else
if (app->pcm_audio_state == pcm_sco)
headsetUpdateVolume(app->codec_task, app->speaker_volume.hfp_volume);
#endif
}
else
{
playVolLimitTone(app);
}
}
/**************************************************************************/
void headsetHandleHfVolDown(headsetTaskData* app)
{
if (app->speaker_volume.hfp_volume > 0)
{
app->speaker_volume.hfp_volume--;
#ifdef INCLUDE_CVC
CvcHeadsetVolume(app);
#else
if (app->pcm_audio_state == pcm_sco)
headsetUpdateVolume(app->codec_task, app->speaker_volume.hfp_volume);
#endif
}
else
{
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)
{
if ((app->hfp_state == headsetActiveCall) && app->sco_sink)
{
VOLUME_DEBUG(("VOLUME: Mic mute on\n"));
app->mic_mute_on = 1;
#ifndef INCLUDE_CVC
/* Disconnect the microphone */
StreamDisconnect(StreamPcmSource(0), 0);
StreamDisconnect(StreamPcmSource(1), 0);
/* Set volume at minimum */
headsetVolumeSetMicLevel (app , 0 ) ;
#else
CvcSetMode(app);
#endif
/* Start mute reminder operation */
MessageSendLater( &app->task , APP_MUTE_REMINDER , 0 , 1000) ;
}
}
/***************************************************************************/
void headsetMicrophoneMuteOff(headsetTaskData *app)
{
if ((app->hfp_state == headsetActiveCall) && app->sco_sink)
{
VOLUME_DEBUG(("VOLUME: Mic mute off\n"));
app->mic_mute_on = 0;
MessageCancelAll( &app->task , APP_MUTE_REMINDER) ;
/* Reconnect the microphone */
#ifndef INCLUDE_CVC
headsetVolumeSetMicLevel (app , 0 ) ;
(void)StreamConnect(StreamPcmSource(0), app->sco_sink);
#else
CvcSetMode(app);
#endif
/* 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) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -