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

Commit 5c94b6c7 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

AudioMixer can be configured for fewer max tracks

Change-Id: I371b17cef071d083eecf35cd3627a3adff907a33
parent 6da08fc3
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -42,12 +42,15 @@ namespace android {


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate)
AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate, uint32_t maxNumTracks)
    :   mTrackNames(0), mSampleRate(sampleRate)
    :   mTrackNames(0), mConfiguredNames((1 << maxNumTracks) - 1), mSampleRate(sampleRate)
{
{
    // AudioMixer is not yet capable of multi-channel beyond stereo
    // AudioMixer is not yet capable of multi-channel beyond stereo
    COMPILE_TIME_ASSERT_FUNCTION_SCOPE(2 == MAX_NUM_CHANNELS);
    COMPILE_TIME_ASSERT_FUNCTION_SCOPE(2 == MAX_NUM_CHANNELS);
    
    
    ALOG_ASSERT(maxNumTracks <= MAX_NUM_TRACKS, "maxNumTracks %u > MAX_NUM_TRACKS %u",
            maxNumTracks, MAX_NUM_TRACKS);

    LocalClock lc;
    LocalClock lc;


    mState.enabledTracks= 0;
    mState.enabledTracks= 0;
@@ -103,7 +106,7 @@ AudioMixer::~AudioMixer()


int AudioMixer::getTrackName()
int AudioMixer::getTrackName()
{
{
    uint32_t names = ~mTrackNames;
    uint32_t names = (~mTrackNames) & mConfiguredNames;
    if (names != 0) {
    if (names != 0) {
        int n = __builtin_ctz(names);
        int n = __builtin_ctz(names);
        ALOGV("add track (%d)", n);
        ALOGV("add track (%d)", n);
+8 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,8 @@ namespace android {
class AudioMixer
class AudioMixer
{
{
public:
public:
                            AudioMixer(size_t frameCount, uint32_t sampleRate);
                            AudioMixer(size_t frameCount, uint32_t sampleRate,
                                       uint32_t maxNumTracks = MAX_NUM_TRACKS);


    /*virtual*/             ~AudioMixer();  // non-virtual saves a v-table, restore if sub-classed
    /*virtual*/             ~AudioMixer();  // non-virtual saves a v-table, restore if sub-classed


@@ -184,11 +185,17 @@ private:
        int32_t         *outputTemp;
        int32_t         *outputTemp;
        int32_t         *resampleTemp;
        int32_t         *resampleTemp;
        int32_t         reserved[2];
        int32_t         reserved[2];
        // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
        track_t         tracks[MAX_NUM_TRACKS]; __attribute__((aligned(32)));
        track_t         tracks[MAX_NUM_TRACKS]; __attribute__((aligned(32)));
    };
    };


    // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
    // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
    uint32_t        mTrackNames;
    uint32_t        mTrackNames;

    // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
    // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
    const uint32_t  mConfiguredNames;

    const uint32_t  mSampleRate;
    const uint32_t  mSampleRate;


    state_t         mState __attribute__((aligned(32)));
    state_t         mState __attribute__((aligned(32)));