blob: e788ac36d0a9041c231dab01e005c61dfd8a96ff [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>
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -070026#include <media/AudioResamplerPublic.h>
Dan Albert36802bd2014-11-20 11:31:17 -080027#include <media/nbaio/NBLog.h>
28#include <system/audio.h>
29#include <utils/Compat.h>
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070030#include <utils/threads.h>
31
Mathias Agopian65ab4712010-07-14 17:59:35 -070032#include "AudioResampler.h"
Andy Hung857d5a22015-03-26 18:46:00 -070033#include "BufferProviders.h"
Mathias Agopian65ab4712010-07-14 17:59:35 -070034
Glenn Kastenc56f3422014-03-21 17:53:17 -070035// FIXME This is actually unity gain, which might not be max in future, expressed in U.12
Andy Hung97ae8242014-05-30 10:35:47 -070036#define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT
Glenn Kastenc56f3422014-03-21 17:53:17 -070037
Mathias Agopian65ab4712010-07-14 17:59:35 -070038namespace android {
39
40// ----------------------------------------------------------------------------
41
Mathias Agopian65ab4712010-07-14 17:59:35 -070042class AudioMixer
43{
44public:
Glenn Kasten5c94b6c2012-03-20 17:01:29 -070045 AudioMixer(size_t frameCount, uint32_t sampleRate,
46 uint32_t maxNumTracks = MAX_NUM_TRACKS);
Mathias Agopian65ab4712010-07-14 17:59:35 -070047
Glenn Kastenc19e2242012-01-30 14:54:39 -080048 /*virtual*/ ~AudioMixer(); // non-virtual saves a v-table, restore if sub-classed
Mathias Agopian65ab4712010-07-14 17:59:35 -070049
Glenn Kasten599fabc2012-03-08 12:33:37 -080050
51 // This mixer has a hard-coded upper limit of 32 active track inputs.
52 // Adding support for > 32 tracks would require more than simply changing this value.
Mathias Agopian65ab4712010-07-14 17:59:35 -070053 static const uint32_t MAX_NUM_TRACKS = 32;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070054 // maximum number of channels supported by the mixer
Glenn Kasten599fabc2012-03-08 12:33:37 -080055
Andy Hunge93b6b72014-07-17 21:30:53 -070056 // This mixer has a hard-coded upper limit of 8 channels for output.
57 static const uint32_t MAX_NUM_CHANNELS = 8;
58 static const uint32_t MAX_NUM_VOLUMES = 2; // stereo volume only
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070059 // maximum number of channels supported for the content
Andy Hunge93b6b72014-07-17 21:30:53 -070060 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
Mathias Agopian65ab4712010-07-14 17:59:35 -070061
Andy Hung97ae8242014-05-30 10:35:47 -070062 static const uint16_t UNITY_GAIN_INT = 0x1000;
Dan Albert36802bd2014-11-20 11:31:17 -080063 static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
Mathias Agopian65ab4712010-07-14 17:59:35 -070064
65 enum { // names
66
Glenn Kasten9c56d4a2011-12-19 15:06:39 -080067 // track names (MAX_NUM_TRACKS units)
Mathias Agopian65ab4712010-07-14 17:59:35 -070068 TRACK0 = 0x1000,
69
Glenn Kasten1c48c3c2011-12-15 14:54:01 -080070 // 0x2000 is unused
Mathias Agopian65ab4712010-07-14 17:59:35 -070071
72 // setParameter targets
73 TRACK = 0x3000,
74 RESAMPLE = 0x3001,
75 RAMP_VOLUME = 0x3002, // ramp to new volume
76 VOLUME = 0x3003, // don't ramp
Andy Hungc5656cc2015-03-26 19:04:33 -070077 TIMESTRETCH = 0x3004,
Mathias Agopian65ab4712010-07-14 17:59:35 -070078
79 // set Parameter names
80 // for target TRACK
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070081 CHANNEL_MASK = 0x4000,
Mathias Agopian65ab4712010-07-14 17:59:35 -070082 FORMAT = 0x4001,
83 MAIN_BUFFER = 0x4002,
84 AUX_BUFFER = 0x4003,
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070085 DOWNMIX_TYPE = 0X4004,
Andy Hung78820702014-02-28 16:23:02 -080086 MIXER_FORMAT = 0x4005, // AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
Andy Hunge93b6b72014-07-17 21:30:53 -070087 MIXER_CHANNEL_MASK = 0x4006, // Channel mask for mixer output
Glenn Kasten362c4e62011-12-14 10:28:06 -080088 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070089 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
90 // parameter 'value' is the new sample rate in Hz.
91 // Only creates a sample rate converter the first time that
92 // the track sample rate is different from the mix sample rate.
93 // If the new sample rate is the same as the mix sample rate,
94 // and a sample rate converter already exists,
95 // then the sample rate converter remains present but is a no-op.
96 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
97 // This clears out the resampler's input buffer.
98 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
99 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -0800100 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -0700101 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -0700102 VOLUME0 = 0x4200,
103 VOLUME1 = 0x4201,
104 AUXLEVEL = 0x4210,
Andy Hungc5656cc2015-03-26 19:04:33 -0700105 // for target TIMESTRETCH
106 PLAYBACK_RATE = 0x4300, // Configure timestretch on this track name;
107 // parameter 'value' is a pointer to the new playback rate.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700108 };
109
110
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800111 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800112
113 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700114 // The failure could be because of an invalid channelMask or format, or that
115 // the track capacity of the mixer is exceeded.
116 int getTrackName(audio_channel_mask_t channelMask,
117 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800118
119 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700120 void deleteTrackName(int name);
121
Glenn Kasten17a736c2012-02-14 08:52:15 -0800122 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800123 void enable(int name);
124 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700125
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800126 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700127
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800128 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
Glenn Kastend79072e2016-01-06 08:41:20 -0800129 void process();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700130
131 uint32_t trackNames() const { return mTrackNames; }
132
Glenn Kastenc59c0042012-02-02 14:06:11 -0800133 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800134
Andy Hunge8a1ced2014-05-09 15:02:21 -0700135 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungabdb9902015-01-12 15:08:22 -0800136 switch (format) {
137 case AUDIO_FORMAT_PCM_8_BIT:
138 case AUDIO_FORMAT_PCM_16_BIT:
139 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
140 case AUDIO_FORMAT_PCM_32_BIT:
141 case AUDIO_FORMAT_PCM_FLOAT:
142 return true;
143 default:
144 return false;
145 }
Andy Hunge8a1ced2014-05-09 15:02:21 -0700146 }
147
Mathias Agopian65ab4712010-07-14 17:59:35 -0700148private:
149
150 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700151 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700152 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700153 };
154
155 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700156 NEEDS_CHANNEL_1 = 0x00000000, // mono
157 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700158
Glenn Kastend6fadf02013-10-30 14:37:29 -0700159 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700160
Glenn Kastend6fadf02013-10-30 14:37:29 -0700161 NEEDS_MUTE = 0x00000100,
162 NEEDS_RESAMPLE = 0x00001000,
163 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700164 };
165
Mathias Agopian65ab4712010-07-14 17:59:35 -0700166 struct state_t;
167 struct track_t;
168
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700169 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
170 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700171 static const int BLOCKSIZE = 16; // 4 cache lines
172
173 struct track_t {
174 uint32_t needs;
175
Andy Hung5e58b0a2014-06-23 19:07:29 -0700176 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700177 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700178 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700179 int32_t volumeRL;
180 };
181
Andy Hunge93b6b72014-07-17 21:30:53 -0700182 int32_t prevVolume[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700183
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800184 // 16-byte boundary
185
Andy Hunge93b6b72014-07-17 21:30:53 -0700186 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700187 int32_t auxInc;
188 int32_t prevAuxLevel;
189
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800190 // 16-byte boundary
191
192 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700193 uint16_t frameCount;
194
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800195 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700196 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800197 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700198 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700199
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700200 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
201 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700202 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800203
204 // 16-byte boundary
205
206 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700207
208 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800209 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700210
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800211 // 16-byte boundary
212
Mathias Agopian65ab4712010-07-14 17:59:35 -0700213 AudioResampler* resampler;
214 uint32_t sampleRate;
215 int32_t* mainBuffer;
216 int32_t* auxBuffer;
217
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800218 // 16-byte boundary
Andy Hung7f475492014-08-25 16:36:37 -0700219
220 /* Buffer providers are constructed to translate the track input data as needed.
221 *
Andy Hungc5656cc2015-03-26 19:04:33 -0700222 * TODO: perhaps make a single PlaybackConverterProvider class to move
223 * all pre-mixer track buffer conversions outside the AudioMixer class.
224 *
Andy Hung7f475492014-08-25 16:36:37 -0700225 * 1) mInputBufferProvider: The AudioTrack buffer provider.
226 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
227 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
228 * requires reformat. For example, it may convert floating point input to
229 * PCM_16_bit if that's required by the downmixer.
230 * 3) downmixerBufferProvider: If not NULL, performs the channel remixing to match
231 * the number of channels required by the mixer sink.
232 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
233 * the downmixer requirements to the mixer engine input requirements.
Andy Hungc5656cc2015-03-26 19:04:33 -0700234 * 5) mTimestretchBufferProvider: Adds timestretching for playback rate
Andy Hung7f475492014-08-25 16:36:37 -0700235 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700236 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung857d5a22015-03-26 18:46:00 -0700237 PassthruBufferProvider* mReformatBufferProvider; // provider wrapper for reformatting.
238 PassthruBufferProvider* downmixerBufferProvider; // wrapper for channel conversion.
239 PassthruBufferProvider* mPostDownmixReformatBufferProvider;
Andy Hungc5656cc2015-03-26 19:04:33 -0700240 PassthruBufferProvider* mTimestretchBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700241
Andy Hung7f475492014-08-25 16:36:37 -0700242 int32_t sessionId;
243
Andy Hunge8a1ced2014-05-09 15:02:21 -0700244 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
245 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700246 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
247 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700248 audio_format_t mDownmixRequiresFormat; // required downmixer format
249 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
250 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700251
Andy Hunge93b6b72014-07-17 21:30:53 -0700252 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
253 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
254 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700255
256 float mAuxLevel; // floating point set aux level
257 float mPrevAuxLevel; // floating point prev aux level
258 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800259
Andy Hunge93b6b72014-07-17 21:30:53 -0700260 audio_channel_mask_t mMixerChannelMask;
261 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800262
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700263 AudioPlaybackRate mPlaybackRate;
Andy Hungc5656cc2015-03-26 19:04:33 -0700264
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();
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700277 bool setPlaybackRate(const AudioPlaybackRate &playbackRate);
Andy Hung0f451e92014-08-04 21:28:47 -0700278 void reconfigureBufferProviders();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700279 };
280
Glenn Kastend79072e2016-01-06 08:41:20 -0800281 typedef void (*process_hook_t)(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700282
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
Glenn Kastend79072e2016-01-06 08:41:20 -0800331 static void process__validate(state_t* state);
332 static void process__nop(state_t* state);
333 static void process__genericNoResampling(state_t* state);
334 static void process__genericResampling(state_t* state);
335 static void process__OneTrack16BitsStereoNoResampling(state_t* state);
John Grossman4ff14ba2012-02-08 16:37:41 -0800336
Glenn Kasten52008f82012-03-18 09:34:41 -0700337 static pthread_once_t sOnceControl;
338 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700339
Andy Hung5e58b0a2014-06-23 19:07:29 -0700340 /* multi-format volume mixing function (calls template functions
341 * in AudioMixerOps.h). The template parameters are as follows:
342 *
343 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
Andy Hung5e58b0a2014-06-23 19:07:29 -0700344 * USEFLOATVOL (set to true if float volume is used)
345 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
346 * TO: int32_t (Q4.27) or float
347 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
348 * TA: int32_t (Q4.27)
349 */
Andy Hunge93b6b72014-07-17 21:30:53 -0700350 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
Andy Hung5e58b0a2014-06-23 19:07:29 -0700351 typename TO, typename TI, typename TA>
352 static void volumeMix(TO *out, size_t outFrames,
353 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
354
Andy Hung296b7412014-06-17 15:25:47 -0700355 // multi-format process hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700356 template <int MIXTYPE, typename TO, typename TI, typename TA>
Glenn Kastend79072e2016-01-06 08:41:20 -0800357 static void process_NoResampleOneTrack(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700358
359 // multi-format track hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700360 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700361 static void track__Resample(track_t* t, TO* out, size_t frameCount,
362 TO* temp __unused, TA* aux);
Andy Hunge93b6b72014-07-17 21:30:53 -0700363 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700364 static void track__NoResample(track_t* t, TO* out, size_t frameCount,
365 TO* temp __unused, TA* aux);
366
367 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
368 void *in, audio_format_t mixerInFormat, size_t sampleCount);
369
370 // hook types
371 enum {
372 PROCESSTYPE_NORESAMPLEONETRACK,
373 };
374 enum {
375 TRACKTYPE_NOP,
376 TRACKTYPE_RESAMPLE,
377 TRACKTYPE_NORESAMPLE,
378 TRACKTYPE_NORESAMPLEMONO,
379 };
380
381 // functions for determining the proper process and track hooks.
Andy Hunge93b6b72014-07-17 21:30:53 -0700382 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700383 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hunge93b6b72014-07-17 21:30:53 -0700384 static hook_t getTrackHook(int trackType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700385 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700386};
387
388// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800389} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700390
391#endif // ANDROID_AUDIO_MIXER_H