[DEV] start create auto type for audio algo ...

This commit is contained in:
Edouard DUPIN 2015-04-07 21:44:57 +02:00
parent ea6d4e7d58
commit d5c9c3b1ff
25 changed files with 705 additions and 2 deletions

10
audio/double_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/double_t.h>

24
audio/double_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_DOUBLE_T_H__
#define __AUDIO_TYPE_DOUBLE_T_H__
namespace audio {
class double_t {
private:
double m_data;
public:
double get() const {
return m_data;
}
};
}
#endif

10
audio/float_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/float_t.h>

24
audio/float_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_FLOAT_T_H__
#define __AUDIO_TYPE_FLOAT_T_H__
namespace audio {
class float_t {
private:
float m_data;
public:
float get() const {
return m_data;
}
};
}
#endif

View File

@ -20,6 +20,7 @@
format_int16 = audio_msg::AudioBuffer::FORMAT_INT16,
format_int16_on_int32 = audio_msg::AudioBuffer::FORMAT_INT16_ON_INT32,
format_int24 = audio_msg::AudioBuffer::FORMAT_INT24,
format_int24_on_int32 = audio_msg::AudioBuffer::FORMAT_INT24_ON_INT32,
format_int32 = audio_msg::AudioBuffer::FORMAT_INT32,
format_int32_on_int64 = audio_msg::AudioBuffer::FORMAT_INT32_ON_INT64,
format_int64 = audio_msg::AudioBuffer::FORMAT_INT64,
@ -35,7 +36,8 @@
format_int8_on_int16, //!< Signed 8 bits on 16 bits data (8 bit fixpoint value)
format_int16, //!< Signed 16 bits
format_int16_on_int32, //!< Signed 16 bits on 32 bits data (16 bit fixpoint value)
format_int24, //!< Signed 24 bits on 32 bits (lower)
format_int24, //!< Signed 24 bits on 24 bits (lower)
format_int24_on_int32, //!< Signed 24 bits on 32 bits (lower)
format_int32, //!< Signed 32 bits
format_int32_on_int64, //!< Signed 32 bits on 64 bits data (32 bit fixpoint value)
format_int64, //!< Signed 64 bits

86
audio/int16_16_t.cpp Normal file
View File

@ -0,0 +1,86 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int16_16_t.h>
audio::int16_16_t::int16_16_t(const audio::int8_8_t& _val) {
m_data = int16_t(_val.get()) << 8;
}
audio::int16_16_t::int16_16_t(const audio::int8_16_t& _val) {
m_data = std::avg(int16_t(INT8_MIN),
_val.get(),
int16_t(INT8_MAX)
) << 8;
}
audio::int16_16_t::int16_16_t(const audio::int16_16_t& _val) {
m_data = _val.m_data;
}
audio::int16_16_t::int16_16_t(const audio::int16_32_t& _val) {
m_data = int16_t(std::avg(int32_t(INT16_MIN),
_val.get(),
int32_t(INT16_MAX)
)
);
}
audio::int16_16_t::int16_16_t(const audio::int24_24_t& _val) {
m_data = int16_t(_val.get() >> 8);
}
audio::int16_16_t::int16_16_t(const audio::int24_32_t& _val) {
m_data = int16_t(std::avg(int32_t(INT24_MIN),
_val.get(),
int32_t(INT24_MAX)
) >> 8
);
}
audio::int16_16_t::int16_16_t(const audio::int32_32_t& _val) {
m_data = int16_t(_val.get() >> 16);
}
audio::int16_16_t::int16_16_t(const audio::int32_64_t& _val) {
m_data = int16_t(std::avg(int64_t(INT32_MIN),
_val.get(),
int64_t(INT32_MAX)
) >> 16
);
}
audio::int16_16_t::int16_16_t(const audio::int64_64_t& _val) {
m_data = int16_t(_val.get() >> 56);
}
audio::int16_16_t::int16_16_t(const audio::float_t& _val) {
m_data = int16_t(std::avg(-1.0f,
_val.get(),
1.0f
) * 32767.0f
);
}
audio::int16_16_t::int16_16_t(const audio::double_t& _val) {
m_data = int16_t(std::avg(-1.0,
_val.get(),
1.0
) * 32767.0
);
}
audio::int16_16_t::int16_16_t(int32_t _value, int32_t _flotingPointPosition) {
set(_value, _flotingPointPosition);
}
void audio::int16_16_t::set(int32_t _value, int32_t _flotingPointPosition) {
int64_t val = _value << (16-_flotingPointPosition);
m_data = std::avg(int64_t(INT16_MIN), val, int64_t(INT16_MAX));
}

