Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

AEConvert: Use a more extensible API. #1295

Closed
wants to merge 1 commit into from

2 participants

@aballier
Collaborator

New API is: create a CAE{Fr,To}FloatConv class foo.
The class is to be considered valid iff foo->is_valid is true.
Call foo->convert to make the conversion.
delete foo when done.

This follows from the discussion on #1290.
With this new API, it should be easy to implement AEConvert stuff based on swr/avr.

How to do this is still to decide:
1) a new .cpp file for the swr based converter, implementing the same classes, and chose at build time which file to build
2) #ifdefery in the current AEConvert.cpp

Anyway, a new converter depends on #1290 to be merged first.

@gnif
Collaborator

I dont like the access to 'is_valid', it should be private and a get function be written as this is read only outside of the class.

@aballier aballier AEConvert: Use a more extensible API.
New API is: create a CAE{Fr,To}FloatConv class foo.
The class is to be considered valid iff foo->is_valid is true.
Call foo->convert to make the conversion.
delete foo when done.
159989e
@aballier
Collaborator

re is_valid: Changed to a function, it makes more sense here.
usually i'm not a fan of this OO religion of babysitting developers by duplicating the code using getters/setters, but in this case it just makes more sense for it to be a function, and allows more flexibility for implementations.

@aballier
Collaborator

this pr is seriously superseeded by activeae

@aballier aballier closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2012
  1. @aballier

    AEConvert: Use a more extensible API.

    aballier authored
    New API is: create a CAE{Fr,To}FloatConv class foo.
    The class is to be considered valid iff foo->is_valid is true.
    Call foo->convert to make the conversion.
    delete foo when done.
