/* printf ("For output frame %d, tape position is from %ld - %ld\n", outframe, tape_position_line_zero, tape_position_last_line); */
if (flag_stutter_on_pause==1) {
if (tape_position_line_zero==tape_position_last_line && tape_velocity==0) {
/* printf ("Multi-frame pause at %d\n",frame); */
tape_position_last_line=tape_position_last_line+(SCALE*frame_height)-1;
}
if (tape_position_line_zero==tape_position_last_line && tape_velocity!=0) {
/* printf ("Single-frame pause or end of multi-frame pause at %d\n",frame); */
}
}
sample_from=((tape_position_line_zero/SCALE)*sample_rate/frame_height/fps);
sample_to=(((tape_position_last_line/SCALE)*sample_rate/frame_height/fps)-1);
if (sample_to<0) { sample_to=0; }
if (sample_to>audio_in_total_samples-1) { sample_to=audio_in_total_samples-1; }
if (sample_from<0) { sample_from=0; }
if (sample_from>audio_in_total_samples-1) { sample_from=audio_in_total_samples-1; }
/* printf ("For output frame %d, input audio samples are from %ld - %ld.\n\n", outframe, sample_from, sample_to); */
if (labs(sample_from-sample_to)<(samples_per_frame-1)) {
/* Fewer than samples_per_frame input samples, so we need to duplicate or interpolate them to the output. */
if (sample_from>sample_to) {
/* Audio is being reversed at < 1x normal speed. */
for (a=0; a<samples_per_frame; a++) {
/* printf ("Out sample %d, from in %ld\n",a,sample_from-(labs(sample_from-sample_to)*a/samples_per_frame)); */
if (audiobuffer_in!=NULL) {
for (sample_subbyte=0; sample_subbyte<bytes_per_sample; sample_subbyte++) {
*(sample_subbyte+audiobuffer_out+bytes_per_sample*(samples_per_frame*outframe+a))=
*(sample_subbyte+audiobuffer_in+(sample_from-labs(sample_from-sample_to)*a/samples_per_frame)*bytes_per_sample);
}
} else {
/* No input audio supplied, so we generate a sawtooth wave */
*(audiobuffer_out+bytes_per_sample*(samples_per_frame*outframe+a))=
((((sample_from+labs(sample_from-sample_to)*a/samples_per_frame))%48)-24)/4;
}
}
} else {
/* Audio is going in the forward direction at < 1x normal speed. */
for (a=0; a<samples_per_frame; a++) {
/* printf ("Out sample %d, from in %ld\n",a,sample_from+(labs(sample_from-sample_to)*a/samples_per_frame)); */
if (audiobuffer_in!=NULL) {
for (sample_subbyte=0; sample_subbyte<bytes_per_sample; sample_subbyte++) {
*(sample_subbyte+audiobuffer_out+bytes_per_sample*(samples_per_frame*outframe+a))=
*(sample_subbyte+audiobuffer_in+(sample_from+labs(sample_from-sample_to)*a/samples_per_frame)*bytes_per_sample);
}
} else {
/* No input audio supplied, so we generate a sawtooth wave */
*(audiobuffer_out+bytes_per_sample*(samples_per_frame*outframe+a))=
((((sample_from+labs(sample_from-sample_to)*a/samples_per_frame))%48)-24)/4;
}
}
}
} else {
/* At least samples_per_frame input samples, so we can just skip some of them, or average several samples to produce the output ones. */
for (a=sample_from; ((sample_to>sample_from && a<=sample_to) || (sample_to<sample_from && a>=sample_to)) && (sample_from!=sample_to); ) {
sample_out=(samples_per_frame*outframe+((samples_per_frame-1)*(a-sample_from)/(sample_to-sample_from)));
/* printf ("Input sample %d goes to output sample %ld\n",a,sample_out); */
if (audiobuffer_in!=NULL) {
for (sample_subbyte=0; sample_subbyte<bytes_per_sample; sample_subbyte++) {
*(audiobuffer_out+bytes_per_sample*sample_out+sample_subbyte)=*(audiobuffer_in+bytes_per_sample*a+sample_subbyte);
}
} else {
/* No input audio supplied, so we generate a sawtooth wave */
*(audiobuffer_out+bytes_per_sample*sample_out)=(((bytes_per_sample*a)%48)-24)/4;
}
if (sample_to<sample_from) { a--; } else { a++; }
}
}