40
audio/int16_16_t.h Normal file
View File

@ -0,0 +1,40 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT16_16_T_H__
#define __AUDIO_TYPE_INT16_16_T_H__
namespace audio {
class int16_16_t{
private:
int16_t m_data;
public:
int16_16_t() {}
// transformation operator:
int16_16_t(const audio::int8_8_t& _val);
int16_16_t(const audio::int8_16_t& _val);
int16_16_t(const audio::int16_16_t& _val);
int16_16_t(const audio::int16_32_t& _val);
int16_16_t(const audio::int24_24_t& _val);
int16_16_t(const audio::int24_32_t& _val);
int16_16_t(const audio::int32_32_t& _val);
int16_16_t(const audio::int32_64_t& _val);
int16_16_t(const audio::int64_64_t& _val);
int16_16_t(const audio::float_t& _val);
int16_16_t(const audio::double_t& _val);
// set operator
int16_16_t(int32_t _value, int32_t _flotingPointPosition);
void set(int32_t _value, int32_t _flotingPointPosition);
int16_t get() const {
return m_data;
}
};
}
#endif

85
audio/int16_32_t.cpp Normal file
View File

@ -0,0 +1,85 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int16_32_t.h>
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int16_32_t.h>
audio::int16_32_t::int16_32_t(const audio::int8_8_t& _val) {
m_data = int32_t(_val.get()) << 8;
}
audio::int16_32_t::int16_32_t(const audio::int8_16_t& _val) {
m_data = int32_t(_val.get()) << 8;
}
audio::int16_32_t::int16_32_t(const audio::int16_16_t& _val) {
m_data = _val.get();
}
audio::int16_32_t::int16_32_t(const audio::int16_32_t& _val) {
m_data = _val.m_data;
}
audio::int16_32_t::int16_32_t(const audio::int24_24_t& _val) {
m_data = int32_t(_val.get() >> 8);
}
audio::int16_32_t::int16_32_t(const audio::int24_32_t& _val) {
m_data = int32_t(_val.get() >> 8);;
}
audio::int16_32_t::int16_32_t(const audio::int32_32_t& _val) {
m_data = int16_t(_val.get() >> 16);
}
audio::int16_32_t::int16_32_t(const audio::int32_64_t& _val) {
m_data = int16_t(std::avg(int64_t(INT56_MIN),
_val.get(),
int64_t(INT56_MAX)
) >> 16
);
}
audio::int16_32_t::int16_32_t(const audio::int64_64_t& _val) {
m_data = int16_t(_val.get() >> 56);
}
audio::int16_32_t::int16_32_t(const audio::float_t& _val) {
m_data = int16_t(std::avg(-1.0f,
_val.get(),
1.0f
) * 32767.0f
);
}
audio::int16_32_t::int16_32_t(const audio::double_t& _val) {
m_data = int16_t(std::avg(-1.0,
_val.get(),
1.0
) * 32767.0
);
}
audio::int16_32_t::int16_32_t(int32_t _value, int32_t _flotingPointPosition) {
set(_value, _flotingPointPosition);
}
void audio::int16_32_t::set(int32_t _value, int32_t _flotingPointPosition) {
int64_t val = _value << (16-_flotingPointPosition);
m_data = std::avg(int64_t(INT32_MIN), val, int64_t(INT32_MAX));
}

40
audio/int16_32_t.h Normal file
View File

