blob: cf7d90fe7145870864cb27149532f9adf993b4e8 [file] [log] [blame]
Glenn Kasten99e53b82012-01-19 08:59:58 -08001/*
Mathias Agopian65ab4712010-07-14 17:59:35 -07002**
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#ifndef ANDROID_AUDIO_MIXER_H
19#define ANDROID_AUDIO_MIXER_H
20
Andy Hung8ed196a2018-01-05 13:21:11 -080021#include <pthread.h>
22#include <sstream>
Mathias Agopian65ab4712010-07-14 17:59:35 -070023#include <stdint.h>
24#include <sys/types.h>
Andy Hung8ed196a2018-01-05 13:21:11 -080025#include <unordered_map>
Mathias Agopian65ab4712010-07-14 17:59:35 -070026
Dan Albert36802bd2014-11-20 11:31:17 -080027#include <media/AudioBufferProvider.h>
Andy Hung068561c2017-01-03 17:09:32 -080028#include <media/AudioResampler.h>
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -070029#include <media/AudioResamplerPublic.h>
Andy Hung068561c2017-01-03 17:09:32 -080030#include <media/BufferProviders.h>
Glenn Kasten8589ce72017-09-08 17:03:42 -070031#include <media/nblog/NBLog.h>
Dan Albert36802bd2014-11-20 11:31:17 -080032#include <system/audio.h>
33#include <utils/Compat.h>
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070034#include <utils/threads.h>
35
Glenn Kastenc56f3422014-03-21 17:53:17 -070036// FIXME This is actually unity gain, which might not be max in future, expressed in U.12
Andy Hung97ae8242014-05-30 10:35:47 -070037#define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT
Glenn Kastenc56f3422014-03-21 17:53:17 -070038
Andy Hung116a4982017-11-30 10:15:08 -080039// This must match frameworks/av/services/audioflinger/Configuration.h
40#define FLOAT_AUX
41
Mathias Agopian65ab4712010-07-14 17:59:35 -070042namespace android {
43
44// ----------------------------------------------------------------------------
45
Mathias Agopian65ab4712010-07-14 17:59:35 -070046class AudioMixer
47{
48public:
Andy Hung8ed196a2018-01-05 13:21:11 -080049 // Do not change these unless underlying code changes.
Andy Hunge93b6b72014-07-17 21:30:53 -070050 // This mixer has a hard-coded upper limit of 8 channels for output.
Andy Hung8ed196a2018-01-05 13:21:11 -080051 static constexpr uint32_t MAX_NUM_CHANNELS = FCC_8;
52 static constexpr uint32_t MAX_NUM_VOLUMES = FCC_2; // stereo volume only
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070053 // maximum number of channels supported for the content
Andy Hunge93b6b72014-07-17 21:30:53 -070054 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
Mathias Agopian65ab4712010-07-14 17:59:35 -070055
Andy Hung97ae8242014-05-30 10:35:47 -070056 static const uint16_t UNITY_GAIN_INT = 0x1000;
Dan Albert36802bd2014-11-20 11:31:17 -080057 static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
Mathias Agopian65ab4712010-07-14 17:59:35 -070058
59 enum { // names
Mathias Agopian65ab4712010-07-14 17:59:35 -070060 // setParameter targets
61 TRACK = 0x3000,
62 RESAMPLE = 0x3001,
63 RAMP_VOLUME = 0x3002, // ramp to new volume
64 VOLUME = 0x3003, // don't ramp
Andy Hungc5656cc2015-03-26 19:04:33 -070065 TIMESTRETCH = 0x3004,
Mathias Agopian65ab4712010-07-14 17:59:35 -070066
67 // set Parameter names
68 // for target TRACK
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070069 CHANNEL_MASK = 0x4000,
Mathias Agopian65ab4712010-07-14 17:59:35 -070070 FORMAT = 0x4001,
71 MAIN_BUFFER = 0x4002,
72 AUX_BUFFER = 0x4003,
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070073 DOWNMIX_TYPE = 0X4004,
Andy Hung78820702014-02-28 16:23:02 -080074 MIXER_FORMAT = 0x4005, // AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
Andy Hunge93b6b72014-07-17 21:30:53 -070075 MIXER_CHANNEL_MASK = 0x4006, // Channel mask for mixer output
Glenn Kasten362c4e62011-12-14 10:28:06 -080076 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070077 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
78 // parameter 'value' is the new sample rate in Hz.
79 // Only creates a sample rate converter the first time that
80 // the track sample rate is different from the mix sample rate.
81 // If the new sample rate is the same as the mix sample rate,
82 // and a sample rate converter already exists,
83 // then the sample rate converter remains present but is a no-op.
84 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
85 // This clears out the resampler's input buffer.
86 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
87 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -080088 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -070089 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -070090 VOLUME0 = 0x4200,
91 VOLUME1 = 0x4201,
92 AUXLEVEL = 0x4210,
Andy Hungc5656cc2015-03-26 19:04:33 -070093 // for target TIMESTRETCH
94 PLAYBACK_RATE = 0x4300, // Configure timestretch on this track name;
95 // parameter 'value' is a pointer to the new playback rate.
Mathias Agopian65ab4712010-07-14 17:59:35 -070096 };
97
Andy Hung1bc088a2018-02-09 15:57:31 -080098 AudioMixer(size_t frameCount, uint32_t sampleRate)
99 : mSampleRate(sampleRate)
Andy Hung8ed196a2018-01-05 13:21:11 -0800100 , mFrameCount(frameCount) {
101 pthread_once(&sOnceControl, &sInitRoutine);
102 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700103
Andy Hung1bc088a2018-02-09 15:57:31 -0800104 // Create a new track in the mixer.
105 //
106 // \param name a unique user-provided integer associated with the track.
107 // If name already exists, the function will abort.
108 // \param channelMask output channel mask.
109 // \param format PCM format
110 // \param sessionId Session id for the track. Tracks with the same
111 // session id will be submixed together.
112 //
113 // \return OK on success.
114 // BAD_VALUE if the format does not satisfy isValidFormat()
115 // or the channelMask does not satisfy isValidChannelMask().
116 status_t create(
117 int name, audio_channel_mask_t channelMask, audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800118
Andy Hung1bc088a2018-02-09 15:57:31 -0800119 bool exists(int name) const {
120 return mTracks.count(name) > 0;
121 }
Glenn Kasten17a736c2012-02-14 08:52:15 -0800122
Andy Hung1bc088a2018-02-09 15:57:31 -0800123 // Free an allocated track by name.
124 void destroy(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700125
Glenn Kasten17a736c2012-02-14 08:52:15 -0800126 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800127 void enable(int name);
128 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700129
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800130 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700131
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800132 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700133
Andy Hung8ed196a2018-01-05 13:21:11 -0800134 void process() {
135 (this->*mHook)();
136 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700137
Glenn Kastenc59c0042012-02-02 14:06:11 -0800138 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800139
Andy Hung8ed196a2018-01-05 13:21:11 -0800140 std::string trackNames() const {
141 std::stringstream ss;
142 for (const auto &pair : mTracks) {
143 ss << pair.first << " ";
Andy Hungabdb9902015-01-12 15:08:22 -0800144 }
Andy Hung8ed196a2018-01-05 13:21:11 -0800145 return ss.str();
146 }
147
148 void setNBLogWriter(NBLog::Writer *logWriter) {
149 mNBLogWriter = logWriter;
Andy Hunge8a1ced2014-05-09 15:02:21 -0700150 }
151
Andy Hung1bc088a2018-02-09 15:57:31 -0800152 static inline bool isValidFormat(audio_format_t format) {
153 switch (format) {
154 case AUDIO_FORMAT_PCM_8_BIT:
155 case AUDIO_FORMAT_PCM_16_BIT:
156 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
157 case AUDIO_FORMAT_PCM_32_BIT:
158 case AUDIO_FORMAT_PCM_FLOAT:
159 return true;
160 default:
161 return false;
162 }
163 }
164
165 static inline bool isValidChannelMask(audio_channel_mask_t channelMask) {
166 return audio_channel_mask_is_valid(channelMask); // the RemixBufferProvider is flexible.
167 }
168
Mathias Agopian65ab4712010-07-14 17:59:35 -0700169private:
170
Andy Hung8ed196a2018-01-05 13:21:11 -0800171 /* For multi-format functions (calls template functions
172 * in AudioMixerOps.h). The template parameters are as follows:
173 *
174 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
175 * USEFLOATVOL (set to true if float volume is used)
176 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
177 * TO: int32_t (Q4.27) or float
178 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
179 * TA: int32_t (Q4.27)
180 */
181
Mathias Agopian65ab4712010-07-14 17:59:35 -0700182 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700183 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700184 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700185 };
186
187 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700188 NEEDS_CHANNEL_1 = 0x00000000, // mono
189 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700190
Glenn Kastend6fadf02013-10-30 14:37:29 -0700191 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700192
Glenn Kastend6fadf02013-10-30 14:37:29 -0700193 NEEDS_MUTE = 0x00000100,
194 NEEDS_RESAMPLE = 0x00001000,
195 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700196 };
197
Andy Hung8ed196a2018-01-05 13:21:11 -0800198 // hook types
199 enum {
200 PROCESSTYPE_NORESAMPLEONETRACK, // others set elsewhere
201 };
Mathias Agopian65ab4712010-07-14 17:59:35 -0700202
Andy Hung8ed196a2018-01-05 13:21:11 -0800203 enum {
204 TRACKTYPE_NOP,
205 TRACKTYPE_RESAMPLE,
206 TRACKTYPE_NORESAMPLE,
207 TRACKTYPE_NORESAMPLEMONO,
208 };
Mathias Agopian65ab4712010-07-14 17:59:35 -0700209
Andy Hung8ed196a2018-01-05 13:21:11 -0800210 // process hook functionality
211 using process_hook_t = void(AudioMixer::*)();
212
213 struct Track;
214 using hook_t = void(Track::*)(int32_t* output, size_t numOutFrames, int32_t* temp, int32_t* aux);
215
216 struct Track {
217 Track()
218 : bufferProvider(nullptr)
219 {
220 // TODO: move additional initialization here.
221 }
222
223 ~Track()
224 {
225 // bufferProvider, mInputBufferProvider need not be deleted.
226 mResampler.reset(nullptr);
227 // Ensure the order of destruction of buffer providers as they
228 // release the upstream provider in the destructor.
229 mTimestretchBufferProvider.reset(nullptr);
230 mPostDownmixReformatBufferProvider.reset(nullptr);
231 mDownmixerBufferProvider.reset(nullptr);
232 mReformatBufferProvider.reset(nullptr);
233 }
234
235 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
236 bool setResampler(uint32_t trackSampleRate, uint32_t devSampleRate);
237 bool doesResample() const { return mResampler.get() != nullptr; }
238 void resetResampler() { if (mResampler.get() != nullptr) mResampler->reset(); }
239 void adjustVolumeRamp(bool aux, bool useFloat = false);
240 size_t getUnreleasedFrames() const { return mResampler.get() != nullptr ?
241 mResampler->getUnreleasedFrames() : 0; };
242
243 status_t prepareForDownmix();
244 void unprepareForDownmix();
245 status_t prepareForReformat();
246 void unprepareForReformat();
247 bool setPlaybackRate(const AudioPlaybackRate &playbackRate);
248 void reconfigureBufferProviders();
249
250 static hook_t getTrackHook(int trackType, uint32_t channelCount,
251 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
252
253 void track__nop(int32_t* out, size_t numFrames, int32_t* temp, int32_t* aux);
254
255 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
256 typename TO, typename TI, typename TA>
257 void volumeMix(TO *out, size_t outFrames, const TI *in, TA *aux, bool ramp);
258
Mathias Agopian65ab4712010-07-14 17:59:35 -0700259 uint32_t needs;
260
Andy Hung5e58b0a2014-06-23 19:07:29 -0700261 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700262 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700263 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700264 int32_t volumeRL;
265 };
266
Andy Hunge93b6b72014-07-17 21:30:53 -0700267 int32_t prevVolume[MAX_NUM_VOLUMES];
Andy Hunge93b6b72014-07-17 21:30:53 -0700268 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700269 int32_t auxInc;
270 int32_t prevAuxLevel;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800271 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Andy Hung8ed196a2018-01-05 13:21:11 -0800272
Mathias Agopian65ab4712010-07-14 17:59:35 -0700273 uint16_t frameCount;
274
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800275 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700276 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800277 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700278 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700279
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700280 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
281 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700282 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800283
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800284 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700285
286 hook_t hook;
Andy Hung8ed196a2018-01-05 13:21:11 -0800287 const void *mIn; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700288
Andy Hung8ed196a2018-01-05 13:21:11 -0800289 std::unique_ptr<AudioResampler> mResampler;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700290 uint32_t sampleRate;
291 int32_t* mainBuffer;
292 int32_t* auxBuffer;
293
Andy Hung7f475492014-08-25 16:36:37 -0700294 /* Buffer providers are constructed to translate the track input data as needed.
295 *
Andy Hungc5656cc2015-03-26 19:04:33 -0700296 * TODO: perhaps make a single PlaybackConverterProvider class to move
297 * all pre-mixer track buffer conversions outside the AudioMixer class.
298 *
Andy Hung7f475492014-08-25 16:36:37 -0700299 * 1) mInputBufferProvider: The AudioTrack buffer provider.
300 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
301 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
302 * requires reformat. For example, it may convert floating point input to
303 * PCM_16_bit if that's required by the downmixer.
Andy Hung8ed196a2018-01-05 13:21:11 -0800304 * 3) mDownmixerBufferProvider: If not NULL, performs the channel remixing to match
Andy Hung7f475492014-08-25 16:36:37 -0700305 * the number of channels required by the mixer sink.
306 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
307 * the downmixer requirements to the mixer engine input requirements.
Andy Hungc5656cc2015-03-26 19:04:33 -0700308 * 5) mTimestretchBufferProvider: Adds timestretching for playback rate
Andy Hung7f475492014-08-25 16:36:37 -0700309 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700310 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung8ed196a2018-01-05 13:21:11 -0800311 std::unique_ptr<PassthruBufferProvider> mReformatBufferProvider;
312 std::unique_ptr<PassthruBufferProvider> mDownmixerBufferProvider;
313 std::unique_ptr<PassthruBufferProvider> mPostDownmixReformatBufferProvider;
314 std::unique_ptr<PassthruBufferProvider> mTimestretchBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700315
Andy Hung7f475492014-08-25 16:36:37 -0700316 int32_t sessionId;
317
Andy Hunge8a1ced2014-05-09 15:02:21 -0700318 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
319 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700320 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
321 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700322 audio_format_t mDownmixRequiresFormat; // required downmixer format
323 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
324 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700325
Andy Hunge93b6b72014-07-17 21:30:53 -0700326 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
327 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
328 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700329
330 float mAuxLevel; // floating point set aux level
331 float mPrevAuxLevel; // floating point prev aux level
332 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800333
Andy Hunge93b6b72014-07-17 21:30:53 -0700334 audio_channel_mask_t mMixerChannelMask;
335 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800336
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700337 AudioPlaybackRate mPlaybackRate;
Andy Hungc5656cc2015-03-26 19:04:33 -0700338
Andy Hung8ed196a2018-01-05 13:21:11 -0800339 private:
340 // hooks
341 void track__genericResample(int32_t* out, size_t numFrames, int32_t* temp, int32_t* aux);
342 void track__16BitsStereo(int32_t* out, size_t numFrames, int32_t* temp, int32_t* aux);
343 void track__16BitsMono(int32_t* out, size_t numFrames, int32_t* temp, int32_t* aux);
Andy Hung0f451e92014-08-04 21:28:47 -0700344
Andy Hung8ed196a2018-01-05 13:21:11 -0800345 void volumeRampStereo(int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux);
346 void volumeStereo(int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux);
347
348 // multi-format track hooks
349 template <int MIXTYPE, typename TO, typename TI, typename TA>
350 void track__Resample(TO* out, size_t frameCount, TO* temp __unused, TA* aux);
351 template <int MIXTYPE, typename TO, typename TI, typename TA>
352 void track__NoResample(TO* out, size_t frameCount, TO* temp __unused, TA* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700353 };
354
Andy Hung8ed196a2018-01-05 13:21:11 -0800355 // TODO: remove BLOCKSIZE unit of processing - it isn't needed anymore.
356 static constexpr int BLOCKSIZE = 16;
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700357
Andy Hunge93b6b72014-07-17 21:30:53 -0700358 bool setChannelMasks(int name,
359 audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask);
360
Andy Hung8ed196a2018-01-05 13:21:11 -0800361 // Called when track info changes and a new process hook should be determined.
362 void invalidate() {
363 mHook = &AudioMixer::process__validate;
364 }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700365
Andy Hung8ed196a2018-01-05 13:21:11 -0800366 void process__validate();
367 void process__nop();
368 void process__genericNoResampling();
369 void process__genericResampling();
370 void process__oneTrack16BitsStereoNoResampling();
John Grossman4ff14ba2012-02-08 16:37:41 -0800371
Andy Hunge93b6b72014-07-17 21:30:53 -0700372 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung8ed196a2018-01-05 13:21:11 -0800373 void process__noResampleOneTrack();
Andy Hung296b7412014-06-17 15:25:47 -0700374
Andy Hung8ed196a2018-01-05 13:21:11 -0800375 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
376 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hung296b7412014-06-17 15:25:47 -0700377
378 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
379 void *in, audio_format_t mixerInFormat, size_t sampleCount);
380
Andy Hung8ed196a2018-01-05 13:21:11 -0800381 static void sInitRoutine();
382
383 // initialization constants
Andy Hung8ed196a2018-01-05 13:21:11 -0800384 const uint32_t mSampleRate;
385 const size_t mFrameCount;
386
387 NBLog::Writer *mNBLogWriter = nullptr; // associated NBLog::Writer
388
389 process_hook_t mHook = &AudioMixer::process__nop; // one of process__*, never nullptr
390
391 // the size of the type (int32_t) should be the largest of all types supported
392 // by the mixer.
393 std::unique_ptr<int32_t[]> mOutputTemp;
394 std::unique_ptr<int32_t[]> mResampleTemp;
395
Andy Hung8ed196a2018-01-05 13:21:11 -0800396 // track names grouped by main buffer, in no particular order of main buffer.
397 // however names for a particular main buffer are in order (by construction).
398 std::unordered_map<void * /* mainBuffer */, std::vector<int /* name */>> mGroups;
399
400 // track names that are enabled, in increasing order (by construction).
401 std::vector<int /* name */> mEnabled;
402
403 // track smart pointers, by name, in increasing order of name.
404 std::map<int /* name */, std::shared_ptr<Track>> mTracks;
405
406 static pthread_once_t sOnceControl; // initialized in constructor by first new
Mathias Agopian65ab4712010-07-14 17:59:35 -0700407};
408
409// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800410} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700411
412#endif // ANDROID_AUDIO_MIXER_H