hal.c

来自「蓝牙HANDFREE软件源代码」· C语言 代码 · 共 62 行

C
62
字号
#include "handsfree_private.h"
#include "handsfree.h"


#include <codec.h>
#include <message.h>


/* Scale the supplied gain to be within the specified range */
static uint16 scaleGainToRange(uint8 gain, uint16 max_range, uint16 max_gain)
{
    return (((((gain * 10) * max_range)/max_gain) + 5)/10);
}


/*
    hfHalSetSpeakerGain

    Set the speaker volume. 
*/
void hfHalSetSpeakerGain(uint8  vol)
{
    uint16 scaled_val = 0;
    
    /* Get the range supported by the codec */
    uint16 range = CodecOutputGainRange() - 1;
    
    /* If the range is zero don't bother setting anything */
    if (!range)
        return;
        
    /* If the range is not zero scale the gain to be in that range */
    scaled_val = scaleGainToRange(vol, range, 15);
        
    /* Set the codec gain */
    CodecSetOutputGain(scaled_val);
}


/*
    hfHalSetMicrophoneGain
    
    Set the microphone gain.
*/
void hfHalSetMicrophoneGain(uint8 gain)
{
    uint16 scaled_val = 0;

    /* Get the range supported by the codec */
    uint16 range = CodecInputGainRange() - 1;

    /* If the range is zero don't bother setting anything */
    if (!range)
        return;

    /* If the range is not zero scale the gain to be in that range */
    scaled_val = scaleGainToRange(gain, range, 15);

    /* Set the codec gain */
    CodecSetInputGain(scaled_val);
}

⌨️ 快捷键说明

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