AEDSPUtilities.h
Go to the documentation of this file.
1 //
2 // AEDSPUtilities.h
3 // TheAmazingAudioEngine
4 //
5 // Created by Michael Tyson on 1/04/2016.
6 // Copyright © 2016 A Tasty Pixel. All rights reserved.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source distribution.
25 //
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #import <Foundation/Foundation.h>
32 #import <AudioToolbox/AudioToolbox.h>
34 
42 void AEDSPApplyGain(const AudioBufferList * bufferList, float gain, UInt32 frames);
43 
52 void AEDSPApplyRamp(const AudioBufferList * bufferList, float * start, float step, UInt32 frames);
53 
66 void AEDSPApplyEqualPowerRamp(const AudioBufferList * bufferList, float * start, float step, UInt32 frames, float * scratch);
67 
77 void AEDSPApplyGainSmoothed(const AudioBufferList * bufferList, float targetGain, float * currentGain, UInt32 frames);
78 
89 void AEDSPApplyGainWithRamp(const AudioBufferList * bufferList, float targetGain, float * currentGain, UInt32 frames,
90  UInt32 rampDuration);
91 
100 void AEDSPApplyGainSmoothedMono(float * buffer, float targetGain, float * currentGain, UInt32 frames);
101 
117 void AEDSPApplyVolumeAndBalance(const AudioBufferList * bufferList, float targetVolume, float * currentVolume,
118  float targetBalance, float * currentBalance, UInt32 frames);
119 
120 
141 void AEDSPMix(const AudioBufferList * bufferList1, const AudioBufferList * bufferList2, float gain1, float gain2,
142  BOOL monoToStereo, UInt32 frames, const AudioBufferList * output);
143 
154 void AEDSPMixMono(const float * buffer1, const float * buffer2, float gain1, float gain2, UInt32 frames, float * output);
155 
163 #define AEDSPSilence AEAudioBufferListSilence
164 
175 static inline float AEDSPGenerateOscillator(float rate, float * position) {
176  float x = *position;
177  x *= x;
178  x -= 1.0;
179  x *= x;
180  *position += rate;
181  if ( *position > 1.0 ) *position -= 2.0;
182  return x;
183 }
184 
191 static inline double AEDSPDecibelsToRatio(double decibels) {
192  return pow(10.0, decibels / 20.0);
193 }
194 
201 static inline double AEDSPRatioToDecibels(double ratio) {
202  return 20.0 * log10(ratio);
203 }
204 
205 #ifdef __cplusplus
206 }
207 #endif