mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Improvements to mal_calculate_cpu_speed_factor().
This commit is contained in:
@@ -20961,17 +20961,23 @@ 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;
|
||||||
|
|
||||||
|
size_t inputDataSize = sampleRateIn * channelsIn * sizeof(*pInputFrames);
|
||||||
|
size_t outputDataSize = sampleRateOut * channelsOut * sizeof(*pOutputFrames);
|
||||||
|
|
||||||
|
void* pData = mal_malloc(inputDataSize + outputDataSize);
|
||||||
|
if (pData == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float* pOutputFrames = (float*)mal_aligned_malloc(sampleRateOut * channelsOut * sizeof(*pOutputFrames), MAL_SIMD_ALIGNMENT);
|
pInputFrames = (mal_uint8*)pData;
|
||||||
if (pOutputFrames == NULL) {
|
pOutputFrames = (float*)(pInputFrames + inputDataSize);
|
||||||
mal_aligned_free(pInputFrames);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mal_calculate_cpu_speed_factor_data data;
|
mal_calculate_cpu_speed_factor_data data;
|
||||||
data.pInputFrames = pInputFrames;
|
data.pInputFrames = pInputFrames;
|
||||||
@@ -20979,6 +20985,10 @@ float mal_calculate_cpu_speed_factor()
|
|||||||
|
|
||||||
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()
|
|||||||
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()
|
|||||||
executionTimeInSeconds /= iterationCount;
|
executionTimeInSeconds /= iterationCount;
|
||||||
|
|
||||||
|
|
||||||
mal_aligned_free(pInputFrames);
|
mal_free(pData);
|
||||||
mal_aligned_free(pOutputFrames);
|
|
||||||
|
|
||||||
return (float)(executionTimeInSeconds * f);
|
return (float)(executionTimeInSeconds * f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user