Skip to content

Commit 14bda56

Browse files
committed
Addressing test instability
1 parent 9638bcd commit 14bda56

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

Sources/Soundpipe/modules/custom/circular_buffer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#include "circular_buffer.h"
55

66
void cb_init(circular_buffer *cb, size_t capacity, size_t sz) {
7-
cb->buffer = malloc(capacity * sz);
7+
// calloc: pitchcalculate/pitchcorrect read via cb_read_at_index_behind_write
8+
// before the buffer has been fully populated; zeroing prevents those early
9+
// reads from returning allocator-state-dependent garbage.
10+
cb->buffer = calloc(capacity, sz);
811
if(cb->buffer == NULL)
912
// handle error
1013
cb->buffer_end = (char *)cb->buffer + capacity * sz;

Sources/Soundpipe/modules/custom/pitchcalculate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#include <stdio.h>
88

99
int pitchcalculate_create(pitchcalculate **p) {
10-
*p = malloc(sizeof(pitchcalculate));
10+
// calloc: pitchcalculate_init does not set asdf_offset or cur_period;
11+
// pitchcalculate_compute reads them before initial_freq is ever valid,
12+
// so zeroing avoids allocator-state-dependent output across tests.
13+
*p = calloc(1, sizeof(pitchcalculate));
1114
return SP_OK;
1215
}
1316

Sources/Soundpipe/modules/custom/pitchcorrect.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ float min_freq = 20.0;
1212
float max_freq = 3000.0;
1313

1414
int pitchcorrect_create(pitchcorrect **p) {
15-
*p = malloc(sizeof(pitchcorrect));
15+
// calloc: pitchcorrect_init does not assign every field (e.g.
16+
// should_update_scale_freqs, should_smooth_target_freq,
17+
// nearest_scale_freq_index, target_freq, tmp_scale_freqs*), and the
18+
// compute path reads them. Zeroing here avoids order-dependent output.
19+
*p = calloc(1, sizeof(pitchcorrect));
1620
return SP_OK;
1721
}
1822

Sources/Soundpipe/modules/custom/pitchshift2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ float delay_window = 75.;
99
float pi = 3.1415926535;
1010

1111
int pitchshift2_create(pitchshift2 **p) {
12-
*p = malloc(sizeof(pitchshift2));
12+
// calloc: pitchshift2_init leaves several fields unset (e.g. playhead_incr,
13+
// window_advance, fader_target). Zeroing avoids heap-state-dependent output.
14+
*p = calloc(1, sizeof(pitchshift2));
1315
return SP_OK;
1416
}
1517

Tests/SoundpipeAudioKitTests/Effects Tests/PitchShifterTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ class PitchShifterTests: XCTestCase {
1414
input.start()
1515
let audio = engine.startTest(totalDuration: 1.0)
1616
audio.append(engine.render(duration: 1.0))
17-
audio.audition()
1817
}
1918
}

0 commit comments

Comments
 (0)