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

Commit 1e54e6df authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Pass stereo gains as packed minifloat"

parents 5859b984 c56f3426
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>

#include <audio_utils/minifloat.h>
#include <utils/threads.h>
#include <utils/Log.h>
#include <utils/RefBase.h>
@@ -110,11 +111,8 @@ private:
                // force to 32-bit.  The client and server may have different typedefs for size_t.
                uint32_t    mMinimum;       // server wakes up client if available >= mMinimum

                // Channel volumes are fixed point U4.12, so 0x1000 means 1.0.
                // Left channel is in [0:15], right channel is in [16:31].
                // Always read and write the combined pair atomically.
                // For AudioTrack only, not used by AudioRecord.
                uint32_t    mVolumeLR;
                // Stereo gains for AudioTrack only, not used by AudioRecord.
                gain_minifloat_packed_t mVolumeLR;

                uint32_t    mSampleRate;    // AudioTrack only: client's requested sample rate in Hz
                                            // or 0 == default. Write-only client, read-only server.
@@ -285,8 +283,8 @@ public:
        mCblk->mSendLevel = uint16_t(sendLevel * 0x1000);
    }

    // caller must limit to 0 <= volumeLR <= 0x10001000
    void        setVolumeLR(uint32_t volumeLR) {
    // set stereo gains
    void        setVolumeLR(gain_minifloat_packed_t volumeLR) {
        mCblk->mVolumeLR = volumeLR;
    }

@@ -405,7 +403,7 @@ public:
    // return value of these methods must be validated by the caller
    uint32_t    getSampleRate() const { return mCblk->mSampleRate; }
    uint16_t    getSendLevel_U4_12() const { return mCblk->mSendLevel; }
    uint32_t    getVolumeLR() const { return mCblk->mVolumeLR; }
    gain_minifloat_packed_t getVolumeLR() const { return mCblk->mVolumeLR; }

    // estimated total number of filled frames available to server to read,
    // which may include non-contiguous frames
+8 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "AudioTrack"

#include <math.h>
#include <sys/resource.h>
#include <audio_utils/primitives.h>
#include <binder/IPCThreadState.h>
@@ -566,7 +567,9 @@ void AudioTrack::pause()

status_t AudioTrack::setVolume(float left, float right)
{
    if (left < 0.0f || left > 1.0f || right < 0.0f || right > 1.0f) {
    // This duplicates a test by AudioTrack JNI, but that is not the only caller
    if (isnanf(left) || left < GAIN_FLOAT_ZERO || left > GAIN_FLOAT_UNITY ||
            isnanf(right) || right < GAIN_FLOAT_ZERO || right > GAIN_FLOAT_UNITY) {
        return BAD_VALUE;
    }

@@ -574,7 +577,7 @@ status_t AudioTrack::setVolume(float left, float right)
    mVolume[AUDIO_INTERLEAVE_LEFT] = left;
    mVolume[AUDIO_INTERLEAVE_RIGHT] = right;

    mProxy->setVolumeLR((uint32_t(uint16_t(right * 0x1000)) << 16) | uint16_t(left * 0x1000));
    mProxy->setVolumeLR(gain_minifloat_pack(gain_from_float(left), gain_from_float(right)));

    if (isOffloaded_l()) {
        mAudioTrack->signal();
@@ -589,7 +592,8 @@ status_t AudioTrack::setVolume(float volume)

status_t AudioTrack::setAuxEffectSendLevel(float level)
{
    if (level < 0.0f || level > 1.0f) {
    // This duplicates a test by AudioTrack JNI, but that is not the only caller
    if (isnanf(level) || level < GAIN_FLOAT_ZERO || level > GAIN_FLOAT_UNITY) {
        return BAD_VALUE;
    }

@@ -1137,8 +1141,7 @@ status_t AudioTrack::createTrack_l(size_t epoch)
        mStaticProxy = new StaticAudioTrackClientProxy(cblk, buffers, frameCount, mFrameSizeAF);
        mProxy = mStaticProxy;
    }
    mProxy->setVolumeLR((uint32_t(uint16_t(mVolume[AUDIO_INTERLEAVE_RIGHT] * 0x1000)) << 16) |
            uint16_t(mVolume[AUDIO_INTERLEAVE_LEFT] * 0x1000));
    mProxy->setVolumeLR(GAIN_MINIFLOAT_PACKED_UNITY);
    mProxy->setSendLevel(mSendLevel);
    mProxy->setSampleRate(mSampleRate);
    mProxy->setEpoch(epoch);
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace android {

audio_track_cblk_t::audio_track_cblk_t()
    : mServer(0), mFutex(0), mMinimum(0),
    mVolumeLR(0x10001000), mSampleRate(0), mSendLevel(0), mFlags(0)
    mVolumeLR(GAIN_MINIFLOAT_PACKED_UNITY), mSampleRate(0), mSendLevel(0), mFlags(0)
{
    memset(&u, 0, sizeof(u));
}
+2 −1
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ LOCAL_C_INCLUDES := \
    frameworks/av/services/medialog \
    frameworks/av/services/audioflinger \
    frameworks/av/services/audiopolicy \
    frameworks/av/services/camera/libcameraservice
    frameworks/av/services/camera/libcameraservice \
    $(call include-path-for, audio-utils)

LOCAL_MODULE:= mediaserver
LOCAL_32_BIT_ONLY := true
+0 −3
Original line number Diff line number Diff line
@@ -82,9 +82,6 @@ class ServerProxy;

static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);

#define MAX_GAIN 4096.0f
#define MAX_GAIN_INT 0x1000

#define INCLUDING_FROM_AUDIOFLINGER_H

class AudioFlinger :
Loading