blob: 87ada766799682b6689df7326225f41c52c30056 [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>
Dan Albert36802bd2014-11-20 11:31:17 -080028#include <media/nbaio/NBLog.h>
29#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
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
Andy Hunge93b6b72014-07-17 21:30:53 -070054 // This mixer has a hard-coded upper limit of 8 channels for output.
55 static const uint32_t MAX_NUM_CHANNELS = 8;
56 static const uint32_t MAX_NUM_VOLUMES = 2; // stereo volume only
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -070057 // maximum number of channels supported for the content
Andy Hunge93b6b72014-07-17 21:30:53 -070058 static const uint32_t MAX_NUM_CHANNELS_TO_DOWNMIX = AUDIO_CHANNEL_COUNT_MAX;
Mathias Agopian65ab4712010-07-14 17:59:35 -070059
Andy Hung97ae8242014-05-30 10:35:47 -070060 static const uint16_t UNITY_GAIN_INT = 0x1000;
Dan Albert36802bd2014-11-20 11:31:17 -080061 static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f;
Mathias Agopian65ab4712010-07-14 17:59:35 -070062
63 enum { // names
64
Glenn Kasten9c56d4a2011-12-19 15:06:39 -080065 // track names (MAX_NUM_TRACKS units)
Mathias Agopian65ab4712010-07-14 17:59:35 -070066 TRACK0 = 0x1000,
67
Glenn Kasten1c48c3c2011-12-15 14:54:01 -080068 // 0x2000 is unused
Mathias Agopian65ab4712010-07-14 17:59:35 -070069
70 // setParameter targets
71 TRACK = 0x3000,
72 RESAMPLE = 0x3001,
73 RAMP_VOLUME = 0x3002, // ramp to new volume
74 VOLUME = 0x3003, // don't ramp
Andy Hungc5656cc2015-03-26 19:04:33 -070075 TIMESTRETCH = 0x3004,
Mathias Agopian65ab4712010-07-14 17:59:35 -070076
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,
Andy Hungc5656cc2015-03-26 19:04:33 -0700103 // for target TIMESTRETCH
104 PLAYBACK_RATE = 0x4300, // Configure timestretch on this track name;
105 // parameter 'value' is a pointer to the new playback rate.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700106 };
107
108
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800109 // For all APIs with "name": TRACK0 <= name < TRACK0 + MAX_NUM_TRACKS
Glenn Kasten17a736c2012-02-14 08:52:15 -0800110
111 // Allocate a track name. Returns new track name if successful, -1 on failure.
Andy Hunge8a1ced2014-05-09 15:02:21 -0700112 // The failure could be because of an invalid channelMask or format, or that
113 // the track capacity of the mixer is exceeded.
114 int getTrackName(audio_channel_mask_t channelMask,
115 audio_format_t format, int sessionId);
Glenn Kasten17a736c2012-02-14 08:52:15 -0800116
117 // Free an allocated track by name
Mathias Agopian65ab4712010-07-14 17:59:35 -0700118 void deleteTrackName(int name);
119
Glenn Kasten17a736c2012-02-14 08:52:15 -0800120 // Enable or disable an allocated track by name
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800121 void enable(int name);
122 void disable(int name);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700123
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800124 void setParameter(int name, int target, int param, void *value);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700125
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800126 void setBufferProvider(int name, AudioBufferProvider* bufferProvider);
Glenn Kastend79072e2016-01-06 08:41:20 -0800127 void process();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700128
129 uint32_t trackNames() const { return mTrackNames; }
130
Glenn Kastenc59c0042012-02-02 14:06:11 -0800131 size_t getUnreleasedFrames(int name) const;
Eric Laurent071ccd52011-12-22 16:08:41 -0800132
Andy Hunge8a1ced2014-05-09 15:02:21 -0700133 static inline bool isValidPcmTrackFormat(audio_format_t format) {
Andy Hungabdb9902015-01-12 15:08:22 -0800134 switch (format) {
135 case AUDIO_FORMAT_PCM_8_BIT:
136 case AUDIO_FORMAT_PCM_16_BIT:
137 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
138 case AUDIO_FORMAT_PCM_32_BIT:
139 case AUDIO_FORMAT_PCM_FLOAT:
140 return true;
141 default:
142 return false;
143 }
Andy Hunge8a1ced2014-05-09 15:02:21 -0700144 }
145
Mathias Agopian65ab4712010-07-14 17:59:35 -0700146private:
147
148 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700149 // FIXME this representation permits up to 8 channels
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700150 NEEDS_CHANNEL_COUNT__MASK = 0x00000007,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700151 };
152
153 enum {
Glenn Kastend6fadf02013-10-30 14:37:29 -0700154 NEEDS_CHANNEL_1 = 0x00000000, // mono
155 NEEDS_CHANNEL_2 = 0x00000001, // stereo
Mathias Agopian65ab4712010-07-14 17:59:35 -0700156
Glenn Kastend6fadf02013-10-30 14:37:29 -0700157 // sample format is not explicitly specified, and is assumed to be AUDIO_FORMAT_PCM_16_BIT
Mathias Agopian65ab4712010-07-14 17:59:35 -0700158
Glenn Kastend6fadf02013-10-30 14:37:29 -0700159 NEEDS_MUTE = 0x00000100,
160 NEEDS_RESAMPLE = 0x00001000,
161 NEEDS_AUX = 0x00010000,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700162 };
163
Mathias Agopian65ab4712010-07-14 17:59:35 -0700164 struct state_t;
165 struct track_t;
166
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700167 typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp,
168 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700169 static const int BLOCKSIZE = 16; // 4 cache lines
170
171 struct track_t {
172 uint32_t needs;
173
Andy Hung5e58b0a2014-06-23 19:07:29 -0700174 // TODO: Eventually remove legacy integer volume settings
Mathias Agopian65ab4712010-07-14 17:59:35 -0700175 union {
Andy Hunge93b6b72014-07-17 21:30:53 -0700176 int16_t volume[MAX_NUM_VOLUMES]; // U4.12 fixed point (top bit should be zero)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700177 int32_t volumeRL;
178 };
179
Andy Hunge93b6b72014-07-17 21:30:53 -0700180 int32_t prevVolume[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700181
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800182 // 16-byte boundary
183
Andy Hunge93b6b72014-07-17 21:30:53 -0700184 int32_t volumeInc[MAX_NUM_VOLUMES];
Mathias Agopian65ab4712010-07-14 17:59:35 -0700185 int32_t auxInc;
186 int32_t prevAuxLevel;
187
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800188 // 16-byte boundary
189
190 int16_t auxLevel; // 0 <= auxLevel <= MAX_GAIN_INT, but signed for mul performance
Mathias Agopian65ab4712010-07-14 17:59:35 -0700191 uint16_t frameCount;
192
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800193 uint8_t channelCount; // 1 or 2, redundant with (needs & NEEDS_CHANNEL_COUNT__MASK)
Andy Hungef7c7fb2014-05-12 16:51:41 -0700194 uint8_t unused_padding; // formerly format, was always 16
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800195 uint16_t enabled; // actually bool
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700196 audio_channel_mask_t channelMask;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700197
Jean-Michel Trivi7d5b2622012-04-04 18:54:36 -0700198 // actual buffer provider used by the track hooks, see DownmixerBufferProvider below
199 // for how the Track buffer provider is wrapped by another one when dowmixing is required
Mathias Agopian65ab4712010-07-14 17:59:35 -0700200 AudioBufferProvider* bufferProvider;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800201
202 // 16-byte boundary
203
204 mutable AudioBufferProvider::Buffer buffer; // 8 bytes
Mathias Agopian65ab4712010-07-14 17:59:35 -0700205
206 hook_t hook;
Glenn Kasten54c3b662012-01-06 07:46:30 -0800207 const void* in; // current location in buffer
Mathias Agopian65ab4712010-07-14 17:59:35 -0700208
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800209 // 16-byte boundary
210
Mathias Agopian65ab4712010-07-14 17:59:35 -0700211 AudioResampler* resampler;
212 uint32_t sampleRate;
213 int32_t* mainBuffer;
214 int32_t* auxBuffer;
215
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800216 // 16-byte boundary
Andy Hung7f475492014-08-25 16:36:37 -0700217
218 /* Buffer providers are constructed to translate the track input data as needed.
219 *
Andy Hungc5656cc2015-03-26 19:04:33 -0700220 * TODO: perhaps make a single PlaybackConverterProvider class to move
221 * all pre-mixer track buffer conversions outside the AudioMixer class.
222 *
Andy Hung7f475492014-08-25 16:36:37 -0700223 * 1) mInputBufferProvider: The AudioTrack buffer provider.
224 * 2) mReformatBufferProvider: If not NULL, performs the audio reformat to
225 * match either mMixerInFormat or mDownmixRequiresFormat, if the downmixer
226 * requires reformat. For example, it may convert floating point input to
227 * PCM_16_bit if that's required by the downmixer.
228 * 3) downmixerBufferProvider: If not NULL, performs the channel remixing to match
229 * the number of channels required by the mixer sink.
230 * 4) mPostDownmixReformatBufferProvider: If not NULL, performs reformatting from
231 * the downmixer requirements to the mixer engine input requirements.
Andy Hungc5656cc2015-03-26 19:04:33 -0700232 * 5) mTimestretchBufferProvider: Adds timestretching for playback rate
Andy Hung7f475492014-08-25 16:36:37 -0700233 */
Andy Hung1b2fdcb2014-07-16 17:44:34 -0700234 AudioBufferProvider* mInputBufferProvider; // externally provided buffer provider.
Andy Hung857d5a22015-03-26 18:46:00 -0700235 PassthruBufferProvider* mReformatBufferProvider; // provider wrapper for reformatting.
236 PassthruBufferProvider* downmixerBufferProvider; // wrapper for channel conversion.
237 PassthruBufferProvider* mPostDownmixReformatBufferProvider;
Andy Hungc5656cc2015-03-26 19:04:33 -0700238 PassthruBufferProvider* mTimestretchBufferProvider;
Jean-Michel Trivid06e1322012-09-12 15:47:07 -0700239
Andy Hung7f475492014-08-25 16:36:37 -0700240 int32_t sessionId;
241
Andy Hunge8a1ced2014-05-09 15:02:21 -0700242 audio_format_t mMixerFormat; // output mix format: AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
243 audio_format_t mFormat; // input track format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700244 audio_format_t mMixerInFormat; // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
245 // each track must be converted to this format.
Andy Hung7f475492014-08-25 16:36:37 -0700246 audio_format_t mDownmixRequiresFormat; // required downmixer format
247 // AUDIO_FORMAT_PCM_16_BIT if 16 bit necessary
248 // AUDIO_FORMAT_INVALID if no required format
Andy Hungef7c7fb2014-05-12 16:51:41 -0700249
Andy Hunge93b6b72014-07-17 21:30:53 -0700250 float mVolume[MAX_NUM_VOLUMES]; // floating point set volume
251 float mPrevVolume[MAX_NUM_VOLUMES]; // floating point previous volume
252 float mVolumeInc[MAX_NUM_VOLUMES]; // floating point volume increment
Andy Hung5e58b0a2014-06-23 19:07:29 -0700253
254 float mAuxLevel; // floating point set aux level
255 float mPrevAuxLevel; // floating point prev aux level
256 float mAuxInc; // floating point aux increment
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800257
Andy Hunge93b6b72014-07-17 21:30:53 -0700258 audio_channel_mask_t mMixerChannelMask;
259 uint32_t mMixerChannelCount;
Glenn Kasten3b81aca2012-01-27 15:26:23 -0800260
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700261 AudioPlaybackRate mPlaybackRate;
Andy Hungc5656cc2015-03-26 19:04:33 -0700262
Andy Hung296b7412014-06-17 15:25:47 -0700263 bool needsRamp() { return (volumeInc[0] | volumeInc[1] | auxInc) != 0; }
Andy Hunge93b6b72014-07-17 21:30:53 -0700264 bool setResampler(uint32_t trackSampleRate, uint32_t devSampleRate);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800265 bool doesResample() const { return resampler != NULL; }
266 void resetResampler() { if (resampler != NULL) resampler->reset(); }
Andy Hung5e58b0a2014-06-23 19:07:29 -0700267 void adjustVolumeRamp(bool aux, bool useFloat = false);
Glenn Kastenc59c0042012-02-02 14:06:11 -0800268 size_t getUnreleasedFrames() const { return resampler != NULL ?
269 resampler->getUnreleasedFrames() : 0; };
Andy Hung0f451e92014-08-04 21:28:47 -0700270
271 status_t prepareForDownmix();
272 void unprepareForDownmix();
273 status_t prepareForReformat();
274 void unprepareForReformat();
Ricardo Garcia5a8a95d2015-04-18 14:47:04 -0700275 bool setPlaybackRate(const AudioPlaybackRate &playbackRate);
Andy Hung0f451e92014-08-04 21:28:47 -0700276 void reconfigureBufferProviders();
Mathias Agopian65ab4712010-07-14 17:59:35 -0700277 };
278
Glenn Kastend79072e2016-01-06 08:41:20 -0800279 typedef void (*process_hook_t)(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700280
Mathias Agopian65ab4712010-07-14 17:59:35 -0700281 // pad to 32-bytes to fill cache line
282 struct state_t {
283 uint32_t enabledTracks;
284 uint32_t needsChanged;
285 size_t frameCount;
Andy Hung296b7412014-06-17 15:25:47 -0700286 process_hook_t hook; // one of process__*, never NULL
Mathias Agopian65ab4712010-07-14 17:59:35 -0700287 int32_t *outputTemp;
288 int32_t *resampleTemp;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800289 NBLog::Writer* mLog;
290 int32_t reserved[1];
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700291 // FIXME allocate dynamically to save some memory when maxNumTracks < MAX_NUM_TRACKS
Glenn Kasten01d3acb2014-02-06 08:24:07 -0800292 track_t tracks[MAX_NUM_TRACKS] __attribute__((aligned(32)));
Mathias Agopian65ab4712010-07-14 17:59:35 -0700293 };
294
Glenn Kasten9c56d4a2011-12-19 15:06:39 -0800295 // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700296 uint32_t mTrackNames;
Glenn Kasten5c94b6c2012-03-20 17:01:29 -0700297
298 // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
299 // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
300 const uint32_t mConfiguredNames;
301
Mathias Agopian65ab4712010-07-14 17:59:35 -0700302 const uint32_t mSampleRate;
303
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800304 NBLog::Writer mDummyLog;
305public:
306 void setLog(NBLog::Writer* log);
307private:
Mathias Agopian65ab4712010-07-14 17:59:35 -0700308 state_t mState __attribute__((aligned(32)));
309
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700310 // Call after changing either the enabled status of a track, or parameters of an enabled track.
311 // OK to call more often than that, but unnecessary.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700312 void invalidateState(uint32_t mask);
Glenn Kasten4e2293f2012-04-12 09:39:07 -0700313
Andy Hunge93b6b72014-07-17 21:30:53 -0700314 bool setChannelMasks(int name,
315 audio_channel_mask_t trackChannelMask, audio_channel_mask_t mixerChannelMask);
316
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700317 static void track__genericResample(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
318 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700319 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 -0700320 static void track__16BitsStereo(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
321 int32_t* aux);
322 static void track__16BitsMono(track_t* t, int32_t* out, size_t numFrames, int32_t* temp,
323 int32_t* aux);
324 static void volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
325 int32_t* aux);
326 static void volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp,
327 int32_t* aux);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700328
Glenn Kastend79072e2016-01-06 08:41:20 -0800329 static void process__validate(state_t* state);
330 static void process__nop(state_t* state);
331 static void process__genericNoResampling(state_t* state);
332 static void process__genericResampling(state_t* state);
333 static void process__OneTrack16BitsStereoNoResampling(state_t* state);
John Grossman4ff14ba2012-02-08 16:37:41 -0800334
Glenn Kasten52008f82012-03-18 09:34:41 -0700335 static pthread_once_t sOnceControl;
336 static void sInitRoutine();
Andy Hung296b7412014-06-17 15:25:47 -0700337
Andy Hung5e58b0a2014-06-23 19:07:29 -0700338 /* multi-format volume mixing function (calls template functions
339 * in AudioMixerOps.h). The template parameters are as follows:
340 *
341 * MIXTYPE (see AudioMixerOps.h MIXTYPE_* enumeration)
Andy Hung5e58b0a2014-06-23 19:07:29 -0700342 * USEFLOATVOL (set to true if float volume is used)
343 * ADJUSTVOL (set to true if volume ramp parameters needs adjustment afterwards)
344 * TO: int32_t (Q4.27) or float
345 * TI: int32_t (Q4.27) or int16_t (Q0.15) or float
346 * TA: int32_t (Q4.27)
347 */
Andy Hunge93b6b72014-07-17 21:30:53 -0700348 template <int MIXTYPE, bool USEFLOATVOL, bool ADJUSTVOL,
Andy Hung5e58b0a2014-06-23 19:07:29 -0700349 typename TO, typename TI, typename TA>
350 static void volumeMix(TO *out, size_t outFrames,
351 const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
352
Andy Hung296b7412014-06-17 15:25:47 -0700353 // multi-format process hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700354 template <int MIXTYPE, typename TO, typename TI, typename TA>
Glenn Kastend79072e2016-01-06 08:41:20 -0800355 static void process_NoResampleOneTrack(state_t* state);
Andy Hung296b7412014-06-17 15:25:47 -0700356
357 // multi-format track hooks
Andy Hunge93b6b72014-07-17 21:30:53 -0700358 template <int MIXTYPE, typename TO, typename TI, typename TA>
Andy Hung296b7412014-06-17 15:25:47 -0700359 static void track__Resample(track_t* t, TO* out, size_t frameCount,
360 TO* temp __unused, TA* aux);
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 track__NoResample(track_t* t, TO* out, size_t frameCount,
363 TO* temp __unused, TA* aux);
364
365 static void convertMixerFormat(void *out, audio_format_t mixerOutFormat,
366 void *in, audio_format_t mixerInFormat, size_t sampleCount);
367
368 // hook types
369 enum {
370 PROCESSTYPE_NORESAMPLEONETRACK,
371 };
372 enum {
373 TRACKTYPE_NOP,
374 TRACKTYPE_RESAMPLE,
375 TRACKTYPE_NORESAMPLE,
376 TRACKTYPE_NORESAMPLEMONO,
377 };
378
379 // functions for determining the proper process and track hooks.
Andy Hunge93b6b72014-07-17 21:30:53 -0700380 static process_hook_t getProcessHook(int processType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700381 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Andy Hunge93b6b72014-07-17 21:30:53 -0700382 static hook_t getTrackHook(int trackType, uint32_t channelCount,
Andy Hung296b7412014-06-17 15:25:47 -0700383 audio_format_t mixerInFormat, audio_format_t mixerOutFormat);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700384};
385
386// ----------------------------------------------------------------------------
Glenn Kasten63238ef2015-03-02 15:50:29 -0800387} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700388
389#endif // ANDROID_AUDIO_MIXER_H