blob: e27a0d163ed8e4bb27ef61001c4d9cd6fa633067 [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
21#include <stdint.h>
22#include <sys/types.h>
23
Dan Albert36802bd2014-11-20 11:31:17 -080024#include <hardware/audio_effect.h>
25#include <media/AudioBufferProvider.h>
26#include <media/nbaio/NBLog.h>
27#include <system/audio.h>
28#include <utils/Compat.h>
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070029#include <utils/threads.h>
30
Mathias Agopian65ab4712010-07-14 17:59:35 -070031#include "AudioResampler.h"
Andy Hung857d5a22015-03-26 18:46:00 -070032#include "BufferProviders.h"
Mathias Agopian65ab4712010-07-14 17:59:35 -070033
Glenn Kastenc56f3422014-03-21 17:53:17 -070034// FIXME This is actually unity gain, which might not be max in future, expressed in U.12
Andy Hung97ae8242014-05-30 10:35:47 -070035#define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT
Glenn Kastenc56f3422014-03-21 17:53:17 -070036
Mathias Agopian65ab4712010-07-14 17:59:35 -070037namespace android {
38
39// ----------------------------------------------------------------------------
40
Mathias Agopian65ab4712010-07-14 17:59:35 -070041class AudioMixer
42{
43public:
Glenn Kasten5c94b6c2012-03-20 17:01:29 -070044 AudioMixer(size_t frameCount, uint32_t sampleRate,
45 uint32_t maxNumTracks = MAX_NUM_TRACKS);
Mathias Agopian65ab4712010-07-14 17:59:35 -070046
Glenn Kastenc19e2242012-01-30 14:54:39 -080047 /*virtual*/ ~AudioMixer(); // non-virtual saves a v-table, restore if sub-classed
Mathias Agopian65ab4712010-07-14 17:59:35 -070048
Glenn Kasten599fabc2012-03-08 12:33:37 -080049
50 // This mixer has a hard-coded upper limit of 32 active track inputs.
51 // Adding support for > 32 tracks would require more than simply changing this value.
Mathias Agopian65ab4712010-07-14 17:59:35 -070052 static const uint32_t MAX_NUM_TRACKS = 32;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070053 // maximum number of channels supported by the mixer
Glenn Kasten599fabc2012-03-08 12:33:37 -080054
Andy Hunge93b6b72014-07-17 21:30:53 -070055 // This mixer has a hard-coded upper limit of 8 channels for output.
56 static const uint32_t MAX_NUM_CHANNELS = 8;
57 static const uint32_t MAX_NUM_VOLUMES = 2; // stereo volume only
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070058 // maximum number of channels supported for the content
Andy Hunge93b6b72014-07-17 21:30:53 -070059 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
Mathias Agopian65ab4712010-07-14 17:59:35 -070060
Andy Hung97ae8242014-05-30 10:35:47 -070061 static const uint16_t UNITY_GAIN_INT = 0x1000;
Dan Albert36802bd2014-11-20 11:31:17 -080062 static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
Mathias Agopian65ab4712010-07-14 17:59:35 -070063
64 enum { // names
65
Glenn Kasten9c56d4a2011-12-19 15:06:39 -080066 // track names (MAX_NUM_TRACKS units)
Mathias Agopian65ab4712010-07-14 17:59:35 -070067 TRACK0 = 0x1000,
68
Glenn Kasten1c48c3c2011-12-15 14:54:01 -080069 // 0x2000 is unused
Mathias Agopian65ab4712010-07-14 17:59:35 -070070
71 // setParameter targets
72 TRACK = 0x3000,
73 RESAMPLE = 0x3001,
74 RAMP_VOLUME = 0x3002, // ramp to new volume
75 VOLUME = 0x3003, // don't ramp
Andy Hungc5656cc2015-03-26 19:04:33 -070076 TIMESTRETCH = 0x3004,
Mathias Agopian65ab4712010-07-14 17:59:35 -070077
78 // set Parameter names
79 // for target TRACK
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070080 CHANNEL_MASK = 0x4000,
Mathias Agopian65ab4712010-07-14 17:59:35 -070081 FORMAT = 0x4001,
82 MAIN_BUFFER = 0x4002,
83 AUX_BUFFER = 0x4003,
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070084 DOWNMIX_TYPE = 0X4004,
Andy Hung78820702014-02-28 16:23:02 -080085 MIXER_FORMAT = 0x4005, // AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
Andy Hunge93b6b72014-07-17 21:30:53 -070086 MIXER_CHANNEL_MASK = 0x4006, // Channel mask for mixer output
Glenn Kasten362c4e62011-12-14 10:28:06 -080087 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070088 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
89 // parameter 'value' is the new sample rate in Hz.
90 // Only creates a sample rate converter the first time that
91 // the track sample rate is different from the mix sample rate.
92 // If the new sample rate is the same as the mix sample rate,
93 // and a sample rate converter already exists,
94 // then the sample rate converter remains present but is a no-op.
95 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
96 // This clears out the resampler's input buffer.
97 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
98 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -080099 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -0700100 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -0700101 VOLUME0 = 0x4200,
102 VOLUME1 = 0x4201,
103 AUXLEVEL = 0x4210,
Andy Hungc5656cc2015-03-26 19:04:33 -0700104 // for target TIMESTRETCH
105 PLAYBACK_RATE = 0x4300, // Configure timestretch on this track name;
106 // parameter 'value' is a pointer to the new playback rate.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700107 };
108
109
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800110 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800111
112 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700113 // The failure could be because of an invalid channelMask or format, or that
114 // the track capacity of the mixer is exceeded.
115 int getTrackName(audio_channel_mask_t channelMask,
116 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800117
118 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700119 void deleteTrackName(int name);
120
Glenn Kasten17a736c2012-02-14 08:52:15 -0800121 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800122 void enable(int name);
123 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700124
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800125 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700126
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800127 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
John Grossman4ff14ba2012-02-08 16:37:41 -0800128 void process(int64_t pts);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700129
130 uint32_t trackNames() const { return mTrackNames; }
131
Glenn Kastenc59c0042012-02-02 14:06:11 -0800132 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800133
Andy Hunge8a1ced2014-05-09 15:02:21 -0700134 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungabdb9902015-01-12 15:08:22 -0800135 switch (format) {
136 case AUDIO_FORMAT_PCM_8_BIT:
137 case AUDIO_FORMAT_PCM_16_BIT:
138 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
139 case AUDIO_FORMAT_PCM_32_BIT:
140 case AUDIO_FORMAT_PCM_FLOAT:
141 return true;
142 default:
143 return false;
144 }
Andy Hunge8a1ced2014-05-09 15:02:21 -0700145 }
146
Mathias Agopian65ab4712010-07-14 17:59:35 -0700147private:
148
149 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700150 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700151 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700152 };
153
154 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700155 NEEDS_CHANNEL_1 = 0x00000000, // mono
156 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700157
Glenn Kastend6fadf02013-10-30 14:37:29 -0700158 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700159
Glenn Kastend6fadf02013-10-30 14:37:29 -0700160 NEEDS_MUTE = 0x00000100,
161 NEEDS_RESAMPLE = 0x00001000,
162 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700163 };
164
Mathias Agopian65ab4712010-07-14 17:59:35 -0700165 struct state_t;
166 struct track_t;
167
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700168 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
169 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700170 static const int BLOCKSIZE = 16; // 4 cache lines
171
172 struct track_t {
173 uint32_t needs;
174
Andy Hung5e58b0a2014-06-23 19:07:29 -0700175 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700176 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700177 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700178 int32_t volumeRL;
179 };
180
Andy Hunge93b6b72014-07-17 21:30:53 -0700181 int32_t prevVolume[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700182
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800183 // 16-byte boundary
184
Andy Hunge93b6b72014-07-17 21:30:53 -0700185 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700186 int32_t auxInc;
187 int32_t prevAuxLevel;
188
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800189 // 16-byte boundary
190
191 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700192 uint16_t frameCount;
193
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800194 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700195 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800196 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700197 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700198
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700199 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
200 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700201 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800202
203 // 16-byte boundary
204
205 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700206
207 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800208 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700209
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800210 // 16-byte boundary
211
Mathias Agopian65ab4712010-07-14 17:59:35 -0700212 AudioResampler* resampler;
213 uint32_t sampleRate;
214 int32_t* mainBuffer;
215 int32_t* auxBuffer;
216
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800217 // 16-byte boundary
Andy Hung7f475492014-08-25 16:36:37 -0700218
219 /* Buffer providers are constructed to translate the track input data as needed.
220 *
Andy Hungc5656cc2015-03-26 19:04:33 -0700221 * TODO: perhaps make a single PlaybackConverterProvider class to move
222 * all pre-mixer track buffer conversions outside the AudioMixer class.
223 *
Andy Hung7f475492014-08-25 16:36:37 -0700224 * 1) mInputBufferProvider: The AudioTrack buffer provider.
225 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
226 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
227 * requires reformat. For example, it may convert floating point input to
228 * PCM_16_bit if that's required by the downmixer.
229 * 3) downmixerBufferProvider: If not NULL, performs the channel remixing to match
230 * the number of channels required by the mixer sink.
231 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
232 * the downmixer requirements to the mixer engine input requirements.
Andy Hungc5656cc2015-03-26 19:04:33 -0700233 * 5) mTimestretchBufferProvider: Adds timestretching for playback rate
Andy Hung7f475492014-08-25 16:36:37 -0700234 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700235 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung857d5a22015-03-26 18:46:00 -0700236 PassthruBufferProvider* mReformatBufferProvider; // provider wrapper for reformatting.
237 PassthruBufferProvider* downmixerBufferProvider; // wrapper for channel conversion.
238 PassthruBufferProvider* mPostDownmixReformatBufferProvider;
Andy Hungc5656cc2015-03-26 19:04:33 -0700239 PassthruBufferProvider* mTimestretchBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700240
Andy Hung7f475492014-08-25 16:36:37 -0700241 int32_t sessionId;
242
Andy Hunge8a1ced2014-05-09 15:02:21 -0700243 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
244 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700245 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
246 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700247 audio_format_t mDownmixRequiresFormat; // required downmixer format
248 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
249 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700250
Andy Hunge93b6b72014-07-17 21:30:53 -0700251 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
252 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
253 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700254
255 float mAuxLevel; // floating point set aux level
256 float mPrevAuxLevel; // floating point prev aux level
257 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800258
Andy Hunge93b6b72014-07-17 21:30:53 -0700259 audio_channel_mask_t mMixerChannelMask;
260 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800261
Andy Hungc5656cc2015-03-26 19:04:33 -0700262 float mSpeed;
263 float mPitch;
264
Andy Hung296b7412014-06-17 15:25:47 -0700265 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
Andy Hunge93b6b72014-07-17 21:30:53 -0700266 bool setResampler(uint32_t trackSampleRate, uint32_t devSampleRate);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800267 bool doesResample() const { return resampler != NULL; }
268 void resetResampler() { if (resampler != NULL) resampler->reset(); }
Andy Hung5e58b0a2014-06-23 19:07:29 -0700269 void adjustVolumeRamp(bool aux, bool useFloat = false);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800270 size_t getUnreleasedFrames() const { return resampler != NULL ?
271 resampler->getUnreleasedFrames() : 0; };
Andy Hung0f451e92014-08-04 21:28:47 -0700272
273 status_t prepareForDownmix();
274 void unprepareForDownmix();
275 status_t prepareForReformat();
276 void unprepareForReformat();
Andy Hungc5656cc2015-03-26 19:04:33 -0700277 bool setPlaybackRate(float speed, float pitch);
Andy Hung0f451e92014-08-04 21:28:47 -0700278 void reconfigureBufferProviders();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700279 };
280
Andy Hung296b7412014-06-17 15:25:47 -0700281 typedef void (*process_hook_t)(state_t* state, int64_t pts);
282
Mathias Agopian65ab4712010-07-14 17:59:35 -0700283 // pad to 32-bytes to fill cache line
284 struct state_t {
285 uint32_t enabledTracks;
286 uint32_t needsChanged;
287 size_t frameCount;
Andy Hung296b7412014-06-17 15:25:47 -0700288 process_hook_t hook; // one of process__*, never NULL
Mathias Agopian65ab4712010-07-14 17:59:35 -0700289 int32_t *outputTemp;
290 int32_t *resampleTemp;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800291 NBLog::Writer* mLog;
292 int32_t reserved[1];
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700293 // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800294 track_t tracks[MAX_NUM_TRACKS] __attribute__((aligned(32)));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700295 };
296
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800297 // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700298 uint32_t mTrackNames;
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700299
300 // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
301 // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
302 const uint32_t mConfiguredNames;
303
Mathias Agopian65ab4712010-07-14 17:59:35 -0700304 const uint32_t mSampleRate;
305
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800306 NBLog::Writer mDummyLog;
307public:
308 void setLog(NBLog::Writer* log);
309private:
Mathias Agopian65ab4712010-07-14 17:59:35 -0700310 state_t mState __attribute__((aligned(32)));
311
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700312 // Call after changing either the enabled status of a track, or parameters of an enabled track.
313 // OK to call more often than that, but unnecessary.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700314 void invalidateState(uint32_t mask);
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700315
Andy Hunge93b6b72014-07-17 21:30:53 -0700316 bool setChannelMasks(int name,
317 audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask);
318
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700319 static void track__genericResample(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
320 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700321 static void track__nop(track_t* t, int32_t* out, size_t numFrames, int32_t* temp, int32_t* aux);
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700322 static void track__16BitsStereo(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
323 int32_t* aux);
324 static void track__16BitsMono(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
325 int32_t* aux);
326 static void volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
327 int32_t* aux);
328 static void volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
329 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700330
John Grossman4ff14ba2012-02-08 16:37:41 -0800331 static void process__validate(state_t* state, int64_t pts);
332 static void process__nop(state_t* state, int64_t pts);
333 static void process__genericNoResampling(state_t* state, int64_t pts);
334 static void process__genericResampling(state_t* state, int64_t pts);
335 static void process__OneTrack16BitsStereoNoResampling(state_t* state,
336 int64_t pts);
John Grossman4ff14ba2012-02-08 16:37:41 -0800337
338 static int64_t calculateOutputPTS(const track_t& t, int64_t basePTS,
339 int outputFrameIndex);
Glenn Kasten52008f82012-03-18 09:34:41 -0700340
341 static uint64_t sLocalTimeFreq;
342 static pthread_once_t sOnceControl;
343 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700344
Andy Hung5e58b0a2014-06-23 19:07:29 -0700345 /* multi-format volume mixing function (calls template functions
346 * in AudioMixerOps.h). The template parameters are as follows:
347 *
348 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
Andy Hung5e58b0a2014-06-23 19:07:29 -0700349 * USEFLOATVOL (set to true if float volume is used)
350 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
351 * TO: int32_t (Q4.27) or float
352 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
353 * TA: int32_t (Q4.27)
354 */
Andy Hunge93b6b72014-07-17 21:30:53 -0700355 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
Andy Hung5e58b0a2014-06-23 19:07:29 -0700356 typename TO, typename TI, typename TA>
357 static void volumeMix(TO *out, size_t outFrames,
358 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
359
Andy Hung296b7412014-06-17 15:25:47 -0700360 // multi-format process hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700361 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700362 static void process_NoResampleOneTrack(state_t* state, int64_t pts);
363
364 // multi-format track hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700365 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700366 static void track__Resample(track_t* t, TO* out, size_t frameCount,
367 TO* temp __unused, TA* aux);
Andy Hunge93b6b72014-07-17 21:30:53 -0700368 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700369 static void track__NoResample(track_t* t, TO* out, size_t frameCount,
370 TO* temp __unused, TA* aux);
371
372 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
373 void *in, audio_format_t mixerInFormat, size_t sampleCount);
374
375 // hook types
376 enum {
377 PROCESSTYPE_NORESAMPLEONETRACK,
378 };
379 enum {
380 TRACKTYPE_NOP,
381 TRACKTYPE_RESAMPLE,
382 TRACKTYPE_NORESAMPLE,
383 TRACKTYPE_NORESAMPLEMONO,
384 };
385
386 // functions for determining the proper process and track hooks.
Andy Hunge93b6b72014-07-17 21:30:53 -0700387 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700388 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hunge93b6b72014-07-17 21:30:53 -0700389 static hook_t getTrackHook(int trackType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700390 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700391};
392
393// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800394} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700395
396#endif // ANDROID_AUDIO_MIXER_H