Loading media/libaudioprocessing/AudioMixer.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,24 @@ status_t AudioMixer::Track::prepareForDownmix() // mDownmixerBufferProvider reset below. } // See if we should use our built-in non-effect downmixer. if (mMixerInFormat == AUDIO_FORMAT_PCM_FLOAT && mMixerChannelMask == AUDIO_CHANNEL_OUT_STEREO && audio_channel_mask_get_representation(channelMask) == AUDIO_CHANNEL_REPRESENTATION_POSITION) { mDownmixerBufferProvider.reset(new ChannelMixBufferProvider(channelMask, mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount)); if (static_cast<ChannelMixBufferProvider *>(mDownmixerBufferProvider.get()) ->isValid()) { mDownmixRequiresFormat = mMixerInFormat; reconfigureBufferProviders(); ALOGD("%s: Fallback using ChannelMix", __func__); return NO_ERROR; } else { ALOGD("%s: ChannelMix not supported for channel mask %#x", __func__, channelMask); } } // Effect downmixer does not accept the channel conversion. Let's use our remixer. mDownmixerBufferProvider.reset(new RemixBufferProvider(channelMask, mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount)); Loading media/libaudioprocessing/BufferProviders.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -364,6 +364,29 @@ void RemixBufferProvider::copyFrames(void *dst, const void *src, size_t frames) src, mInputChannels, mIdxAry, mSampleSize, frames); } ChannelMixBufferProvider::ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask, audio_channel_mask_t outputChannelMask, audio_format_t format, size_t bufferFrameCount) : CopyBufferProvider( audio_bytes_per_sample(format) * audio_channel_count_from_out_mask(inputChannelMask), audio_bytes_per_sample(format) * audio_channel_count_from_out_mask(outputChannelMask), bufferFrameCount) { ALOGV("ChannelMixBufferProvider(%p)(%#x, %#x, %#x)", this, format, inputChannelMask, outputChannelMask); if (outputChannelMask == AUDIO_CHANNEL_OUT_STEREO && format == AUDIO_FORMAT_PCM_FLOAT) { mIsValid = mChannelMix.setInputChannelMask(inputChannelMask); } } void ChannelMixBufferProvider::copyFrames(void *dst, const void *src, size_t frames) { mChannelMix.process(static_cast<const float *>(src), static_cast<float *>(dst), frames, false /* accumulate */); } ReformatBufferProvider::ReformatBufferProvider(int32_t channelCount, audio_format_t inputFormat, audio_format_t outputFormat, size_t bufferFrameCount) : Loading media/libaudioprocessing/include/media/BufferProviders.h +18 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <stdint.h> #include <sys/types.h> #include <audio_utils/ChannelMix.h> #include <media/AudioBufferProvider.h> #include <media/AudioResamplerPublic.h> #include <system/audio.h> Loading Loading @@ -129,6 +130,23 @@ protected: static const int32_t SESSION_ID_INVALID_AND_IGNORED = -2; }; // ChannelMixBufferProvider derives from CopyBufferProvider to perform an // downmix to the proper channel count and mask. class ChannelMixBufferProvider : public CopyBufferProvider { public: ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask, audio_channel_mask_t outputChannelMask, audio_format_t format, size_t bufferFrameCount); void copyFrames(void *dst, const void *src, size_t frames) override; bool isValid() const { return mIsValid; } protected: audio_utils::channels::ChannelMix mChannelMix; bool mIsValid = false; }; // RemixBufferProvider derives from CopyBufferProvider to perform an // upmix or downmix to the proper channel count and mask. class RemixBufferProvider : public CopyBufferProvider { Loading Loading
media/libaudioprocessing/AudioMixer.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -193,6 +193,24 @@ status_t AudioMixer::Track::prepareForDownmix() // mDownmixerBufferProvider reset below. } // See if we should use our built-in non-effect downmixer. if (mMixerInFormat == AUDIO_FORMAT_PCM_FLOAT && mMixerChannelMask == AUDIO_CHANNEL_OUT_STEREO && audio_channel_mask_get_representation(channelMask) == AUDIO_CHANNEL_REPRESENTATION_POSITION) { mDownmixerBufferProvider.reset(new ChannelMixBufferProvider(channelMask, mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount)); if (static_cast<ChannelMixBufferProvider *>(mDownmixerBufferProvider.get()) ->isValid()) { mDownmixRequiresFormat = mMixerInFormat; reconfigureBufferProviders(); ALOGD("%s: Fallback using ChannelMix", __func__); return NO_ERROR; } else { ALOGD("%s: ChannelMix not supported for channel mask %#x", __func__, channelMask); } } // Effect downmixer does not accept the channel conversion. Let's use our remixer. mDownmixerBufferProvider.reset(new RemixBufferProvider(channelMask, mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount)); Loading
media/libaudioprocessing/BufferProviders.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -364,6 +364,29 @@ void RemixBufferProvider::copyFrames(void *dst, const void *src, size_t frames) src, mInputChannels, mIdxAry, mSampleSize, frames); } ChannelMixBufferProvider::ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask, audio_channel_mask_t outputChannelMask, audio_format_t format, size_t bufferFrameCount) : CopyBufferProvider( audio_bytes_per_sample(format) * audio_channel_count_from_out_mask(inputChannelMask), audio_bytes_per_sample(format) * audio_channel_count_from_out_mask(outputChannelMask), bufferFrameCount) { ALOGV("ChannelMixBufferProvider(%p)(%#x, %#x, %#x)", this, format, inputChannelMask, outputChannelMask); if (outputChannelMask == AUDIO_CHANNEL_OUT_STEREO && format == AUDIO_FORMAT_PCM_FLOAT) { mIsValid = mChannelMix.setInputChannelMask(inputChannelMask); } } void ChannelMixBufferProvider::copyFrames(void *dst, const void *src, size_t frames) { mChannelMix.process(static_cast<const float *>(src), static_cast<float *>(dst), frames, false /* accumulate */); } ReformatBufferProvider::ReformatBufferProvider(int32_t channelCount, audio_format_t inputFormat, audio_format_t outputFormat, size_t bufferFrameCount) : Loading
media/libaudioprocessing/include/media/BufferProviders.h +18 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <stdint.h> #include <sys/types.h> #include <audio_utils/ChannelMix.h> #include <media/AudioBufferProvider.h> #include <media/AudioResamplerPublic.h> #include <system/audio.h> Loading Loading @@ -129,6 +130,23 @@ protected: static const int32_t SESSION_ID_INVALID_AND_IGNORED = -2; }; // ChannelMixBufferProvider derives from CopyBufferProvider to perform an // downmix to the proper channel count and mask. class ChannelMixBufferProvider : public CopyBufferProvider { public: ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask, audio_channel_mask_t outputChannelMask, audio_format_t format, size_t bufferFrameCount); void copyFrames(void *dst, const void *src, size_t frames) override; bool isValid() const { return mIsValid; } protected: audio_utils::channels::ChannelMix mChannelMix; bool mIsValid = false; }; // RemixBufferProvider derives from CopyBufferProvider to perform an // upmix or downmix to the proper channel count and mask. class RemixBufferProvider : public CopyBufferProvider { Loading