Commit 20e48137 authored by David Reid's avatar David Reid

Improvements to mal_calculate_cpu_speed_factor().

parent 21962f53
...@@ -20961,24 +20961,34 @@ float mal_calculate_cpu_speed_factor() ...@@ -20961,24 +20961,34 @@ float mal_calculate_cpu_speed_factor()
mal_uint32 channelsIn = 2; mal_uint32 channelsIn = 2;
mal_uint32 channelsOut = 6; mal_uint32 channelsOut = 6;
// Using the heap here to avoid an unnecessary static memory allocation. Also too big for the stack. TODO: Make this a single malloc. Also doesn't need to be aligned. // Using the heap here to avoid an unnecessary static memory allocation. Also too big for the stack.
mal_uint8* pInputFrames = (mal_uint8*)mal_aligned_malloc(sampleRateIn * channelsIn * sizeof(*pInputFrames), MAL_SIMD_ALIGNMENT); mal_uint8* pInputFrames = NULL;
if (pInputFrames == NULL) { float* pOutputFrames = NULL;
return 1;
} size_t inputDataSize = sampleRateIn * channelsIn * sizeof(*pInputFrames);
size_t outputDataSize = sampleRateOut * channelsOut * sizeof(*pOutputFrames);
float* pOutputFrames = (float*)mal_aligned_malloc(sampleRateOut * channelsOut * sizeof(*pOutputFrames), MAL_SIMD_ALIGNMENT); void* pData = mal_malloc(inputDataSize + outputDataSize);
if (pOutputFrames == NULL) { if (pData == NULL) {
mal_aligned_free(pInputFrames);
return 1; return 1;
} }
pInputFrames = (mal_uint8*)pData;
pOutputFrames = (float*)(pInputFrames + inputDataSize);
mal_calculate_cpu_speed_factor_data data; mal_calculate_cpu_speed_factor_data data;
data.pInputFrames = pInputFrames; data.pInputFrames = pInputFrames;
data.framesRemaining = sampleRateIn; data.framesRemaining = sampleRateIn;
mal_dsp_config config = mal_dsp_config_init(mal_format_u8, channelsIn, sampleRateIn, mal_format_f32, channelsOut, sampleRateOut, mal_calculate_cpu_speed_factor__on_read, &data); mal_dsp_config config = mal_dsp_config_init(mal_format_u8, channelsIn, sampleRateIn, mal_format_f32, channelsOut, sampleRateOut, mal_calculate_cpu_speed_factor__on_read, &data);
// Use linear sample rate conversion because it's the simplest and least likely to cause skewing as a result of tweaks to default
// configurations in the future.
config.srcAlgorithm = mal_src_algorithm_linear;
// Experiment: Disable SIMD extensions when profiling just to try and keep things a bit more consistent. The idea is to get a general // Experiment: Disable SIMD extensions when profiling just to try and keep things a bit more consistent. The idea is to get a general
// indication on the speed of the system, but SIMD is used more heavily in the DSP pipeline than in the general case which may make // indication on the speed of the system, but SIMD is used more heavily in the DSP pipeline than in the general case which may make
// the results a little less realistic. // the results a little less realistic.
...@@ -20990,8 +21000,7 @@ float mal_calculate_cpu_speed_factor() ...@@ -20990,8 +21000,7 @@ float mal_calculate_cpu_speed_factor()
mal_dsp dsp; mal_dsp dsp;
mal_result result = mal_dsp_init(&config, &dsp); mal_result result = mal_dsp_init(&config, &dsp);
if (result != MAL_SUCCESS) { if (result != MAL_SUCCESS) {
mal_aligned_free(pInputFrames); mal_free(pData);
mal_aligned_free(pOutputFrames);
return 1; return 1;
} }
...@@ -21012,9 +21021,7 @@ float mal_calculate_cpu_speed_factor() ...@@ -21012,9 +21021,7 @@ float mal_calculate_cpu_speed_factor()
executionTimeInSeconds /= iterationCount; executionTimeInSeconds /= iterationCount;
mal_aligned_free(pInputFrames); mal_free(pData);
mal_aligned_free(pOutputFrames);
return (float)(executionTimeInSeconds * f); return (float)(executionTimeInSeconds * f);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment