2008-02-17 18:44:11 +00:00
|
|
|
/*
|
|
|
|
* Helper.c
|
|
|
|
* CogAudio
|
|
|
|
*
|
|
|
|
* Created by Andre Reffhaug on 2/17/08.
|
|
|
|
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Helper.h"
|
2022-02-07 05:49:27 +00:00
|
|
|
#include <math.h>
|
2008-02-17 18:44:11 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// These functions are helpers for the process of converting volume from a linear to logarithmic scale.
|
|
|
|
// Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear.
|
|
|
|
// Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
|
2023-05-05 06:04:35 +00:00
|
|
|
// We are using the approximation of X^2 when volume is limited to 100% and X^4 when volume is limited to 800%.
|
2022-02-07 05:49:27 +00:00
|
|
|
// Input/Output values are in percents.
|
2023-05-05 06:04:35 +00:00
|
|
|
double logarithmicToLinear(const double logarithmic, double MAX_VOLUME) {
|
|
|
|
return (MAX_VOLUME == 100.0) ? pow((logarithmic / MAX_VOLUME), 0.5) * 100.0 : pow((logarithmic / MAX_VOLUME), 0.25) * 100.0;
|
2008-02-17 18:44:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 06:04:35 +00:00
|
|
|
double linearToLogarithmic(const double linear, double MAX_VOLUME) {
|
|
|
|
return (MAX_VOLUME == 100.0) ? (linear / 100.0) * (linear / 100.0) * MAX_VOLUME : (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * MAX_VOLUME;
|
2008-02-17 18:44:11 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
// End helper volume function thingies. ONWARDS TO GLORY!
|