first commit
This commit is contained in:
41
thirdparty/miniaudio/tests/test_generation/ma_test_generation.c
vendored
Normal file
41
thirdparty/miniaudio/tests/test_generation/ma_test_generation.c
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
#define MA_NO_DEVICE_IO
|
||||
#include "../test_common/ma_test_common.c"
|
||||
|
||||
#include "ma_test_generation_noise.c"
|
||||
#include "ma_test_generation_waveform.c"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
size_t iTest;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
result = ma_register_test("Noise", test_entry__noise);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = ma_register_test("Waveform", test_entry__waveform);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (iTest = 0; iTest < g_Tests.count; iTest += 1) {
|
||||
printf("=== BEGIN %s ===\n", g_Tests.pTests[iTest].pName);
|
||||
result = g_Tests.pTests[iTest].onEntry(argc, argv);
|
||||
printf("=== END %s : %s ===\n", g_Tests.pTests[iTest].pName, (result == 0) ? "PASSED" : "FAILED");
|
||||
|
||||
if (result != 0) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return -1; /* Something failed. */
|
||||
} else {
|
||||
return 0; /* Everything passed. */
|
||||
}
|
||||
}
|
||||
145
thirdparty/miniaudio/tests/test_generation/ma_test_generation_noise.c
vendored
Normal file
145
thirdparty/miniaudio/tests/test_generation/ma_test_generation_noise.c
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
|
||||
ma_result test_noise__by_format_and_type(ma_format format, ma_noise_type type, const char* pFileName)
|
||||
{
|
||||
ma_result result;
|
||||
ma_noise_config noiseConfig;
|
||||
ma_noise noise;
|
||||
ma_encoder_config encoderConfig;
|
||||
ma_encoder encoder;
|
||||
ma_uint32 iFrame;
|
||||
|
||||
printf(" %s\n", pFileName);
|
||||
|
||||
noiseConfig = ma_noise_config_init(format, 1, type, 0, 0.1);
|
||||
result = ma_noise_init(&noiseConfig, NULL, &noise);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
encoderConfig = ma_encoder_config_init(ma_encoding_format_wav, format, noiseConfig.channels, 48000);
|
||||
result = ma_encoder_init_file(pFileName, &encoderConfig, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* We'll do a few seconds of data. */
|
||||
for (iFrame = 0; iFrame < encoder.config.sampleRate * 10; iFrame += 1) {
|
||||
ma_uint8 temp[1024];
|
||||
ma_noise_read_pcm_frames(&noise, temp, 1, NULL);
|
||||
ma_encoder_write_pcm_frames(&encoder, temp, 1, NULL);
|
||||
}
|
||||
|
||||
ma_encoder_uninit(&encoder);
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_noise__f32()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_f32, ma_noise_type_white, TEST_OUTPUT_DIR"/noise_f32_white.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_f32, ma_noise_type_pink, TEST_OUTPUT_DIR"/noise_f32_pink.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_f32, ma_noise_type_brownian, TEST_OUTPUT_DIR"/noise_f32_brownian.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
ma_result test_noise__s16()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_s16, ma_noise_type_white, TEST_OUTPUT_DIR"/output/noise_s16_white.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_s16, ma_noise_type_pink, TEST_OUTPUT_DIR"/output/noise_s16_pink.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_s16, ma_noise_type_brownian, TEST_OUTPUT_DIR"/output/noise_s16_brownian.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
ma_result test_noise__u8()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_u8, ma_noise_type_white, TEST_OUTPUT_DIR"/noise_u8_white.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_u8, ma_noise_type_pink, TEST_OUTPUT_DIR"/noise_u8_pink.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__by_format_and_type(ma_format_u8, ma_noise_type_brownian, TEST_OUTPUT_DIR"/noise_u8_brownian.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int test_entry__noise(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
result = test_noise__f32();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__s16();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_noise__u8();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
240
thirdparty/miniaudio/tests/test_generation/ma_test_generation_waveform.c
vendored
Normal file
240
thirdparty/miniaudio/tests/test_generation/ma_test_generation_waveform.c
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
|
||||
ma_result test_waveform__by_format_and_type(ma_format format, ma_waveform_type type, double amplitude, const char* pFileName)
|
||||
{
|
||||
ma_result result;
|
||||
ma_waveform_config waveformConfig;
|
||||
ma_waveform waveform;
|
||||
ma_encoder_config encoderConfig;
|
||||
ma_encoder encoder;
|
||||
ma_uint32 iFrame;
|
||||
|
||||
printf(" %s\n", pFileName);
|
||||
|
||||
waveformConfig = ma_waveform_config_init(format, 2, 48000, type, amplitude, 220);
|
||||
result = ma_waveform_init(&waveformConfig, &waveform);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
encoderConfig = ma_encoder_config_init(ma_encoding_format_wav, waveformConfig.format, waveformConfig.channels, waveformConfig.sampleRate);
|
||||
result = ma_encoder_init_file(pFileName, &encoderConfig, &encoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result; /* Failed to initialize encoder. */
|
||||
}
|
||||
|
||||
/* We'll do a few seconds of data. */
|
||||
for (iFrame = 0; iFrame < waveformConfig.sampleRate * 10; iFrame += 1) {
|
||||
float temp[MA_MAX_CHANNELS];
|
||||
ma_waveform_read_pcm_frames(&waveform, temp, 1, NULL);
|
||||
ma_encoder_write_pcm_frames(&encoder, temp, 1, NULL);
|
||||
}
|
||||
|
||||
ma_encoder_uninit(&encoder);
|
||||
ma_waveform_uninit(&waveform);
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
ma_result test_waveform__f32()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
double amplitude = 0.2;
|
||||
|
||||
/* Sine */
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_sine, +amplitude, TEST_OUTPUT_DIR"/waveform_f32_sine.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_sine, -amplitude, TEST_OUTPUT_DIR"/waveform_f32_sine_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Square */
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_square, +amplitude, TEST_OUTPUT_DIR"/waveform_f32_square.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_square, -amplitude, TEST_OUTPUT_DIR"/waveform_f32_square_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Triangle */
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_triangle, +amplitude, TEST_OUTPUT_DIR"/waveform_f32_triangle.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_triangle, -amplitude, TEST_OUTPUT_DIR"/waveform_f32_triangle_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Sawtooth */
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_sawtooth, +amplitude, TEST_OUTPUT_DIR"/waveform_f32_sawtooth.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_f32, ma_waveform_type_sawtooth, -amplitude, TEST_OUTPUT_DIR"/waveform_f32_sawtooth_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
ma_result test_waveform__s16()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
double amplitude = 0.2;
|
||||
|
||||
/* Sine */
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_sine, +amplitude, TEST_OUTPUT_DIR"/waveform_s16_sine.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_sine, -amplitude, TEST_OUTPUT_DIR"/waveform_s16_sine_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Square */
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_square, +amplitude, TEST_OUTPUT_DIR"/waveform_s16_square.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_square, -amplitude, TEST_OUTPUT_DIR"/waveform_s16_square_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Triangle */
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_triangle, +amplitude, TEST_OUTPUT_DIR"/waveform_s16_triangle.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_triangle, -amplitude, TEST_OUTPUT_DIR"/waveform_s16_triangle_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Sawtooth */
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_sawtooth, +amplitude, TEST_OUTPUT_DIR"/waveform_s16_sawtooth.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_s16, ma_waveform_type_sawtooth, -amplitude, TEST_OUTPUT_DIR"/waveform_s16_sawtooth_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
ma_result test_waveform__u8()
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
double amplitude = 0.2;
|
||||
|
||||
/* Sine */
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_sine, +amplitude, TEST_OUTPUT_DIR"/waveform_u8_sine.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_sine, -amplitude, TEST_OUTPUT_DIR"/waveform_u8_sine_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Square */
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_square, +amplitude, TEST_OUTPUT_DIR"/waveform_u8_square.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_square, -amplitude, TEST_OUTPUT_DIR"/waveform_u8_square_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Triangle */
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_triangle, +amplitude, TEST_OUTPUT_DIR"/waveform_u8_triangle.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_triangle, -amplitude, TEST_OUTPUT_DIR"/waveform_u8_triangle_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
/* Sawtooth */
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_sawtooth, +amplitude, TEST_OUTPUT_DIR"/waveform_u8_sawtooth.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__by_format_and_type(ma_format_u8, ma_waveform_type_sawtooth, -amplitude, TEST_OUTPUT_DIR"/waveform_u8_sawtooth_neg.wav");
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (hasError) {
|
||||
return MA_ERROR;
|
||||
} else {
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int test_entry__waveform(int argc, char** argv)
|
||||
{
|
||||
ma_result result;
|
||||
ma_bool32 hasError = MA_FALSE;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
result = test_waveform__f32();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__s16();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
result = test_waveform__u8();
|
||||
if (result != MA_SUCCESS) {
|
||||
hasError = MA_TRUE;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user