/* _______ ____ __ ___ ___ * \ _ \ \ / \ / \ \ / / ' ' ' * | | \ \ | | || | \/ | . . * | | | | | | || ||\ /| | * | | | | | | || || \/ | | ' ' ' * | | | | | | || || | | . . * | |_/ / \ \__// || | | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque * / \ * / . \ * itrender.c - Code to render an Impulse Tracker / / \ \ * module. | < / \_ * | \/ /\ / * Written - painstakingly - by entheh. \_ / > / * | \ / / * | ' / * \__/ */ #include <math.h>#include <stdlib.h>#include <string.h> #include "dumb.h"#include "internal/dumb.h"#include "internal/it.h"#include "internal/lpc.h" #include "internal/resampler.h" // Keep this disabled, as it's actually slower than the original C/integer// version////#ifdef __APPLE__//#include <TargetConditionals.h>//#if TARGET_CPU_ARM || TARGET_CPU_ARM64//#include <arm_neon.h>//#define FILTER_NEON//#endif//#endif // #define BIT_ARRAY_BULLSHIT static IT_PLAYING *new_playing(void) { IT_PLAYING *r = (IT_PLAYING *)malloc(sizeof(*r)); if (r) { r->resampler.fir_resampler_ratio = 0.0; r->resampler.fir_resampler[0] = resampler_create(); if (!r->resampler.fir_resampler[0]) { free(r); return NULL; } r->resampler.fir_resampler[1] = resampler_create(); if (!r->resampler.fir_resampler[1]) { resampler_delete(r->resampler.fir_resampler[0]); free(r); return NULL; } } return r;} static void free_playing(IT_PLAYING *r) { resampler_delete(r->resampler.fir_resampler[1]); resampler_delete(r->resampler.fir_resampler[0]); free(r);} static IT_PLAYING *dup_playing(IT_PLAYING *src, IT_CHANNEL *dstchannel, IT_CHANNEL *srcchannel) { IT_PLAYING *dst; if (!src) return NULL; dst = malloc(sizeof(*dst)); if (!dst) return NULL; dst->flags = src->flags; dst->resampling_quality = src->resampling_quality; ASSERT(src->channel); dst->channel = &dstchannel[src->channel - srcchannel]; dst->sample = src->sample; dst->instrument = src->instrument; dst->env_instrument = src->env_instrument; dst->sampnum = src->sampnum; dst->instnum = src->instnum; dst->declick_stage = src->declick_stage; dst->float_volume[0] = src->float_volume[0]; dst->float_volume[1] = src->float_volume[1]; dst->ramp_volume[0] = src->ramp_volume[0]; dst->ramp_volume[1] = src->ramp_volume[1]; dst->ramp_delta[0] = src->ramp_delta[0]; dst->ramp_delta[1] = src->ramp_delta[1]; dst->channel_volume = src->channel_volume; dst->volume = src->volume; dst->pan = src->pan; dst->volume_offset = src->volume_offset; dst->panning_offset = src->panning_offset; dst->note = src->note; dst->enabled_envelopes = src->enabled_envelopes; dst->filter_cutoff = src->filter_cutoff; dst->filter_resonance = src->filter_resonance; dst->true_filter_cutoff = src->true_filter_cutoff; dst->true_filter_resonance = src->true_filter_resonance; dst->vibrato_speed = src->vibrato_speed; dst->vibrato_depth = src->vibrato_depth; dst->vibrato_n = src->vibrato_n; dst->vibrato_time = src->vibrato_time; dst->vibrato_waveform = src->vibrato_waveform; dst->tremolo_speed = src->tremolo_speed; dst->tremolo_depth = src->tremolo_depth; dst->tremolo_time = src->tremolo_time; dst->tremolo_waveform = src->tremolo_waveform; dst->panbrello_speed = src->panbrello_speed; dst->panbrello_depth = src->panbrello_depth; dst->panbrello_time = src->panbrello_time; dst->panbrello_waveform = src->panbrello_waveform; dst->panbrello_random = src->panbrello_random; dst->sample_vibrato_time = src->sample_vibrato_time; dst->sample_vibrato_waveform = src->sample_vibrato_waveform; dst->sample_vibrato_depth = src->sample_vibrato_depth; dst->slide = src->slide; dst->delta = src->delta; dst->finetune = src->finetune; dst->volume_envelope = src->volume_envelope; dst->pan_envelope = src->pan_envelope; dst->pitch_envelope = src->pitch_envelope; dst->fadeoutcount = src->fadeoutcount; dst->filter_state[0] = src->filter_state[0]; dst->filter_state[1] = src->filter_state[1]; dst->resampler = src->resampler; dst->resampler.pickup_data = dst; dst->resampler.fir_resampler_ratio = src->resampler.fir_resampler_ratio; dst->resampler.fir_resampler[0] = resampler_dup(src->resampler.fir_resampler[0]); if (!dst->resampler.fir_resampler[0]) { free(dst); return NULL; } dst->resampler.fir_resampler[1] = resampler_dup(src->resampler.fir_resampler[1]); if (!dst->resampler.fir_resampler[1]) { resampler_delete(dst->resampler.fir_resampler[0]); free(dst); return NULL; } dst->time_lost = src->time_lost; // dst->output = src->output; return dst;} static void dup_channel(IT_CHANNEL *dst, IT_CHANNEL *src) { dst->flags = src->flags; dst->volume = src->volume; dst->volslide = src->volslide; dst->xm_volslide = src->xm_volslide; dst->panslide = src->panslide; dst->pan = src->pan; dst->truepan = src->truepan; dst->channelvolume = src->channelvolume; dst->channelvolslide = src->channelvolslide; dst->instrument = src->instrument; dst->note = src->note; dst->SFmacro = src->SFmacro; dst->filter_cutoff = src->filter_cutoff; dst->filter_resonance = src->filter_resonance; dst->key_off_count = src->key_off_count; dst->note_cut_count = src->note_cut_count; dst->note_delay_count = src->note_delay_count; dst->note_delay_entry = src->note_delay_entry; dst->new_note_action = src->new_note_action; dst->arpeggio_table = src->arpeggio_table; memcpy(dst->arpeggio_offsets, src->arpeggio_offsets, sizeof(dst->arpeggio_offsets)); dst->retrig = src->retrig; dst->xm_retrig = src->xm_retrig; dst->retrig_tick = src->retrig_tick; dst->tremor_time = src->tremor_time; dst->vibrato_waveform = src->vibrato_waveform; dst->tremolo_waveform = src->tremolo_waveform; dst->panbrello_waveform = src->panbrello_waveform; dst->portamento = src->portamento; dst->toneporta = src->toneporta; dst->toneslide = src->toneslide; dst->toneslide_tick = src->toneslide_tick; dst->last_toneslide_tick = src->last_toneslide_tick; dst->ptm_toneslide = src->ptm_toneslide; dst->ptm_last_toneslide = src->ptm_last_toneslide; dst->okt_toneslide = src->okt_toneslide; dst->destnote = src->destnote; dst->glissando = src->glissando; dst->sample = src->sample; dst->truenote = src->truenote; dst->midi_state = src->midi_state; dst->lastvolslide = src->lastvolslide; dst->lastDKL = src->lastDKL; dst->lastEF = src->lastEF; dst->lastG = src->lastG; dst->lastHspeed = src->lastHspeed; dst->lastHdepth = src->lastHdepth; dst->lastRspeed = src->lastRspeed; dst->lastRdepth = src->lastRdepth; dst->lastYspeed = src->lastYspeed; dst->lastYdepth = src->lastYdepth; dst->lastI = src->lastI; dst->lastJ = src->lastJ; dst->lastN = src->lastN; dst->lastO = src->lastO; dst->high_offset = src->high_offset; dst->lastP = src->lastP; dst->lastQ = src->lastQ; dst->lastS = src->lastS; dst->pat_loop_row = src->pat_loop_row; dst->pat_loop_count = src->pat_loop_count; dst->pat_loop_end_row = src->pat_loop_end_row; dst->lastW = src->lastW; dst->xm_lastE1 = src->xm_lastE1; dst->xm_lastE2 = src->xm_lastE2; dst->xm_lastEA = src->xm_lastEA; dst->xm_lastEB = src->xm_lastEB; dst->xm_lastX1 = src->xm_lastX1; dst->xm_lastX2 = src->xm_lastX2; dst->inv_loop_delay = src->inv_loop_delay; dst->inv_loop_speed = src->inv_loop_speed; dst->inv_loop_offset = src->inv_loop_offset; dst->playing = dup_playing(src->playing, dst, src); #ifdef BIT_ARRAY_BULLSHIT dst->played_patjump = bit_array_dup(src->played_patjump); dst->played_patjump_order = src->played_patjump_order;#endif // dst->output = src->output;} /* Allocate the new callbacks first, then pass them to this function! * It will free them on failure. */static DUMB_IT_SIGRENDERER *dup_sigrenderer(DUMB_IT_SIGRENDERER *src, int n_channels, IT_CALLBACKS *callbacks) { DUMB_IT_SIGRENDERER *dst; int i; if (!src) { if (callbacks) free(callbacks); return NULL; } dst = malloc(sizeof(*dst)); if (!dst) { if (callbacks) free(callbacks); return NULL; } dst->sigdata = src->sigdata; dst->n_channels = n_channels; dst->resampling_quality = src->resampling_quality; dst->globalvolume = src->globalvolume; dst->globalvolslide = src->globalvolslide; dst->tempo = src->tempo; dst->temposlide = src->temposlide; for (i = 0; i < DUMB_IT_N_CHANNELS; i++) dup_channel(&dst->channel[i], &src->channel[i]); for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) dst->playing[i] = dup_playing(src->playing[i], dst->channel, src->channel); dst->tick = src->tick; dst->speed = src->speed; dst->rowcount = src->rowcount; dst->order = src->order; dst->row = src->row; dst->processorder = src->processorder; dst->processrow = src->processrow; dst->breakrow = src->breakrow; dst->restart_position = src->restart_position; dst->n_rows = src->n_rows; dst->entry_start = src->entry_start; dst->entry = src->entry; dst->entry_end = src->entry_end; dst->time_left = src->time_left; dst->sub_time_left = src->sub_time_left; dst->ramp_style = src->ramp_style; dst->click_remover = NULL; dst->callbacks = callbacks; #ifdef BIT_ARRAY_BULLSHIT dst->played = bit_array_dup(src->played); dst->looped = src->looped; dst->time_played = src->time_played; dst->row_timekeeper = timekeeping_array_dup(src->row_timekeeper);#endif dst->gvz_time = src->gvz_time; dst->gvz_sub_time = src->gvz_sub_time; // dst->max_output = src->max_output; return dst;} static const IT_MIDI default_midi = { /* unsigned char SFmacro[16][16]; */ {{0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, /* unsigned char SFmacrolen[16]; */ {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* unsigned short SFmacroz[16]; */ /* Bitfield; bit 0 set = z in first position */ {0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, /* unsigned char Zmacro[128][16]; */ {{0xF0, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,Lines 1–500 of 6594. Load more
/* _______ ____ __ ___ ___ * \ _ \ \ / \ / \ \ / / ' ' ' * | | \ \ | | || | \/ | . . * | | | | | | || ||\ /| | * | | | | | | || || \/ | | ' ' ' * | | | | | | || || | | . . * | |_/ / \ \__// || | | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque * / \ * / . \ * itrender.c - Code to render an Impulse Tracker / / \ \ * module. | < / \_ * | \/ /\ / * Written - painstakingly - by entheh. \_ / > / * | \ / / * | ' / * \__/ */ #include <math.h> #include <stdlib.h> #include <string.h> #include "dumb.h" #include "internal/dumb.h" #include "internal/it.h" #include "internal/lpc.h" #include "internal/resampler.h" // Keep this disabled, as it's actually slower than the original C/integer // version // //#ifdef __APPLE__ //#include <TargetConditionals.h> //#if TARGET_CPU_ARM || TARGET_CPU_ARM64 //#include <arm_neon.h> //#define FILTER_NEON //#endif //#endif // #define BIT_ARRAY_BULLSHIT static IT_PLAYING *new_playing(void) { IT_PLAYING *r = (IT_PLAYING *)malloc(sizeof(*r)); if (r) { r->resampler.fir_resampler_ratio = 0.0; r->resampler.fir_resampler[0] = resampler_create(); if (!r->resampler.fir_resampler[0]) { free(r); return NULL; } r->resampler.fir_resampler[1] = resampler_create(); if (!r->resampler.fir_resampler[1]) { resampler_delete(r->resampler.fir_resampler[0]); free(r); return NULL; } } return r; } static void free_playing(IT_PLAYING *r) { resampler_delete(r->resampler.fir_resampler[1]); resampler_delete(r->resampler.fir_resampler[0]); free(r); } static IT_PLAYING *dup_playing(IT_PLAYING *src, IT_CHANNEL *dstchannel, IT_CHANNEL *srcchannel) { IT_PLAYING *dst; if (!src) return NULL; dst = malloc(sizeof(*dst)); if (!dst) return NULL; dst->flags = src->flags; dst->resampling_quality = src->resampling_quality; ASSERT(src->channel); dst->channel = &dstchannel[src->channel - srcchannel]; dst->sample = src->sample; dst->instrument = src->instrument; dst->env_instrument = src->env_instrument; dst->sampnum = src->sampnum; dst->instnum = src->instnum; dst->declick_stage = src->declick_stage; dst->float_volume[0] = src->float_volume[0]; dst->float_volume[1] = src->float_volume[1]; dst->ramp_volume[0] = src->ramp_volume[0]; dst->ramp_volume[1] = src->ramp_volume[1]; dst->ramp_delta[0] = src->ramp_delta[0]; dst->ramp_delta[1] = src->ramp_delta[1]; dst->channel_volume = src->channel_volume; dst->volume = src->volume; dst->pan = src->pan; dst->volume_offset = src->volume_offset; dst->panning_offset = src->panning_offset; dst->note = src->note; dst->enabled_envelopes = src->enabled_envelopes; dst->filter_cutoff = src->filter_cutoff; dst->filter_resonance = src->filter_resonance; dst->true_filter_cutoff = src->true_filter_cutoff; dst->true_filter_resonance = src->true_filter_resonance; dst->vibrato_speed = src->vibrato_speed; dst->vibrato_depth = src->vibrato_depth; dst->vibrato_n = src->vibrato_n; dst->vibrato_time = src->vibrato_time; dst->vibrato_waveform = src->vibrato_waveform; dst->tremolo_speed = src->tremolo_speed; dst->tremolo_depth = src->tremolo_depth; dst->tremolo_time = src->tremolo_time; dst->tremolo_waveform = src->tremolo_waveform; dst->panbrello_speed = src->panbrello_speed; dst->panbrello_depth = src->panbrello_depth; dst->panbrello_time = src->panbrello_time; dst->panbrello_waveform = src->panbrello_waveform; dst->panbrello_random = src->panbrello_random; dst->sample_vibrato_time = src->sample_vibrato_time; dst->sample_vibrato_waveform = src->sample_vibrato_waveform; dst->sample_vibrato_depth = src->sample_vibrato_depth; dst->slide = src->slide; dst->delta = src->delta; dst->finetune = src->finetune; dst->volume_envelope = src->volume_envelope; dst->pan_envelope = src->pan_envelope; dst->pitch_envelope = src->pitch_envelope; dst->fadeoutcount = src->fadeoutcount; dst->filter_state[0] = src->filter_state[0]; dst->filter_state[1] = src->filter_state[1]; dst->resampler = src->resampler; dst->resampler.pickup_data = dst; dst->resampler.fir_resampler_ratio = src->resampler.fir_resampler_ratio; dst->resampler.fir_resampler[0] = resampler_dup(src->resampler.fir_resampler[0]); if (!dst->resampler.fir_resampler[0]) { free(dst); return NULL; } dst->resampler.fir_resampler[1] = resampler_dup(src->resampler.fir_resampler[1]); if (!dst->resampler.fir_resampler[1]) { resampler_delete(dst->resampler.fir_resampler[0]); free(dst); return NULL; } dst->time_lost = src->time_lost; // dst->output = src->output; return dst; } static void dup_channel(IT_CHANNEL *dst, IT_CHANNEL *src) { dst->flags = src->flags; dst->volume = src->volume; dst->volslide = src->volslide; dst->xm_volslide = src->xm_volslide; dst->panslide = src->panslide; dst->pan = src->pan; dst->truepan = src->truepan; dst->channelvolume = src->channelvolume; dst->channelvolslide = src->channelvolslide; dst->instrument = src->instrument; dst->note = src->note; dst->SFmacro = src->SFmacro; dst->filter_cutoff = src->filter_cutoff; dst->filter_resonance = src->filter_resonance; dst->key_off_count = src->key_off_count; dst->note_cut_count = src->note_cut_count; dst->note_delay_count = src->note_delay_count; dst->note_delay_entry = src->note_delay_entry; dst->new_note_action = src->new_note_action; dst->arpeggio_table = src->arpeggio_table; memcpy(dst->arpeggio_offsets, src->arpeggio_offsets, sizeof(dst->arpeggio_offsets)); dst->retrig = src->retrig; dst->xm_retrig = src->xm_retrig; dst->retrig_tick = src->retrig_tick; dst->tremor_time = src->tremor_time; dst->vibrato_waveform = src->vibrato_waveform; dst->tremolo_waveform = src->tremolo_waveform; dst->panbrello_waveform = src->panbrello_waveform; dst->portamento = src->portamento; dst->toneporta = src->toneporta; dst->toneslide = src->toneslide; dst->toneslide_tick = src->toneslide_tick; dst->last_toneslide_tick = src->last_toneslide_tick; dst->ptm_toneslide = src->ptm_toneslide; dst->ptm_last_toneslide = src->ptm_last_toneslide; dst->okt_toneslide = src->okt_toneslide; dst->destnote = src->destnote; dst->glissando = src->glissando; dst->sample = src->sample; dst->truenote = src->truenote; dst->midi_state = src->midi_state; dst->lastvolslide = src->lastvolslide; dst->lastDKL = src->lastDKL; dst->lastEF = src->lastEF; dst->lastG = src->lastG; dst->lastHspeed = src->lastHspeed; dst->lastHdepth = src->lastHdepth; dst->lastRspeed = src->lastRspeed; dst->lastRdepth = src->lastRdepth; dst->lastYspeed = src->lastYspeed; dst->lastYdepth = src->lastYdepth; dst->lastI = src->lastI; dst->lastJ = src->lastJ; dst->lastN = src->lastN; dst->lastO = src->lastO; dst->high_offset = src->high_offset; dst->lastP = src->lastP; dst->lastQ = src->lastQ; dst->lastS = src->lastS; dst->pat_loop_row = src->pat_loop_row; dst->pat_loop_count = src->pat_loop_count; dst->pat_loop_end_row = src->pat_loop_end_row; dst->lastW = src->lastW; dst->xm_lastE1 = src->xm_lastE1; dst->xm_lastE2 = src->xm_lastE2; dst->xm_lastEA = src->xm_lastEA; dst->xm_lastEB = src->xm_lastEB; dst->xm_lastX1 = src->xm_lastX1; dst->xm_lastX2 = src->xm_lastX2; dst->inv_loop_delay = src->inv_loop_delay; dst->inv_loop_speed = src->inv_loop_speed; dst->inv_loop_offset = src->inv_loop_offset; dst->playing = dup_playing(src->playing, dst, src); #ifdef BIT_ARRAY_BULLSHIT dst->played_patjump = bit_array_dup(src->played_patjump); dst->played_patjump_order = src->played_patjump_order; #endif // dst->output = src->output; } /* Allocate the new callbacks first, then pass them to this function! * It will free them on failure. */ static DUMB_IT_SIGRENDERER *dup_sigrenderer(DUMB_IT_SIGRENDERER *src, int n_channels, IT_CALLBACKS *callbacks) { DUMB_IT_SIGRENDERER *dst; int i; if (!src) { if (callbacks) free(callbacks); return NULL; } dst = malloc(sizeof(*dst)); if (!dst) { if (callbacks) free(callbacks); return NULL; } dst->sigdata = src->sigdata; dst->n_channels = n_channels; dst->resampling_quality = src->resampling_quality; dst->globalvolume = src->globalvolume; dst->globalvolslide = src->globalvolslide; dst->tempo = src->tempo; dst->temposlide = src->temposlide; for (i = 0; i < DUMB_IT_N_CHANNELS; i++) dup_channel(&dst->channel[i], &src->channel[i]); for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) dst->playing[i] = dup_playing(src->playing[i], dst->channel, src->channel); dst->tick = src->tick; dst->speed = src->speed; dst->rowcount = src->rowcount; dst->order = src->order; dst->row = src->row; dst->processorder = src->processorder; dst->processrow = src->processrow; dst->breakrow = src->breakrow; dst->restart_position = src->restart_position; dst->n_rows = src->n_rows; dst->entry_start = src->entry_start; dst->entry = src->entry; dst->entry_end = src->entry_end; dst->time_left = src->time_left; dst->sub_time_left = src->sub_time_left; dst->ramp_style = src->ramp_style; dst->click_remover = NULL; dst->callbacks = callbacks; #ifdef BIT_ARRAY_BULLSHIT dst->played = bit_array_dup(src->played); dst->looped = src->looped; dst->time_played = src->time_played; dst->row_timekeeper = timekeeping_array_dup(src->row_timekeeper); #endif dst->gvz_time = src->gvz_time; dst->gvz_sub_time = src->gvz_sub_time; // dst->max_output = src->max_output; return dst; } static const IT_MIDI default_midi = { /* unsigned char SFmacro[16][16]; */ {{0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, /* unsigned char SFmacrolen[16]; */ {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* unsigned short SFmacroz[16]; */ /* Bitfield; bit 0 set = z in first position */ {0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, /* unsigned char Zmacro[128][16]; */ {{0xF0, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xF0, 0xF0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,