@ -0,0 +1,40 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT16_32_T_H__
#define __AUDIO_TYPE_INT16_32_T_H__
namespace audio {
class int16_32_t{
private:
int32_t m_data;
public:
int16_32_t() {}
// transformation operator:
int16_32_t(const audio::int8_8_t& _val);
int16_32_t(const audio::int8_16_t& _val);
int16_32_t(const audio::int16_16_t& _val);
int16_32_t(const audio::int16_32_t& _val);
int16_32_t(const audio::int24_24_t& _val);
int16_32_t(const audio::int24_32_t& _val);
int16_32_t(const audio::int32_32_t& _val);
int16_32_t(const audio::int32_64_t& _val);
int16_32_t(const audio::int64_64_t& _val);
int16_32_t(const audio::float_t& _val);
int16_32_t(const audio::double_t& _val);
// set operator
int16_32_t(int32_t _value, int32_t _flotingPointPosition);
void set(int32_t _value, int32_t _flotingPointPosition);
int32_t get() const {
return m_data;
}
};
}
#endif

85
audio/int24_24_t.cpp Normal file
View File

@ -0,0 +1,85 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int24_24_t.h>
audio::int24_24_t::int24_24_t(const audio::int8_8_t& _val) {
int32_t val = _val.get();
set(int32_t(val), 8);
}
audio::int24_24_t::int24_24_t(const audio::int8_16_t& _val) {
int32_t val = _val.get();
set(int32_t(val), 8);
}
audio::int24_24_t::int24_24_t(const audio::int16_16_t& _val) {
int32_t val = _val.get();
set(int32_t(val), 16);
}
audio::int24_24_t::int24_24_t(const audio::int16_32_t& _val) {
int32_t val = _val.get();
set(int32_t(val), 16);
}
audio::int24_24_t::int24_24_t(const audio::int24_24_t& _val) {
m_data[0] = _val.m_data[0];
m_data[1] = _val.m_data[1];
m_data[2] = _val.m_data[2];
}
audio::int24_24_t::int24_24_t(const audio::int24_32_t& _val) {
set(int32_t(_val.get()), 24);
}
audio::int24_24_t::int24_24_t(const audio::int32_32_t& _val) {
int32_t val = _val.get() >> 8;
set(val, 24);
}
audio::int24_24_t::int24_24_t(const audio::int32_64_t& _val) {
int64_t val = _val.get() >> 8;
set(int32_t(val), 24);
}
audio::int24_24_t::int24_24_t(const audio::int64_64_t& _val) {
int64_t val = _val.get() >> (32+8);
set(int32_t(val), 24);
}
audio::int24_24_t::int24_24_t(const audio::float_t& _val) {
float val = _val.get() * float(INT24_MAX);
set(int32_t(val), 24);
}
audio::int24_24_t::int24_24_t(const audio::double_t& _val) {
double val = _val.get() * double(INT24_MAX);
set(int32_t(val), 24);
}
// set operator
audio::int24_24_t::int24_24_t(int32_t _value, int32_t _flotingPointPosition) {
set(_value, _flotingPointPosition);
}
void audio::int24_24_t::set(int32_t _value, int32_t _flotingPointPosition) {
int64_t val = _value << (24-_flotingPointPosition);
val = std::avg(int64_t(INT24_MIN), val, int64_t(INT24_MAX));
m_data[0] = (val & 0x000000ff);
m_data[1] = (val & 0x0000ff00) >> 8;
m_data[2] = (val & 0x00ff0000) >> 16;
}
int32_t audio::int24_24_t::get() const {
int32_t val = 0;
val += int32_t(m_data[0]);
val += int32_t(m_data[1]) << 8;
val += int32_t(m_data[2]) << 16;
return val;
}

38
audio/int24_24_t.h Normal file
View File

@ -0,0 +1,38 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT24_24_T_H__
#define __AUDIO_TYPE_INT24_24_T_H__
namespace audio {
class int24_24_t {
private:
int8_t m_data[3];
public:
int24_24_t() {}
// transformation operator:
int24_24_t(const audio::int8_8_t& _val);
int24_24_t(const audio::int8_16_t& _val);
int24_24_t(const audio::int16_16_t& _val);
int24_24_t(const audio::int16_32_t& _val);
int24_24_t(const audio::int24_24_t& _val);
int24_24_t(const audio::int24_32_t& _val);
int24_24_t(const audio::int32_32_t& _val);
int24_24_t(const audio::int32_64_t& _val);
int24_24_t(const audio::int64_64_t& _val);
int24_24_t(const audio::float_t& _val);
int24_24_t(const audio::double_t& _val);
// set operator
int24_24_t(int32_t _value, int32_t _flotingPointPosition);
void set(int32_t _value, int32_t _flotingPointPosition);
int32_t get() const;
};
}
#endif

