test/test_pcm: use C++11 random instead of GLib
This commit is contained in:
parent
8e063829c4
commit
7cb803ad5c
@ -25,7 +25,7 @@ void
|
|||||||
PcmDitherTest::TestDither24()
|
PcmDitherTest::TestDither24()
|
||||||
{
|
{
|
||||||
constexpr unsigned N = 256;
|
constexpr unsigned N = 256;
|
||||||
const auto src = TestDataBuffer<int32_t, N>(GlibRandomInt24());
|
const auto src = TestDataBuffer<int32_t, N>(RandomInt24());
|
||||||
|
|
||||||
int16_t dest[N];
|
int16_t dest[N];
|
||||||
PcmDither dither;
|
PcmDither dither;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "test_pcm_util.hxx"
|
#include "test_pcm_util.hxx"
|
||||||
#include "pcm/PcmMix.hxx"
|
#include "pcm/PcmMix.hxx"
|
||||||
|
|
||||||
template<typename T, SampleFormat format, typename G=GlibRandomInt<T>>
|
template<typename T, SampleFormat format, typename G=RandomInt<T>>
|
||||||
static void
|
static void
|
||||||
TestPcmMix(G g=G())
|
TestPcmMix(G g=G())
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ PcmMixTest::TestMix16()
|
|||||||
void
|
void
|
||||||
PcmMixTest::TestMix24()
|
PcmMixTest::TestMix24()
|
||||||
{
|
{
|
||||||
TestPcmMix<int32_t, SampleFormat::S24_P32>(GlibRandomInt24());
|
TestPcmMix<int32_t, SampleFormat::S24_P32>(RandomInt24());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,13 +22,11 @@
|
|||||||
#include "pcm/PcmPack.hxx"
|
#include "pcm/PcmPack.hxx"
|
||||||
#include "system/ByteOrder.hxx"
|
#include "system/ByteOrder.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PcmPackTest::TestPack24()
|
PcmPackTest::TestPack24()
|
||||||
{
|
{
|
||||||
constexpr unsigned N = 256;
|
constexpr unsigned N = 256;
|
||||||
const auto src = TestDataBuffer<int32_t, N>(GlibRandomInt24());
|
const auto src = TestDataBuffer<int32_t, N>(RandomInt24());
|
||||||
|
|
||||||
uint8_t dest[N * 3];
|
uint8_t dest[N * 3];
|
||||||
pcm_pack_24(dest, src.begin(), src.end());
|
pcm_pack_24(dest, src.begin(), src.end());
|
||||||
|
@ -17,23 +17,28 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct GlibRandomInt {
|
struct RandomInt {
|
||||||
T operator()() const {
|
typedef std::minstd_rand Engine;
|
||||||
return T(g_random_int());
|
Engine engine;
|
||||||
|
|
||||||
|
static_assert(sizeof(T) <= sizeof(Engine::result_type),
|
||||||
|
"RNG result type too small");
|
||||||
|
|
||||||
|
T operator()() {
|
||||||
|
return T(random());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GlibRandomInt24 : GlibRandomInt<int32_t> {
|
struct RandomInt24 : RandomInt<int32_t> {
|
||||||
int32_t operator()() const {
|
int32_t operator()() {
|
||||||
auto t = GlibRandomInt::operator()();
|
auto t = RandomInt::operator()();
|
||||||
t &= 0xffffff;
|
t &= 0xffffff;
|
||||||
if (t & 0x800000)
|
if (t & 0x800000)
|
||||||
t |= 0xff000000;
|
t |= 0xff000000;
|
||||||
@ -41,9 +46,14 @@ struct GlibRandomInt24 : GlibRandomInt<int32_t> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GlibRandomFloat {
|
struct RandomFloat {
|
||||||
float operator()() const {
|
std::mt19937 gen;
|
||||||
return g_random_double_range(-1.0, 1.0);
|
std::uniform_real_distribution<float> dis;
|
||||||
|
|
||||||
|
RandomFloat():gen(std::random_device()()), dis(-1.0, 1.0) {}
|
||||||
|
|
||||||
|
float operator()() {
|
||||||
|
return dis(gen);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -56,7 +66,7 @@ public:
|
|||||||
using std::array<T, N>::end;
|
using std::array<T, N>::end;
|
||||||
using std::array<T, N>::operator[];
|
using std::array<T, N>::operator[];
|
||||||
|
|
||||||
template<typename G=GlibRandomInt<T>>
|
template<typename G=RandomInt<T>>
|
||||||
TestDataBuffer(G g=G()):std::array<T, N>() {
|
TestDataBuffer(G g=G()):std::array<T, N>() {
|
||||||
for (auto &i : *this)
|
for (auto &i : *this)
|
||||||
i = g();
|
i = g();
|
||||||
|
@ -94,7 +94,7 @@ PcmVolumeTest::TestVolume24()
|
|||||||
{
|
{
|
||||||
constexpr unsigned N = 256;
|
constexpr unsigned N = 256;
|
||||||
static int32_t zero[N];
|
static int32_t zero[N];
|
||||||
const auto src = TestDataBuffer<int32_t, N>(GlibRandomInt24());
|
const auto src = TestDataBuffer<int32_t, N>(RandomInt24());
|
||||||
|
|
||||||
int32_t dest[N];
|
int32_t dest[N];
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ PcmVolumeTest::TestVolumeFloat()
|
|||||||
{
|
{
|
||||||
constexpr unsigned N = 256;
|
constexpr unsigned N = 256;
|
||||||
static float zero[N];
|
static float zero[N];
|
||||||
const auto src = TestDataBuffer<float, N>(GlibRandomFloat());
|
const auto src = TestDataBuffer<float, N>(RandomFloat());
|
||||||
|
|
||||||
float dest[N];
|
float dest[N];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user