Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e333bc9 authored by Steve Kondik's avatar Steve Kondik Committed by Christopher Lais
Browse files

audioflinger: Nasty hack for adjusting BCM FM volume

Normally this kind of nasty hack could go into libaudio, but on this
particular device, we have no access to the source code of libaudio.

Put the nasty hack into audioflinger and wrap it in ifdefs.

Change-Id: I5e3e495e3bd6b671823967b61ba5ceb49e59a401
parent d98418db
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -259,11 +259,13 @@ public:
        DEVICE_OUT_AUX_DIGITAL = 0x400,
#ifdef HAVE_FM_RADIO
        DEVICE_OUT_FM = 0x800,
        DEVICE_OUT_FM_SPEAKER = 0x1000,
        DEVICE_OUT_FM_ALL = (DEVICE_OUT_FM | DEVICE_OUT_FM_SPEAKER),
#endif
        DEVICE_OUT_DEFAULT = 0x8000,
        DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
#ifdef HAVE_FM_RADIO
                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_FM | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_FM | DEVICE_OUT_FM_SPEAKER | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
#else
                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
#endif
+4 −0
Original line number Diff line number Diff line
@@ -130,6 +130,10 @@ ifeq ($(BOARD_HAVE_FM_RADIO),true)
  LOCAL_CFLAGS += -DHAVE_FM_RADIO
endif

ifeq ($(BOARD_USE_BROADCOM_FM_VOLUME_HACK),true)
  LOCAL_CFLAGS += -DUSE_BROADCOM_FM_VOLUME_HACK
endif

ifeq ($(TARGET_SIMULATOR),true)
    ifeq ($(HOST_OS),linux)
        LOCAL_LDLIBS += -lrt -lpthread
+44 −3
Original line number Diff line number Diff line
@@ -615,9 +615,9 @@ status_t AudioFlinger::setParameters(int ioHandle, const String8& keyValuePairs)
    String8 key = String8(AudioParameter::keyRouting);
    int device;
    if (param.getInt(key, device) == NO_ERROR) {
        if((device & AudioSystem::DEVICE_OUT_FM) && mFmOn == false){
        if((device & AudioSystem::DEVICE_OUT_FM_ALL) && mFmOn == false){
            mFmOn = true;
         } else if (mFmOn == true && !(device & AudioSystem::DEVICE_OUT_FM)){
         } else if (mFmOn == true && !(device & AudioSystem::DEVICE_OUT_FM_ALL)){
            mFmOn = false;
         }
    }
@@ -744,8 +744,43 @@ status_t AudioFlinger::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrame
}

#ifdef HAVE_FM_RADIO
#ifdef USE_BROADCOM_FM_VOLUME_HACK
/*
 * NASTY HACK: Send raw HCI data to adjust the FM volume.
 *
 * Normally we would do this in libaudio, but this is for the case where
 * we have a prebuilt libaudio and cannot modify it.
 */
static status_t set_volume_fm(uint32_t volume)
{
    int returnval = 0;
    float ratio = 2.5;

     char s1[100] = "hcitool cmd 0x3f 0xa 0x5 0xc0 0x41 0xf 0 0x20 0 0 0";
     char s2[100] = "hcitool cmd 0x3f 0xa 0x5 0xe4 0x41 0xf 0 0x00 0 0 0";
     char s3[100] = "hcitool cmd 0x3f 0xa 0x5 0xe0 0x41 0xf 0 ";

     char stemp[10] = "";
     char *pstarget = s3;

     volume = (unsigned int)(volume * ratio);

     sprintf(stemp, "0x%x ", volume);
     pstarget = strcat(s3, stemp);
     pstarget = strcat(s3, "0 0 0");

     system(s1);
     system(s2);
     system(s3);

     return returnval;
}
#endif

status_t AudioFlinger::setFmVolume(float value)
{
	status_t ret;

    // check calling permissions
    if (!settingsAllowed()) {
        return PERMISSION_DENIED;
@@ -753,7 +788,13 @@ status_t AudioFlinger::setFmVolume(float value)

    AutoMutex lock(mHardwareLock);
    mHardwareStatus = AUDIO_SET_FM_VOLUME;
    status_t ret = mAudioHardware->setFmVolume(value);
#ifdef USE_BROADCOM_FM_VOLUME_HACK
    int vol = AudioSystem::logToLinear(value);
    LOGI("setFmVolume %d", vol);
    ret = set_volume_fm(vol);
#else
    ret = mAudioHardware->setFmVolume(value);
#endif
    mHardwareStatus = AUDIO_HW_IDLE;

    return ret;
+1 −1
Original line number Diff line number Diff line
@@ -717,7 +717,7 @@ bool AudioSystem::isInputDevice(audio_devices device)
bool AudioSystem::isFmDevice(audio_devices device)
{
    if ((popCount(device) == 1 ) &&
        ((device & ~AudioSystem::DEVICE_OUT_FM) == 0)) {
        ((device & ~AudioSystem::DEVICE_OUT_FM_ALL) == 0)) {
        return true;
    } else {
        return false;