This page is out of date. Refresh to see the latest.
View
12 xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.cpp
@@ -284,10 +284,14 @@ void CCoreAudioAEStream::Initialize()
{
// get the conversion function and allocate a buffer for the data
CLog::Log(LOGDEBUG, "CCoreAudioAEStream::CCoreAudioAEStream - Converting from %s to AE_FMT_FLOAT", CAEUtil::DataFormatToStr(m_StreamFormat.m_dataFormat));
- m_convertFn = CAEConvert::ToFloat(m_StreamFormat.m_dataFormat);
+ m_convertFn = new CAEToFloatConv(m_StreamFormat.m_dataFormat);
- if (!m_convertFn)
+ if (!m_convertFn || !m_convertFn->is_valid())
+ {
m_valid = false;
+ delete m_convertFn;
+ m_convertFn = NULL;
+ }
}
// if we need to resample, set it up
@@ -320,6 +324,8 @@ void CCoreAudioAEStream::Destroy()
{
m_valid = false;
m_delete = true;
+ delete m_convertFn;
+ m_convertFn = NULL;
InternalFlush();
}
@@ -349,7 +355,7 @@ unsigned int CCoreAudioAEStream::AddData(void *data, unsigned int size)
{
CheckOutputBufferSize((void **)&m_convertBuffer, &m_convertBufferSize, frames * channelsInBuffer * m_OutputBytesPerSample);
- samples = m_convertFn(adddata, size / m_StreamBytesPerSample, m_convertBuffer);
+ samples = m_convertFn->convert(adddata, size / m_StreamBytesPerSample, m_convertBuffer);
frames = samples / channelsInBuffer;
addsize = frames * channelsInBuffer * m_OutputBytesPerSample;
adddata = (uint8_t *)m_convertBuffer;
View
2  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.h
@@ -132,7 +132,7 @@ class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
float m_rgain; /* replay gain level */
IAEStream *m_slave; /* slave aestream */
- CAEConvert::AEConvertToFn m_convertFn;
+ CAEToFloatConv *m_convertFn;
CoreAudioRingBuffer *m_Buffer;
float *m_convertBuffer; /* buffer for converted data */
View
15 xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
@@ -380,13 +380,13 @@ void CSoftAE::InternalOpenSink()
/* remap directly to the format we need for encode */
reInit = (reInit || m_chLayout != m_encoderFormat.m_channelLayout);
m_chLayout = m_encoderFormat.m_channelLayout;
- m_convertFn = CAEConvert::FrFloat(m_encoderFormat.m_dataFormat);
+ m_convertFn = new CAEFrFloatConv(m_encoderFormat.m_dataFormat);
neededBufferSize = m_encoderFormat.m_frames * sizeof(float) * m_chLayout.Count();
CLog::Log(LOGDEBUG, "CSoftAE::Initialize - Encoding using layout: %s", ((std::string)m_chLayout).c_str());
}
else
{
- m_convertFn = CAEConvert::FrFloat(m_sinkFormat.m_dataFormat);
+ m_convertFn = new CAEFrFloatConv(m_sinkFormat.m_dataFormat);
neededBufferSize = m_sinkFormat.m_frames * sizeof(float) * m_chLayout.Count();
CLog::Log(LOGDEBUG, "CSoftAE::Initialize - Using speaker layout: %s", CAEUtil::GetStdChLayoutName(m_stdChLayout));
}
@@ -585,6 +585,9 @@ void CSoftAE::Deinitialize()
m_sink = NULL;
}
+ delete m_convertFn;
+ m_convertFn = NULL;
+
delete m_encoder;
m_encoder = NULL;
@@ -1025,12 +1028,12 @@ int CSoftAE::RunOutputStage(bool hasAudio)
hasAudio = FinalizeSamples((float*)data, needSamples, hasAudio);
int wroteFrames;
- if (m_convertFn)
+ if (m_convertFn && m_convertFn->is_valid())
{
const unsigned int convertedBytes = m_sinkFormat.m_frames * m_sinkFormat.m_frameSize;
AllocateConvIfNeeded(convertedBytes, !hasAudio);
if (hasAudio)
- m_convertFn((float*)data, needSamples, m_converted);
+ m_convertFn->convert((const float*)data, needSamples, m_converted);
data = m_converted;
}
@@ -1099,12 +1102,12 @@ int CSoftAE::RunTranscodeStage(bool hasAudio)
hasAudio = FinalizeSamples((float*)m_buffer.Raw(block), m_encoderFormat.m_frameSamples, hasAudio);
void *buffer;
- if (m_convertFn)
+ if (m_convertFn && m_convertFn->is_valid())
{
unsigned int newsize = m_encoderFormat.m_frames * m_encoderFormat.m_frameSize;
AllocateConvIfNeeded(newsize, !hasAudio);
if (hasAudio)
- m_convertFn((float*)m_buffer.Raw(block),
+ m_convertFn->convert((const float*)m_buffer.Raw(block),
m_encoderFormat.m_frames * m_encoderFormat.m_channelLayout.Count(), m_converted);
buffer = m_converted;
}
View
2  xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.h
@@ -155,7 +155,7 @@ class CSoftAE : public IThreadedAE
AEAudioFormat m_encoderFormat;
float m_encoderFrameSizeMul;
unsigned int m_bytesPerSample;
- CAEConvert::AEConvertFrFn m_convertFn;
+ CAEFrFloatConv *m_convertFn;
/* currently playing sounds */
typedef struct {
View
17 xbmc/cores/AudioEngine/Engines/SoftAE/SoftAEStream.cpp
@@ -177,11 +177,15 @@ void CSoftAEStream::Initialize()
{
/* get the conversion function and allocate a buffer for the data */
CLog::Log(LOGDEBUG, "CSoftAEStream::CSoftAEStream - Converting from %s to AE_FMT_FLOAT", CAEUtil::DataFormatToStr(m_initDataFormat));
- m_convertFn = CAEConvert::ToFloat(m_initDataFormat);
- if (m_convertFn)
+ m_convertFn = new CAEToFloatConv(m_initDataFormat);
+ if (m_convertFn && m_convertFn->is_valid())
m_convertBuffer = (float*)_aligned_malloc(m_format.m_frameSamples * sizeof(float), 16);
else
- m_valid = false;
+ {
+ m_valid = false;
+ delete m_convertFn;
+ m_convertFn = NULL;
+ }
}
else
m_convertBuffer = (float*)m_inputBuffer.Raw(m_format.m_frames * m_format.m_frameSize);
@@ -218,6 +222,9 @@ CSoftAEStream::~CSoftAEStream()
if (m_convert)
_aligned_free(m_convertBuffer);
+ delete m_convertFn;
+ m_convertFn = NULL;
+
if (m_resample)
{
_aligned_free(m_ssrcData.data_out);
@@ -298,8 +305,8 @@ unsigned int CSoftAEStream::ProcessFrameBuffer()
if (m_convert)
{
data = (uint8_t*)m_convertBuffer;
- samples = m_convertFn(
- (uint8_t*)m_inputBuffer.Raw(m_inputBuffer.Used()),
+ samples = m_convertFn->convert(
+ (const uint8_t*)m_inputBuffer.Raw(m_inputBuffer.Used()),
m_inputBuffer.Used() / m_bytesPerSample,
m_convertBuffer
);
View
2  xbmc/cores/AudioEngine/Engines/SoftAE/SoftAEStream.h
@@ -115,8 +115,8 @@ class CSoftAEStream : public IAEStream
float m_rgain; /* replay gain level */
unsigned int m_waterLevel; /* the fill level to fall below before calling the data callback */
unsigned int m_refillBuffer; /* how many frames that need to be buffered before we return any frames */
+ CAEToFloatConv *m_convertFn;
- CAEConvert::AEConvertToFn m_convertFn;
CAEBuffer m_inputBuffer;
unsigned int m_bytesPerSample;
View
238 xbmc/cores/AudioEngine/Utils/AEConvert.cpp
@@ -43,6 +43,9 @@
#include <arm_neon.h>
#endif
+typedef unsigned int (*ConvertToFn)(const uint8_t *data, unsigned int samples, float *dest);
+typedef unsigned int (*ConvertFrFn)(const float *data, unsigned int samples, uint8_t *dest);
+
#define CLAMP(x) std::min(-1.0f, std::max(1.0f, (float)(x)))
#ifndef INT24_MAX
@@ -66,73 +69,7 @@ static inline int safeRound(double f)
return MathUtils::round_int(f);
}
-CAEConvert::AEConvertToFn CAEConvert::ToFloat(enum AEDataFormat dataFormat)
-{
- switch (dataFormat)
- {
- case AE_FMT_U8 : return &U8_Float;
- case AE_FMT_S8 : return &S8_Float;
-#ifdef __BIG_ENDIAN__
- case AE_FMT_S16NE : return &S16BE_Float;
- case AE_FMT_S32NE : return &S32BE_Float;
- case AE_FMT_S24NE4: return &S24BE4_Float;
- case AE_FMT_S24NE3: return &S24BE3_Float;
-#else
- case AE_FMT_S16NE : return &S16LE_Float;
- case AE_FMT_S32NE : return &S32LE_Float;
- case AE_FMT_S24NE4: return &S24LE4_Float;
- case AE_FMT_S24NE3: return &S24LE3_Float;
-#endif
- case AE_FMT_S16LE : return &S16LE_Float;
- case AE_FMT_S16BE : return &S16BE_Float;
- case AE_FMT_S24LE4: return &S24LE4_Float;
- case AE_FMT_S24BE4: return &S24BE4_Float;
- case AE_FMT_S24LE3: return &S24LE3_Float;
- case AE_FMT_S24BE3: return &S24BE3_Float;
-#if defined(__ARM_NEON__)
- case AE_FMT_S32LE : return &S32LE_Float_Neon;
- case AE_FMT_S32BE : return &S32BE_Float_Neon;
-#else
- case AE_FMT_S32LE : return &S32LE_Float;
- case AE_FMT_S32BE : return &S32BE_Float;
-#endif
- case AE_FMT_DOUBLE: return &DOUBLE_Float;
- default:
- return NULL;
- }
-}
-
-CAEConvert::AEConvertFrFn CAEConvert::FrFloat(enum AEDataFormat dataFormat)
-{
- switch (dataFormat)
- {
- case AE_FMT_U8 : return &Float_U8;
- case AE_FMT_S8 : return &Float_S8;
-#ifdef __BIG_ENDIAN__
- case AE_FMT_S16NE : return &Float_S16BE;
- case AE_FMT_S32NE : return &Float_S32BE;
-#else
- case AE_FMT_S16NE : return &Float_S16LE;
- case AE_FMT_S32NE : return &Float_S32LE;
-#endif
- case AE_FMT_S16LE : return &Float_S16LE;
- case AE_FMT_S16BE : return &Float_S16BE;
- case AE_FMT_S24NE4: return &Float_S24NE4;
- case AE_FMT_S24NE3: return &Float_S24NE3;
-#if defined(__ARM_NEON__)
- case AE_FMT_S32LE : return &Float_S32LE_Neon;
- case AE_FMT_S32BE : return &Float_S32BE_Neon;
-#else
- case AE_FMT_S32LE : return &Float_S32LE;
- case AE_FMT_S32BE : return &Float_S32BE;
-#endif
- case AE_FMT_DOUBLE: return &Float_DOUBLE;
- default:
- return NULL;
- }
-}
-
-unsigned int CAEConvert::U8_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int U8_Float(const uint8_t *data, unsigned int samples, float *dest)
{
const float mul = 2.0f / UINT8_MAX;
@@ -142,7 +79,7 @@ unsigned int CAEConvert::U8_Float(uint8_t *data, const unsigned int samples, flo
return samples;
}
-unsigned int CAEConvert::S8_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S8_Float(const uint8_t *data, unsigned int samples, float *dest)
{
const float mul = 1.0f / (INT8_MAX + 0.5f);
@@ -152,7 +89,7 @@ unsigned int CAEConvert::S8_Float(uint8_t *data, const unsigned int samples, flo
return samples;
}
-unsigned int CAEConvert::S16LE_Float(uint8_t* data, const unsigned int samples, float *dest)
+static unsigned int S16LE_Float(const uint8_t* data, unsigned int samples, float *dest)
{
static const float mul = 1.0f / (INT16_MAX + 0.5f);
@@ -183,7 +120,7 @@ unsigned int CAEConvert::S16LE_Float(uint8_t* data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S16BE_Float(uint8_t* data, const unsigned int samples, float *dest)
+static unsigned int S16BE_Float(const uint8_t* data, unsigned int samples, float *dest)
{
static const float mul = 1.0f / (INT16_MAX + 0.5f);
@@ -214,7 +151,7 @@ unsigned int CAEConvert::S16BE_Float(uint8_t* data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S24LE4_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S24LE4_Float(const uint8_t *data, unsigned int samples, float *dest)
{
for (unsigned int i = 0; i < samples; ++i, data += 4)
{
@@ -224,7 +161,7 @@ unsigned int CAEConvert::S24LE4_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S24BE4_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S24BE4_Float(const uint8_t *data, unsigned int samples, float *dest)
{
for (unsigned int i = 0; i < samples; ++i, data += 4)
{
@@ -234,7 +171,7 @@ unsigned int CAEConvert::S24BE4_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S24LE3_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S24LE3_Float(const uint8_t *data, unsigned int samples, float *dest)
{
for (unsigned int i = 0; i < samples; ++i, data += 3)
{
@@ -244,7 +181,7 @@ unsigned int CAEConvert::S24LE3_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S24BE3_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S24BE3_Float(const uint8_t *data, unsigned int samples, float *dest)
{
for (unsigned int i = 0; i < samples; ++i, data += 3)
{
@@ -254,7 +191,7 @@ unsigned int CAEConvert::S24BE3_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S32LE_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S32LE_Float(const uint8_t *data, unsigned int samples, float *dest)
{
static const float factor = 1.0f / (float)INT32_MAX;
int32_t *src = (int32_t*)data;
@@ -275,9 +212,9 @@ unsigned int CAEConvert::S32LE_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S32LE_Float_Neon(uint8_t *data, const unsigned int samples, float *dest)
-{
#if defined(__ARM_NEON__)
+static unsigned int S32LE_Float_Neon(const uint8_t *data, unsigned int samples, float *dest)
+{
static const float factor = 1.0f / (float)INT32_MAX;
int32_t *src = (int32_t*)data;
@@ -309,11 +246,11 @@ unsigned int CAEConvert::S32LE_Float_Neon(uint8_t *data, const unsigned int samp
if (samples & 0x1)
dest[0] = (float)src[0] * factor;
-#endif /* !defined(__ARM_NEON__) */
return samples;
}
+#endif /* !defined(__ARM_NEON__) */
-unsigned int CAEConvert::S32BE_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int S32BE_Float(const uint8_t *data, unsigned int samples, float *dest)
{
static const float factor = 1.0f / (float)INT32_MAX;
int32_t *src = (int32_t*)data;
@@ -334,9 +271,9 @@ unsigned int CAEConvert::S32BE_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::S32BE_Float_Neon(uint8_t *data, const unsigned int samples, float *dest)
-{
#if defined(__ARM_NEON__)
+static unsigned int S32BE_Float_Neon(const uint8_t *data, unsigned int samples, float *dest)
+{
static const float factor = 1.0f / (float)INT32_MAX;
int32_t *src = (int32_t*)data;
@@ -368,11 +305,11 @@ unsigned int CAEConvert::S32BE_Float_Neon(uint8_t *data, const unsigned int samp
if (samples & 0x1)
dest[0] = (float)src[0] * factor;
-#endif /* !defined(__ARM_NEON__) */
return samples;
}
+#endif /* !defined(__ARM_NEON__) */
-unsigned int CAEConvert::DOUBLE_Float(uint8_t *data, const unsigned int samples, float *dest)
+static unsigned int DOUBLE_Float(const uint8_t *data, unsigned int samples, float *dest)
{
double *src = (double*)data;
for (unsigned int i = 0; i < samples; ++i)
@@ -381,7 +318,7 @@ unsigned int CAEConvert::DOUBLE_Float(uint8_t *data, const unsigned int samples,
return samples;
}
-unsigned int CAEConvert::Float_U8(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_U8(const float *data, unsigned int samples, uint8_t *dest)
{
#ifdef __SSE__
const __m128 mul = _mm_set_ps1((float)INT8_MAX+.5f);
@@ -456,7 +393,7 @@ unsigned int CAEConvert::Float_U8(float *data, const unsigned int samples, uint8
return samples;
}
-unsigned int CAEConvert::Float_S8(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S8(const float *data, unsigned int samples, uint8_t *dest)
{
#ifdef __SSE__
const __m128 mul = _mm_set_ps1((float)INT8_MAX+.5f);
@@ -515,7 +452,7 @@ unsigned int CAEConvert::Float_S8(float *data, const unsigned int samples, uint8
return samples;
}
-unsigned int CAEConvert::Float_S16LE(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S16LE(const float *data, unsigned int samples, uint8_t *dest)
{
int16_t *dst = (int16_t*)dest;
#ifdef __SSE__
@@ -649,7 +586,7 @@ unsigned int CAEConvert::Float_S16LE(float *data, const unsigned int samples, ui
return samples << 1;
}
-unsigned int CAEConvert::Float_S16BE(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S16BE(const float *data, unsigned int samples, uint8_t *dest)
{
int16_t *dst = (int16_t*)dest;
#ifdef __SSE__
@@ -783,7 +720,7 @@ unsigned int CAEConvert::Float_S16BE(float *data, const unsigned int samples, ui
return samples << 1;
}
-unsigned int CAEConvert::Float_S24NE4(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S24NE4(const float *data, unsigned int samples, uint8_t *dest)
{
int32_t *dst = (int32_t*)dest;
#ifdef __SSE__
@@ -844,7 +781,7 @@ unsigned int CAEConvert::Float_S24NE4(float *data, const unsigned int samples, u
return samples << 2;
}
-unsigned int CAEConvert::Float_S24NE3(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S24NE3(const float *data, unsigned int samples, uint8_t *dest)
{
/* We do not want to shift for S24LE3, since left-shifting would actually
* push the MSB to the 4th byte. */
@@ -923,7 +860,7 @@ unsigned int CAEConvert::Float_S24NE3(float *data, const unsigned int samples, u
return samples * 3;
}
-unsigned int CAEConvert::Float_S32LE(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S32LE(const float *data, unsigned int samples, uint8_t *dest)
{
int32_t *dst = (int32_t*)dest;
#ifdef __SSE__
@@ -997,9 +934,9 @@ unsigned int CAEConvert::Float_S32LE(float *data, const unsigned int samples, ui
}
-unsigned int CAEConvert::Float_S32LE_Neon(float *data, const unsigned int samples, uint8_t *dest)
-{
#if defined(__ARM_NEON__)
+static unsigned int Float_S32LE_Neon(const float *data, unsigned int samples, uint8_t *dest)
+{
int32_t *dst = (int32_t*)dest;
for (float *end = data + (samples & ~0x3); data < end; data += 4, dst += 4)
{
@@ -1028,11 +965,11 @@ unsigned int CAEConvert::Float_S32LE_Neon(float *data, const unsigned int sample
dst[0] = safeRound(data[0] * (float)INT32_MAX);
dst[0] = Endian_SwapLE32(dst[0]);
}
-#endif
return samples << 2;
}
+#endif
-unsigned int CAEConvert::Float_S32BE(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_S32BE(const float *data, unsigned int samples, uint8_t *dest)
{
int32_t *dst = (int32_t*)dest;
#ifdef __SSE__
@@ -1105,9 +1042,9 @@ unsigned int CAEConvert::Float_S32BE(float *data, const unsigned int samples, ui
return samples << 2;
}
-unsigned int CAEConvert::Float_S32BE_Neon(float *data, const unsigned int samples, uint8_t *dest)
-{
#if defined(__ARM_NEON__)
+static unsigned int Float_S32BE_Neon(const float *data, unsigned int samples, uint8_t *dest)
+{
int32_t *dst = (int32_t*)dest;
for (float *end = data + (samples & ~0x3); data < end; data += 4, dst += 4)
{
@@ -1136,11 +1073,11 @@ unsigned int CAEConvert::Float_S32BE_Neon(float *data, const unsigned int sample
dst[0] = safeRound(data[0] * (float)INT32_MAX);
dst[0] = Endian_SwapBE32(dst[0]);
}
-#endif
return samples << 2;
}
+#endif
-unsigned int CAEConvert::Float_DOUBLE(float *data, const unsigned int samples, uint8_t *dest)
+static unsigned int Float_DOUBLE(const float *data, unsigned int samples, uint8_t *dest)
{
double *dst = (double*)dest;
for (unsigned int i = 0; i < samples; ++i)
@@ -1149,3 +1086,108 @@ unsigned int CAEConvert::Float_DOUBLE(float *data, const unsigned int samples, u
return samples * sizeof(double);
}
+static ConvertToFn GetToFloatConv(enum AEDataFormat dataFormat)
+{
+ switch (dataFormat)
+ {
+ case AE_FMT_U8 : return &U8_Float;
+ case AE_FMT_S8 : return &S8_Float;
+#ifdef __BIG_ENDIAN__
+ case AE_FMT_S16NE : return &S16BE_Float;
+ case AE_FMT_S32NE : return &S32BE_Float;
+ case AE_FMT_S24NE4: return &S24BE4_Float;
+ case AE_FMT_S24NE3: return &S24BE3_Float;
+#else
+ case AE_FMT_S16NE : return &S16LE_Float;
+ case AE_FMT_S32NE : return &S32LE_Float;
+ case AE_FMT_S24NE4: return &S24LE4_Float;
+ case AE_FMT_S24NE3: return &S24LE3_Float;
+#endif
+ case AE_FMT_S16LE : return &S16LE_Float;
+ case AE_FMT_S16BE : return &S16BE_Float;
+ case AE_FMT_S24LE4: return &S24LE4_Float;
+ case AE_FMT_S24BE4: return &S24BE4_Float;
+ case AE_FMT_S24LE3: return &S24LE3_Float;
+ case AE_FMT_S24BE3: return &S24BE3_Float;
+#if defined(__ARM_NEON__)
+ case AE_FMT_S32LE : return &S32LE_Float_Neon;
+ case AE_FMT_S32BE : return &S32BE_Float_Neon;
+#else
+ case AE_FMT_S32LE : return &S32LE_Float;
+ case AE_FMT_S32BE : return &S32BE_Float;
+#endif
+ case AE_FMT_DOUBLE: return &DOUBLE_Float;
+ default:
+ return NULL;
+ }
+}
+
+CAEToFloatConv::CAEToFloatConv(enum AEDataFormat dataFormat)
+{
+ this->priv_data = (void*)(GetToFloatConv(dataFormat));
+}
+
+CAEToFloatConv::~CAEToFloatConv()
+{
+}
+
+bool CAEToFloatConv::is_valid()
+{
+ return (this->priv_data != NULL);
+}
+
+unsigned int CAEToFloatConv::convert(const uint8_t *data, unsigned int samples, float *dest){
+ if(this->priv_data)
+ return ((ConvertToFn)(this->priv_data))(data, samples, dest);
+ else return 0;
+}
+
+static ConvertFrFn GetFrFloatConv(enum AEDataFormat dataFormat)
+{
+ switch (dataFormat)
+ {
+ case AE_FMT_U8 : return &Float_U8;
+ case AE_FMT_S8 : return &Float_S8;
+#ifdef __BIG_ENDIAN__
+ case AE_FMT_S16NE : return &Float_S16BE;
+ case AE_FMT_S32NE : return &Float_S32BE;
+#else
+ case AE_FMT_S16NE : return &Float_S16LE;
+ case AE_FMT_S32NE : return &Float_S32LE;
+#endif
+ case AE_FMT_S16LE : return &Float_S16LE;
+ case AE_FMT_S16BE : return &Float_S16BE;
+ case AE_FMT_S24NE4: return &Float_S24NE4;
+ case AE_FMT_S24NE3: return &Float_S24NE3;
+#if defined(__ARM_NEON__)
+ case AE_FMT_S32LE : return &Float_S32LE_Neon;
+ case AE_FMT_S32BE : return &Float_S32BE_Neon;
+#else
+ case AE_FMT_S32LE : return &Float_S32LE;
+ case AE_FMT_S32BE : return &Float_S32BE;
+#endif
+ case AE_FMT_DOUBLE: return &Float_DOUBLE;
+ default:
+ return NULL;
+ }
+}
+
+CAEFrFloatConv::CAEFrFloatConv(enum AEDataFormat dataFormat)
+{
+ this->priv_data = (void*)(GetFrFloatConv(dataFormat));
+}
+
+CAEFrFloatConv::~CAEFrFloatConv()
+{
+}
+
+bool CAEFrFloatConv::is_valid()
+{
+ return (this->priv_data != NULL);
+}
+
+unsigned int CAEFrFloatConv::convert(const float *data, unsigned int samples, uint8_t *dest){
+ if(this->priv_data)
+ return ((ConvertFrFn)(this->priv_data))(data, samples, dest);
+ else return 0;
+}
View
48 xbmc/cores/AudioEngine/Utils/AEConvert.h
@@ -23,40 +23,22 @@
#include <stdint.h>
#include "../AEAudioFormat.h"
-class CAEConvert{
+class CAEToFloatConv{
+public:
+ CAEToFloatConv(enum AEDataFormat dataFormat);
+ ~CAEToFloatConv();
+ unsigned int convert(const uint8_t *data, unsigned int samples, float *dest);
+ bool is_valid();
private:
- static unsigned int U8_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S8_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S16LE_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S16BE_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S24LE4_Float(uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S24BE4_Float(uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S24LE3_Float(uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S24BE3_Float(uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S32LE_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S32BE_Float (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int DOUBLE_Float(uint8_t *data, const unsigned int samples, float *dest);
-
- static unsigned int Float_U8 (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S8 (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S16LE (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S16BE (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S24NE4(float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S24NE3(float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S32LE (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S32BE (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_DOUBLE(float *data, const unsigned int samples, uint8_t *dest);
-
- static unsigned int S32LE_Float_Neon (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int S32BE_Float_Neon (uint8_t *data, const unsigned int samples, float *dest);
- static unsigned int Float_S32LE_Neon (float *data, const unsigned int samples, uint8_t *dest);
- static unsigned int Float_S32BE_Neon (float *data, const unsigned int samples, uint8_t *dest);
+ void* priv_data;
+};
+class CAEFrFloatConv{
public:
- typedef unsigned int (*AEConvertToFn)(uint8_t *data, const unsigned int samples, float *dest);
- typedef unsigned int (*AEConvertFrFn)(float *data, const unsigned int samples, uint8_t *dest);
-
- static AEConvertToFn ToFloat(enum AEDataFormat dataFormat);
- static AEConvertFrFn FrFloat(enum AEDataFormat dataFormat);
+ CAEFrFloatConv(enum AEDataFormat dataFormat);
+ ~CAEFrFloatConv();
+ unsigned int convert(const float *data, unsigned int samples, uint8_t *dest);
+ bool is_valid();
+private:
+ void* priv_data;
};
-
View
11 xbmc/cores/AudioEngine/Utils/AEWAVLoader.cpp
@@ -161,12 +161,12 @@ bool CAEWAVLoader::Initialize(const std::string &filename, unsigned int resample
isDATA = m_frameCount > 0;
/* get the conversion function */
- CAEConvert::AEConvertToFn convertFn;
+ CAEToFloatConv *convertFn = NULL;
switch (bitsPerSample)
{
- case 8 : convertFn = CAEConvert::ToFloat(AE_FMT_U8 ); break;
- case 16: convertFn = CAEConvert::ToFloat(AE_FMT_S16LE); break;
- case 32: convertFn = CAEConvert::ToFloat(AE_FMT_S32LE); break;
+ case 8 : convertFn = new CAEToFloatConv(AE_FMT_U8 ); break;
+ case 16: convertFn = new CAEToFloatConv(AE_FMT_S16LE); break;
+ case 32: convertFn = new CAEToFloatConv(AE_FMT_S32LE); break;
default:
CLog::Log(LOGERROR, "CAEWAVLoader::Initialize - Unsupported data format in wav: %s", m_filename.c_str());
file.Close();
@@ -190,9 +190,10 @@ bool CAEWAVLoader::Initialize(const std::string &filename, unsigned int resample
}
/* convert the sample to float */
- convertFn(raw, 1, &m_samples[s]);
+ convertFn->convert(raw, 1, &m_samples[s]);
}
_aligned_free(raw);
+ delete convertFn;
}
else
{
Something went wrong with that request. Please try again.