Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "AudioMixer" |
Glenn Kasten | 7f5d335 | 2013-02-15 23:55:04 +0000 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <stdlib.h> |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 24 | #include <math.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | |
| 27 | #include <utils/Errors.h> |
| 28 | #include <utils/Log.h> |
| 29 | |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 30 | #include <cutils/compiler.h> |
Glenn Kasten | 5798d4e | 2012-03-08 12:18:35 -0800 | [diff] [blame] | 31 | #include <utils/Debug.h> |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 32 | |
| 33 | #include <system/audio.h> |
| 34 | |
Glenn Kasten | 3b21c50 | 2011-12-15 09:52:39 -0800 | [diff] [blame] | 35 | #include <audio_utils/primitives.h> |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 36 | #include <audio_utils/format.h> |
Andy Hung | 068561c | 2017-01-03 17:09:32 -0800 | [diff] [blame] | 37 | #include <media/AudioMixer.h> |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 38 | |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 39 | #include "AudioMixerOps.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 40 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 41 | // The FCC_2 macro refers to the Fixed Channel Count of 2 for the legacy integer mixer. |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 42 | #ifndef FCC_2 |
| 43 | #define FCC_2 2 |
| 44 | #endif |
| 45 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 46 | // Look for MONO_HACK for any Mono hack involving legacy mono channel to |
| 47 | // stereo channel conversion. |
| 48 | |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 49 | /* VERY_VERY_VERBOSE_LOGGING will show exactly which process hook and track hook is |
| 50 | * being used. This is a considerable amount of log spam, so don't enable unless you |
| 51 | * are verifying the hook based code. |
| 52 | */ |
| 53 | //#define VERY_VERY_VERBOSE_LOGGING |
| 54 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 55 | #define ALOGVV ALOGV |
| 56 | //define ALOGVV printf // for test-mixer.cpp |
| 57 | #else |
| 58 | #define ALOGVV(a...) do { } while (0) |
| 59 | #endif |
| 60 | |
Andy Hung | a08810b | 2014-07-16 21:53:43 -0700 | [diff] [blame] | 61 | #ifndef ARRAY_SIZE |
| 62 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) |
| 63 | #endif |
| 64 | |
Andy Hung | 5b8fde7 | 2014-09-02 21:14:34 -0700 | [diff] [blame] | 65 | // Set kUseNewMixer to true to use the new mixer engine always. Otherwise the |
| 66 | // original code will be used for stereo sinks, the new mixer for multichannel. |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 67 | static constexpr bool kUseNewMixer = true; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 68 | |
| 69 | // Set kUseFloat to true to allow floating input into the mixer engine. |
| 70 | // If kUseNewMixer is false, this is ignored or may be overridden internally |
| 71 | // because of downmix/upmix support. |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 72 | static constexpr bool kUseFloat = true; |
| 73 | |
| 74 | #ifdef FLOAT_AUX |
| 75 | using TYPE_AUX = float; |
| 76 | static_assert(kUseNewMixer && kUseFloat, |
| 77 | "kUseNewMixer and kUseFloat must be true for FLOAT_AUX option"); |
| 78 | #else |
| 79 | using TYPE_AUX = int32_t; // q4.27 |
| 80 | #endif |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 81 | |
Andy Hung | 1b2fdcb | 2014-07-16 17:44:34 -0700 | [diff] [blame] | 82 | // Set to default copy buffer size in frames for input processing. |
| 83 | static const size_t kCopyBufferFrameCount = 256; |
| 84 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 85 | namespace android { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 86 | |
| 87 | // ---------------------------------------------------------------------------- |
Andy Hung | 1b2fdcb | 2014-07-16 17:44:34 -0700 | [diff] [blame] | 88 | |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 89 | static inline audio_format_t selectMixerInFormat(audio_format_t inputFormat __unused) { |
| 90 | return kUseFloat && kUseNewMixer ? AUDIO_FORMAT_PCM_FLOAT : AUDIO_FORMAT_PCM_16_BIT; |
| 91 | } |
| 92 | |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 93 | status_t AudioMixer::create( |
| 94 | int name, audio_channel_mask_t channelMask, audio_format_t format, int sessionId) |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 95 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 96 | LOG_ALWAYS_FATAL_IF(exists(name), "name %d already exists", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 97 | |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 98 | if (!isValidChannelMask(channelMask)) { |
| 99 | ALOGE("%s invalid channelMask: %#x", __func__, channelMask); |
| 100 | return BAD_VALUE; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 101 | } |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 102 | if (!isValidFormat(format)) { |
| 103 | ALOGE("%s invalid format: %#x", __func__, format); |
| 104 | return BAD_VALUE; |
| 105 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 106 | |
| 107 | auto t = std::make_shared<Track>(); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 108 | { |
| 109 | // TODO: move initialization to the Track constructor. |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 110 | // assume default parameters for the track, except where noted below |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 111 | t->needs = 0; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 112 | |
| 113 | // Integer volume. |
| 114 | // Currently integer volume is kept for the legacy integer mixer. |
| 115 | // Will be removed when the legacy mixer path is removed. |
Andy Hung | 97ae824 | 2014-05-30 10:35:47 -0700 | [diff] [blame] | 116 | t->volume[0] = UNITY_GAIN_INT; |
| 117 | t->volume[1] = UNITY_GAIN_INT; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 118 | t->prevVolume[0] = UNITY_GAIN_INT << 16; |
| 119 | t->prevVolume[1] = UNITY_GAIN_INT << 16; |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 120 | t->volumeInc[0] = 0; |
| 121 | t->volumeInc[1] = 0; |
| 122 | t->auxLevel = 0; |
| 123 | t->auxInc = 0; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 124 | t->prevAuxLevel = 0; |
| 125 | |
| 126 | // Floating point volume. |
| 127 | t->mVolume[0] = UNITY_GAIN_FLOAT; |
| 128 | t->mVolume[1] = UNITY_GAIN_FLOAT; |
| 129 | t->mPrevVolume[0] = UNITY_GAIN_FLOAT; |
| 130 | t->mPrevVolume[1] = UNITY_GAIN_FLOAT; |
| 131 | t->mVolumeInc[0] = 0.; |
| 132 | t->mVolumeInc[1] = 0.; |
| 133 | t->mAuxLevel = 0.; |
| 134 | t->mAuxInc = 0.; |
| 135 | t->mPrevAuxLevel = 0.; |
| 136 | |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 137 | // no initialization needed |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 138 | // t->frameCount |
Andy Hung | 68112fc | 2014-05-14 14:13:23 -0700 | [diff] [blame] | 139 | t->channelCount = audio_channel_count_from_out_mask(channelMask); |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 140 | t->enabled = false; |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 141 | ALOGV_IF(audio_channel_mask_get_bits(channelMask) != AUDIO_CHANNEL_OUT_STEREO, |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 142 | "Non-stereo channel mask: %d\n", channelMask); |
Andy Hung | 68112fc | 2014-05-14 14:13:23 -0700 | [diff] [blame] | 143 | t->channelMask = channelMask; |
Jean-Michel Trivi | d06e132 | 2012-09-12 15:47:07 -0700 | [diff] [blame] | 144 | t->sessionId = sessionId; |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 145 | // setBufferProvider(name, AudioBufferProvider *) is required before enable(name) |
| 146 | t->bufferProvider = NULL; |
| 147 | t->buffer.raw = NULL; |
| 148 | // no initialization needed |
| 149 | // t->buffer.frameCount |
| 150 | t->hook = NULL; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 151 | t->mIn = NULL; |
Glenn Kasten | deeb128 | 2012-03-25 11:59:31 -0700 | [diff] [blame] | 152 | t->sampleRate = mSampleRate; |
| 153 | // setParameter(name, TRACK, MAIN_BUFFER, mixBuffer) is required before enable(name) |
| 154 | t->mainBuffer = NULL; |
| 155 | t->auxBuffer = NULL; |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 156 | t->mInputBufferProvider = NULL; |
Andy Hung | 7882070 | 2014-02-28 16:23:02 -0800 | [diff] [blame] | 157 | t->mMixerFormat = AUDIO_FORMAT_PCM_16_BIT; |
Andy Hung | e8a1ced | 2014-05-09 15:02:21 -0700 | [diff] [blame] | 158 | t->mFormat = format; |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 159 | t->mMixerInFormat = selectMixerInFormat(format); |
| 160 | t->mDownmixRequiresFormat = AUDIO_FORMAT_INVALID; // no format required |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 161 | t->mMixerChannelMask = audio_channel_mask_from_representation_and_bits( |
| 162 | AUDIO_CHANNEL_REPRESENTATION_POSITION, AUDIO_CHANNEL_OUT_STEREO); |
| 163 | t->mMixerChannelCount = audio_channel_count_from_out_mask(t->mMixerChannelMask); |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 164 | t->mPlaybackRate = AUDIO_PLAYBACK_RATE_DEFAULT; |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 165 | // haptic |
| 166 | t->mAdjustInChannelCount = 0; |
| 167 | t->mAdjustOutChannelCount = 0; |
| 168 | t->mAdjustNonDestructiveInChannelCount = 0; |
| 169 | t->mAdjustNonDestructiveOutChannelCount = 0; |
| 170 | t->mKeepContractedChannels = false; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 171 | // Check the downmixing (or upmixing) requirements. |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 172 | status_t status = t->prepareForDownmix(); |
Andy Hung | 68112fc | 2014-05-14 14:13:23 -0700 | [diff] [blame] | 173 | if (status != OK) { |
| 174 | ALOGE("AudioMixer::getTrackName invalid channelMask (%#x)", channelMask); |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 175 | return BAD_VALUE; |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 176 | } |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 177 | // prepareForDownmix() may change mDownmixRequiresFormat |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 178 | ALOGVV("mMixerFormat:%#x mMixerInFormat:%#x\n", t->mMixerFormat, t->mMixerInFormat); |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 179 | t->prepareForReformat(); |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 180 | t->prepareForAdjustChannelsNonDestructive(mFrameCount); |
| 181 | t->prepareForAdjustChannels(); |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 182 | |
| 183 | mTracks[name] = t; |
| 184 | return OK; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 185 | } |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 186 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 187 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 188 | // Called when channel masks have changed for a track name |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 189 | // TODO: Fix DownmixerBufferProvider not to (possibly) change mixer input format, |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 190 | // which will simplify this logic. |
| 191 | bool AudioMixer::setChannelMasks(int name, |
| 192 | audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask) { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 193 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 194 | const std::shared_ptr<Track> &track = mTracks[name]; |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 195 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 196 | if (trackChannelMask == track->channelMask |
| 197 | && mixerChannelMask == track->mMixerChannelMask) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 198 | return false; // no need to change |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 199 | } |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 200 | // always recompute for both channel masks even if only one has changed. |
| 201 | const uint32_t trackChannelCount = audio_channel_count_from_out_mask(trackChannelMask); |
| 202 | const uint32_t mixerChannelCount = audio_channel_count_from_out_mask(mixerChannelMask); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 203 | |
| 204 | ALOG_ASSERT((trackChannelCount <= MAX_NUM_CHANNELS_TO_DOWNMIX) |
| 205 | && trackChannelCount |
| 206 | && mixerChannelCount); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 207 | track->channelMask = trackChannelMask; |
| 208 | track->channelCount = trackChannelCount; |
| 209 | track->mMixerChannelMask = mixerChannelMask; |
| 210 | track->mMixerChannelCount = mixerChannelCount; |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 211 | |
| 212 | // channel masks have changed, does this track need a downmixer? |
| 213 | // update to try using our desired format (if we aren't already using it) |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 214 | const status_t status = track->prepareForDownmix(); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 215 | ALOGE_IF(status != OK, |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 216 | "prepareForDownmix error %d, track channel mask %#x, mixer channel mask %#x", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 217 | status, track->channelMask, track->mMixerChannelMask); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 218 | |
Yung Ti Su | 1a0ecc3 | 2018-05-07 11:09:15 +0800 | [diff] [blame] | 219 | // always do reformat since channel mask changed, |
| 220 | // do it after downmix since track format may change! |
| 221 | track->prepareForReformat(); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 222 | |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 223 | track->prepareForAdjustChannelsNonDestructive(mFrameCount); |
| 224 | track->prepareForAdjustChannels(); |
| 225 | |
Yung Ti Su | b5d1195 | 2018-05-22 22:31:14 +0800 | [diff] [blame] | 226 | if (track->mResampler.get() != nullptr) { |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 227 | // resampler channels may have changed. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 228 | const uint32_t resetToSampleRate = track->sampleRate; |
| 229 | track->mResampler.reset(nullptr); |
| 230 | track->sampleRate = mSampleRate; // without resampler, track rate is device sample rate. |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 231 | // recreate the resampler with updated format, channels, saved sampleRate. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 232 | track->setResampler(resetToSampleRate /*trackSampleRate*/, mSampleRate /*devSampleRate*/); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 233 | } |
| 234 | return true; |
| 235 | } |
| 236 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 237 | void AudioMixer::Track::unprepareForDownmix() { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 238 | ALOGV("AudioMixer::unprepareForDownmix(%p)", this); |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 239 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 240 | if (mPostDownmixReformatBufferProvider.get() != nullptr) { |
Andy Hung | 8539589 | 2017-04-25 16:47:52 -0700 | [diff] [blame] | 241 | // release any buffers held by the mPostDownmixReformatBufferProvider |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 242 | // before deallocating the mDownmixerBufferProvider. |
Andy Hung | 8539589 | 2017-04-25 16:47:52 -0700 | [diff] [blame] | 243 | mPostDownmixReformatBufferProvider->reset(); |
| 244 | } |
| 245 | |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 246 | mDownmixRequiresFormat = AUDIO_FORMAT_INVALID; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 247 | if (mDownmixerBufferProvider.get() != nullptr) { |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 248 | // this track had previously been configured with a downmixer, delete it |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 249 | mDownmixerBufferProvider.reset(nullptr); |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 250 | reconfigureBufferProviders(); |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 251 | } else { |
| 252 | ALOGV(" nothing to do, no downmixer to delete"); |
| 253 | } |
| 254 | } |
| 255 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 256 | status_t AudioMixer::Track::prepareForDownmix() |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 257 | { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 258 | ALOGV("AudioMixer::prepareForDownmix(%p) with mask 0x%x", |
| 259 | this, channelMask); |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 260 | |
Jean-Michel Trivi | 9bd2322 | 2012-04-16 13:43:48 -0700 | [diff] [blame] | 261 | // discard the previous downmixer if there was one |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 262 | unprepareForDownmix(); |
Andy Hung | 73e62e2 | 2015-04-20 12:06:38 -0700 | [diff] [blame] | 263 | // MONO_HACK Only remix (upmix or downmix) if the track and mixer/device channel masks |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 264 | // are not the same and not handled internally, as mono -> stereo currently is. |
| 265 | if (channelMask == mMixerChannelMask |
| 266 | || (channelMask == AUDIO_CHANNEL_OUT_MONO |
| 267 | && mMixerChannelMask == AUDIO_CHANNEL_OUT_STEREO)) { |
| 268 | return NO_ERROR; |
| 269 | } |
Andy Hung | 650ceb9 | 2015-01-29 13:31:12 -0800 | [diff] [blame] | 270 | // DownmixerBufferProvider is only used for position masks. |
| 271 | if (audio_channel_mask_get_representation(channelMask) |
| 272 | == AUDIO_CHANNEL_REPRESENTATION_POSITION |
| 273 | && DownmixerBufferProvider::isMultichannelCapable()) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 274 | mDownmixerBufferProvider.reset(new DownmixerBufferProvider(channelMask, |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 275 | mMixerChannelMask, |
| 276 | AUDIO_FORMAT_PCM_16_BIT /* TODO: use mMixerInFormat, now only PCM 16 */, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 277 | sampleRate, sessionId, kCopyBufferFrameCount)); |
| 278 | if (static_cast<DownmixerBufferProvider *>(mDownmixerBufferProvider.get())->isValid()) { |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 279 | mDownmixRequiresFormat = AUDIO_FORMAT_PCM_16_BIT; // PCM 16 bit required for downmix |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 280 | reconfigureBufferProviders(); |
Andy Hung | 34803d5 | 2014-07-16 21:41:35 -0700 | [diff] [blame] | 281 | return NO_ERROR; |
| 282 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 283 | // mDownmixerBufferProvider reset below. |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 284 | } |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 285 | |
| 286 | // Effect downmixer does not accept the channel conversion. Let's use our remixer. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 287 | mDownmixerBufferProvider.reset(new RemixBufferProvider(channelMask, |
| 288 | mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount)); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 289 | // Remix always finds a conversion whereas Downmixer effect above may fail. |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 290 | reconfigureBufferProviders(); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 291 | return NO_ERROR; |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 294 | void AudioMixer::Track::unprepareForReformat() { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 295 | ALOGV("AudioMixer::unprepareForReformat(%p)", this); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 296 | bool requiresReconfigure = false; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 297 | if (mReformatBufferProvider.get() != nullptr) { |
| 298 | mReformatBufferProvider.reset(nullptr); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 299 | requiresReconfigure = true; |
| 300 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 301 | if (mPostDownmixReformatBufferProvider.get() != nullptr) { |
| 302 | mPostDownmixReformatBufferProvider.reset(nullptr); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 303 | requiresReconfigure = true; |
| 304 | } |
| 305 | if (requiresReconfigure) { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 306 | reconfigureBufferProviders(); |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 310 | status_t AudioMixer::Track::prepareForReformat() |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 311 | { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 312 | ALOGV("AudioMixer::prepareForReformat(%p) with format %#x", this, mFormat); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 313 | // discard previous reformatters |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 314 | unprepareForReformat(); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 315 | // only configure reformatters as needed |
| 316 | const audio_format_t targetFormat = mDownmixRequiresFormat != AUDIO_FORMAT_INVALID |
| 317 | ? mDownmixRequiresFormat : mMixerInFormat; |
| 318 | bool requiresReconfigure = false; |
| 319 | if (mFormat != targetFormat) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 320 | mReformatBufferProvider.reset(new ReformatBufferProvider( |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 321 | audio_channel_count_from_out_mask(channelMask), |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 322 | mFormat, |
| 323 | targetFormat, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 324 | kCopyBufferFrameCount)); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 325 | requiresReconfigure = true; |
Kevin Rocard | e053bfa | 2017-11-09 22:07:34 -0800 | [diff] [blame] | 326 | } else if (mFormat == AUDIO_FORMAT_PCM_FLOAT) { |
| 327 | // Input and output are floats, make sure application did not provide > 3db samples |
| 328 | // that would break volume application (b/68099072) |
| 329 | // TODO: add a trusted source flag to avoid the overhead |
| 330 | mReformatBufferProvider.reset(new ClampFloatBufferProvider( |
| 331 | audio_channel_count_from_out_mask(channelMask), |
| 332 | kCopyBufferFrameCount)); |
| 333 | requiresReconfigure = true; |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 334 | } |
| 335 | if (targetFormat != mMixerInFormat) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 336 | mPostDownmixReformatBufferProvider.reset(new ReformatBufferProvider( |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 337 | audio_channel_count_from_out_mask(mMixerChannelMask), |
| 338 | targetFormat, |
| 339 | mMixerInFormat, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 340 | kCopyBufferFrameCount)); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 341 | requiresReconfigure = true; |
| 342 | } |
| 343 | if (requiresReconfigure) { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 344 | reconfigureBufferProviders(); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 345 | } |
| 346 | return NO_ERROR; |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 347 | } |
| 348 | |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 349 | void AudioMixer::Track::unprepareForAdjustChannels() |
| 350 | { |
| 351 | ALOGV("AUDIOMIXER::unprepareForAdjustChannels"); |
| 352 | if (mAdjustChannelsBufferProvider.get() != nullptr) { |
| 353 | mAdjustChannelsBufferProvider.reset(nullptr); |
| 354 | reconfigureBufferProviders(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | status_t AudioMixer::Track::prepareForAdjustChannels() |
| 359 | { |
| 360 | ALOGV("AudioMixer::prepareForAdjustChannels(%p) with inChannelCount: %u, outChannelCount: %u", |
| 361 | this, mAdjustInChannelCount, mAdjustOutChannelCount); |
| 362 | unprepareForAdjustChannels(); |
| 363 | if (mAdjustInChannelCount != mAdjustOutChannelCount) { |
| 364 | mAdjustChannelsBufferProvider.reset(new AdjustChannelsBufferProvider( |
| 365 | mFormat, mAdjustInChannelCount, mAdjustOutChannelCount, kCopyBufferFrameCount)); |
| 366 | reconfigureBufferProviders(); |
| 367 | } |
| 368 | return NO_ERROR; |
| 369 | } |
| 370 | |
| 371 | void AudioMixer::Track::unprepareForAdjustChannelsNonDestructive() |
| 372 | { |
| 373 | ALOGV("AUDIOMIXER::unprepareForAdjustChannelsNonDestructive"); |
| 374 | if (mAdjustChannelsNonDestructiveBufferProvider.get() != nullptr) { |
| 375 | mAdjustChannelsNonDestructiveBufferProvider.reset(nullptr); |
| 376 | reconfigureBufferProviders(); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | status_t AudioMixer::Track::prepareForAdjustChannelsNonDestructive(size_t frames) |
| 381 | { |
| 382 | ALOGV("AudioMixer::prepareForAdjustChannelsNonDestructive(%p) with inChannelCount: %u, " |
| 383 | "outChannelCount: %u, keepContractedChannels: %d", |
| 384 | this, mAdjustNonDestructiveInChannelCount, mAdjustNonDestructiveOutChannelCount, |
| 385 | mKeepContractedChannels); |
| 386 | unprepareForAdjustChannelsNonDestructive(); |
| 387 | if (mAdjustNonDestructiveInChannelCount != mAdjustNonDestructiveOutChannelCount) { |
| 388 | uint8_t* buffer = mKeepContractedChannels |
| 389 | ? (uint8_t*)mainBuffer + frames * audio_bytes_per_frame( |
| 390 | mMixerChannelCount, mMixerFormat) |
| 391 | : NULL; |
| 392 | mAdjustChannelsNonDestructiveBufferProvider.reset( |
| 393 | new AdjustChannelsNonDestructiveBufferProvider( |
| 394 | mFormat, |
| 395 | mAdjustNonDestructiveInChannelCount, |
| 396 | mAdjustNonDestructiveOutChannelCount, |
| 397 | mKeepContractedChannels ? mMixerFormat : AUDIO_FORMAT_INVALID, |
| 398 | frames, |
| 399 | buffer)); |
| 400 | reconfigureBufferProviders(); |
| 401 | } |
| 402 | return NO_ERROR; |
| 403 | } |
| 404 | |
| 405 | void AudioMixer::Track::clearContractedBuffer() |
| 406 | { |
| 407 | if (mAdjustChannelsNonDestructiveBufferProvider.get() != nullptr) { |
| 408 | static_cast<AdjustChannelsNonDestructiveBufferProvider*>( |
| 409 | mAdjustChannelsNonDestructiveBufferProvider.get())->clearContractedFrames(); |
| 410 | } |
| 411 | } |
| 412 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 413 | void AudioMixer::Track::reconfigureBufferProviders() |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 414 | { |
Andy Hung | 3a34df9 | 2018-08-21 12:32:30 -0700 | [diff] [blame] | 415 | // configure from upstream to downstream buffer providers. |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 416 | bufferProvider = mInputBufferProvider; |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 417 | if (mAdjustChannelsBufferProvider.get() != nullptr) { |
| 418 | mAdjustChannelsBufferProvider->setBufferProvider(bufferProvider); |
| 419 | bufferProvider = mAdjustChannelsBufferProvider.get(); |
| 420 | } |
| 421 | if (mAdjustChannelsNonDestructiveBufferProvider.get() != nullptr) { |
| 422 | mAdjustChannelsNonDestructiveBufferProvider->setBufferProvider(bufferProvider); |
| 423 | bufferProvider = mAdjustChannelsNonDestructiveBufferProvider.get(); |
| 424 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 425 | if (mReformatBufferProvider.get() != nullptr) { |
Andy Hung | 0f451e9 | 2014-08-04 21:28:47 -0700 | [diff] [blame] | 426 | mReformatBufferProvider->setBufferProvider(bufferProvider); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 427 | bufferProvider = mReformatBufferProvider.get(); |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 428 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 429 | if (mDownmixerBufferProvider.get() != nullptr) { |
| 430 | mDownmixerBufferProvider->setBufferProvider(bufferProvider); |
| 431 | bufferProvider = mDownmixerBufferProvider.get(); |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 432 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 433 | if (mPostDownmixReformatBufferProvider.get() != nullptr) { |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 434 | mPostDownmixReformatBufferProvider->setBufferProvider(bufferProvider); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 435 | bufferProvider = mPostDownmixReformatBufferProvider.get(); |
Andy Hung | 7f47549 | 2014-08-25 16:36:37 -0700 | [diff] [blame] | 436 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 437 | if (mTimestretchBufferProvider.get() != nullptr) { |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 438 | mTimestretchBufferProvider->setBufferProvider(bufferProvider); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 439 | bufferProvider = mTimestretchBufferProvider.get(); |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 440 | } |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 443 | void AudioMixer::destroy(int name) |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 444 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 445 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Glenn Kasten | 237a624 | 2011-12-15 15:32:27 -0800 | [diff] [blame] | 446 | ALOGV("deleteTrackName(%d)", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 447 | |
| 448 | if (mTracks[name]->enabled) { |
| 449 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 450 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 451 | mTracks.erase(name); // deallocate track |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 452 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 453 | |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 454 | void AudioMixer::enable(int name) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 455 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 456 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 457 | const std::shared_ptr<Track> &track = mTracks[name]; |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 458 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 459 | if (!track->enabled) { |
| 460 | track->enabled = true; |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 461 | ALOGV("enable(%d)", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 462 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 463 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 466 | void AudioMixer::disable(int name) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 467 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 468 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 469 | const std::shared_ptr<Track> &track = mTracks[name]; |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 470 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 471 | if (track->enabled) { |
| 472 | track->enabled = false; |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 473 | ALOGV("disable(%d)", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 474 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 475 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 478 | /* Sets the volume ramp variables for the AudioMixer. |
| 479 | * |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 480 | * The volume ramp variables are used to transition from the previous |
| 481 | * volume to the set volume. ramp controls the duration of the transition. |
| 482 | * Its value is typically one state framecount period, but may also be 0, |
| 483 | * meaning "immediate." |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 484 | * |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 485 | * FIXME: 1) Volume ramp is enabled only if there is a nonzero integer increment |
| 486 | * even if there is a nonzero floating point increment (in that case, the volume |
| 487 | * change is immediate). This restriction should be changed when the legacy mixer |
| 488 | * is removed (see #2). |
| 489 | * FIXME: 2) Integer volume variables are used for Legacy mixing and should be removed |
| 490 | * when no longer needed. |
| 491 | * |
| 492 | * @param newVolume set volume target in floating point [0.0, 1.0]. |
| 493 | * @param ramp number of frames to increment over. if ramp is 0, the volume |
| 494 | * should be set immediately. Currently ramp should not exceed 65535 (frames). |
| 495 | * @param pIntSetVolume pointer to the U4.12 integer target volume, set on return. |
| 496 | * @param pIntPrevVolume pointer to the U4.28 integer previous volume, set on return. |
| 497 | * @param pIntVolumeInc pointer to the U4.28 increment per output audio frame, set on return. |
| 498 | * @param pSetVolume pointer to the float target volume, set on return. |
| 499 | * @param pPrevVolume pointer to the float previous volume, set on return. |
| 500 | * @param pVolumeInc pointer to the float increment per output audio frame, set on return. |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 501 | * @return true if the volume has changed, false if volume is same. |
| 502 | */ |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 503 | static inline bool setVolumeRampVariables(float newVolume, int32_t ramp, |
| 504 | int16_t *pIntSetVolume, int32_t *pIntPrevVolume, int32_t *pIntVolumeInc, |
| 505 | float *pSetVolume, float *pPrevVolume, float *pVolumeInc) { |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 506 | // check floating point volume to see if it is identical to the previously |
| 507 | // set volume. |
| 508 | // We do not use a tolerance here (and reject changes too small) |
| 509 | // as it may be confusing to use a different value than the one set. |
| 510 | // If the resulting volume is too small to ramp, it is a direct set of the volume. |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 511 | if (newVolume == *pSetVolume) { |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 512 | return false; |
| 513 | } |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 514 | if (newVolume < 0) { |
| 515 | newVolume = 0; // should not have negative volumes |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 516 | } else { |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 517 | switch (fpclassify(newVolume)) { |
| 518 | case FP_SUBNORMAL: |
| 519 | case FP_NAN: |
| 520 | newVolume = 0; |
| 521 | break; |
| 522 | case FP_ZERO: |
| 523 | break; // zero volume is fine |
| 524 | case FP_INFINITE: |
| 525 | // Infinite volume could be handled consistently since |
| 526 | // floating point math saturates at infinities, |
| 527 | // but we limit volume to unity gain float. |
| 528 | // ramp = 0; break; |
| 529 | // |
| 530 | newVolume = AudioMixer::UNITY_GAIN_FLOAT; |
| 531 | break; |
| 532 | case FP_NORMAL: |
| 533 | default: |
| 534 | // Floating point does not have problems with overflow wrap |
| 535 | // that integer has. However, we limit the volume to |
| 536 | // unity gain here. |
| 537 | // TODO: Revisit the volume limitation and perhaps parameterize. |
| 538 | if (newVolume > AudioMixer::UNITY_GAIN_FLOAT) { |
| 539 | newVolume = AudioMixer::UNITY_GAIN_FLOAT; |
| 540 | } |
| 541 | break; |
| 542 | } |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 543 | } |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 544 | |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 545 | // set floating point volume ramp |
| 546 | if (ramp != 0) { |
| 547 | // when the ramp completes, *pPrevVolume is set to *pSetVolume, so there |
| 548 | // is no computational mismatch; hence equality is checked here. |
| 549 | ALOGD_IF(*pPrevVolume != *pSetVolume, "previous float ramp hasn't finished," |
| 550 | " prev:%f set_to:%f", *pPrevVolume, *pSetVolume); |
| 551 | const float inc = (newVolume - *pPrevVolume) / ramp; // could be inf, nan, subnormal |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 552 | // could be inf, cannot be nan, subnormal |
| 553 | const float maxv = std::max(newVolume, *pPrevVolume); |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 554 | |
| 555 | if (isnormal(inc) // inc must be a normal number (no subnormals, infinite, nan) |
| 556 | && maxv + inc != maxv) { // inc must make forward progress |
| 557 | *pVolumeInc = inc; |
| 558 | // ramp is set now. |
| 559 | // Note: if newVolume is 0, then near the end of the ramp, |
| 560 | // it may be possible that the ramped volume may be subnormal or |
| 561 | // temporarily negative by a small amount or subnormal due to floating |
| 562 | // point inaccuracies. |
| 563 | } else { |
| 564 | ramp = 0; // ramp not allowed |
| 565 | } |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 566 | } |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 567 | |
| 568 | // compute and check integer volume, no need to check negative values |
| 569 | // The integer volume is limited to "unity_gain" to avoid wrapping and other |
| 570 | // audio artifacts, so it never reaches the range limit of U4.28. |
| 571 | // We safely use signed 16 and 32 bit integers here. |
| 572 | const float scaledVolume = newVolume * AudioMixer::UNITY_GAIN_INT; // not neg, subnormal, nan |
| 573 | const int32_t intVolume = (scaledVolume >= (float)AudioMixer::UNITY_GAIN_INT) ? |
| 574 | AudioMixer::UNITY_GAIN_INT : (int32_t)scaledVolume; |
| 575 | |
| 576 | // set integer volume ramp |
| 577 | if (ramp != 0) { |
| 578 | // integer volume is U4.12 (to use 16 bit multiplies), but ramping uses U4.28. |
| 579 | // when the ramp completes, *pIntPrevVolume is set to *pIntSetVolume << 16, so there |
| 580 | // is no computational mismatch; hence equality is checked here. |
| 581 | ALOGD_IF(*pIntPrevVolume != *pIntSetVolume << 16, "previous int ramp hasn't finished," |
| 582 | " prev:%d set_to:%d", *pIntPrevVolume, *pIntSetVolume << 16); |
| 583 | const int32_t inc = ((intVolume << 16) - *pIntPrevVolume) / ramp; |
| 584 | |
| 585 | if (inc != 0) { // inc must make forward progress |
| 586 | *pIntVolumeInc = inc; |
| 587 | } else { |
| 588 | ramp = 0; // ramp not allowed |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | // if no ramp, or ramp not allowed, then clear float and integer increments |
| 593 | if (ramp == 0) { |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 594 | *pVolumeInc = 0; |
| 595 | *pPrevVolume = newVolume; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 596 | *pIntVolumeInc = 0; |
| 597 | *pIntPrevVolume = intVolume << 16; |
| 598 | } |
Andy Hung | e09c994 | 2015-05-08 16:58:13 -0700 | [diff] [blame] | 599 | *pSetVolume = newVolume; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 600 | *pIntSetVolume = intVolume; |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 601 | return true; |
| 602 | } |
| 603 | |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 604 | void AudioMixer::setParameter(int name, int target, int param, void *value) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 605 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 606 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 607 | const std::shared_ptr<Track> &track = mTracks[name]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 608 | |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 609 | int valueInt = static_cast<int>(reinterpret_cast<uintptr_t>(value)); |
| 610 | int32_t *valueBuf = reinterpret_cast<int32_t*>(value); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 611 | |
| 612 | switch (target) { |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 613 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 614 | case TRACK: |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 615 | switch (param) { |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 616 | case CHANNEL_MASK: { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 617 | const audio_channel_mask_t trackChannelMask = |
| 618 | static_cast<audio_channel_mask_t>(valueInt); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 619 | if (setChannelMasks(name, trackChannelMask, track->mMixerChannelMask)) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 620 | ALOGV("setParameter(TRACK, CHANNEL_MASK, %x)", trackChannelMask); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 621 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 622 | } |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 623 | } break; |
| 624 | case MAIN_BUFFER: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 625 | if (track->mainBuffer != valueBuf) { |
| 626 | track->mainBuffer = valueBuf; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 627 | ALOGV("setParameter(TRACK, MAIN_BUFFER, %p)", valueBuf); |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 628 | if (track->mKeepContractedChannels) { |
| 629 | track->prepareForAdjustChannelsNonDestructive(mFrameCount); |
| 630 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 631 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 632 | } |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 633 | break; |
| 634 | case AUX_BUFFER: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 635 | if (track->auxBuffer != valueBuf) { |
| 636 | track->auxBuffer = valueBuf; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 637 | ALOGV("setParameter(TRACK, AUX_BUFFER, %p)", valueBuf); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 638 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 639 | } |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 640 | break; |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 641 | case FORMAT: { |
| 642 | audio_format_t format = static_cast<audio_format_t>(valueInt); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 643 | if (track->mFormat != format) { |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 644 | ALOG_ASSERT(audio_is_linear_pcm(format), "Invalid format %#x", format); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 645 | track->mFormat = format; |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 646 | ALOGV("setParameter(TRACK, FORMAT, %#x)", format); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 647 | track->prepareForReformat(); |
| 648 | invalidate(); |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 649 | } |
| 650 | } break; |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 651 | // FIXME do we want to support setting the downmix type from AudioFlinger? |
| 652 | // for a specific track? or per mixer? |
| 653 | /* case DOWNMIX_TYPE: |
| 654 | break */ |
Andy Hung | 7882070 | 2014-02-28 16:23:02 -0800 | [diff] [blame] | 655 | case MIXER_FORMAT: { |
Andy Hung | a1ab7cc | 2014-02-24 19:26:52 -0800 | [diff] [blame] | 656 | audio_format_t format = static_cast<audio_format_t>(valueInt); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 657 | if (track->mMixerFormat != format) { |
| 658 | track->mMixerFormat = format; |
Andy Hung | 7882070 | 2014-02-28 16:23:02 -0800 | [diff] [blame] | 659 | ALOGV("setParameter(TRACK, MIXER_FORMAT, %#x)", format); |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 660 | if (track->mKeepContractedChannels) { |
| 661 | track->prepareForAdjustChannelsNonDestructive(mFrameCount); |
| 662 | } |
Andy Hung | a1ab7cc | 2014-02-24 19:26:52 -0800 | [diff] [blame] | 663 | } |
| 664 | } break; |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 665 | case MIXER_CHANNEL_MASK: { |
| 666 | const audio_channel_mask_t mixerChannelMask = |
| 667 | static_cast<audio_channel_mask_t>(valueInt); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 668 | if (setChannelMasks(name, track->channelMask, mixerChannelMask)) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 669 | ALOGV("setParameter(TRACK, MIXER_CHANNEL_MASK, %#x)", mixerChannelMask); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 670 | invalidate(); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 671 | } |
| 672 | } break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 673 | default: |
Glenn Kasten | adad3d7 | 2014-02-21 14:51:43 -0800 | [diff] [blame] | 674 | LOG_ALWAYS_FATAL("setParameter track: bad param %d", param); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 675 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 676 | break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 677 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 678 | case RESAMPLE: |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 679 | switch (param) { |
| 680 | case SAMPLE_RATE: |
Glenn Kasten | 5798d4e | 2012-03-08 12:18:35 -0800 | [diff] [blame] | 681 | ALOG_ASSERT(valueInt > 0, "bad sample rate %d", valueInt); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 682 | if (track->setResampler(uint32_t(valueInt), mSampleRate)) { |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 683 | ALOGV("setParameter(RESAMPLE, SAMPLE_RATE, %u)", |
| 684 | uint32_t(valueInt)); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 685 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 686 | } |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 687 | break; |
| 688 | case RESET: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 689 | track->resetResampler(); |
| 690 | invalidate(); |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 691 | break; |
Glenn Kasten | 4e2293f | 2012-04-12 09:39:07 -0700 | [diff] [blame] | 692 | case REMOVE: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 693 | track->mResampler.reset(nullptr); |
| 694 | track->sampleRate = mSampleRate; |
| 695 | invalidate(); |
Glenn Kasten | 4e2293f | 2012-04-12 09:39:07 -0700 | [diff] [blame] | 696 | break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 697 | default: |
Glenn Kasten | adad3d7 | 2014-02-21 14:51:43 -0800 | [diff] [blame] | 698 | LOG_ALWAYS_FATAL("setParameter resample: bad param %d", param); |
Eric Laurent | 243f5f9 | 2011-02-28 16:52:51 -0800 | [diff] [blame] | 699 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 700 | break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 701 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 702 | case RAMP_VOLUME: |
| 703 | case VOLUME: |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 704 | switch (param) { |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 705 | case AUXLEVEL: |
Andy Hung | 6be4940 | 2014-05-30 10:42:03 -0700 | [diff] [blame] | 706 | if (setVolumeRampVariables(*reinterpret_cast<float*>(value), |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 707 | target == RAMP_VOLUME ? mFrameCount : 0, |
| 708 | &track->auxLevel, &track->prevAuxLevel, &track->auxInc, |
| 709 | &track->mAuxLevel, &track->mPrevAuxLevel, &track->mAuxInc)) { |
Andy Hung | 5866a3b | 2014-05-29 21:33:13 -0700 | [diff] [blame] | 710 | ALOGV("setParameter(%s, AUXLEVEL: %04x)", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 711 | target == VOLUME ? "VOLUME" : "RAMP_VOLUME", track->auxLevel); |
| 712 | invalidate(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 713 | } |
Glenn Kasten | 9c56d4a | 2011-12-19 15:06:39 -0800 | [diff] [blame] | 714 | break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 715 | default: |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 716 | if ((unsigned)param >= VOLUME0 && (unsigned)param < VOLUME0 + MAX_NUM_VOLUMES) { |
| 717 | if (setVolumeRampVariables(*reinterpret_cast<float*>(value), |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 718 | target == RAMP_VOLUME ? mFrameCount : 0, |
| 719 | &track->volume[param - VOLUME0], |
| 720 | &track->prevVolume[param - VOLUME0], |
| 721 | &track->volumeInc[param - VOLUME0], |
| 722 | &track->mVolume[param - VOLUME0], |
| 723 | &track->mPrevVolume[param - VOLUME0], |
| 724 | &track->mVolumeInc[param - VOLUME0])) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 725 | ALOGV("setParameter(%s, VOLUME%d: %04x)", |
| 726 | target == VOLUME ? "VOLUME" : "RAMP_VOLUME", param - VOLUME0, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 727 | track->volume[param - VOLUME0]); |
| 728 | invalidate(); |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 729 | } |
| 730 | } else { |
| 731 | LOG_ALWAYS_FATAL("setParameter volume: bad param %d", param); |
| 732 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 733 | } |
| 734 | break; |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 735 | case TIMESTRETCH: |
| 736 | switch (param) { |
| 737 | case PLAYBACK_RATE: { |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 738 | const AudioPlaybackRate *playbackRate = |
| 739 | reinterpret_cast<AudioPlaybackRate*>(value); |
Ricardo Garcia | 6c7f062 | 2015-04-30 18:39:16 -0700 | [diff] [blame] | 740 | ALOGW_IF(!isAudioPlaybackRateValid(*playbackRate), |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 741 | "bad parameters speed %f, pitch %f", |
| 742 | playbackRate->mSpeed, playbackRate->mPitch); |
| 743 | if (track->setPlaybackRate(*playbackRate)) { |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 744 | ALOGV("setParameter(TIMESTRETCH, PLAYBACK_RATE, STRETCH_MODE, FALLBACK_MODE " |
| 745 | "%f %f %d %d", |
| 746 | playbackRate->mSpeed, |
| 747 | playbackRate->mPitch, |
| 748 | playbackRate->mStretchMode, |
| 749 | playbackRate->mFallbackMode); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 750 | // invalidate(); (should not require reconfigure) |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 751 | } |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 752 | } break; |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 753 | default: |
| 754 | LOG_ALWAYS_FATAL("setParameter timestretch: bad param %d", param); |
| 755 | } |
| 756 | break; |
Glenn Kasten | 788040c | 2011-05-05 08:19:00 -0700 | [diff] [blame] | 757 | |
| 758 | default: |
Glenn Kasten | adad3d7 | 2014-02-21 14:51:43 -0800 | [diff] [blame] | 759 | LOG_ALWAYS_FATAL("setParameter: bad target %d", target); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 760 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 763 | bool AudioMixer::Track::setResampler(uint32_t trackSampleRate, uint32_t devSampleRate) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 764 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 765 | if (trackSampleRate != devSampleRate || mResampler.get() != nullptr) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 766 | if (sampleRate != trackSampleRate) { |
| 767 | sampleRate = trackSampleRate; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 768 | if (mResampler.get() == nullptr) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 769 | ALOGV("Creating resampler from track %d Hz to device %d Hz", |
| 770 | trackSampleRate, devSampleRate); |
Glenn Kasten | ac60205 | 2012-10-01 14:04:31 -0700 | [diff] [blame] | 771 | AudioResampler::src_quality quality; |
| 772 | // force lowest quality level resampler if use case isn't music or video |
| 773 | // FIXME this is flawed for dynamic sample rates, as we choose the resampler |
| 774 | // quality level based on the initial ratio, but that could change later. |
| 775 | // Should have a way to distinguish tracks with static ratios vs. dynamic ratios. |
Andy Hung | db4c031 | 2015-05-06 08:46:52 -0700 | [diff] [blame] | 776 | if (isMusicRate(trackSampleRate)) { |
Glenn Kasten | ac60205 | 2012-10-01 14:04:31 -0700 | [diff] [blame] | 777 | quality = AudioResampler::DEFAULT_QUALITY; |
Andy Hung | db4c031 | 2015-05-06 08:46:52 -0700 | [diff] [blame] | 778 | } else { |
| 779 | quality = AudioResampler::DYN_LOW_QUALITY; |
Glenn Kasten | ac60205 | 2012-10-01 14:04:31 -0700 | [diff] [blame] | 780 | } |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 781 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 782 | // TODO: Remove MONO_HACK. Resampler sees #channels after the downmixer |
| 783 | // but if none exists, it is the channel count (1 for mono). |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 784 | const int resamplerChannelCount = mDownmixerBufferProvider.get() != nullptr |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 785 | ? mMixerChannelCount : channelCount; |
Andy Hung | 9a59276 | 2014-07-21 21:56:01 -0700 | [diff] [blame] | 786 | ALOGVV("Creating resampler:" |
| 787 | " format(%#x) channels(%d) devSampleRate(%u) quality(%d)\n", |
| 788 | mMixerInFormat, resamplerChannelCount, devSampleRate, quality); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 789 | mResampler.reset(AudioResampler::create( |
Andy Hung | 3348e36 | 2014-07-07 10:21:44 -0700 | [diff] [blame] | 790 | mMixerInFormat, |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 791 | resamplerChannelCount, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 792 | devSampleRate, quality)); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 793 | } |
| 794 | return true; |
| 795 | } |
| 796 | } |
| 797 | return false; |
| 798 | } |
| 799 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 800 | bool AudioMixer::Track::setPlaybackRate(const AudioPlaybackRate &playbackRate) |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 801 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 802 | if ((mTimestretchBufferProvider.get() == nullptr && |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 803 | fabs(playbackRate.mSpeed - mPlaybackRate.mSpeed) < AUDIO_TIMESTRETCH_SPEED_MIN_DELTA && |
| 804 | fabs(playbackRate.mPitch - mPlaybackRate.mPitch) < AUDIO_TIMESTRETCH_PITCH_MIN_DELTA) || |
| 805 | isAudioPlaybackRateEqual(playbackRate, mPlaybackRate)) { |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 806 | return false; |
| 807 | } |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 808 | mPlaybackRate = playbackRate; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 809 | if (mTimestretchBufferProvider.get() == nullptr) { |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 810 | // TODO: Remove MONO_HACK. Resampler sees #channels after the downmixer |
| 811 | // but if none exists, it is the channel count (1 for mono). |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 812 | const int timestretchChannelCount = mDownmixerBufferProvider.get() != nullptr |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 813 | ? mMixerChannelCount : channelCount; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 814 | mTimestretchBufferProvider.reset(new TimestretchBufferProvider(timestretchChannelCount, |
| 815 | mMixerInFormat, sampleRate, playbackRate)); |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 816 | reconfigureBufferProviders(); |
| 817 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 818 | static_cast<TimestretchBufferProvider*>(mTimestretchBufferProvider.get()) |
Ricardo Garcia | 5a8a95d | 2015-04-18 14:47:04 -0700 | [diff] [blame] | 819 | ->setPlaybackRate(playbackRate); |
Andy Hung | c5656cc | 2015-03-26 19:04:33 -0700 | [diff] [blame] | 820 | } |
| 821 | return true; |
| 822 | } |
| 823 | |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 824 | /* Checks to see if the volume ramp has completed and clears the increment |
| 825 | * variables appropriately. |
| 826 | * |
| 827 | * FIXME: There is code to handle int/float ramp variable switchover should it not |
| 828 | * complete within a mixer buffer processing call, but it is preferred to avoid switchover |
| 829 | * due to precision issues. The switchover code is included for legacy code purposes |
| 830 | * and can be removed once the integer volume is removed. |
| 831 | * |
| 832 | * It is not sufficient to clear only the volumeInc integer variable because |
| 833 | * if one channel requires ramping, all channels are ramped. |
| 834 | * |
| 835 | * There is a bit of duplicated code here, but it keeps backward compatibility. |
| 836 | */ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 837 | inline void AudioMixer::Track::adjustVolumeRamp(bool aux, bool useFloat) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 838 | { |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 839 | if (useFloat) { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 840 | for (uint32_t i = 0; i < MAX_NUM_VOLUMES; i++) { |
Eric Laurent | 43412fc | 2015-05-08 16:14:36 -0700 | [diff] [blame] | 841 | if ((mVolumeInc[i] > 0 && mPrevVolume[i] + mVolumeInc[i] >= mVolume[i]) || |
| 842 | (mVolumeInc[i] < 0 && mPrevVolume[i] + mVolumeInc[i] <= mVolume[i])) { |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 843 | volumeInc[i] = 0; |
| 844 | prevVolume[i] = volume[i] << 16; |
| 845 | mVolumeInc[i] = 0.; |
| 846 | mPrevVolume[i] = mVolume[i]; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 847 | } else { |
| 848 | //ALOGV("ramp: %f %f %f", mVolume[i], mPrevVolume[i], mVolumeInc[i]); |
| 849 | prevVolume[i] = u4_28_from_float(mPrevVolume[i]); |
| 850 | } |
| 851 | } |
| 852 | } else { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 853 | for (uint32_t i = 0; i < MAX_NUM_VOLUMES; i++) { |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 854 | if (((volumeInc[i]>0) && (((prevVolume[i]+volumeInc[i])>>16) >= volume[i])) || |
| 855 | ((volumeInc[i]<0) && (((prevVolume[i]+volumeInc[i])>>16) <= volume[i]))) { |
| 856 | volumeInc[i] = 0; |
| 857 | prevVolume[i] = volume[i] << 16; |
| 858 | mVolumeInc[i] = 0.; |
| 859 | mPrevVolume[i] = mVolume[i]; |
| 860 | } else { |
| 861 | //ALOGV("ramp: %d %d %d", volume[i] << 16, prevVolume[i], volumeInc[i]); |
| 862 | mPrevVolume[i] = float_from_u4_28(prevVolume[i]); |
| 863 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 864 | } |
| 865 | } |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 866 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 867 | if (aux) { |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 868 | #ifdef FLOAT_AUX |
| 869 | if (useFloat) { |
| 870 | if ((mAuxInc > 0.f && mPrevAuxLevel + mAuxInc >= mAuxLevel) || |
| 871 | (mAuxInc < 0.f && mPrevAuxLevel + mAuxInc <= mAuxLevel)) { |
| 872 | auxInc = 0; |
| 873 | prevAuxLevel = auxLevel << 16; |
| 874 | mAuxInc = 0.f; |
| 875 | mPrevAuxLevel = mAuxLevel; |
| 876 | } |
| 877 | } else |
| 878 | #endif |
| 879 | if ((auxInc > 0 && ((prevAuxLevel + auxInc) >> 16) >= auxLevel) || |
| 880 | (auxInc < 0 && ((prevAuxLevel + auxInc) >> 16) <= auxLevel)) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 881 | auxInc = 0; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 882 | prevAuxLevel = auxLevel << 16; |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 883 | mAuxInc = 0.f; |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 884 | mPrevAuxLevel = mAuxLevel; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | } |
| 888 | |
Glenn Kasten | c59c004 | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 889 | size_t AudioMixer::getUnreleasedFrames(int name) const |
Eric Laurent | 071ccd5 | 2011-12-22 16:08:41 -0800 | [diff] [blame] | 890 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 891 | const auto it = mTracks.find(name); |
| 892 | if (it != mTracks.end()) { |
| 893 | return it->second->getUnreleasedFrames(); |
Eric Laurent | 071ccd5 | 2011-12-22 16:08:41 -0800 | [diff] [blame] | 894 | } |
| 895 | return 0; |
| 896 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 897 | |
Glenn Kasten | 01c4ebf | 2012-02-22 10:47:35 -0800 | [diff] [blame] | 898 | void AudioMixer::setBufferProvider(int name, AudioBufferProvider* bufferProvider) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 899 | { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 900 | LOG_ALWAYS_FATAL_IF(!exists(name), "invalid name: %d", name); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 901 | const std::shared_ptr<Track> &track = mTracks[name]; |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 902 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 903 | if (track->mInputBufferProvider == bufferProvider) { |
Andy Hung | 1d26ddf | 2014-05-29 15:53:09 -0700 | [diff] [blame] | 904 | return; // don't reset any buffer providers if identical. |
| 905 | } |
Andy Hung | 3a34df9 | 2018-08-21 12:32:30 -0700 | [diff] [blame] | 906 | // reset order from downstream to upstream buffer providers. |
| 907 | if (track->mTimestretchBufferProvider.get() != nullptr) { |
| 908 | track->mTimestretchBufferProvider->reset(); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 909 | } else if (track->mPostDownmixReformatBufferProvider.get() != nullptr) { |
| 910 | track->mPostDownmixReformatBufferProvider->reset(); |
Andy Hung | 3a34df9 | 2018-08-21 12:32:30 -0700 | [diff] [blame] | 911 | } else if (track->mDownmixerBufferProvider != nullptr) { |
| 912 | track->mDownmixerBufferProvider->reset(); |
| 913 | } else if (track->mReformatBufferProvider.get() != nullptr) { |
| 914 | track->mReformatBufferProvider->reset(); |
jiabin | dce8f8c | 2018-12-10 17:49:31 -0800 | [diff] [blame^] | 915 | } else if (track->mAdjustChannelsNonDestructiveBufferProvider.get() != nullptr) { |
| 916 | track->mAdjustChannelsNonDestructiveBufferProvider->reset(); |
| 917 | } else if (track->mAdjustChannelsBufferProvider.get() != nullptr) { |
| 918 | track->mAdjustChannelsBufferProvider->reset(); |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 919 | } |
Andy Hung | ef7c7fb | 2014-05-12 16:51:41 -0700 | [diff] [blame] | 920 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 921 | track->mInputBufferProvider = bufferProvider; |
| 922 | track->reconfigureBufferProviders(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 925 | void AudioMixer::process__validate() |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 926 | { |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 927 | // TODO: fix all16BitsStereNoResample logic to |
| 928 | // either properly handle muted tracks (it should ignore them) |
| 929 | // or remove altogether as an obsolete optimization. |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 930 | bool all16BitsStereoNoResample = true; |
| 931 | bool resampling = false; |
| 932 | bool volumeRamp = false; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 933 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 934 | mEnabled.clear(); |
| 935 | mGroups.clear(); |
| 936 | for (const auto &pair : mTracks) { |
| 937 | const int name = pair.first; |
| 938 | const std::shared_ptr<Track> &t = pair.second; |
| 939 | if (!t->enabled) continue; |
| 940 | |
| 941 | mEnabled.emplace_back(name); // we add to mEnabled in order of name. |
| 942 | mGroups[t->mainBuffer].emplace_back(name); // mGroups also in order of name. |
| 943 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 944 | uint32_t n = 0; |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 945 | // FIXME can overflow (mask is only 3 bits) |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 946 | n |= NEEDS_CHANNEL_1 + t->channelCount - 1; |
| 947 | if (t->doesResample()) { |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 948 | n |= NEEDS_RESAMPLE; |
| 949 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 950 | if (t->auxLevel != 0 && t->auxBuffer != NULL) { |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 951 | n |= NEEDS_AUX; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 954 | if (t->volumeInc[0]|t->volumeInc[1]) { |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 955 | volumeRamp = true; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 956 | } else if (!t->doesResample() && t->volumeRL == 0) { |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 957 | n |= NEEDS_MUTE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 958 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 959 | t->needs = n; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 960 | |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 961 | if (n & NEEDS_MUTE) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 962 | t->hook = &Track::track__nop; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 963 | } else { |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 964 | if (n & NEEDS_AUX) { |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 965 | all16BitsStereoNoResample = false; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 966 | } |
Glenn Kasten | d6fadf0 | 2013-10-30 14:37:29 -0700 | [diff] [blame] | 967 | if (n & NEEDS_RESAMPLE) { |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 968 | all16BitsStereoNoResample = false; |
| 969 | resampling = true; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 970 | t->hook = Track::getTrackHook(TRACKTYPE_RESAMPLE, t->mMixerChannelCount, |
| 971 | t->mMixerInFormat, t->mMixerFormat); |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 972 | ALOGV_IF((n & NEEDS_CHANNEL_COUNT__MASK) > NEEDS_CHANNEL_2, |
Chih-Hung Hsieh | 09f9c02 | 2018-07-27 10:22:35 -0700 | [diff] [blame] | 973 | "Track %d needs downmix + resample", name); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 974 | } else { |
| 975 | if ((n & NEEDS_CHANNEL_COUNT__MASK) == NEEDS_CHANNEL_1){ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 976 | t->hook = Track::getTrackHook( |
| 977 | (t->mMixerChannelMask == AUDIO_CHANNEL_OUT_STEREO // TODO: MONO_HACK |
| 978 | && t->channelMask == AUDIO_CHANNEL_OUT_MONO) |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 979 | ? TRACKTYPE_NORESAMPLEMONO : TRACKTYPE_NORESAMPLE, |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 980 | t->mMixerChannelCount, |
| 981 | t->mMixerInFormat, t->mMixerFormat); |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 982 | all16BitsStereoNoResample = false; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 983 | } |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 984 | if ((n & NEEDS_CHANNEL_COUNT__MASK) >= NEEDS_CHANNEL_2){ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 985 | t->hook = Track::getTrackHook(TRACKTYPE_NORESAMPLE, t->mMixerChannelCount, |
| 986 | t->mMixerInFormat, t->mMixerFormat); |
Jean-Michel Trivi | 7d5b262 | 2012-04-04 18:54:36 -0700 | [diff] [blame] | 987 | ALOGV_IF((n & NEEDS_CHANNEL_COUNT__MASK) > NEEDS_CHANNEL_2, |
Chih-Hung Hsieh | 09f9c02 | 2018-07-27 10:22:35 -0700 | [diff] [blame] | 988 | "Track %d needs downmix", name); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | // select the processing hooks |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 995 | mHook = &AudioMixer::process__nop; |
| 996 | if (mEnabled.size() > 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 997 | if (resampling) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 998 | if (mOutputTemp.get() == nullptr) { |
| 999 | mOutputTemp.reset(new int32_t[MAX_NUM_CHANNELS * mFrameCount]); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1000 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1001 | if (mResampleTemp.get() == nullptr) { |
| 1002 | mResampleTemp.reset(new int32_t[MAX_NUM_CHANNELS * mFrameCount]); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1003 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1004 | mHook = &AudioMixer::process__genericResampling; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1005 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1006 | // we keep temp arrays around. |
| 1007 | mHook = &AudioMixer::process__genericNoResampling; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1008 | if (all16BitsStereoNoResample && !volumeRamp) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1009 | if (mEnabled.size() == 1) { |
| 1010 | const std::shared_ptr<Track> &t = mTracks[mEnabled[0]]; |
| 1011 | if ((t->needs & NEEDS_MUTE) == 0) { |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1012 | // The check prevents a muted track from acquiring a process hook. |
| 1013 | // |
| 1014 | // This is dangerous if the track is MONO as that requires |
| 1015 | // special case handling due to implicit channel duplication. |
| 1016 | // Stereo or Multichannel should actually be fine here. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1017 | mHook = getProcessHook(PROCESSTYPE_NORESAMPLEONETRACK, |
| 1018 | t->mMixerChannelCount, t->mMixerInFormat, t->mMixerFormat); |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1019 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1025 | ALOGV("mixer configuration change: %zu " |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1026 | "all16BitsStereoNoResample=%d, resampling=%d, volumeRamp=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1027 | mEnabled.size(), all16BitsStereoNoResample, resampling, volumeRamp); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1028 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1029 | process(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1030 | |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1031 | // Now that the volume ramp has been done, set optimal state and |
| 1032 | // track hooks for subsequent mixer process |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1033 | if (mEnabled.size() > 0) { |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 1034 | bool allMuted = true; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1035 | |
| 1036 | for (const int name : mEnabled) { |
| 1037 | const std::shared_ptr<Track> &t = mTracks[name]; |
| 1038 | if (!t->doesResample() && t->volumeRL == 0) { |
| 1039 | t->needs |= NEEDS_MUTE; |
| 1040 | t->hook = &Track::track__nop; |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1041 | } else { |
Glenn Kasten | 4c340c6 | 2012-01-27 12:33:54 -0800 | [diff] [blame] | 1042 | allMuted = false; |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | if (allMuted) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1046 | mHook = &AudioMixer::process__nop; |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1047 | } else if (all16BitsStereoNoResample) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1048 | if (mEnabled.size() == 1) { |
| 1049 | //const int i = 31 - __builtin_clz(enabledTracks); |
| 1050 | const std::shared_ptr<Track> &t = mTracks[mEnabled[0]]; |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1051 | // Muted single tracks handled by allMuted above. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1052 | mHook = getProcessHook(PROCESSTYPE_NORESAMPLEONETRACK, |
| 1053 | t->mMixerChannelCount, t->mMixerInFormat, t->mMixerFormat); |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1059 | void AudioMixer::Track::track__genericResample( |
| 1060 | int32_t* out, size_t outFrameCount, int32_t* temp, int32_t* aux) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1061 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1062 | ALOGVV("track__genericResample\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1063 | mResampler->setSampleRate(sampleRate); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1064 | |
| 1065 | // ramp gain - resample to temp buffer and scale/mix in 2nd step |
| 1066 | if (aux != NULL) { |
| 1067 | // always resample with unity gain when sending to auxiliary buffer to be able |
| 1068 | // to apply send level after resampling |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1069 | mResampler->setVolume(UNITY_GAIN_FLOAT, UNITY_GAIN_FLOAT); |
| 1070 | memset(temp, 0, outFrameCount * mMixerChannelCount * sizeof(int32_t)); |
| 1071 | mResampler->resample(temp, outFrameCount, bufferProvider); |
| 1072 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1]|auxInc)) { |
| 1073 | volumeRampStereo(out, outFrameCount, temp, aux); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1074 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1075 | volumeStereo(out, outFrameCount, temp, aux); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1076 | } |
| 1077 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1078 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1])) { |
| 1079 | mResampler->setVolume(UNITY_GAIN_FLOAT, UNITY_GAIN_FLOAT); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1080 | memset(temp, 0, outFrameCount * MAX_NUM_CHANNELS * sizeof(int32_t)); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1081 | mResampler->resample(temp, outFrameCount, bufferProvider); |
| 1082 | volumeRampStereo(out, outFrameCount, temp, aux); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | // constant gain |
| 1086 | else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1087 | mResampler->setVolume(mVolume[0], mVolume[1]); |
| 1088 | mResampler->resample(out, outFrameCount, bufferProvider); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1093 | void AudioMixer::Track::track__nop(int32_t* out __unused, |
Andy Hung | ee931ff | 2014-01-28 13:44:14 -0800 | [diff] [blame] | 1094 | size_t outFrameCount __unused, int32_t* temp __unused, int32_t* aux __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1095 | { |
| 1096 | } |
| 1097 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1098 | void AudioMixer::Track::volumeRampStereo( |
| 1099 | int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1100 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1101 | int32_t vl = prevVolume[0]; |
| 1102 | int32_t vr = prevVolume[1]; |
| 1103 | const int32_t vlInc = volumeInc[0]; |
| 1104 | const int32_t vrInc = volumeInc[1]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1105 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1106 | //ALOGD("[0] %p: inc=%f, v0=%f, v1=%d, final=%f, count=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1107 | // t, vlInc/65536.0f, vl/65536.0f, volume[0], |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1108 | // (vl + vlInc*frameCount)/65536.0f, frameCount); |
| 1109 | |
| 1110 | // ramp volume |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 1111 | if (CC_UNLIKELY(aux != NULL)) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1112 | int32_t va = prevAuxLevel; |
| 1113 | const int32_t vaInc = auxInc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1114 | int32_t l; |
| 1115 | int32_t r; |
| 1116 | |
| 1117 | do { |
| 1118 | l = (*temp++ >> 12); |
| 1119 | r = (*temp++ >> 12); |
| 1120 | *out++ += (vl >> 16) * l; |
| 1121 | *out++ += (vr >> 16) * r; |
| 1122 | *aux++ += (va >> 17) * (l + r); |
| 1123 | vl += vlInc; |
| 1124 | vr += vrInc; |
| 1125 | va += vaInc; |
| 1126 | } while (--frameCount); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1127 | prevAuxLevel = va; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1128 | } else { |
| 1129 | do { |
| 1130 | *out++ += (vl >> 16) * (*temp++ >> 12); |
| 1131 | *out++ += (vr >> 16) * (*temp++ >> 12); |
| 1132 | vl += vlInc; |
| 1133 | vr += vrInc; |
| 1134 | } while (--frameCount); |
| 1135 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1136 | prevVolume[0] = vl; |
| 1137 | prevVolume[1] = vr; |
| 1138 | adjustVolumeRamp(aux != NULL); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1141 | void AudioMixer::Track::volumeStereo( |
| 1142 | int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1143 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1144 | const int16_t vl = volume[0]; |
| 1145 | const int16_t vr = volume[1]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1146 | |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 1147 | if (CC_UNLIKELY(aux != NULL)) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1148 | const int16_t va = auxLevel; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1149 | do { |
| 1150 | int16_t l = (int16_t)(*temp++ >> 12); |
| 1151 | int16_t r = (int16_t)(*temp++ >> 12); |
| 1152 | out[0] = mulAdd(l, vl, out[0]); |
| 1153 | int16_t a = (int16_t)(((int32_t)l + r) >> 1); |
| 1154 | out[1] = mulAdd(r, vr, out[1]); |
| 1155 | out += 2; |
| 1156 | aux[0] = mulAdd(a, va, aux[0]); |
| 1157 | aux++; |
| 1158 | } while (--frameCount); |
| 1159 | } else { |
| 1160 | do { |
| 1161 | int16_t l = (int16_t)(*temp++ >> 12); |
| 1162 | int16_t r = (int16_t)(*temp++ >> 12); |
| 1163 | out[0] = mulAdd(l, vl, out[0]); |
| 1164 | out[1] = mulAdd(r, vr, out[1]); |
| 1165 | out += 2; |
| 1166 | } while (--frameCount); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1170 | void AudioMixer::Track::track__16BitsStereo( |
| 1171 | int32_t* out, size_t frameCount, int32_t* temp __unused, int32_t* aux) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1172 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1173 | ALOGVV("track__16BitsStereo\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1174 | const int16_t *in = static_cast<const int16_t *>(mIn); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1175 | |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 1176 | if (CC_UNLIKELY(aux != NULL)) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1177 | int32_t l; |
| 1178 | int32_t r; |
| 1179 | // ramp gain |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1180 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1]|auxInc)) { |
| 1181 | int32_t vl = prevVolume[0]; |
| 1182 | int32_t vr = prevVolume[1]; |
| 1183 | int32_t va = prevAuxLevel; |
| 1184 | const int32_t vlInc = volumeInc[0]; |
| 1185 | const int32_t vrInc = volumeInc[1]; |
| 1186 | const int32_t vaInc = auxInc; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1187 | // ALOGD("[1] %p: inc=%f, v0=%f, v1=%d, final=%f, count=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1188 | // t, vlInc/65536.0f, vl/65536.0f, volume[0], |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1189 | // (vl + vlInc*frameCount)/65536.0f, frameCount); |
| 1190 | |
| 1191 | do { |
| 1192 | l = (int32_t)*in++; |
| 1193 | r = (int32_t)*in++; |
| 1194 | *out++ += (vl >> 16) * l; |
| 1195 | *out++ += (vr >> 16) * r; |
| 1196 | *aux++ += (va >> 17) * (l + r); |
| 1197 | vl += vlInc; |
| 1198 | vr += vrInc; |
| 1199 | va += vaInc; |
| 1200 | } while (--frameCount); |
| 1201 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1202 | prevVolume[0] = vl; |
| 1203 | prevVolume[1] = vr; |
| 1204 | prevAuxLevel = va; |
| 1205 | adjustVolumeRamp(true); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | // constant gain |
| 1209 | else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1210 | const uint32_t vrl = volumeRL; |
| 1211 | const int16_t va = (int16_t)auxLevel; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1212 | do { |
Glenn Kasten | 54c3b66 | 2012-01-06 07:46:30 -0800 | [diff] [blame] | 1213 | uint32_t rl = *reinterpret_cast<const uint32_t *>(in); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1214 | int16_t a = (int16_t)(((int32_t)in[0] + in[1]) >> 1); |
| 1215 | in += 2; |
| 1216 | out[0] = mulAddRL(1, rl, vrl, out[0]); |
| 1217 | out[1] = mulAddRL(0, rl, vrl, out[1]); |
| 1218 | out += 2; |
| 1219 | aux[0] = mulAdd(a, va, aux[0]); |
| 1220 | aux++; |
| 1221 | } while (--frameCount); |
| 1222 | } |
| 1223 | } else { |
| 1224 | // ramp gain |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1225 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1])) { |
| 1226 | int32_t vl = prevVolume[0]; |
| 1227 | int32_t vr = prevVolume[1]; |
| 1228 | const int32_t vlInc = volumeInc[0]; |
| 1229 | const int32_t vrInc = volumeInc[1]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1230 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1231 | // ALOGD("[1] %p: inc=%f, v0=%f, v1=%d, final=%f, count=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1232 | // t, vlInc/65536.0f, vl/65536.0f, volume[0], |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1233 | // (vl + vlInc*frameCount)/65536.0f, frameCount); |
| 1234 | |
| 1235 | do { |
| 1236 | *out++ += (vl >> 16) * (int32_t) *in++; |
| 1237 | *out++ += (vr >> 16) * (int32_t) *in++; |
| 1238 | vl += vlInc; |
| 1239 | vr += vrInc; |
| 1240 | } while (--frameCount); |
| 1241 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1242 | prevVolume[0] = vl; |
| 1243 | prevVolume[1] = vr; |
| 1244 | adjustVolumeRamp(false); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | // constant gain |
| 1248 | else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1249 | const uint32_t vrl = volumeRL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1250 | do { |
Glenn Kasten | 54c3b66 | 2012-01-06 07:46:30 -0800 | [diff] [blame] | 1251 | uint32_t rl = *reinterpret_cast<const uint32_t *>(in); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1252 | in += 2; |
| 1253 | out[0] = mulAddRL(1, rl, vrl, out[0]); |
| 1254 | out[1] = mulAddRL(0, rl, vrl, out[1]); |
| 1255 | out += 2; |
| 1256 | } while (--frameCount); |
| 1257 | } |
| 1258 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1259 | mIn = in; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1262 | void AudioMixer::Track::track__16BitsMono( |
| 1263 | int32_t* out, size_t frameCount, int32_t* temp __unused, int32_t* aux) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1264 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1265 | ALOGVV("track__16BitsMono\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1266 | const int16_t *in = static_cast<int16_t const *>(mIn); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1267 | |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 1268 | if (CC_UNLIKELY(aux != NULL)) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1269 | // ramp gain |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1270 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1]|auxInc)) { |
| 1271 | int32_t vl = prevVolume[0]; |
| 1272 | int32_t vr = prevVolume[1]; |
| 1273 | int32_t va = prevAuxLevel; |
| 1274 | const int32_t vlInc = volumeInc[0]; |
| 1275 | const int32_t vrInc = volumeInc[1]; |
| 1276 | const int32_t vaInc = auxInc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1277 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1278 | // ALOGD("[2] %p: inc=%f, v0=%f, v1=%d, final=%f, count=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1279 | // t, vlInc/65536.0f, vl/65536.0f, volume[0], |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1280 | // (vl + vlInc*frameCount)/65536.0f, frameCount); |
| 1281 | |
| 1282 | do { |
| 1283 | int32_t l = *in++; |
| 1284 | *out++ += (vl >> 16) * l; |
| 1285 | *out++ += (vr >> 16) * l; |
| 1286 | *aux++ += (va >> 16) * l; |
| 1287 | vl += vlInc; |
| 1288 | vr += vrInc; |
| 1289 | va += vaInc; |
| 1290 | } while (--frameCount); |
| 1291 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1292 | prevVolume[0] = vl; |
| 1293 | prevVolume[1] = vr; |
| 1294 | prevAuxLevel = va; |
| 1295 | adjustVolumeRamp(true); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1296 | } |
| 1297 | // constant gain |
| 1298 | else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1299 | const int16_t vl = volume[0]; |
| 1300 | const int16_t vr = volume[1]; |
| 1301 | const int16_t va = (int16_t)auxLevel; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1302 | do { |
| 1303 | int16_t l = *in++; |
| 1304 | out[0] = mulAdd(l, vl, out[0]); |
| 1305 | out[1] = mulAdd(l, vr, out[1]); |
| 1306 | out += 2; |
| 1307 | aux[0] = mulAdd(l, va, aux[0]); |
| 1308 | aux++; |
| 1309 | } while (--frameCount); |
| 1310 | } |
| 1311 | } else { |
| 1312 | // ramp gain |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1313 | if (CC_UNLIKELY(volumeInc[0]|volumeInc[1])) { |
| 1314 | int32_t vl = prevVolume[0]; |
| 1315 | int32_t vr = prevVolume[1]; |
| 1316 | const int32_t vlInc = volumeInc[0]; |
| 1317 | const int32_t vrInc = volumeInc[1]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1318 | |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1319 | // ALOGD("[2] %p: inc=%f, v0=%f, v1=%d, final=%f, count=%d", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1320 | // t, vlInc/65536.0f, vl/65536.0f, volume[0], |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1321 | // (vl + vlInc*frameCount)/65536.0f, frameCount); |
| 1322 | |
| 1323 | do { |
| 1324 | int32_t l = *in++; |
| 1325 | *out++ += (vl >> 16) * l; |
| 1326 | *out++ += (vr >> 16) * l; |
| 1327 | vl += vlInc; |
| 1328 | vr += vrInc; |
| 1329 | } while (--frameCount); |
| 1330 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1331 | prevVolume[0] = vl; |
| 1332 | prevVolume[1] = vr; |
| 1333 | adjustVolumeRamp(false); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1334 | } |
| 1335 | // constant gain |
| 1336 | else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1337 | const int16_t vl = volume[0]; |
| 1338 | const int16_t vr = volume[1]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1339 | do { |
| 1340 | int16_t l = *in++; |
| 1341 | out[0] = mulAdd(l, vl, out[0]); |
| 1342 | out[1] = mulAdd(l, vr, out[1]); |
| 1343 | out += 2; |
| 1344 | } while (--frameCount); |
| 1345 | } |
| 1346 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1347 | mIn = in; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1350 | // no-op case |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1351 | void AudioMixer::process__nop() |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1352 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1353 | ALOGVV("process__nop\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1354 | |
| 1355 | for (const auto &pair : mGroups) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1356 | // process by group of tracks with same output buffer to |
| 1357 | // avoid multiple memset() on same buffer |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1358 | const auto &group = pair.second; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1359 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1360 | const std::shared_ptr<Track> &t = mTracks[group[0]]; |
| 1361 | memset(t->mainBuffer, 0, |
| 1362 | mFrameCount * t->mMixerChannelCount |
| 1363 | * audio_bytes_per_sample(t->mMixerFormat)); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1364 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1365 | // now consume data |
| 1366 | for (const int name : group) { |
| 1367 | const std::shared_ptr<Track> &t = mTracks[name]; |
| 1368 | size_t outFrames = mFrameCount; |
| 1369 | while (outFrames) { |
| 1370 | t->buffer.frameCount = outFrames; |
| 1371 | t->bufferProvider->getNextBuffer(&t->buffer); |
| 1372 | if (t->buffer.raw == NULL) break; |
| 1373 | outFrames -= t->buffer.frameCount; |
| 1374 | t->bufferProvider->releaseBuffer(&t->buffer); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | // generic code without resampling |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1381 | void AudioMixer::process__genericNoResampling() |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1382 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1383 | ALOGVV("process__genericNoResampling\n"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1384 | int32_t outTemp[BLOCKSIZE * MAX_NUM_CHANNELS] __attribute__((aligned(32))); |
| 1385 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1386 | for (const auto &pair : mGroups) { |
| 1387 | // process by group of tracks with same output main buffer to |
| 1388 | // avoid multiple memset() on same buffer |
| 1389 | const auto &group = pair.second; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1390 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1391 | // acquire buffer |
| 1392 | for (const int name : group) { |
| 1393 | const std::shared_ptr<Track> &t = mTracks[name]; |
| 1394 | t->buffer.frameCount = mFrameCount; |
| 1395 | t->bufferProvider->getNextBuffer(&t->buffer); |
| 1396 | t->frameCount = t->buffer.frameCount; |
| 1397 | t->mIn = t->buffer.raw; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1398 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1399 | |
| 1400 | int32_t *out = (int *)pair.first; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1401 | size_t numFrames = 0; |
| 1402 | do { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1403 | const size_t frameCount = std::min((size_t)BLOCKSIZE, mFrameCount - numFrames); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1404 | memset(outTemp, 0, sizeof(outTemp)); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1405 | for (const int name : group) { |
| 1406 | const std::shared_ptr<Track> &t = mTracks[name]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1407 | int32_t *aux = NULL; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1408 | if (CC_UNLIKELY(t->needs & NEEDS_AUX)) { |
| 1409 | aux = t->auxBuffer + numFrames; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1410 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1411 | for (int outFrames = frameCount; outFrames > 0; ) { |
| 1412 | // t->in == nullptr can happen if the track was flushed just after having |
Gaurav Kumar | 7e79cd2 | 2014-01-06 10:57:18 +0530 | [diff] [blame] | 1413 | // been enabled for mixing. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1414 | if (t->mIn == nullptr) { |
Gaurav Kumar | 7e79cd2 | 2014-01-06 10:57:18 +0530 | [diff] [blame] | 1415 | break; |
| 1416 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1417 | size_t inFrames = (t->frameCount > outFrames)?outFrames:t->frameCount; |
Glenn Kasten | 34fca34 | 2013-08-13 09:48:14 -0700 | [diff] [blame] | 1418 | if (inFrames > 0) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1419 | (t.get()->*t->hook)( |
| 1420 | outTemp + (frameCount - outFrames) * t->mMixerChannelCount, |
| 1421 | inFrames, mResampleTemp.get() /* naked ptr */, aux); |
| 1422 | t->frameCount -= inFrames; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1423 | outFrames -= inFrames; |
Glenn Kasten | f6b1678 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 1424 | if (CC_UNLIKELY(aux != NULL)) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1425 | aux += inFrames; |
| 1426 | } |
| 1427 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1428 | if (t->frameCount == 0 && outFrames) { |
| 1429 | t->bufferProvider->releaseBuffer(&t->buffer); |
| 1430 | t->buffer.frameCount = (mFrameCount - numFrames) - |
Yahan Zhou | c1c11b4 | 2018-01-16 12:44:04 -0800 | [diff] [blame] | 1431 | (frameCount - outFrames); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1432 | t->bufferProvider->getNextBuffer(&t->buffer); |
| 1433 | t->mIn = t->buffer.raw; |
| 1434 | if (t->mIn == nullptr) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1435 | break; |
| 1436 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1437 | t->frameCount = t->buffer.frameCount; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | } |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1441 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1442 | const std::shared_ptr<Track> &t1 = mTracks[group[0]]; |
| 1443 | convertMixerFormat(out, t1->mMixerFormat, outTemp, t1->mMixerInFormat, |
| 1444 | frameCount * t1->mMixerChannelCount); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1445 | // TODO: fix ugly casting due to choice of out pointer type |
| 1446 | out = reinterpret_cast<int32_t*>((uint8_t*)out |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1447 | + frameCount * t1->mMixerChannelCount |
| 1448 | * audio_bytes_per_sample(t1->mMixerFormat)); |
Yahan Zhou | c1c11b4 | 2018-01-16 12:44:04 -0800 | [diff] [blame] | 1449 | numFrames += frameCount; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1450 | } while (numFrames < mFrameCount); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1451 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1452 | // release each track's buffer |
| 1453 | for (const int name : group) { |
| 1454 | const std::shared_ptr<Track> &t = mTracks[name]; |
| 1455 | t->bufferProvider->releaseBuffer(&t->buffer); |
| 1456 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
Glenn Kasten | c5ac4cb | 2011-12-12 09:05:55 -0800 | [diff] [blame] | 1460 | // generic code with resampling |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1461 | void AudioMixer::process__genericResampling() |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1462 | { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1463 | ALOGVV("process__genericResampling\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1464 | int32_t * const outTemp = mOutputTemp.get(); // naked ptr |
| 1465 | size_t numFrames = mFrameCount; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1466 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1467 | for (const auto &pair : mGroups) { |
| 1468 | const auto &group = pair.second; |
| 1469 | const std::shared_ptr<Track> &t1 = mTracks[group[0]]; |
| 1470 | |
| 1471 | // clear temp buffer |
| 1472 | memset(outTemp, 0, sizeof(*outTemp) * t1->mMixerChannelCount * mFrameCount); |
| 1473 | for (const int name : group) { |
| 1474 | const std::shared_ptr<Track> &t = mTracks[name]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1475 | int32_t *aux = NULL; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1476 | if (CC_UNLIKELY(t->needs & NEEDS_AUX)) { |
| 1477 | aux = t->auxBuffer; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | // this is a little goofy, on the resampling case we don't |
| 1481 | // acquire/release the buffers because it's done by |
| 1482 | // the resampler. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1483 | if (t->needs & NEEDS_RESAMPLE) { |
| 1484 | (t.get()->*t->hook)(outTemp, numFrames, mResampleTemp.get() /* naked ptr */, aux); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1485 | } else { |
| 1486 | |
| 1487 | size_t outFrames = 0; |
| 1488 | |
| 1489 | while (outFrames < numFrames) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1490 | t->buffer.frameCount = numFrames - outFrames; |
| 1491 | t->bufferProvider->getNextBuffer(&t->buffer); |
| 1492 | t->mIn = t->buffer.raw; |
| 1493 | // t->mIn == nullptr can happen if the track was flushed just after having |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1494 | // been enabled for mixing. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1495 | if (t->mIn == nullptr) break; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1496 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1497 | (t.get()->*t->hook)( |
| 1498 | outTemp + outFrames * t->mMixerChannelCount, t->buffer.frameCount, |
Andy Hung | a601889 | 2018-02-21 14:32:16 -0800 | [diff] [blame] | 1499 | mResampleTemp.get() /* naked ptr */, |
| 1500 | aux != nullptr ? aux + outFrames : nullptr); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1501 | outFrames += t->buffer.frameCount; |
Andy Hung | a601889 | 2018-02-21 14:32:16 -0800 | [diff] [blame] | 1502 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1503 | t->bufferProvider->releaseBuffer(&t->buffer); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1507 | convertMixerFormat(t1->mainBuffer, t1->mMixerFormat, |
| 1508 | outTemp, t1->mMixerInFormat, numFrames * t1->mMixerChannelCount); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | // one track, 16 bits stereo without resampling is the most common case |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1513 | void AudioMixer::process__oneTrack16BitsStereoNoResampling() |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1514 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1515 | ALOGVV("process__oneTrack16BitsStereoNoResampling\n"); |
| 1516 | LOG_ALWAYS_FATAL_IF(mEnabled.size() != 0, |
| 1517 | "%zu != 1 tracks enabled", mEnabled.size()); |
| 1518 | const int name = mEnabled[0]; |
| 1519 | const std::shared_ptr<Track> &t = mTracks[name]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1520 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1521 | AudioBufferProvider::Buffer& b(t->buffer); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1522 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1523 | int32_t* out = t->mainBuffer; |
Andy Hung | f8a106a | 2014-05-29 18:52:38 -0700 | [diff] [blame] | 1524 | float *fout = reinterpret_cast<float*>(out); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1525 | size_t numFrames = mFrameCount; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1526 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1527 | const int16_t vl = t->volume[0]; |
| 1528 | const int16_t vr = t->volume[1]; |
| 1529 | const uint32_t vrl = t->volumeRL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1530 | while (numFrames) { |
| 1531 | b.frameCount = numFrames; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1532 | t->bufferProvider->getNextBuffer(&b); |
Glenn Kasten | 54c3b66 | 2012-01-06 07:46:30 -0800 | [diff] [blame] | 1533 | const int16_t *in = b.i16; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1534 | |
| 1535 | // in == NULL can happen if the track was flushed just after having |
| 1536 | // been enabled for mixing. |
Andy Hung | f8a106a | 2014-05-29 18:52:38 -0700 | [diff] [blame] | 1537 | if (in == NULL || (((uintptr_t)in) & 3)) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1538 | if ( AUDIO_FORMAT_PCM_FLOAT == t->mMixerFormat ) { |
Jinguang Dong | 7c5ec03 | 2016-11-14 19:57:14 +0800 | [diff] [blame] | 1539 | memset((char*)fout, 0, numFrames |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1540 | * t->mMixerChannelCount * audio_bytes_per_sample(t->mMixerFormat)); |
Jinguang Dong | 7c5ec03 | 2016-11-14 19:57:14 +0800 | [diff] [blame] | 1541 | } else { |
| 1542 | memset((char*)out, 0, numFrames |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1543 | * t->mMixerChannelCount * audio_bytes_per_sample(t->mMixerFormat)); |
Jinguang Dong | 7c5ec03 | 2016-11-14 19:57:14 +0800 | [diff] [blame] | 1544 | } |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1545 | ALOGE_IF((((uintptr_t)in) & 3), |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1546 | "process__oneTrack16BitsStereoNoResampling: misaligned buffer" |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1547 | " %p track %d, channels %d, needs %08x, volume %08x vfl %f vfr %f", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1548 | in, name, t->channelCount, t->needs, vrl, t->mVolume[0], t->mVolume[1]); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1549 | return; |
| 1550 | } |
| 1551 | size_t outFrames = b.frameCount; |
| 1552 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1553 | switch (t->mMixerFormat) { |
Andy Hung | f8a106a | 2014-05-29 18:52:38 -0700 | [diff] [blame] | 1554 | case AUDIO_FORMAT_PCM_FLOAT: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1555 | do { |
Glenn Kasten | 54c3b66 | 2012-01-06 07:46:30 -0800 | [diff] [blame] | 1556 | uint32_t rl = *reinterpret_cast<const uint32_t *>(in); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1557 | in += 2; |
Andy Hung | a1ab7cc | 2014-02-24 19:26:52 -0800 | [diff] [blame] | 1558 | int32_t l = mulRL(1, rl, vrl); |
| 1559 | int32_t r = mulRL(0, rl, vrl); |
Andy Hung | 84a0c6e | 2014-04-02 11:24:53 -0700 | [diff] [blame] | 1560 | *fout++ = float_from_q4_27(l); |
| 1561 | *fout++ = float_from_q4_27(r); |
Andy Hung | 3375bde | 2014-02-28 15:51:47 -0800 | [diff] [blame] | 1562 | // Note: In case of later int16_t sink output, |
| 1563 | // conversion and clamping is done by memcpy_to_i16_from_float(). |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1564 | } while (--outFrames); |
Andy Hung | f8a106a | 2014-05-29 18:52:38 -0700 | [diff] [blame] | 1565 | break; |
Andy Hung | a1ab7cc | 2014-02-24 19:26:52 -0800 | [diff] [blame] | 1566 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 97ae824 | 2014-05-30 10:35:47 -0700 | [diff] [blame] | 1567 | if (CC_UNLIKELY(uint32_t(vl) > UNITY_GAIN_INT || uint32_t(vr) > UNITY_GAIN_INT)) { |
Andy Hung | a1ab7cc | 2014-02-24 19:26:52 -0800 | [diff] [blame] | 1568 | // volume is boosted, so we might need to clamp even though |
| 1569 | // we process only one track. |
| 1570 | do { |
| 1571 | uint32_t rl = *reinterpret_cast<const uint32_t *>(in); |
| 1572 | in += 2; |
| 1573 | int32_t l = mulRL(1, rl, vrl) >> 12; |
| 1574 | int32_t r = mulRL(0, rl, vrl) >> 12; |
| 1575 | // clamping... |
| 1576 | l = clamp16(l); |
| 1577 | r = clamp16(r); |
| 1578 | *out++ = (r<<16) | (l & 0xFFFF); |
| 1579 | } while (--outFrames); |
| 1580 | } else { |
| 1581 | do { |
| 1582 | uint32_t rl = *reinterpret_cast<const uint32_t *>(in); |
| 1583 | in += 2; |
| 1584 | int32_t l = mulRL(1, rl, vrl) >> 12; |
| 1585 | int32_t r = mulRL(0, rl, vrl) >> 12; |
| 1586 | *out++ = (r<<16) | (l & 0xFFFF); |
| 1587 | } while (--outFrames); |
| 1588 | } |
| 1589 | break; |
| 1590 | default: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1591 | LOG_ALWAYS_FATAL("bad mixer format: %d", t->mMixerFormat); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1592 | } |
| 1593 | numFrames -= b.frameCount; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1594 | t->bufferProvider->releaseBuffer(&b); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
Glenn Kasten | 52008f8 | 2012-03-18 09:34:41 -0700 | [diff] [blame] | 1598 | /*static*/ pthread_once_t AudioMixer::sOnceControl = PTHREAD_ONCE_INIT; |
| 1599 | |
| 1600 | /*static*/ void AudioMixer::sInitRoutine() |
| 1601 | { |
Andy Hung | 34803d5 | 2014-07-16 21:41:35 -0700 | [diff] [blame] | 1602 | DownmixerBufferProvider::init(); // for the downmixer |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 1603 | } |
| 1604 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1605 | /* TODO: consider whether this level of optimization is necessary. |
| 1606 | * Perhaps just stick with a single for loop. |
| 1607 | */ |
| 1608 | |
| 1609 | // Needs to derive a compile time constant (constexpr). Could be targeted to go |
| 1610 | // to a MONOVOL mixtype based on MAX_NUM_VOLUMES, but that's an unnecessary complication. |
Chih-Hung Hsieh | bf29173 | 2016-05-17 15:16:07 -0700 | [diff] [blame] | 1611 | #define MIXTYPE_MONOVOL(mixtype) ((mixtype) == MIXTYPE_MULTI ? MIXTYPE_MULTI_MONOVOL : \ |
| 1612 | (mixtype) == MIXTYPE_MULTI_SAVEONLY ? MIXTYPE_MULTI_SAVEONLY_MONOVOL : (mixtype)) |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1613 | |
| 1614 | /* MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1615 | * TO: int32_t (Q4.27) or float |
| 1616 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1617 | * TA: int32_t (Q4.27) or float |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1618 | */ |
| 1619 | template <int MIXTYPE, |
| 1620 | typename TO, typename TI, typename TV, typename TA, typename TAV> |
| 1621 | static void volumeRampMulti(uint32_t channels, TO* out, size_t frameCount, |
| 1622 | const TI* in, TA* aux, TV *vol, const TV *volinc, TAV *vola, TAV volainc) |
| 1623 | { |
| 1624 | switch (channels) { |
| 1625 | case 1: |
| 1626 | volumeRampMulti<MIXTYPE, 1>(out, frameCount, in, aux, vol, volinc, vola, volainc); |
| 1627 | break; |
| 1628 | case 2: |
| 1629 | volumeRampMulti<MIXTYPE, 2>(out, frameCount, in, aux, vol, volinc, vola, volainc); |
| 1630 | break; |
| 1631 | case 3: |
| 1632 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 3>(out, |
| 1633 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1634 | break; |
| 1635 | case 4: |
| 1636 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 4>(out, |
| 1637 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1638 | break; |
| 1639 | case 5: |
| 1640 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 5>(out, |
| 1641 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1642 | break; |
| 1643 | case 6: |
| 1644 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 6>(out, |
| 1645 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1646 | break; |
| 1647 | case 7: |
| 1648 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 7>(out, |
| 1649 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1650 | break; |
| 1651 | case 8: |
| 1652 | volumeRampMulti<MIXTYPE_MONOVOL(MIXTYPE), 8>(out, |
| 1653 | frameCount, in, aux, vol, volinc, vola, volainc); |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | /* MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1659 | * TO: int32_t (Q4.27) or float |
| 1660 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1661 | * TA: int32_t (Q4.27) or float |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1662 | */ |
| 1663 | template <int MIXTYPE, |
| 1664 | typename TO, typename TI, typename TV, typename TA, typename TAV> |
| 1665 | static void volumeMulti(uint32_t channels, TO* out, size_t frameCount, |
| 1666 | const TI* in, TA* aux, const TV *vol, TAV vola) |
| 1667 | { |
| 1668 | switch (channels) { |
| 1669 | case 1: |
| 1670 | volumeMulti<MIXTYPE, 1>(out, frameCount, in, aux, vol, vola); |
| 1671 | break; |
| 1672 | case 2: |
| 1673 | volumeMulti<MIXTYPE, 2>(out, frameCount, in, aux, vol, vola); |
| 1674 | break; |
| 1675 | case 3: |
| 1676 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 3>(out, frameCount, in, aux, vol, vola); |
| 1677 | break; |
| 1678 | case 4: |
| 1679 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 4>(out, frameCount, in, aux, vol, vola); |
| 1680 | break; |
| 1681 | case 5: |
| 1682 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 5>(out, frameCount, in, aux, vol, vola); |
| 1683 | break; |
| 1684 | case 6: |
| 1685 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 6>(out, frameCount, in, aux, vol, vola); |
| 1686 | break; |
| 1687 | case 7: |
| 1688 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 7>(out, frameCount, in, aux, vol, vola); |
| 1689 | break; |
| 1690 | case 8: |
| 1691 | volumeMulti<MIXTYPE_MONOVOL(MIXTYPE), 8>(out, frameCount, in, aux, vol, vola); |
| 1692 | break; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | /* MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1697 | * USEFLOATVOL (set to true if float volume is used) |
| 1698 | * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards) |
| 1699 | * TO: int32_t (Q4.27) or float |
| 1700 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1701 | * TA: int32_t (Q4.27) or float |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1702 | */ |
| 1703 | template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL, |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1704 | typename TO, typename TI, typename TA> |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1705 | void AudioMixer::Track::volumeMix(TO *out, size_t outFrames, |
| 1706 | const TI *in, TA *aux, bool ramp) |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1707 | { |
| 1708 | if (USEFLOATVOL) { |
| 1709 | if (ramp) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1710 | volumeRampMulti<MIXTYPE>(mMixerChannelCount, out, outFrames, in, aux, |
| 1711 | mPrevVolume, mVolumeInc, |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1712 | #ifdef FLOAT_AUX |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1713 | &mPrevAuxLevel, mAuxInc |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1714 | #else |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1715 | &prevAuxLevel, auxInc |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1716 | #endif |
| 1717 | ); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1718 | if (ADJUSTVOL) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1719 | adjustVolumeRamp(aux != NULL, true); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1722 | volumeMulti<MIXTYPE>(mMixerChannelCount, out, outFrames, in, aux, |
| 1723 | mVolume, |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1724 | #ifdef FLOAT_AUX |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1725 | mAuxLevel |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1726 | #else |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1727 | auxLevel |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1728 | #endif |
| 1729 | ); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | } else { |
| 1732 | if (ramp) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1733 | volumeRampMulti<MIXTYPE>(mMixerChannelCount, out, outFrames, in, aux, |
| 1734 | prevVolume, volumeInc, &prevAuxLevel, auxInc); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1735 | if (ADJUSTVOL) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1736 | adjustVolumeRamp(aux != NULL); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1737 | } |
| 1738 | } else { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1739 | volumeMulti<MIXTYPE>(mMixerChannelCount, out, outFrames, in, aux, |
| 1740 | volume, auxLevel); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1745 | /* This process hook is called when there is a single track without |
| 1746 | * aux buffer, volume ramp, or resampling. |
| 1747 | * TODO: Update the hook selection: this can properly handle aux and ramp. |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1748 | * |
| 1749 | * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1750 | * TO: int32_t (Q4.27) or float |
| 1751 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
| 1752 | * TA: int32_t (Q4.27) |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1753 | */ |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1754 | template <int MIXTYPE, typename TO, typename TI, typename TA> |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1755 | void AudioMixer::process__noResampleOneTrack() |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1756 | { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1757 | ALOGVV("process__noResampleOneTrack\n"); |
| 1758 | LOG_ALWAYS_FATAL_IF(mEnabled.size() != 1, |
| 1759 | "%zu != 1 tracks enabled", mEnabled.size()); |
| 1760 | const std::shared_ptr<Track> &t = mTracks[mEnabled[0]]; |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1761 | const uint32_t channels = t->mMixerChannelCount; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1762 | TO* out = reinterpret_cast<TO*>(t->mainBuffer); |
| 1763 | TA* aux = reinterpret_cast<TA*>(t->auxBuffer); |
| 1764 | const bool ramp = t->needsRamp(); |
| 1765 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1766 | for (size_t numFrames = mFrameCount; numFrames > 0; ) { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1767 | AudioBufferProvider::Buffer& b(t->buffer); |
| 1768 | // get input buffer |
| 1769 | b.frameCount = numFrames; |
Glenn Kasten | d79072e | 2016-01-06 08:41:20 -0800 | [diff] [blame] | 1770 | t->bufferProvider->getNextBuffer(&b); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1771 | const TI *in = reinterpret_cast<TI*>(b.raw); |
| 1772 | |
| 1773 | // in == NULL can happen if the track was flushed just after having |
| 1774 | // been enabled for mixing. |
| 1775 | if (in == NULL || (((uintptr_t)in) & 3)) { |
| 1776 | memset(out, 0, numFrames |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1777 | * channels * audio_bytes_per_sample(t->mMixerFormat)); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1778 | ALOGE_IF((((uintptr_t)in) & 3), "process__noResampleOneTrack: bus error: " |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1779 | "buffer %p track %p, channels %d, needs %#x", |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1780 | in, &t, t->channelCount, t->needs); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | const size_t outFrames = b.frameCount; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1785 | t->volumeMix<MIXTYPE, is_same<TI, float>::value /* USEFLOATVOL */, false /* ADJUSTVOL */> ( |
| 1786 | out, outFrames, in, aux, ramp); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1787 | |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1788 | out += outFrames * channels; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1789 | if (aux != NULL) { |
Andy Hung | a601889 | 2018-02-21 14:32:16 -0800 | [diff] [blame] | 1790 | aux += outFrames; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1791 | } |
| 1792 | numFrames -= b.frameCount; |
| 1793 | |
| 1794 | // release buffer |
| 1795 | t->bufferProvider->releaseBuffer(&b); |
| 1796 | } |
| 1797 | if (ramp) { |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1798 | t->adjustVolumeRamp(aux != NULL, is_same<TI, float>::value); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | /* This track hook is called to do resampling then mixing, |
| 1803 | * pulling from the track's upstream AudioBufferProvider. |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1804 | * |
| 1805 | * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1806 | * TO: int32_t (Q4.27) or float |
| 1807 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1808 | * TA: int32_t (Q4.27) or float |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1809 | */ |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1810 | template <int MIXTYPE, typename TO, typename TI, typename TA> |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1811 | void AudioMixer::Track::track__Resample(TO* out, size_t outFrameCount, TO* temp, TA* aux) |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1812 | { |
| 1813 | ALOGVV("track__Resample\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1814 | mResampler->setSampleRate(sampleRate); |
| 1815 | const bool ramp = needsRamp(); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1816 | if (ramp || aux != NULL) { |
| 1817 | // if ramp: resample with unity gain to temp buffer and scale/mix in 2nd step. |
| 1818 | // if aux != NULL: resample with unity gain to temp buffer then apply send level. |
| 1819 | |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1820 | mResampler->setVolume(UNITY_GAIN_FLOAT, UNITY_GAIN_FLOAT); |
| 1821 | memset(temp, 0, outFrameCount * mMixerChannelCount * sizeof(TO)); |
| 1822 | mResampler->resample((int32_t*)temp, outFrameCount, bufferProvider); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1823 | |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1824 | volumeMix<MIXTYPE, is_same<TI, float>::value /* USEFLOATVOL */, true /* ADJUSTVOL */>( |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1825 | out, outFrameCount, temp, aux, ramp); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1826 | |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1827 | } else { // constant volume gain |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1828 | mResampler->setVolume(mVolume[0], mVolume[1]); |
| 1829 | mResampler->resample((int32_t*)out, outFrameCount, bufferProvider); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | /* This track hook is called to mix a track, when no resampling is required. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1834 | * The input buffer should be present in in. |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1835 | * |
| 1836 | * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration) |
| 1837 | * TO: int32_t (Q4.27) or float |
| 1838 | * TI: int32_t (Q4.27) or int16_t (Q0.15) or float |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1839 | * TA: int32_t (Q4.27) or float |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1840 | */ |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1841 | template <int MIXTYPE, typename TO, typename TI, typename TA> |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1842 | void AudioMixer::Track::track__NoResample(TO* out, size_t frameCount, TO* temp __unused, TA* aux) |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1843 | { |
| 1844 | ALOGVV("track__NoResample\n"); |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1845 | const TI *in = static_cast<const TI *>(mIn); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1846 | |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1847 | volumeMix<MIXTYPE, is_same<TI, float>::value /* USEFLOATVOL */, true /* ADJUSTVOL */>( |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1848 | out, frameCount, in, aux, needsRamp()); |
Andy Hung | 5e58b0a | 2014-06-23 19:07:29 -0700 | [diff] [blame] | 1849 | |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1850 | // MIXTYPE_MONOEXPAND reads a single input channel and expands to NCHAN output channels. |
| 1851 | // MIXTYPE_MULTI reads NCHAN input channels and places to NCHAN output channels. |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1852 | in += (MIXTYPE == MIXTYPE_MONOEXPAND) ? frameCount : frameCount * mMixerChannelCount; |
| 1853 | mIn = in; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | /* The Mixer engine generates either int32_t (Q4_27) or float data. |
| 1857 | * We use this function to convert the engine buffers |
| 1858 | * to the desired mixer output format, either int16_t (Q.15) or float. |
| 1859 | */ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1860 | /* static */ |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1861 | void AudioMixer::convertMixerFormat(void *out, audio_format_t mixerOutFormat, |
| 1862 | void *in, audio_format_t mixerInFormat, size_t sampleCount) |
| 1863 | { |
| 1864 | switch (mixerInFormat) { |
| 1865 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1866 | switch (mixerOutFormat) { |
| 1867 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1868 | memcpy(out, in, sampleCount * sizeof(float)); // MEMCPY. TODO optimize out |
| 1869 | break; |
| 1870 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1871 | memcpy_to_i16_from_float((int16_t*)out, (float*)in, sampleCount); |
| 1872 | break; |
| 1873 | default: |
| 1874 | LOG_ALWAYS_FATAL("bad mixerOutFormat: %#x", mixerOutFormat); |
| 1875 | break; |
| 1876 | } |
| 1877 | break; |
| 1878 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1879 | switch (mixerOutFormat) { |
| 1880 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 5effdf6 | 2017-11-27 13:51:40 -0800 | [diff] [blame] | 1881 | memcpy_to_float_from_q4_27((float*)out, (const int32_t*)in, sampleCount); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1882 | break; |
| 1883 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 5effdf6 | 2017-11-27 13:51:40 -0800 | [diff] [blame] | 1884 | memcpy_to_i16_from_q4_27((int16_t*)out, (const int32_t*)in, sampleCount); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1885 | break; |
| 1886 | default: |
| 1887 | LOG_ALWAYS_FATAL("bad mixerOutFormat: %#x", mixerOutFormat); |
| 1888 | break; |
| 1889 | } |
| 1890 | break; |
| 1891 | default: |
| 1892 | LOG_ALWAYS_FATAL("bad mixerInFormat: %#x", mixerInFormat); |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | /* Returns the proper track hook to use for mixing the track into the output buffer. |
| 1898 | */ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1899 | /* static */ |
| 1900 | AudioMixer::hook_t AudioMixer::Track::getTrackHook(int trackType, uint32_t channelCount, |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1901 | audio_format_t mixerInFormat, audio_format_t mixerOutFormat __unused) |
| 1902 | { |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1903 | if (!kUseNewMixer && channelCount == FCC_2 && mixerInFormat == AUDIO_FORMAT_PCM_16_BIT) { |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1904 | switch (trackType) { |
| 1905 | case TRACKTYPE_NOP: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1906 | return &Track::track__nop; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1907 | case TRACKTYPE_RESAMPLE: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1908 | return &Track::track__genericResample; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1909 | case TRACKTYPE_NORESAMPLEMONO: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1910 | return &Track::track__16BitsMono; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1911 | case TRACKTYPE_NORESAMPLE: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1912 | return &Track::track__16BitsStereo; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1913 | default: |
| 1914 | LOG_ALWAYS_FATAL("bad trackType: %d", trackType); |
| 1915 | break; |
| 1916 | } |
| 1917 | } |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1918 | LOG_ALWAYS_FATAL_IF(channelCount > MAX_NUM_CHANNELS); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1919 | switch (trackType) { |
| 1920 | case TRACKTYPE_NOP: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1921 | return &Track::track__nop; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1922 | case TRACKTYPE_RESAMPLE: |
| 1923 | switch (mixerInFormat) { |
| 1924 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1925 | return (AudioMixer::hook_t) &Track::track__Resample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1926 | MIXTYPE_MULTI, float /*TO*/, float /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1927 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1928 | return (AudioMixer::hook_t) &Track::track__Resample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1929 | MIXTYPE_MULTI, int32_t /*TO*/, int16_t /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1930 | default: |
| 1931 | LOG_ALWAYS_FATAL("bad mixerInFormat: %#x", mixerInFormat); |
| 1932 | break; |
| 1933 | } |
| 1934 | break; |
| 1935 | case TRACKTYPE_NORESAMPLEMONO: |
| 1936 | switch (mixerInFormat) { |
| 1937 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1938 | return (AudioMixer::hook_t) &Track::track__NoResample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1939 | MIXTYPE_MONOEXPAND, float /*TO*/, float /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1940 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1941 | return (AudioMixer::hook_t) &Track::track__NoResample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1942 | MIXTYPE_MONOEXPAND, int32_t /*TO*/, int16_t /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1943 | default: |
| 1944 | LOG_ALWAYS_FATAL("bad mixerInFormat: %#x", mixerInFormat); |
| 1945 | break; |
| 1946 | } |
| 1947 | break; |
| 1948 | case TRACKTYPE_NORESAMPLE: |
| 1949 | switch (mixerInFormat) { |
| 1950 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1951 | return (AudioMixer::hook_t) &Track::track__NoResample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1952 | MIXTYPE_MULTI, float /*TO*/, float /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1953 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1954 | return (AudioMixer::hook_t) &Track::track__NoResample< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1955 | MIXTYPE_MULTI, int32_t /*TO*/, int16_t /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1956 | default: |
| 1957 | LOG_ALWAYS_FATAL("bad mixerInFormat: %#x", mixerInFormat); |
| 1958 | break; |
| 1959 | } |
| 1960 | break; |
| 1961 | default: |
| 1962 | LOG_ALWAYS_FATAL("bad trackType: %d", trackType); |
| 1963 | break; |
| 1964 | } |
| 1965 | return NULL; |
| 1966 | } |
| 1967 | |
| 1968 | /* Returns the proper process hook for mixing tracks. Currently works only for |
| 1969 | * PROCESSTYPE_NORESAMPLEONETRACK, a mix involving one track, no resampling. |
Andy Hung | 395db4b | 2014-08-25 17:15:29 -0700 | [diff] [blame] | 1970 | * |
| 1971 | * TODO: Due to the special mixing considerations of duplicating to |
| 1972 | * a stereo output track, the input track cannot be MONO. This should be |
| 1973 | * prevented by the caller. |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1974 | */ |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1975 | /* static */ |
| 1976 | AudioMixer::process_hook_t AudioMixer::getProcessHook( |
| 1977 | int processType, uint32_t channelCount, |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1978 | audio_format_t mixerInFormat, audio_format_t mixerOutFormat) |
| 1979 | { |
| 1980 | if (processType != PROCESSTYPE_NORESAMPLEONETRACK) { // Only NORESAMPLEONETRACK |
| 1981 | LOG_ALWAYS_FATAL("bad processType: %d", processType); |
| 1982 | return NULL; |
| 1983 | } |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1984 | if (!kUseNewMixer && channelCount == FCC_2 && mixerInFormat == AUDIO_FORMAT_PCM_16_BIT) { |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1985 | return &AudioMixer::process__oneTrack16BitsStereoNoResampling; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1986 | } |
Andy Hung | e93b6b7 | 2014-07-17 21:30:53 -0700 | [diff] [blame] | 1987 | LOG_ALWAYS_FATAL_IF(channelCount > MAX_NUM_CHANNELS); |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1988 | switch (mixerInFormat) { |
| 1989 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1990 | switch (mixerOutFormat) { |
| 1991 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1992 | return &AudioMixer::process__noResampleOneTrack< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1993 | MIXTYPE_MULTI_SAVEONLY, float /*TO*/, float /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1994 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 1995 | return &AudioMixer::process__noResampleOneTrack< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 1996 | MIXTYPE_MULTI_SAVEONLY, int16_t /*TO*/, float /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 1997 | default: |
| 1998 | LOG_ALWAYS_FATAL("bad mixerOutFormat: %#x", mixerOutFormat); |
| 1999 | break; |
| 2000 | } |
| 2001 | break; |
| 2002 | case AUDIO_FORMAT_PCM_16_BIT: |
| 2003 | switch (mixerOutFormat) { |
| 2004 | case AUDIO_FORMAT_PCM_FLOAT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 2005 | return &AudioMixer::process__noResampleOneTrack< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 2006 | MIXTYPE_MULTI_SAVEONLY, float /*TO*/, int16_t /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 2007 | case AUDIO_FORMAT_PCM_16_BIT: |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 2008 | return &AudioMixer::process__noResampleOneTrack< |
Andy Hung | 116a498 | 2017-11-30 10:15:08 -0800 | [diff] [blame] | 2009 | MIXTYPE_MULTI_SAVEONLY, int16_t /*TO*/, int16_t /*TI*/, TYPE_AUX>; |
Andy Hung | 296b741 | 2014-06-17 15:25:47 -0700 | [diff] [blame] | 2010 | default: |
| 2011 | LOG_ALWAYS_FATAL("bad mixerOutFormat: %#x", mixerOutFormat); |
| 2012 | break; |
| 2013 | } |
| 2014 | break; |
| 2015 | default: |
| 2016 | LOG_ALWAYS_FATAL("bad mixerInFormat: %#x", mixerInFormat); |
| 2017 | break; |
| 2018 | } |
| 2019 | return NULL; |
| 2020 | } |
| 2021 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2022 | // ---------------------------------------------------------------------------- |
Glenn Kasten | 63238ef | 2015-03-02 15:50:29 -0800 | [diff] [blame] | 2023 | } // namespace android |