1
// ---------------------------------------------------------------------------
2
// This file is part of reSID, a MOS6581 SID emulator engine.
3
// Copyright (C) 2004 Dag Lem <resid@nimrod.no>
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// ---------------------------------------------------------------------------
24
extern float convolve(const float *a, const float *b, int n);
25
extern float convolve_sse(const float *a, const float *b, int n);
27
enum host_cpu_feature {
28
HOST_CPU_MMX=1, HOST_CPU_SSE=2, HOST_CPU_SSE2=4, HOST_CPU_SSE3=8
31
/* This code is appropriate for 32-bit and 64-bit x86 CPUs. */
32
#if defined(__x86_64__) || defined(__i386__) || defined(_MSC_VER)
34
struct cpu_x86_regs_s {
40
typedef struct cpu_x86_regs_s cpu_x86_regs_t;
42
static cpu_x86_regs_t get_cpuid_regs(unsigned int index)
44
cpu_x86_regs_t retval;
46
#if defined(_MSC_VER) /* MSVC assembly */
55
#else /* GNU assembly */
56
asm("movl %4, %%eax; cpuid; movl %%eax, %0; movl %%ebx, %1; movl %%ecx, %2; movl %%edx, %3;"
62
: "eax", "ebx", "ecx", "edx");
68
static int host_cpu_features_by_cpuid(void)
70
cpu_x86_regs_t regs = get_cpuid_regs(1);
73
if (regs.edx & (1 << 23))
74
features |= HOST_CPU_MMX;
75
if (regs.edx & (1 << 25))
76
features |= HOST_CPU_SSE;
77
if (regs.edx & (1 << 26))
78
features |= HOST_CPU_SSE2;
79
if (regs.ecx & (1 << 0))
80
features |= HOST_CPU_SSE3;
85
static int host_cpu_features(void)
87
static int features = 0;
88
static int features_detected = 0;
90
#if defined(__i386__) || (defined(_MSC_VER) && defined(_WIN32))
91
unsigned long temp1, temp2;
94
if (features_detected)
96
features_detected = 1;
98
#if defined(_MSC_VER) && defined(_WIN32) /* MSVC compatible assembly appropriate for 32-bit Windows */
99
/* see if we are dealing with a cpu that has the cpuid instruction */
114
#if defined(__i386__) /* GNU assembly */
115
asm("pushfl; popl %%eax; movl %%eax, %0; xorl $0x200000, %%eax; pushl %%eax; popfl; pushfl; popl %%eax; movl %%eax, %1; pushl %0; popfl "
121
#if defined(__i386__) || (defined(_MSC_VER) && defined(_WIN32))
124
if (temp1 == temp2) {
125
/* no cpuid support, so we can't test for SSE availability -> false */
130
/* find the highest supported cpuid function, returned in %eax */
131
if (get_cpuid_regs(0).eax < 1) {
132
/* no cpuid 1 function, we can't test for features -> no features */
136
features = host_cpu_features_by_cpuid();
140
#else /* !__x86_64__ && !__i386__ && !_MSC_VER */
141
static int host_cpu_features(void)
147
float SIDFP::kinked_dac(const int x, const float nonlinearity, const int max)
153
const float dir = 2.0f * nonlinearity;
154
for (int i = 0; i < max; i ++) {
161
return value / (weight / nonlinearity) * (1 << max);
164
// ----------------------------------------------------------------------------
166
// ----------------------------------------------------------------------------
169
#if (RESID_USE_SSE==1)
170
can_use_sse = (host_cpu_features() & HOST_CPU_SSE) != 0;
175
// Initialize pointers.
179
voice[0].set_sync_source(&voice[2]);
180
voice[1].set_sync_source(&voice[0]);
181
voice[2].set_sync_source(&voice[1]);
183
set_sampling_parameters(985248, SAMPLE_INTERPOLATE, 44100);
192
// ----------------------------------------------------------------------------
194
// ----------------------------------------------------------------------------
202
// ----------------------------------------------------------------------------
204
// ----------------------------------------------------------------------------
205
void SIDFP::set_chip_model(chip_model model)
207
for (int i = 0; i < 3; i++) {
208
voice[i].set_chip_model(model);
211
filter.set_chip_model(model);
212
extfilt.set_chip_model(model);
215
/* nonlinear DAC support, set 1 for 8580 / no effect, about 0.96 otherwise */
216
void SIDFP::set_voice_nonlinearity(float nl)
218
for (int i = 0; i < 3; i++) {
219
voice[i].set_nonlinearity(nl);
223
// ----------------------------------------------------------------------------
225
// ----------------------------------------------------------------------------
228
for (int i = 0; i < 3; i++) {
239
// ----------------------------------------------------------------------------
240
// Write 16-bit sample to audio input.
241
// NB! The caller is responsible for keeping the value within 16 bits.
242
// Note that to mix in an external audio signal, the signal should be
243
// resampled to 1MHz first to avoid sampling noise.
244
// ----------------------------------------------------------------------------
245
void SIDFP::input(int sample)
247
// Voice outputs are 20 bits. Scale up to match three voices in order
248
// to facilitate simulation of the MOS8580 "digi boost" hardware hack.
249
ext_in = (float) ( (sample << 4) * 3 );
252
float SIDFP::output()
254
const float range = 1 << 15;
255
return extfilt.output() / (4095.f * 255.f * 3.f * 1.5f / range);
258
// ----------------------------------------------------------------------------
261
// Reading a write only register returns the last byte written to any SID
262
// register. The individual bits in this value start to fade down towards
263
// zero after a few cycles. All bits reach zero within approximately
264
// $2000 - $4000 cycles.
265
// It has been claimed that this fading happens in an orderly fashion, however
266
// sampling of write only registers reveals that this is not the case.
267
// NB! This is not correctly modeled.
268
// The actual use of write only registers has largely been made in the belief
269
// that all SID registers are readable. To support this belief the read
270
// would have to be done immediately after a write to the same register
271
// (remember that an intermediate write to another register would yield that
272
// value instead). With this in mind we return the last value written to
273
// any SID register for $2000 cycles without modeling the bit fading.
274
// ----------------------------------------------------------------------------
275
reg8 SIDFP::read(reg8 offset)
279
return potx.readPOT();
281
return poty.readPOT();
283
return voice[2].wave.readOSC();
285
return voice[2].envelope.readENV();
292
// ----------------------------------------------------------------------------
294
// ----------------------------------------------------------------------------
295
void SIDFP::write(reg8 offset, reg8 value)
298
bus_value_ttl = 0x4000;
302
voice[0].wave.writeFREQ_LO(value);
305
voice[0].wave.writeFREQ_HI(value);
308
voice[0].wave.writePW_LO(value);
311
voice[0].wave.writePW_HI(value);
314
voice[0].writeCONTROL_REG(value);
317
voice[0].envelope.writeATTACK_DECAY(value);
320
voice[0].envelope.writeSUSTAIN_RELEASE(value);
323
voice[1].wave.writeFREQ_LO(value);
326
voice[1].wave.writeFREQ_HI(value);
329
voice[1].wave.writePW_LO(value);
332
voice[1].wave.writePW_HI(value);
335
voice[1].writeCONTROL_REG(value);
338
voice[1].envelope.writeATTACK_DECAY(value);
341
voice[1].envelope.writeSUSTAIN_RELEASE(value);
344
voice[2].wave.writeFREQ_LO(value);
347
voice[2].wave.writeFREQ_HI(value);
350
voice[2].wave.writePW_LO(value);
353
voice[2].wave.writePW_HI(value);
356
voice[2].writeCONTROL_REG(value);
359
voice[2].envelope.writeATTACK_DECAY(value);
362
voice[2].envelope.writeSUSTAIN_RELEASE(value);
365
filter.writeFC_LO(value);
368
filter.writeFC_HI(value);
371
filter.writeRES_FILT(value);
374
filter.writeMODE_VOL(value);
382
// ----------------------------------------------------------------------------
384
// ----------------------------------------------------------------------------
385
SIDFP::State::State()
389
for (i = 0; i < 0x20; i++) {
396
for (i = 0; i < 3; i++) {
398
shift_register[i] = 0x7ffff8;
400
rate_counter_period[i] = 9;
401
exponential_counter[i] = 0;
402
exponential_counter_period[i] = 1;
403
envelope_counter[i] = 0;
404
envelope_state[i] = EnvelopeGeneratorFP::RELEASE;
410
// ----------------------------------------------------------------------------
412
// ----------------------------------------------------------------------------
413
SIDFP::State SIDFP::read_state()
418
for (i = 0, j = 0; i < 3; i++, j += 7) {
419
WaveformGeneratorFP& wave = voice[i].wave;
420
EnvelopeGeneratorFP& envelope = voice[i].envelope;
421
state.sid_register[j + 0] = wave.freq & 0xff;
422
state.sid_register[j + 1] = wave.freq >> 8;
423
state.sid_register[j + 2] = wave.pw & 0xff;
424
state.sid_register[j + 3] = wave.pw >> 8;
425
state.sid_register[j + 4] =
427
| (wave.test ? 0x08 : 0)
428
| (wave.ring_mod ? 0x04 : 0)
429
| (wave.sync ? 0x02 : 0)
430
| (envelope.gate ? 0x01 : 0);
431
state.sid_register[j + 5] = (envelope.attack << 4) | envelope.decay;
432
state.sid_register[j + 6] = (envelope.sustain << 4) | envelope.release;
435
state.sid_register[j++] = filter.fc & 0x007;
436
state.sid_register[j++] = filter.fc >> 3;
437
state.sid_register[j++] = (filter.res << 4) | filter.filt;
438
state.sid_register[j++] =
439
(filter.voice3off ? 0x80 : 0)
440
| (filter.hp_bp_lp << 4)
443
// These registers are superfluous, but included for completeness.
444
for (; j < 0x1d; j++) {
445
state.sid_register[j] = read(j);
447
for (; j < 0x20; j++) {
448
state.sid_register[j] = 0;
451
state.bus_value = bus_value;
452
state.bus_value_ttl = bus_value_ttl;
454
for (i = 0; i < 3; i++) {
455
state.accumulator[i] = voice[i].wave.accumulator;
456
state.shift_register[i] = voice[i].wave.shift_register;
457
state.rate_counter[i] = voice[i].envelope.rate_counter;
458
state.rate_counter_period[i] = voice[i].envelope.rate_period;
459
state.exponential_counter[i] = voice[i].envelope.exponential_counter;
460
state.exponential_counter_period[i] = voice[i].envelope.exponential_counter_period;
461
state.envelope_counter[i] = voice[i].envelope.envelope_counter;
462
state.envelope_state[i] = voice[i].envelope.state;
463
state.hold_zero[i] = voice[i].envelope.hold_zero;
470
// ----------------------------------------------------------------------------
472
// ----------------------------------------------------------------------------
473
void SIDFP::write_state(const State& state)
477
for (i = 0; i <= 0x18; i++) {
478
write(i, state.sid_register[i]);
481
bus_value = state.bus_value;
482
bus_value_ttl = state.bus_value_ttl;
484
for (i = 0; i < 3; i++) {
485
voice[i].wave.accumulator = state.accumulator[i];
486
voice[i].wave.shift_register = state.shift_register[i];
487
voice[i].envelope.rate_counter = state.rate_counter[i];
488
voice[i].envelope.rate_period = state.rate_counter_period[i];
489
voice[i].envelope.exponential_counter = state.exponential_counter[i];
490
voice[i].envelope.exponential_counter_period = state.exponential_counter_period[i];
491
voice[i].envelope.envelope_counter = state.envelope_counter[i];
492
voice[i].envelope.state = state.envelope_state[i];
493
voice[i].envelope.hold_zero = state.hold_zero[i];
498
// ----------------------------------------------------------------------------
500
// ----------------------------------------------------------------------------
501
void SIDFP::enable_filter(bool enable)
503
filter.enable_filter(enable);
507
// ----------------------------------------------------------------------------
508
// Enable external filter.
509
// ----------------------------------------------------------------------------
510
void SIDFP::enable_external_filter(bool enable)
512
extfilt.enable_filter(enable);
516
// ----------------------------------------------------------------------------
517
// I0() computes the 0th order modified Bessel function of the first kind.
518
// This function is originally from resample-1.5/filterkit.c by J. O. Smith.
519
// ----------------------------------------------------------------------------
520
double SIDFP::I0(double x)
522
// Max error acceptable in I0 could be 1e-6, which gives that 96 dB already.
523
// I'm overspecify these errors to get a beautiful FFT dump of the FIR.
524
const double I0e = 1e-10;
526
double sum, u, halfx, temp;
536
} while (u >= I0e*sum);
542
// ----------------------------------------------------------------------------
543
// Setting of SID sampling parameters.
545
// Use a clock freqency of 985248Hz for PAL C64, 1022730Hz for NTSC C64.
546
// The default end of passband frequency is pass_freq = 0.9*sample_freq/2
547
// for sample frequencies up to ~ 44.1kHz, and 20kHz for higher sample
550
// For resampling, the ratio between the clock frequency and the sample
551
// frequency is limited as follows:
552
// 125*clock_freq/sample_freq < 16384
553
// E.g. provided a clock frequency of ~ 1MHz, the sample frequency can not
554
// be set lower than ~ 8kHz. A lower sample frequency would make the
555
// resampling code overfill its 16k sample ring buffer.
557
// The end of passband frequency is also limited:
558
// pass_freq <= 0.9*sample_freq/2
560
// E.g. for a 44.1kHz sampling rate the end of passband frequency is limited
561
// to slightly below 20kHz. This constraint ensures that the FIR table is
563
// ----------------------------------------------------------------------------
564
bool SIDFP::set_sampling_parameters(float clock_freq, sampling_method method,
565
float sample_freq, float pass_freq)
567
clock_frequency = clock_freq;
570
filter.set_clock_frequency(clock_freq);
571
extfilt.set_clock_frequency(clock_freq);
572
adjust_sampling_frequency(sample_freq);
577
// FIR initialization is only necessary for resampling.
578
if (method != SAMPLE_RESAMPLE_INTERPOLATE)
589
if (pass_freq > 20000)
591
if (2*pass_freq/sample_freq > 0.9)
592
pass_freq = 0.9f*sample_freq/2;
594
// 16 bits -> -96dB stopband attenuation.
595
const double A = -20*log10(1.0/(1 << bits));
597
// For calculation of beta and N see the reference for the kaiserord
598
// function in the MATLAB Signal Processing Toolbox:
599
// http://www.mathworks.com/access/helpdesk/help/toolbox/signal/kaiserord.html
600
const double beta = 0.1102*(A - 8.7);
601
const double I0beta = I0(beta);
603
double f_samples_per_cycle = sample_freq/clock_freq;
604
double f_cycles_per_sample = clock_freq/sample_freq;
606
/* This code utilizes the fact that aliasing back to 20 kHz from
607
* sample_freq/2 is inaudible. This allows us to define a passband
608
* wider than normally. We might also consider aliasing back to pass_freq,
609
* but as this can be less than 20 kHz, it might become audible... */
610
double aliasing_allowance = sample_freq / 2 - 20000;
611
if (aliasing_allowance < 0)
612
aliasing_allowance = 0;
614
double transition_bandwidth = sample_freq/2 - pass_freq + aliasing_allowance;
616
/* Filter order according to Kaiser's paper. */
618
int N = (int) ((A - 7.95)/(2 * M_PI * 2.285 * transition_bandwidth/sample_freq) + 0.5);
621
// The filter length is equal to the filter order + 1.
622
// The filter length must be an odd number (sinc is symmetric about x = 0).
623
fir_N = int(N*f_cycles_per_sample) + 1;
626
// Check whether the sample ring buffer would overfill.
627
if (fir_N > RINGSIZE - 1)
630
/* Error is bound by 1.234 / L^2 */
631
fir_RES = (int) (sqrt(1.234 * (1 << bits)) / f_cycles_per_sample + 0.5);
634
// Allocate memory for FIR tables.
636
fir = new float[fir_N*fir_RES];
638
// The cutoff frequency is midway through the transition band.
639
double wc = (pass_freq + transition_bandwidth/2) / sample_freq * M_PI * 2;
641
// Calculate fir_RES FIR tables for linear interpolation.
642
for (int i = 0; i < fir_RES; i++) {
643
double j_offset = double(i)/fir_RES;
644
// Calculate FIR table. This is the sinc function, weighted by the
646
for (int j = 0; j < fir_N; j ++) {
647
double jx = j - fir_N/2. - j_offset;
648
double wt = wc*jx/f_cycles_per_sample;
649
double temp = jx/(fir_N/2);
651
fabs(temp) <= 1 ? I0(beta*sqrt(1 - temp*temp))/I0beta : 0;
653
fabs(wt) >= 1e-8 ? sin(wt)/wt : 1;
654
fir[i * fir_N + j] = (float) (f_samples_per_cycle*wc/M_PI*sincwt*Kaiser);
658
// Allocate sample buffer.
660
sample = new float[RINGSIZE*2];
662
// Clear sample buffer.
663
for (int j = 0; j < RINGSIZE*2; j++) {
671
// ----------------------------------------------------------------------------
672
// Adjustment of SID sampling frequency.
674
// In some applications, e.g. a C64 emulator, it can be desirable to
675
// synchronize sound with a timer source. This is supported by adjustment of
676
// the SID sampling frequency.
678
// NB! Adjustment of the sampling frequency may lead to noticeable shifts in
679
// frequency, and should only be used for interactive applications. Note also
680
// that any adjustment of the sampling frequency will change the
681
// characteristics of the resampling filter, since the filter is not rebuilt.
682
// ----------------------------------------------------------------------------
683
void SIDFP::adjust_sampling_frequency(float sample_freq)
685
cycles_per_sample = clock_frequency/sample_freq;
688
void SIDFP::age_bus_value(cycle_count n) {
689
if (bus_value_ttl != 0) {
691
if (bus_value_ttl <= 0) {
698
// ----------------------------------------------------------------------------
699
// SID clocking - 1 cycle.
700
// ----------------------------------------------------------------------------
705
// Clock amplitude modulators.
706
for (i = 0; i < 3; i++) {
707
voice[i].envelope.clock();
710
// Clock oscillators.
711
for (i = 0; i < 3; i++) {
712
voice[i].wave.clock();
715
// Synchronize oscillators.
716
for (i = 0; i < 3; i++) {
717
voice[i].wave.synchronize();
721
extfilt.clock(filter.clock(voice[0].output(), voice[1].output(), voice[2].output(), ext_in));
724
// ----------------------------------------------------------------------------
725
// SID clocking with audio sampling.
726
// Fixpoint arithmetics is used.
728
// The example below shows how to clock the SID a specified amount of cycles
729
// while producing audio output:
732
// bufindex += sid.clock(delta_t, buf + bufindex, buflength - bufindex);
733
// write(dsp, buf, bufindex*2);
737
// ----------------------------------------------------------------------------
738
int SIDFP::clock(cycle_count& delta_t, short* buf, int n, int interleave)
740
/* XXX I assume n is generally large enough for delta_t here... */
741
age_bus_value(delta_t);
745
case SAMPLE_INTERPOLATE:
746
res = clock_interpolate(delta_t, buf, n, interleave);
748
case SAMPLE_RESAMPLE_INTERPOLATE:
749
res = clock_resample_interpolate(delta_t, buf, n, interleave);
753
filter.nuke_denormals();
754
extfilt.nuke_denormals();
759
// ----------------------------------------------------------------------------
760
// SID clocking with audio sampling - cycle based with linear sample
763
// Here the chip is clocked every cycle. This yields higher quality
764
// sound since the samples are linearly interpolated, and since the
765
// external filter attenuates frequencies above 16kHz, thus reducing
767
// ----------------------------------------------------------------------------
769
int SIDFP::clock_interpolate(cycle_count& delta_t, short* buf, int n,
776
float next_sample_offset = sample_offset + cycles_per_sample;
777
int delta_t_sample = (int) next_sample_offset;
778
if (delta_t_sample > delta_t) {
784
for (i = 0; i < delta_t_sample - 1; i++) {
787
if (i < delta_t_sample) {
788
sample_prev = output();
792
delta_t -= delta_t_sample;
793
sample_offset = next_sample_offset - delta_t_sample;
795
float sample_now = output();
796
int v = (int)(sample_prev + (sample_offset * (sample_now - sample_prev)));
797
// Saturated arithmetics to guard against 16 bit sample overflow.
798
const int half = 1 << 15;
802
else if (v < -half) {
805
buf[s++*interleave] = v;
807
sample_prev = sample_now;
810
for (i = 0; i < delta_t - 1; i++) {
814
sample_prev = output();
817
sample_offset -= delta_t;
822
// ----------------------------------------------------------------------------
823
// SID clocking with audio sampling - cycle based with audio resampling.
825
// This is the theoretically correct (and computationally intensive) audio
826
// sample generation. The samples are generated by resampling to the specified
827
// sampling frequency. The work rate is inversely proportional to the
828
// percentage of the bandwidth allocated to the filter transition band.
830
// This implementation is based on the paper "A Flexible Sampling-Rate
831
// Conversion Method", by J. O. Smith and P. Gosset, or rather on the
832
// expanded tutorial on the "Digital Audio Resampling Home Page":
833
// http://www-ccrma.stanford.edu/~jos/resample/
835
// By building shifted FIR tables with samples according to the
836
// sampling frequency, this implementation dramatically reduces the
837
// computational effort in the filter convolutions, without any loss
838
// of accuracy. The filter convolutions are also vectorizable on
841
// Further possible optimizations are:
842
// * An equiripple filter design could yield a lower filter order, see
843
// http://www.mwrf.com/Articles/ArticleID/7229/7229.html
844
// * The Convolution Theorem could be used to bring the complexity of
845
// convolution down from O(n*n) to O(n*log(n)) using the Fast Fourier
846
// Transform, see http://en.wikipedia.org/wiki/Convolution_theorem
847
// * Simply resampling in two steps can also yield computational
848
// savings, since the transition band will be wider in the first step
849
// and the required filter order is thus lower in this step.
850
// Laurent Ganier has found the optimal intermediate sampling frequency
851
// to be (via derivation of sum of two steps):
852
// 2 * pass_freq + sqrt [ 2 * pass_freq * orig_sample_freq
853
// * (dest_sample_freq - 2 * pass_freq) / dest_sample_freq ]
855
// NB! the result of right shifting negative numbers is really
856
// implementation dependent in the C++ standard.
857
// ----------------------------------------------------------------------------
859
int SIDFP::clock_resample_interpolate(cycle_count& delta_t, short* buf, int n,
865
float next_sample_offset = sample_offset + cycles_per_sample;
866
/* full clocks left to next sample */
867
int delta_t_sample = (int) next_sample_offset;
868
if (delta_t_sample > delta_t || s >= n)
871
/* clock forward delta_t_sample samples */
872
for (int i = 0; i < delta_t_sample; i++) {
874
sample[sample_index] = sample[sample_index + RINGSIZE] = output();
876
sample_index &= RINGSIZE - 1;
878
delta_t -= delta_t_sample;
880
/* Phase of the sample in terms of clock, [0 .. 1[. */
881
sample_offset = next_sample_offset - (float) delta_t_sample;
883
/* find the first of the nearest fir tables close to the phase */
884
float fir_offset_rmd = sample_offset * fir_RES;
885
int fir_offset = (int) fir_offset_rmd;
887
fir_offset_rmd -= (float) fir_offset;
889
/* find fir_N most recent samples, plus one extra in case the FIR wraps. */
890
float* sample_start = sample + sample_index - fir_N + RINGSIZE - 1;
893
#if (RESID_USE_SSE==1)
894
can_use_sse ? convolve_sse(sample_start, fir + fir_offset*fir_N, fir_N) :
896
convolve(sample_start, fir + fir_offset*fir_N, fir_N);
898
// Use next FIR table, wrap around to first FIR table using
900
if (++ fir_offset == fir_RES) {
905
#if (RESID_USE_SSE==1)
906
can_use_sse ? convolve_sse(sample_start, fir + fir_offset*fir_N, fir_N) :
908
convolve(sample_start, fir + fir_offset*fir_N, fir_N);
910
// Linear interpolation between the sinc tables yields good approximation
911
// for the exact value.
912
int v = (int) (v1 + fir_offset_rmd * (v2 - v1));
914
// Saturated arithmetics to guard against 16 bit sample overflow.
915
const int half = 1 << 15;
919
else if (v < -half) {
923
buf[s ++ * interleave] = v;
926
/* clock forward delta_t samples */
927
for (int i = 0; i < delta_t; i++) {
929
sample[sample_index] = sample[sample_index + RINGSIZE] = output();
931
sample_index &= RINGSIZE - 1;
933
sample_offset -= (float) delta_t;