-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AudioConverterX: split non-wrapper methods into new AudioConverterXX
- Loading branch information
Showing
12 changed files
with
88 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "AudioConverterXX.h" | ||
#include <limits> | ||
#include <cmath> | ||
#include "CoreAudio/AudioCodec.h" | ||
#include "cautil.h" | ||
|
||
double AudioConverterXX::getClosestAvailableBitRate(double value) | ||
{ | ||
std::vector<AudioValueRange> rates; | ||
getApplicableEncodeBitRates(&rates); | ||
double distance = std::numeric_limits<double>::max(); | ||
double pick = 0; | ||
for (auto it = rates.begin(); it != rates.end(); ++it) { | ||
if (!it->mMinimum) continue; | ||
double diff = std::abs(value - it->mMinimum); | ||
if (distance > diff) { | ||
distance = diff; | ||
pick = it->mMinimum; | ||
} | ||
} | ||
return pick; | ||
} | ||
|
||
std::string AudioConverterXX::getConfigAsString() | ||
{ | ||
std::string s; | ||
AudioStreamBasicDescription asbd; | ||
getOutputStreamDescription(&asbd); | ||
UInt32 codec = asbd.mFormatID; | ||
if (codec == 'aac ') | ||
s = "AAC-LC Encoder"; | ||
else if (codec == 'aach') | ||
s = "AAC-HE Encoder"; | ||
else | ||
s = "Apple Lossless Encoder"; | ||
if (codec != 'aac ' && codec != 'aach') | ||
return s; | ||
UInt32 value = getBitRateControlMode(); | ||
const char * strategies[] = { "CBR", "ABR", "CVBR", "TVBR" }; | ||
s += strutil::format(", %s", strategies[value]); | ||
if (value == kAudioCodecBitRateControlMode_Variable) { | ||
value = getSoundQualityForVBR(); | ||
s += strutil::format(" q%d", value); | ||
} else { | ||
value = getEncodeBitRate(); | ||
s += strutil::format(" %gkbps", value / 1000.0); | ||
} | ||
value = getCodecQuality(); | ||
s += strutil::format(", Quality %d", value); | ||
return s; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef AudioConverterXX_H | ||
#define AudioConverterXX_H | ||
|
||
#include "AudioConverterX.h" | ||
|
||
class AudioConverterXX : public AudioConverterX { | ||
public: | ||
AudioConverterXX() {} | ||
AudioConverterXX(AudioConverterRef converter, bool takeOwn) | ||
: AudioConverterX(converter, takeOwn) | ||
{} | ||
AudioConverterXX(const AudioStreamBasicDescription &iasbd, | ||
const AudioStreamBasicDescription &oasbd) | ||
: AudioConverterX(iasbd, oasbd) | ||
{} | ||
double getClosestAvailableBitRate(double value); | ||
std::string getConfigAsString(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters