Device_thread_state* new_Device_thread_state( uint32_t device_id, int32_t audio_buffer_size) { rassert(audio_buffer_size >= 0); Device_thread_state* ts = memory_alloc_item(Device_thread_state); if (ts == NULL) return NULL; ts->device_id = device_id; ts->audio_buffer_size = audio_buffer_size; ts->node_state = DEVICE_NODE_STATE_NEW; ts->has_mixed_audio = false; ts->in_connected = NULL; for (Device_buffer_type buf_type = DEVICE_BUFFER_MIXED; buf_type < DEVICE_BUFFER_TYPES; ++buf_type) { for (Device_port_type port_type = DEVICE_PORT_TYPE_RECV; port_type < DEVICE_PORT_TYPES; ++port_type) ts->buffers[buf_type][port_type] = NULL; } ts->in_connected = new_Bit_array(KQT_DEVICE_PORTS_MAX); if (ts->in_connected == NULL) { del_Device_thread_state(ts); return NULL; } for (Device_buffer_type buf_type = DEVICE_BUFFER_MIXED; buf_type < DEVICE_BUFFER_TYPES; ++buf_type) { for (Device_port_type port_type = DEVICE_PORT_TYPE_RECV; port_type < DEVICE_PORT_TYPES; ++port_type) { ts->buffers[buf_type][port_type] = new_Etable(KQT_DEVICE_PORTS_MAX, (void (*)(void*))del_Work_buffer); if (ts->buffers[buf_type][port_type] == NULL) { del_Device_thread_state(ts); return NULL; } } } return ts; }
DSP_table* new_DSP_table(int size) { assert(size > 0); DSP_table* table = memory_alloc_item(DSP_table); if (table == NULL) return NULL; table->dsps = NULL; table->existents = NULL; table->dsps = new_Etable(size, (void (*)(void*))del_DSP); table->existents = new_Bit_array(size); if (table->dsps == NULL || table->existents == NULL) { del_DSP_table(table); return NULL; } table->size = size; return table; }
Pat_table* new_Pat_table(int size) { rassert(size > 0); Pat_table* table = memory_alloc_item(Pat_table); if (table == NULL) return NULL; table->pats = NULL; table->existents = NULL; table->pats = new_Etable(size, (void (*)(void*))del_Pattern); table->existents = new_Bit_array(size); if (table->pats == NULL || table->existents == NULL) { del_Pat_table(table); return NULL; } table->size = size; return table; }
Module* new_Module(void) { Module* module = memory_alloc_item(Module); if (module == NULL) return NULL; if (!Device_init(&module->parent, false)) { memory_free(module); return NULL; } Device_set_existent(&module->parent, true); // Clear fields module->random_seed = 0; module->songs = NULL; module->album_is_existent = false; module->track_list = NULL; module->ch_defs = NULL; module->pats = NULL; module->au_map = NULL; module->au_controls = NULL; module->au_table = NULL; module->connections = NULL; module->is_dc_blocker_enabled = true; module->mix_vol_dB = COMP_DEFAULT_MIX_VOL; module->mix_vol = exp2(module->mix_vol_dB / 6); module->force_shift = 0; module->env = NULL; module->bind = NULL; for (int i = 0; i < KQT_SONGS_MAX; ++i) module->order_lists[i] = NULL; for (int i = 0; i < KQT_TUNING_TABLES_MAX; ++i) module->tuning_tables[i] = NULL; // Create fields module->songs = new_Song_table(); module->pats = new_Pat_table(KQT_PATTERNS_MAX); module->au_controls = new_Bit_array(KQT_CONTROLS_MAX); module->au_table = new_Au_table(KQT_AUDIO_UNITS_MAX); if (module->songs == NULL || module->pats == NULL || module->au_controls == NULL || module->au_table == NULL) { del_Module(module); return NULL; } module->env = new_Environment(); if (module->env == NULL) { del_Module(module); return NULL; } Streader* conn_sr = Streader_init(STREADER_AUTO, NULL, 0); module->connections = new_Connections_from_string(conn_sr, false, module->au_table, &module->parent); if (module->connections == NULL) { del_Module(module); return NULL; } return module; }