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

Commit 04c1e531 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Effect for multichannel PCM downmix to stereo

First pass at implementing an audio effect whose role is to
 downmix multichannel PCM buffers to stereo.
The effect is not handling volume changes.
The effect code here handles quad, 4.0, 5.1 and 7.1 input configurations,
 to optimize the most commom configurations, and does not yet handle
 generic multichanel configurations.

Change-Id: I74d04bd961348f3f0e4ae7714b70e620808a0829
parent eb7de450
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

# Multichannel downmix effect library
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
	EffectDownmix.c

LOCAL_SHARED_LIBRARIES := \
	libcutils

LOCAL_MODULE:= libdownmix

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx

ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
LOCAL_LDLIBS += -ldl
endif

LOCAL_C_INCLUDES := \
	system/media/audio_effects/include \
	system/media/audio_utils/include

LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)
+889 −0

File added.

Preview size limit exceeded, changes collapsed.

+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_EFFECTDOWNMIX_H_
#define ANDROID_EFFECTDOWNMIX_H_

#include <audio_effects/effect_downmix.h>
#include <audio_utils/primitives.h>
#include <system/audio.h>

/*------------------------------------
 * definitions
 *------------------------------------
*/

#define DOWNMIX_OUTPUT_CHANNELS AUDIO_CHANNEL_OUT_STEREO

typedef enum {
    DOWNMIX_STATE_UNINITIALIZED,
    DOWNMIX_STATE_INITIALIZED,
    DOWNMIX_STATE_ACTIVE,
} downmix_state_t;

/* parameters for each downmixer */
typedef struct {
    downmix_state_t state;
    downmix_type_t type;
    bool apply_volume_correction;
    uint8_t input_channel_count;
} downmix_object_t;


typedef struct downmix_module_s {
    const struct effect_interface_s *itfe;
    effect_config_t config;
    downmix_object_t context;
} downmix_module_t;


/*------------------------------------
 * Effect API
 *------------------------------------
*/
int32_t DownmixLib_QueryNumberEffects(uint32_t *pNumEffects);
int32_t DownmixLib_QueryEffect(uint32_t index,
        effect_descriptor_t *pDescriptor);
int32_t DownmixLib_Create(const effect_uuid_t *uuid,
        int32_t sessionId,
        int32_t ioId,
        effect_handle_t *pHandle);
int32_t DownmixLib_Release(effect_handle_t handle);
int32_t DownmixLib_GetDescriptor(const effect_uuid_t *uuid,
        effect_descriptor_t *pDescriptor);

static int Downmix_Process(effect_handle_t self,
        audio_buffer_t *inBuffer,
        audio_buffer_t *outBuffer);
static int Downmix_Command(effect_handle_t self,
        uint32_t cmdCode,
        uint32_t cmdSize,
        void *pCmdData,
        uint32_t *replySize,
        void *pReplyData);
static int Downmix_GetDescriptor(effect_handle_t self,
        effect_descriptor_t *pDescriptor);


/*------------------------------------
 * internal functions
 *------------------------------------
*/
int Downmix_Init(downmix_module_t *pDwmModule);
int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bool init);
int Downmix_Reset(downmix_object_t *pDownmixer, bool init);
int Downmix_setParameter(downmix_object_t *pDownmixer, int32_t param, size_t size, void *pValue);
int Downmix_getParameter(downmix_object_t *pDownmixer, int32_t param, size_t *pSize, void *pValue);

void Downmix_foldFromQuad(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
void Downmix_foldFromSurround(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
void Downmix_foldFrom5Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);
void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate);

#endif /*ANDROID_EFFECTDOWNMIX_H_*/