10
audio/int24_32_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int24_32_t.h>

24
audio/int24_32_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT24_32_T_H__
#define __AUDIO_TYPE_INT24_32_T_H__
namespace audio {
class int24_32_t {
private:
int32_t m_data;
public:
int32_t get() const {
return m_data;
}
};
}
#endif

10
audio/int32_32_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int32_32_t.h>

24
audio/int32_32_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT32_32_T_H__
#define __AUDIO_TYPE_INT32_32_T_H__
namespace audio {
class int32_32_t {
private:
int32_t m_data;
public:
int32_t get() const {
return m_data;
}
};
}
#endif

10
audio/int32_64_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int32_64_t.h>

24
audio/int32_64_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT32_64_T_H__
#define __AUDIO_TYPE_INT32_64_T_H__
namespace audio {
class int32_64_t {
private:
int64_t m_data;
public:
int64_t get() const {
return m_data;
}
};
}
#endif

10
audio/int64_64_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int64_64_t.h>

24
audio/int64_64_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT64_64_T_H__
#define __AUDIO_TYPE_INT64_64_T_H__
namespace audio {
class int64_64_t {
private:
int64_t m_data;
public:
int64_t get() const {
return m_data;
}
};
}
#endif

10
audio/int8_16_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int8_16_t.h>

24
audio/int8_16_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT8_16_T_H__
#define __AUDIO_TYPE_INT8_16_T_H__
namespace audio {
class int8_16_t {
private:
int16_t m_data;
public:
int16_t get() const {
return m_data;
}
};
}
#endif

10
audio/int8_8_t.cpp Normal file
View File

@ -0,0 +1,10 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/debug.h>
#include <audio/int8_8_t.h>

24
audio/int8_8_t.h Normal file
View File

@ -0,0 +1,24 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <audio/types.h>
#ifndef __AUDIO_TYPE_INT8_8_T_H__
#define __AUDIO_TYPE_INT8_8_T_H__
namespace audio {
class int8_8_t {
private:
int8_t m_data;
public:
int8_t get() const {
return m_data;
}
};
}
#endif

43
audio/types.h Normal file
View File

@ -0,0 +1,43 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_TYPES_H__
#define __AUDIO_TYPES_H__
namespace audio {
class int8_8_t;
class int8_16_t;
class int16_16_t;
class int16_32_t;
class int24_24_t;
class int24_32_t;
class int32_32_t;
class int32_64_t;
class int64_64_t;
class float_t;
class double_t;
}
#define INT24_MIN 0xFF800000
#define INT24_MAX 0x007FFFFF
#define INT56_MIN 0xFFFF800000000000LL
#define INT56_MAX 0x00007FFFFFFFFFFFLL
#include <audio/int8_8_t.h>
#include <audio/int8_16_t.h>
#include <audio/int16_16_t.h>
#include <audio/int16_32_t.h>
#include <audio/int24_24_t.h>
#include <audio/int24_32_t.h>
#include <audio/int32_32_t.h>
#include <audio/int32_64_t.h>
#include <audio/int64_64_t.h>
#include <audio/float_t.h>
#include <audio/double_t.h>
#endif

View File

@ -13,7 +13,18 @@ def create(target):
myModule.add_src_file([
'audio/debug.cpp',
'audio/channel.cpp',
'audio/format.cpp'
'audio/format.cpp',
'audio/int8_8_t.cpp',
'audio/int8_16_t.cpp',
'audio/int16_16_t.cpp',
'audio/int16_32_t.cpp',
'audio/int24_24_t.cpp',
'audio/int24_32_t.cpp',
'audio/int32_32_t.cpp',
'audio/int32_64_t.cpp',
'audio/int64_64_t.cpp',
'audio/float_t.cpp',
'audio/double_t.cpp'
])
myModule.add_module_depend(['etk'])
@ -27,6 +38,7 @@ def create(target):