blob: a9f4761e6b45371d99f8d923b3f9ba400bc3662c [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
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070024#include <utils/threads.h>
25
Glenn Kasten2dd4bdd2012-08-29 11:10:32 -070026#include <media/AudioBufferProvider.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070027#include "AudioResampler.h"
28
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070029#include <audio_effects/effect_downmix.h>
30#include <system/audio.h>
Glenn Kastenab7d72f2013-02-27 09:05:28 -080031#include <media/nbaio/NBLog.h>
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070032
Glenn Kastenc56f3422014-03-21 17:53:17 -070033// FIXME This is actually unity gain, which might not be max in future, expressed in U.12
Andy Hung97ae8242014-05-30 10:35:47 -070034#define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT
Glenn Kastenc56f3422014-03-21 17:53:17 -070035
Mathias Agopian65ab4712010-07-14 17:59:35 -070036namespace android {
37
38// ----------------------------------------------------------------------------
39
Mathias Agopian65ab4712010-07-14 17:59:35 -070040class AudioMixer
41{
42public:
Glenn Kasten5c94b6c2012-03-20 17:01:29 -070043 AudioMixer(size_t frameCount, uint32_t sampleRate,
44 uint32_t maxNumTracks = MAX_NUM_TRACKS);
Mathias Agopian65ab4712010-07-14 17:59:35 -070045
Glenn Kastenc19e2242012-01-30 14:54:39 -080046 /*virtual*/ ~AudioMixer(); // non-virtual saves a v-table, restore if sub-classed
Mathias Agopian65ab4712010-07-14 17:59:35 -070047
Glenn Kasten599fabc2012-03-08 12:33:37 -080048
49 // This mixer has a hard-coded upper limit of 32 active track inputs.
50 // Adding support for > 32 tracks would require more than simply changing this value.
Mathias Agopian65ab4712010-07-14 17:59:35 -070051 static const uint32_t MAX_NUM_TRACKS = 32;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070052 // maximum number of channels supported by the mixer
Glenn Kasten599fabc2012-03-08 12:33:37 -080053
54 // This mixer has a hard-coded upper limit of 2 channels for output.
55 // There is support for > 2 channel tracks down-mixed to 2 channel output via a down-mix effect.
56 // Adding support for > 2 channel output would require more than simply changing this value.
Mathias Agopian65ab4712010-07-14 17:59:35 -070057 static const uint32_t MAX_NUM_CHANNELS = 2;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070058 // maximum number of channels supported for the content
59 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = 8;
Mathias Agopian65ab4712010-07-14 17:59:35 -070060
Andy Hung97ae8242014-05-30 10:35:47 -070061 static const uint16_t UNITY_GAIN_INT = 0x1000;
Andy Hung6be49402014-05-30 10:42:03 -070062 static const 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)
Glenn Kasten362c4e62011-12-14 10:28:06 -080085 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070086 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
87 // parameter 'value' is the new sample rate in Hz.
88 // Only creates a sample rate converter the first time that
89 // the track sample rate is different from the mix sample rate.
90 // If the new sample rate is the same as the mix sample rate,
91 // and a sample rate converter already exists,
92 // then the sample rate converter remains present but is a no-op.
93 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
94 // This clears out the resampler's input buffer.
95 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
96 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -080097 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -070098 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -070099 VOLUME0 = 0x4200,
100 VOLUME1 = 0x4201,
101 AUXLEVEL = 0x4210,
102 };
103
104
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800105 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800106
107 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700108 // The failure could be because of an invalid channelMask or format, or that
109 // the track capacity of the mixer is exceeded.
110 int getTrackName(audio_channel_mask_t channelMask,
111 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800112
113 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700114 void deleteTrackName(int name);
115
Glenn Kasten17a736c2012-02-14 08:52:15 -0800116 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800117 void enable(int name);
118 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700119
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800120 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700121
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800122 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
John Grossman4ff14ba2012-02-08 16:37:41 -0800123 void process(int64_t pts);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700124
125 uint32_t trackNames() const { return mTrackNames; }
126
Glenn Kastenc59c0042012-02-02 14:06:11 -0800127 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800128
Andy Hunge8a1ced2014-05-09 15:02:21 -0700129 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungef7c7fb2014-05-12 16:51:41 -0700130 return format == AUDIO_FORMAT_PCM_16_BIT ||
131 format == AUDIO_FORMAT_PCM_24_BIT_PACKED ||
132 format == AUDIO_FORMAT_PCM_32_BIT ||
133 format == AUDIO_FORMAT_PCM_FLOAT;
Andy Hunge8a1ced2014-05-09 15:02:21 -0700134 }
135
Mathias Agopian65ab4712010-07-14 17:59:35 -0700136private:
137
138 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700139 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700140 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700141 };
142
143 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700144 NEEDS_CHANNEL_1 = 0x00000000, // mono
145 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700146
Glenn Kastend6fadf02013-10-30 14:37:29 -0700147 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700148
Glenn Kastend6fadf02013-10-30 14:37:29 -0700149 NEEDS_MUTE = 0x00000100,
150 NEEDS_RESAMPLE = 0x00001000,
151 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700152 };
153
Mathias Agopian65ab4712010-07-14 17:59:35 -0700154 struct state_t;
155 struct track_t;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700156 class DownmixerBufferProvider;
Andy Hungef7c7fb2014-05-12 16:51:41 -0700157 class ReformatBufferProvider;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700158
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700159 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
160 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700161 static const int BLOCKSIZE = 16; // 4 cache lines
162
163 struct track_t {
164 uint32_t needs;
165
Andy Hung5e58b0a2014-06-23 19:07:29 -0700166 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700167 union {
Andy Hung5e58b0a2014-06-23 19:07:29 -0700168 int16_t volume[MAX_NUM_CHANNELS]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700169 int32_t volumeRL;
170 };
171
Glenn Kastenbf71f1e2011-12-13 11:52:35 -0800172 int32_t prevVolume[MAX_NUM_CHANNELS];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700173
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800174 // 16-byte boundary
175
Glenn Kastenbf71f1e2011-12-13 11:52:35 -0800176 int32_t volumeInc[MAX_NUM_CHANNELS];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700177 int32_t auxInc;
178 int32_t prevAuxLevel;
179
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800180 // 16-byte boundary
181
182 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700183 uint16_t frameCount;
184
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800185 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700186 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800187 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700188 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700189
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700190 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
191 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700192 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800193
194 // 16-byte boundary
195
196 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700197
198 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800199 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700200
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800201 // 16-byte boundary
202
Mathias Agopian65ab4712010-07-14 17:59:35 -0700203 AudioResampler* resampler;
204 uint32_t sampleRate;
205 int32_t* mainBuffer;
206 int32_t* auxBuffer;
207
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800208 // 16-byte boundary
Andy Hungef7c7fb2014-05-12 16:51:41 -0700209 AudioBufferProvider* mInputBufferProvider; // 4 bytes
210 ReformatBufferProvider* mReformatBufferProvider; // 4 bytes
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700211 DownmixerBufferProvider* downmixerBufferProvider; // 4 bytes
212
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700213 int32_t sessionId;
214
Andy Hungef7c7fb2014-05-12 16:51:41 -0700215 // 16-byte boundary
Andy Hunge8a1ced2014-05-09 15:02:21 -0700216 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
217 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700218 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
219 // each track must be converted to this format.
220
Andy Hung5e58b0a2014-06-23 19:07:29 -0700221 float mVolume[MAX_NUM_CHANNELS]; // floating point set volume
222 float mPrevVolume[MAX_NUM_CHANNELS]; // floating point previous volume
223 float mVolumeInc[MAX_NUM_CHANNELS]; // floating point volume increment
224
225 float mAuxLevel; // floating point set aux level
226 float mPrevAuxLevel; // floating point prev aux level
227 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800228
229 // 16-byte boundary
230
Andy Hung296b7412014-06-17 15:25:47 -0700231 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
Mathias Agopian65ab4712010-07-14 17:59:35 -0700232 bool setResampler(uint32_t sampleRate, uint32_t devSampleRate);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800233 bool doesResample() const { return resampler != NULL; }
234 void resetResampler() { if (resampler != NULL) resampler->reset(); }
Andy Hung5e58b0a2014-06-23 19:07:29 -0700235 void adjustVolumeRamp(bool aux, bool useFloat = false);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800236 size_t getUnreleasedFrames() const { return resampler != NULL ?
237 resampler->getUnreleasedFrames() : 0; };
Mathias Agopian65ab4712010-07-14 17:59:35 -0700238 };
239
Andy Hung296b7412014-06-17 15:25:47 -0700240 typedef void (*process_hook_t)(state_t* state, int64_t pts);
241
Mathias Agopian65ab4712010-07-14 17:59:35 -0700242 // pad to 32-bytes to fill cache line
243 struct state_t {
244 uint32_t enabledTracks;
245 uint32_t needsChanged;
246 size_t frameCount;
Andy Hung296b7412014-06-17 15:25:47 -0700247 process_hook_t hook; // one of process__*, never NULL
Mathias Agopian65ab4712010-07-14 17:59:35 -0700248 int32_t *outputTemp;
249 int32_t *resampleTemp;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800250 NBLog::Writer* mLog;
251 int32_t reserved[1];
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700252 // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800253 track_t tracks[MAX_NUM_TRACKS] __attribute__((aligned(32)));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700254 };
255
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700256 // AudioBufferProvider that wraps a track AudioBufferProvider by a call to a downmix effect
257 class DownmixerBufferProvider : public AudioBufferProvider {
258 public:
259 virtual status_t getNextBuffer(Buffer* buffer, int64_t pts);
260 virtual void releaseBuffer(Buffer* buffer);
261 DownmixerBufferProvider();
262 virtual ~DownmixerBufferProvider();
263
264 AudioBufferProvider* mTrackBufferProvider;
265 effect_handle_t mDownmixHandle;
266 effect_config_t mDownmixConfig;
267 };
268
Andy Hungef7c7fb2014-05-12 16:51:41 -0700269 // AudioBufferProvider wrapper that reformats track to acceptable mixer input type
270 class ReformatBufferProvider : public AudioBufferProvider {
271 public:
272 ReformatBufferProvider(int32_t channels,
273 audio_format_t inputFormat, audio_format_t outputFormat);
274 virtual ~ReformatBufferProvider();
275
276 // overrides AudioBufferProvider methods
277 virtual status_t getNextBuffer(Buffer* buffer, int64_t pts);
278 virtual void releaseBuffer(Buffer* buffer);
279
280 void reset();
281 inline bool requiresInternalBuffers() {
282 return true; //mInputFrameSize < mOutputFrameSize;
283 }
284
285 AudioBufferProvider* mTrackBufferProvider;
286 int32_t mChannels;
287 audio_format_t mInputFormat;
288 audio_format_t mOutputFormat;
289 size_t mInputFrameSize;
290 size_t mOutputFrameSize;
291 // (only) required for reformatting to a larger size.
292 AudioBufferProvider::Buffer mBuffer;
293 void* mOutputData;
294 size_t mOutputCount;
295 size_t mConsumed;
296 };
297
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800298 // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700299 uint32_t mTrackNames;
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700300
301 // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
302 // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
303 const uint32_t mConfiguredNames;
304
Mathias Agopian65ab4712010-07-14 17:59:35 -0700305 const uint32_t mSampleRate;
306
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800307 NBLog::Writer mDummyLog;
308public:
309 void setLog(NBLog::Writer* log);
310private:
Mathias Agopian65ab4712010-07-14 17:59:35 -0700311 state_t mState __attribute__((aligned(32)));
312
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700313 // effect descriptor for the downmixer used by the mixer
Glenn Kasten49c34ac2013-10-30 14:37:01 -0700314 static effect_descriptor_t sDwnmFxDesc;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700315 // indicates whether a downmix effect has been found and is usable by this mixer
Glenn Kasten49c34ac2013-10-30 14:37:01 -0700316 static bool sIsMultichannelCapable;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700317
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700318 // Call after changing either the enabled status of a track, or parameters of an enabled track.
319 // OK to call more often than that, but unnecessary.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700320 void invalidateState(uint32_t mask);
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700321
Jean-Michel Trivi9bd23222012-04-16 13:43:48 -0700322 static status_t initTrackDownmix(track_t* pTrack, int trackNum, audio_channel_mask_t mask);
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700323 static status_t prepareTrackForDownmix(track_t* pTrack, int trackNum);
Jean-Michel Trivi9bd23222012-04-16 13:43:48 -0700324 static void unprepareTrackForDownmix(track_t* pTrack, int trackName);
Andy Hungef7c7fb2014-05-12 16:51:41 -0700325 static status_t prepareTrackForReformat(track_t* pTrack, int trackNum);
326 static void unprepareTrackForReformat(track_t* pTrack, int trackName);
327 static void reconfigureBufferProviders(track_t* pTrack);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700328
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700329 static void track__genericResample(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
330 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700331 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 -0700332 static void track__16BitsStereo(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
333 int32_t* aux);
334 static void track__16BitsMono(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
335 int32_t* aux);
336 static void volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
337 int32_t* aux);
338 static void volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
339 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700340
John Grossman4ff14ba2012-02-08 16:37:41 -0800341 static void process__validate(state_t* state, int64_t pts);
342 static void process__nop(state_t* state, int64_t pts);
343 static void process__genericNoResampling(state_t* state, int64_t pts);
344 static void process__genericResampling(state_t* state, int64_t pts);
345 static void process__OneTrack16BitsStereoNoResampling(state_t* state,
346 int64_t pts);
Glenn Kasten81a028f2011-12-15 09:53:12 -0800347#if 0
John Grossman4ff14ba2012-02-08 16:37:41 -0800348 static void process__TwoTracks16BitsStereoNoResampling(state_t* state,
349 int64_t pts);
Glenn Kasten81a028f2011-12-15 09:53:12 -0800350#endif
John Grossman4ff14ba2012-02-08 16:37:41 -0800351
352 static int64_t calculateOutputPTS(const track_t& t, int64_t basePTS,
353 int outputFrameIndex);
Glenn Kasten52008f82012-03-18 09:34:41 -0700354
355 static uint64_t sLocalTimeFreq;
356 static pthread_once_t sOnceControl;
357 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700358
Andy Hung5e58b0a2014-06-23 19:07:29 -0700359 /* multi-format volume mixing function (calls template functions
360 * in AudioMixerOps.h). The template parameters are as follows:
361 *
362 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
363 * NCHAN (number of channels, 2 for now)
364 * USEFLOATVOL (set to true if float volume is used)
365 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
366 * TO: int32_t (Q4.27) or float
367 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
368 * TA: int32_t (Q4.27)
369 */
370 template <int MIXTYPE, int NCHAN, bool USEFLOATVOL, bool ADJUSTVOL,
371 typename TO, typename TI, typename TA>
372 static void volumeMix(TO *out, size_t outFrames,
373 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
374
Andy Hung296b7412014-06-17 15:25:47 -0700375 // multi-format process hooks
376 template <int MIXTYPE, int NCHAN, typename TO, typename TI, typename TA>
377 static void process_NoResampleOneTrack(state_t* state, int64_t pts);
378
379 // multi-format track hooks
380 template <int MIXTYPE, int NCHAN, typename TO, typename TI, typename TA>
381 static void track__Resample(track_t* t, TO* out, size_t frameCount,
382 TO* temp __unused, TA* aux);
383 template <int MIXTYPE, int NCHAN, typename TO, typename TI, typename TA>
384 static void track__NoResample(track_t* t, TO* out, size_t frameCount,
385 TO* temp __unused, TA* aux);
386
387 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
388 void *in, audio_format_t mixerInFormat, size_t sampleCount);
389
390 // hook types
391 enum {
392 PROCESSTYPE_NORESAMPLEONETRACK,
393 };
394 enum {
395 TRACKTYPE_NOP,
396 TRACKTYPE_RESAMPLE,
397 TRACKTYPE_NORESAMPLE,
398 TRACKTYPE_NORESAMPLEMONO,
399 };
400
401 // functions for determining the proper process and track hooks.
402 static process_hook_t getProcessHook(int processType, int channels,
403 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
404 static hook_t getTrackHook(int trackType, int channels,
405 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700406};
407
408// ----------------------------------------------------------------------------
409}; // namespace android
410
411#endif // ANDROID_AUDIO_MIXER_H