Skip to content

Commit

Permalink
fix for 173
Browse files Browse the repository at this point in the history
  • Loading branch information
hoene committed Nov 7, 2021
1 parent e846c89 commit 747e8ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -89,6 +89,7 @@ if(BUILD_TESTS)
167b
168
171
173
)
# issues with osx 96)
add_test(fail-issue-${ISSUE} ${PROJECT_SOURCE_DIR}/tests/notcrashed.sh
Expand Down
45 changes: 22 additions & 23 deletions src/hrtf/resample.c
Expand Up @@ -15,16 +15,16 @@
#include <stdlib.h>
#include <string.h>

MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate)
{
MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate) {
int i, err;
float factor;
unsigned newN;
float *values;
SpeexResamplerState *resampler;
float zero[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

if (hrtf->DataSamplingRate.elements != 1 || samplerate < 8000. || hrtf->DataIR.elements != hrtf->R * hrtf->M * hrtf->N)
if (hrtf->DataSamplingRate.elements != 1 || samplerate < 8000. ||
hrtf->DataIR.elements != hrtf->R * hrtf->M * hrtf->N)
return MYSOFA_INVALID_FORMAT;

if (samplerate == hrtf->DataSamplingRate.values[0])
Expand All @@ -43,31 +43,30 @@ MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate)

resampler = speex_resampler_init(1, hrtf->DataSamplingRate.values[0],
samplerate, 10, &err);
if (resampler == NULL)
{
if (resampler == NULL) {
free(values);
return err;
}

for (i = 0; i < hrtf->R * hrtf->M; i++)
{
unsigned inlen = hrtf->N;
unsigned outlen = newN;
speex_resampler_reset_mem(resampler);
speex_resampler_skip_zeros(resampler);
speex_resampler_process_float(resampler, 0,
hrtf->DataIR.values + i * hrtf->N, &inlen,
values + i * newN, &outlen);
assert(inlen == hrtf->N);
while (outlen < newN)
{
unsigned difflen = newN - outlen;
inlen = 10;
speex_resampler_process_float(resampler, 0, zero, &inlen,
values + i * newN + outlen, &difflen);
outlen += difflen;
if (hrtf->N) {
for (i = 0; i < hrtf->R * hrtf->M; i++) {
unsigned inlen = hrtf->N;
unsigned outlen = newN;
speex_resampler_reset_mem(resampler);
speex_resampler_skip_zeros(resampler);
speex_resampler_process_float(resampler, 0,
hrtf->DataIR.values + i * hrtf->N, &inlen,
values + i * newN, &outlen);
assert(inlen == hrtf->N);
while (outlen < newN) {
unsigned difflen = newN - outlen;
inlen = 10;
speex_resampler_process_float(resampler, 0, zero, &inlen,
values + i * newN + outlen, &difflen);
outlen += difflen;
}
assert(outlen == newN);
}
assert(outlen == newN);
}
speex_resampler_destroy(resampler);

Expand Down
Binary file added tests/fail-issue-173.sofa
Binary file not shown.

0 comments on commit 747e8ed

Please sign in to comment.