blob: d4ce417fc99fc47f73d2f39f672dac7a602954b6 [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 <media/AudioBufferProvider.h>
Andy Hung068561c2017-01-03 17:09:32 -080025#include <media/AudioResampler.h>
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -070026#include <media/AudioResamplerPublic.h>
Andy Hung068561c2017-01-03 17:09:32 -080027#include <media/BufferProviders.h>
Glenn Kasten8589ce72017-09-08 17:03:42 -070028#include <media/nblog/NBLog.h>
Dan Albert36802bd2014-11-20 11:31:17 -080029#include <system/audio.h>
30#include <utils/Compat.h>
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070031#include <utils/threads.h>
32
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
Andy Hung116a4982017-11-30 10:15:08 -080036// This must match frameworks/av/services/audioflinger/Configuration.h
37#define FLOAT_AUX
38
Mathias Agopian65ab4712010-07-14 17:59:35 -070039namespace android {
40
41// ----------------------------------------------------------------------------
42
Mathias Agopian65ab4712010-07-14 17:59:35 -070043class AudioMixer
44{
45public:
Glenn Kasten5c94b6c2012-03-20 17:01:29 -070046 AudioMixer(size_t frameCount, uint32_t sampleRate,
47 uint32_t maxNumTracks = MAX_NUM_TRACKS);
Mathias Agopian65ab4712010-07-14 17:59:35 -070048
Glenn Kastenc19e2242012-01-30 14:54:39 -080049 /*virtual*/ ~AudioMixer(); // non-virtual saves a v-table, restore if sub-classed
Mathias Agopian65ab4712010-07-14 17:59:35 -070050
Glenn Kasten599fabc2012-03-08 12:33:37 -080051
52 // This mixer has a hard-coded upper limit of 32 active track inputs.
53 // Adding support for > 32 tracks would require more than simply changing this value.
Mathias Agopian65ab4712010-07-14 17:59:35 -070054 static const uint32_t MAX_NUM_TRACKS = 32;
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070055 // maximum number of channels supported by the mixer
Glenn Kasten599fabc2012-03-08 12:33:37 -080056
Andy Hunge93b6b72014-07-17 21:30:53 -070057 // This mixer has a hard-coded upper limit of 8 channels for output.
58 static const uint32_t MAX_NUM_CHANNELS = 8;
59 static const uint32_t MAX_NUM_VOLUMES = 2; // stereo volume only
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070060 // maximum number of channels supported for the content
Andy Hunge93b6b72014-07-17 21:30:53 -070061 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
Mathias Agopian65ab4712010-07-14 17:59:35 -070062
Andy Hung97ae8242014-05-30 10:35:47 -070063 static const uint16_t UNITY_GAIN_INT = 0x1000;
Dan Albert36802bd2014-11-20 11:31:17 -080064 static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
Mathias Agopian65ab4712010-07-14 17:59:35 -070065
66 enum { // names
67
Glenn Kasten9c56d4a2011-12-19 15:06:39 -080068 // track names (MAX_NUM_TRACKS units)
Mathias Agopian65ab4712010-07-14 17:59:35 -070069 TRACK0 = 0x1000,
70
Glenn Kasten1c48c3c2011-12-15 14:54:01 -080071 // 0x2000 is unused
Mathias Agopian65ab4712010-07-14 17:59:35 -070072
73 // setParameter targets
74 TRACK = 0x3000,
75 RESAMPLE = 0x3001,
76 RAMP_VOLUME = 0x3002, // ramp to new volume
77 VOLUME = 0x3003, // don't ramp
Andy Hungc5656cc2015-03-26 19:04:33 -070078 TIMESTRETCH = 0x3004,
Mathias Agopian65ab4712010-07-14 17:59:35 -070079
80 // set Parameter names
81 // for target TRACK
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070082 CHANNEL_MASK = 0x4000,
Mathias Agopian65ab4712010-07-14 17:59:35 -070083 FORMAT = 0x4001,
84 MAIN_BUFFER = 0x4002,
85 AUX_BUFFER = 0x4003,
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070086 DOWNMIX_TYPE = 0X4004,
Andy Hung78820702014-02-28 16:23:02 -080087 MIXER_FORMAT = 0x4005, // AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
Andy Hunge93b6b72014-07-17 21:30:53 -070088 MIXER_CHANNEL_MASK = 0x4006, // Channel mask for mixer output
Glenn Kasten362c4e62011-12-14 10:28:06 -080089 // for target RESAMPLE
Glenn Kasten4e2293f2012-04-12 09:39:07 -070090 SAMPLE_RATE = 0x4100, // Configure sample rate conversion on this track name;
91 // parameter 'value' is the new sample rate in Hz.
92 // Only creates a sample rate converter the first time that
93 // the track sample rate is different from the mix sample rate.
94 // If the new sample rate is the same as the mix sample rate,
95 // and a sample rate converter already exists,
96 // then the sample rate converter remains present but is a no-op.
97 RESET = 0x4101, // Reset sample rate converter without changing sample rate.
98 // This clears out the resampler's input buffer.
99 REMOVE = 0x4102, // Remove the sample rate converter on this track name;
100 // the track is restored to the mix sample rate.
Glenn Kasten362c4e62011-12-14 10:28:06 -0800101 // for target RAMP_VOLUME and VOLUME (8 channels max)
Glenn Kastenc56f3422014-03-21 17:53:17 -0700102 // FIXME use float for these 3 to improve the dynamic range
Mathias Agopian65ab4712010-07-14 17:59:35 -0700103 VOLUME0 = 0x4200,
104 VOLUME1 = 0x4201,
105 AUXLEVEL = 0x4210,
Andy Hungc5656cc2015-03-26 19:04:33 -0700106 // for target TIMESTRETCH
107 PLAYBACK_RATE = 0x4300, // Configure timestretch on this track name;
108 // parameter 'value' is a pointer to the new playback rate.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700109 };
110
111
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800112 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800113
114 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700115 // The failure could be because of an invalid channelMask or format, or that
116 // the track capacity of the mixer is exceeded.
117 int getTrackName(audio_channel_mask_t channelMask,
118 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800119
120 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700121 void deleteTrackName(int name);
122
Glenn Kasten17a736c2012-02-14 08:52:15 -0800123 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800124 void enable(int name);
125 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700126
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800127 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700128
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800129 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
Glenn Kastend79072e2016-01-06 08:41:20 -0800130 void process();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700131
132 uint32_t trackNames() const { return mTrackNames; }
133
Glenn Kastenc59c0042012-02-02 14:06:11 -0800134 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800135
Andy Hunge8a1ced2014-05-09 15:02:21 -0700136 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungabdb9902015-01-12 15:08:22 -0800137 switch (format) {
138 case AUDIO_FORMAT_PCM_8_BIT:
139 case AUDIO_FORMAT_PCM_16_BIT:
140 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
141 case AUDIO_FORMAT_PCM_32_BIT:
142 case AUDIO_FORMAT_PCM_FLOAT:
143 return true;
144 default:
145 return false;
146 }
Andy Hunge8a1ced2014-05-09 15:02:21 -0700147 }
148
Mathias Agopian65ab4712010-07-14 17:59:35 -0700149private:
150
151 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700152 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700153 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700154 };
155
156 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700157 NEEDS_CHANNEL_1 = 0x00000000, // mono
158 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700159
Glenn Kastend6fadf02013-10-30 14:37:29 -0700160 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700161
Glenn Kastend6fadf02013-10-30 14:37:29 -0700162 NEEDS_MUTE = 0x00000100,
163 NEEDS_RESAMPLE = 0x00001000,
164 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700165 };
166
Mathias Agopian65ab4712010-07-14 17:59:35 -0700167 struct state_t;
168 struct track_t;
169
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700170 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
171 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700172 static const int BLOCKSIZE = 16; // 4 cache lines
173
174 struct track_t {
175 uint32_t needs;
176
Andy Hung5e58b0a2014-06-23 19:07:29 -0700177 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700178 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700179 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700180 int32_t volumeRL;
181 };
182
Andy Hunge93b6b72014-07-17 21:30:53 -0700183 int32_t prevVolume[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700184
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800185 // 16-byte boundary
186
Andy Hunge93b6b72014-07-17 21:30:53 -0700187 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700188 int32_t auxInc;
189 int32_t prevAuxLevel;
190
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800191 // 16-byte boundary
192
193 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700194 uint16_t frameCount;
195
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800196 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700197 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800198 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700199 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700200
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700201 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
202 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700203 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800204
205 // 16-byte boundary
206
207 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700208
209 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800210 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700211
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800212 // 16-byte boundary
213
Mathias Agopian65ab4712010-07-14 17:59:35 -0700214 AudioResampler* resampler;
215 uint32_t sampleRate;
216 int32_t* mainBuffer;
217 int32_t* auxBuffer;
218
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800219 // 16-byte boundary
Andy Hung7f475492014-08-25 16:36:37 -0700220
221 /* Buffer providers are constructed to translate the track input data as needed.
222 *
Andy Hungc5656cc2015-03-26 19:04:33 -0700223 * TODO: perhaps make a single PlaybackConverterProvider class to move
224 * all pre-mixer track buffer conversions outside the AudioMixer class.
225 *
Andy Hung7f475492014-08-25 16:36:37 -0700226 * 1) mInputBufferProvider: The AudioTrack buffer provider.
227 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
228 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
229 * requires reformat. For example, it may convert floating point input to
230 * PCM_16_bit if that's required by the downmixer.
231 * 3) downmixerBufferProvider: If not NULL, performs the channel remixing to match
232 * the number of channels required by the mixer sink.
233 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
234 * the downmixer requirements to the mixer engine input requirements.
Andy Hungc5656cc2015-03-26 19:04:33 -0700235 * 5) mTimestretchBufferProvider: Adds timestretching for playback rate
Andy Hung7f475492014-08-25 16:36:37 -0700236 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700237 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung857d5a22015-03-26 18:46:00 -0700238 PassthruBufferProvider* mReformatBufferProvider; // provider wrapper for reformatting.
239 PassthruBufferProvider* downmixerBufferProvider; // wrapper for channel conversion.
240 PassthruBufferProvider* mPostDownmixReformatBufferProvider;
Andy Hungc5656cc2015-03-26 19:04:33 -0700241 PassthruBufferProvider* mTimestretchBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700242
Andy Hung7f475492014-08-25 16:36:37 -0700243 int32_t sessionId;
244
Andy Hunge8a1ced2014-05-09 15:02:21 -0700245 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
246 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700247 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
248 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700249 audio_format_t mDownmixRequiresFormat; // required downmixer format
250 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
251 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700252
Andy Hunge93b6b72014-07-17 21:30:53 -0700253 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
254 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
255 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700256
257 float mAuxLevel; // floating point set aux level
258 float mPrevAuxLevel; // floating point prev aux level
259 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800260
Andy Hunge93b6b72014-07-17 21:30:53 -0700261 audio_channel_mask_t mMixerChannelMask;
262 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800263
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700264 AudioPlaybackRate mPlaybackRate;
Andy Hungc5656cc2015-03-26 19:04:33 -0700265
Andy Hung296b7412014-06-17 15:25:47 -0700266 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
Andy Hunge93b6b72014-07-17 21:30:53 -0700267 bool setResampler(uint32_t trackSampleRate, uint32_t devSampleRate);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800268 bool doesResample() const { return resampler != NULL; }
269 void resetResampler() { if (resampler != NULL) resampler->reset(); }
Andy Hung5e58b0a2014-06-23 19:07:29 -0700270 void adjustVolumeRamp(bool aux, bool useFloat = false);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800271 size_t getUnreleasedFrames() const { return resampler != NULL ?
272 resampler->getUnreleasedFrames() : 0; };
Andy Hung0f451e92014-08-04 21:28:47 -0700273
274 status_t prepareForDownmix();
275 void unprepareForDownmix();
276 status_t prepareForReformat();
277 void unprepareForReformat();
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700278 bool setPlaybackRate(const AudioPlaybackRate &playbackRate);
Andy Hung0f451e92014-08-04 21:28:47 -0700279 void reconfigureBufferProviders();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700280 };
281
Glenn Kastend79072e2016-01-06 08:41:20 -0800282 typedef void (*process_hook_t)(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700283
Mathias Agopian65ab4712010-07-14 17:59:35 -0700284 // pad to 32-bytes to fill cache line
285 struct state_t {
286 uint32_t enabledTracks;
287 uint32_t needsChanged;
288 size_t frameCount;
Andy Hung296b7412014-06-17 15:25:47 -0700289 process_hook_t hook; // one of process__*, never NULL
Mathias Agopian65ab4712010-07-14 17:59:35 -0700290 int32_t *outputTemp;
291 int32_t *resampleTemp;
Glenn Kasten3ab8d662017-04-03 14:35:09 -0700292 NBLog::Writer* mNBLogWriter; // associated NBLog::Writer or &mDummyLog
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800293 int32_t reserved[1];
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700294 // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800295 track_t tracks[MAX_NUM_TRACKS] __attribute__((aligned(32)));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296 };
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 Kasten3ab8d662017-04-03 14:35:09 -0700307 NBLog::Writer mDummyLogWriter;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800308public:
Glenn Kasten3ab8d662017-04-03 14:35:09 -0700309 // Called by FastMixer to inform AudioMixer of it's associated NBLog::Writer.
310 // FIXME It would be safer to use TLS for this, so we don't accidentally use wrong one.
311 void setNBLogWriter(NBLog::Writer* log);
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800312private:
Mathias Agopian65ab4712010-07-14 17:59:35 -0700313 state_t mState __attribute__((aligned(32)));
314
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700315 // Call after changing either the enabled status of a track, or parameters of an enabled track.
316 // OK to call more often than that, but unnecessary.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700317 void invalidateState(uint32_t mask);
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700318
Andy Hunge93b6b72014-07-17 21:30:53 -0700319 bool setChannelMasks(int name,
320 audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask);
321
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700322 static void track__genericResample(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
323 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700324 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 -0700325 static void track__16BitsStereo(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
326 int32_t* aux);
327 static void track__16BitsMono(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
328 int32_t* aux);
329 static void volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
330 int32_t* aux);
331 static void volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
332 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700333
Glenn Kastend79072e2016-01-06 08:41:20 -0800334 static void process__validate(state_t* state);
335 static void process__nop(state_t* state);
336 static void process__genericNoResampling(state_t* state);
337 static void process__genericResampling(state_t* state);
338 static void process__OneTrack16BitsStereoNoResampling(state_t* state);
John Grossman4ff14ba2012-02-08 16:37:41 -0800339
Glenn Kasten52008f82012-03-18 09:34:41 -0700340 static pthread_once_t sOnceControl;
341 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700342
Andy Hung5e58b0a2014-06-23 19:07:29 -0700343 /* multi-format volume mixing function (calls template functions
344 * in AudioMixerOps.h). The template parameters are as follows:
345 *
346 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
Andy Hung5e58b0a2014-06-23 19:07:29 -0700347 * USEFLOATVOL (set to true if float volume is used)
348 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
349 * TO: int32_t (Q4.27) or float
350 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
351 * TA: int32_t (Q4.27)
352 */
Andy Hunge93b6b72014-07-17 21:30:53 -0700353 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
Andy Hung5e58b0a2014-06-23 19:07:29 -0700354 typename TO, typename TI, typename TA>
355 static void volumeMix(TO *out, size_t outFrames,
356 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
357
Andy Hung296b7412014-06-17 15:25:47 -0700358 // multi-format process hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700359 template <int MIXTYPE, typename TO, typename TI, typename TA>
Glenn Kastend79072e2016-01-06 08:41:20 -0800360 static void process_NoResampleOneTrack(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700361
362 // multi-format track hooks
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__Resample(track_t* t, TO* out, size_t frameCount,
365 TO* temp __unused, TA* aux);
Andy Hunge93b6b72014-07-17 21:30:53 -0700366 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700367 static void track__NoResample(track_t* t, TO* out, size_t frameCount,
368 TO* temp __unused, TA* aux);
369
370 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
371 void *in, audio_format_t mixerInFormat, size_t sampleCount);
372
373 // hook types
374 enum {
375 PROCESSTYPE_NORESAMPLEONETRACK,
376 };
377 enum {
378 TRACKTYPE_NOP,
379 TRACKTYPE_RESAMPLE,
380 TRACKTYPE_NORESAMPLE,
381 TRACKTYPE_NORESAMPLEMONO,
382 };
383
384 // functions for determining the proper process and track hooks.
Andy Hunge93b6b72014-07-17 21:30:53 -0700385 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700386 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hunge93b6b72014-07-17 21:30:53 -0700387 static hook_t getTrackHook(int trackType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700388 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700389};
390
391// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800392} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700393
394#endif // ANDROID_AUDIO_MIXER_H