blob: e283b83a95b0b6539d459ec1acea14c15b372dab [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
76
77 // set Parameter names
78 // for target TRACK
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070079 CHANNEL_MASK = 0x4000,
Mathias Agopian65ab4712010-07-14 17:59:35 -070080 FORMAT = 0x4001,
81 MAIN_BUFFER = 0x4002,
82 AUX_BUFFER = 0x4003,
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070083 DOWNMIX_TYPE = 0X4004,
Andy Hung78820702014-02-28 16:23:02 -080084 MIXER_FORMAT = 0x4005, // AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
Andy Hunge93b6b72014-07-17 21:30:53 -070085 MIXER_CHANNEL_MASK = 0x4006, // Channel mask for mixer output
Glenn Kasten362c4e62011-12-14 10:28:06 -080086 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070087 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
88 // parameter 'value' is the new sample rate in Hz.
89 // Only creates a sample rate converter the first time that
90 // the track sample rate is different from the mix sample rate.
91 // If the new sample rate is the same as the mix sample rate,
92 // and a sample rate converter already exists,
93 // then the sample rate converter remains present but is a no-op.
94 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
95 // This clears out the resampler's input buffer.
96 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
97 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -080098 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -070099 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -0700100 VOLUME0 = 0x4200,
101 VOLUME1 = 0x4201,
102 AUXLEVEL = 0x4210,
103 };
104
105
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800106 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800107
108 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700109 // The failure could be because of an invalid channelMask or format, or that
110 // the track capacity of the mixer is exceeded.
111 int getTrackName(audio_channel_mask_t channelMask,
112 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800113
114 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700115 void deleteTrackName(int name);
116
Glenn Kasten17a736c2012-02-14 08:52:15 -0800117 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800118 void enable(int name);
119 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700120
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800121 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700122
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800123 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
John Grossman4ff14ba2012-02-08 16:37:41 -0800124 void process(int64_t pts);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700125
126 uint32_t trackNames() const { return mTrackNames; }
127
Glenn Kastenc59c0042012-02-02 14:06:11 -0800128 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800129
Andy Hunge8a1ced2014-05-09 15:02:21 -0700130 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungabdb9902015-01-12 15:08:22 -0800131 switch (format) {
132 case AUDIO_FORMAT_PCM_8_BIT:
133 case AUDIO_FORMAT_PCM_16_BIT:
134 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
135 case AUDIO_FORMAT_PCM_32_BIT:
136 case AUDIO_FORMAT_PCM_FLOAT:
137 return true;
138 default:
139 return false;
140 }
Andy Hunge8a1ced2014-05-09 15:02:21 -0700141 }
142
Mathias Agopian65ab4712010-07-14 17:59:35 -0700143private:
144
145 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700146 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700147 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700148 };
149
150 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700151 NEEDS_CHANNEL_1 = 0x00000000, // mono
152 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700153
Glenn Kastend6fadf02013-10-30 14:37:29 -0700154 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700155
Glenn Kastend6fadf02013-10-30 14:37:29 -0700156 NEEDS_MUTE = 0x00000100,
157 NEEDS_RESAMPLE = 0x00001000,
158 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700159 };
160
Mathias Agopian65ab4712010-07-14 17:59:35 -0700161 struct state_t;
162 struct track_t;
163
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700164 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
165 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700166 static const int BLOCKSIZE = 16; // 4 cache lines
167
168 struct track_t {
169 uint32_t needs;
170
Andy Hung5e58b0a2014-06-23 19:07:29 -0700171 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700172 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700173 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700174 int32_t volumeRL;
175 };
176
Andy Hunge93b6b72014-07-17 21:30:53 -0700177 int32_t prevVolume[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700178
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800179 // 16-byte boundary
180
Andy Hunge93b6b72014-07-17 21:30:53 -0700181 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700182 int32_t auxInc;
183 int32_t prevAuxLevel;
184
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800185 // 16-byte boundary
186
187 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700188 uint16_t frameCount;
189
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800190 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700191 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800192 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700193 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700194
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700195 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
196 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700197 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800198
199 // 16-byte boundary
200
201 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700202
203 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800204 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700205
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800206 // 16-byte boundary
207
Mathias Agopian65ab4712010-07-14 17:59:35 -0700208 AudioResampler* resampler;
209 uint32_t sampleRate;
210 int32_t* mainBuffer;
211 int32_t* auxBuffer;
212
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800213 // 16-byte boundary
Andy Hung7f475492014-08-25 16:36:37 -0700214
215 /* Buffer providers are constructed to translate the track input data as needed.
216 *
217 * 1) mInputBufferProvider: The AudioTrack buffer provider.
218 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
219 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
220 * requires reformat. For example, it may convert floating point input to
221 * PCM_16_bit if that's required by the downmixer.
222 * 3) downmixerBufferProvider: If not NULL, performs the channel remixing to match
223 * the number of channels required by the mixer sink.
224 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
225 * the downmixer requirements to the mixer engine input requirements.
226 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700227 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung857d5a22015-03-26 18:46:00 -0700228 PassthruBufferProvider* mReformatBufferProvider; // provider wrapper for reformatting.
229 PassthruBufferProvider* downmixerBufferProvider; // wrapper for channel conversion.
230 PassthruBufferProvider* mPostDownmixReformatBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700231
Andy Hung7f475492014-08-25 16:36:37 -0700232 int32_t sessionId;
233
Andy Hunge8a1ced2014-05-09 15:02:21 -0700234 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
235 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700236 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
237 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700238 audio_format_t mDownmixRequiresFormat; // required downmixer format
239 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
240 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700241
Andy Hunge93b6b72014-07-17 21:30:53 -0700242 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
243 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
244 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700245
246 float mAuxLevel; // floating point set aux level
247 float mPrevAuxLevel; // floating point prev aux level
248 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800249
Andy Hunge93b6b72014-07-17 21:30:53 -0700250 audio_channel_mask_t mMixerChannelMask;
251 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800252
Andy Hung296b7412014-06-17 15:25:47 -0700253 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
Andy Hunge93b6b72014-07-17 21:30:53 -0700254 bool setResampler(uint32_t trackSampleRate, uint32_t devSampleRate);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800255 bool doesResample() const { return resampler != NULL; }
256 void resetResampler() { if (resampler != NULL) resampler->reset(); }
Andy Hung5e58b0a2014-06-23 19:07:29 -0700257 void adjustVolumeRamp(bool aux, bool useFloat = false);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800258 size_t getUnreleasedFrames() const { return resampler != NULL ?
259 resampler->getUnreleasedFrames() : 0; };
Andy Hung0f451e92014-08-04 21:28:47 -0700260
261 status_t prepareForDownmix();
262 void unprepareForDownmix();
263 status_t prepareForReformat();
264 void unprepareForReformat();
265 void reconfigureBufferProviders();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700266 };
267
Andy Hung296b7412014-06-17 15:25:47 -0700268 typedef void (*process_hook_t)(state_t* state, int64_t pts);
269
Mathias Agopian65ab4712010-07-14 17:59:35 -0700270 // pad to 32-bytes to fill cache line
271 struct state_t {
272 uint32_t enabledTracks;
273 uint32_t needsChanged;
274 size_t frameCount;
Andy Hung296b7412014-06-17 15:25:47 -0700275 process_hook_t hook; // one of process__*, never NULL
Mathias Agopian65ab4712010-07-14 17:59:35 -0700276 int32_t *outputTemp;
277 int32_t *resampleTemp;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800278 NBLog::Writer* mLog;
279 int32_t reserved[1];
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700280 // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800281 track_t tracks[MAX_NUM_TRACKS] __attribute__((aligned(32)));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700282 };
283
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800284 // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700285 uint32_t mTrackNames;
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700286
287 // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
288 // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
289 const uint32_t mConfiguredNames;
290
Mathias Agopian65ab4712010-07-14 17:59:35 -0700291 const uint32_t mSampleRate;
292
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800293 NBLog::Writer mDummyLog;
294public:
295 void setLog(NBLog::Writer* log);
296private:
Mathias Agopian65ab4712010-07-14 17:59:35 -0700297 state_t mState __attribute__((aligned(32)));
298
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700299 // Call after changing either the enabled status of a track, or parameters of an enabled track.
300 // OK to call more often than that, but unnecessary.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700301 void invalidateState(uint32_t mask);
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700302
Andy Hunge93b6b72014-07-17 21:30:53 -0700303 bool setChannelMasks(int name,
304 audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask);
305
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700306 static void track__genericResample(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
307 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700308 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 -0700309 static void track__16BitsStereo(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
310 int32_t* aux);
311 static void track__16BitsMono(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
312 int32_t* aux);
313 static void volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
314 int32_t* aux);
315 static void volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
316 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700317
John Grossman4ff14ba2012-02-08 16:37:41 -0800318 static void process__validate(state_t* state, int64_t pts);
319 static void process__nop(state_t* state, int64_t pts);
320 static void process__genericNoResampling(state_t* state, int64_t pts);
321 static void process__genericResampling(state_t* state, int64_t pts);
322 static void process__OneTrack16BitsStereoNoResampling(state_t* state,
323 int64_t pts);
John Grossman4ff14ba2012-02-08 16:37:41 -0800324
325 static int64_t calculateOutputPTS(const track_t& t, int64_t basePTS,
326 int outputFrameIndex);
Glenn Kasten52008f82012-03-18 09:34:41 -0700327
328 static uint64_t sLocalTimeFreq;
329 static pthread_once_t sOnceControl;
330 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700331
Andy Hung5e58b0a2014-06-23 19:07:29 -0700332 /* multi-format volume mixing function (calls template functions
333 * in AudioMixerOps.h). The template parameters are as follows:
334 *
335 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
Andy Hung5e58b0a2014-06-23 19:07:29 -0700336 * USEFLOATVOL (set to true if float volume is used)
337 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
338 * TO: int32_t (Q4.27) or float
339 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
340 * TA: int32_t (Q4.27)
341 */
Andy Hunge93b6b72014-07-17 21:30:53 -0700342 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
Andy Hung5e58b0a2014-06-23 19:07:29 -0700343 typename TO, typename TI, typename TA>
344 static void volumeMix(TO *out, size_t outFrames,
345 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
346
Andy Hung296b7412014-06-17 15:25:47 -0700347 // multi-format process hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700348 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700349 static void process_NoResampleOneTrack(state_t* state, int64_t pts);
350
351 // multi-format track hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700352 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700353 static void track__Resample(track_t* t, TO* out, size_t frameCount,
354 TO* temp __unused, TA* aux);
Andy Hunge93b6b72014-07-17 21:30:53 -0700355 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700356 static void track__NoResample(track_t* t, TO* out, size_t frameCount,
357 TO* temp __unused, TA* aux);
358
359 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
360 void *in, audio_format_t mixerInFormat, size_t sampleCount);
361
362 // hook types
363 enum {
364 PROCESSTYPE_NORESAMPLEONETRACK,
365 };
366 enum {
367 TRACKTYPE_NOP,
368 TRACKTYPE_RESAMPLE,
369 TRACKTYPE_NORESAMPLE,
370 TRACKTYPE_NORESAMPLEMONO,
371 };
372
373 // functions for determining the proper process and track hooks.
Andy Hunge93b6b72014-07-17 21:30:53 -0700374 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700375 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hunge93b6b72014-07-17 21:30:53 -0700376 static hook_t getTrackHook(int trackType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700377 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700378};
379
380// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800381} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700382
383#endif // ANDROID_AUDIO_MIXER_H