public static void tms5220_update(int ch, _ShortPtr buffer, int length) { short[] sample_data = new short[MAX_SAMPLE_CHUNK]; ShortSubArray curr_data = new ShortSubArray(sample_data); short prev = last_sample, curr = curr_sample; uint final_pos; uint new_samples; /* finish off the current sample */ if (source_pos > 0) { /* interpolate */ while (length > 0 && source_pos < FRAC_ONE) { buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - source_pos)) + ((int)curr * source_pos)) >> FRAC_BITS)); buffer.offset += 2; source_pos += source_step; length--; } /* if we're over, continue; otherwise, we're done */ if (source_pos >= FRAC_ONE) source_pos -= FRAC_ONE; else return; } /* compute how many new samples we need */ final_pos = (uint)(source_pos + length * source_step); new_samples = (final_pos + FRAC_ONE - 1) >> FRAC_BITS; if (new_samples > MAX_SAMPLE_CHUNK) new_samples = MAX_SAMPLE_CHUNK; /* generate them into our buffer */ tms5220_process(sample_data, new_samples); prev = curr; curr = curr_data[0]; curr_data.offset++; /* then sample-rate convert with linear interpolation */ while (length > 0) { /* interpolate */ while (length > 0 && source_pos < FRAC_ONE) { buffer.write16(0, (ushort)((((int)prev * (FRAC_ONE - source_pos)) + ((int)curr * source_pos)) >> FRAC_BITS)); source_pos += source_step; length--; } /* if we're over, grab the next samples */ if (source_pos >= FRAC_ONE) { source_pos -= FRAC_ONE; prev = curr; curr = curr_data[0]; curr_data.offset++; } } /* remember the last samples */ last_sample = prev; curr_sample = curr; }
public ShortSubArray(ShortSubArray subarray, int offset = 0) { this.buffer = subarray.buffer; this.offset = subarray.offset + offset; }