Skip to content

Commit

Permalink
stb_hexwave: Initialize output buffers before freq handling
Browse files Browse the repository at this point in the history
* Move the memset calls that clear the output and temporary
  buffers to occur before the frequency change handling portions
  of the code.

* Addresses Issue nothings#1685
  • Loading branch information
tomice committed Oct 13, 2024
1 parent 31707d1 commit 0d56fe5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stb_hexwave.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ STB_HEXWAVE_DEF void hexwave_generate_samples(float *output, int num_samples, He
// convert parameters to times and slopes
hexwave_generate_linesegs(vert, hex, dt);

// clear the output and temporary buffers before processing
memset(output, 0, sizeof(float)*num_samples);
memset(temp_output, 0, 2*hexblep.width*sizeof(float));

if (hex->prev_dt != dt) {
// if frequency changes, add a fixup at the derivative discontinuity starting at now
float slope;
Expand All @@ -446,10 +450,6 @@ STB_HEXWAVE_DEF void hexwave_generate_samples(float *output, int num_samples, He
hex->prev_dt = dt;
}

// copy the buffered data from last call and clear the rest of the output array
memset(output, 0, sizeof(float)*num_samples);
memset(temp_output, 0, 2*hexblep.width*sizeof(float));

if (num_samples >= hexblep.width) {
memcpy(output, hex->buffer, buffered_length);
} else {
Expand Down

0 comments on commit 0d56fe5

Please sign in to comment.