fluid_evt_heap_t* _fluid_evt_heap_init(int nbEvents) { #ifdef HEAP_WITH_DYNALLOC int i; fluid_evt_heap_t* heap; fluid_evt_entry *tmp; heap = FLUID_NEW(fluid_evt_heap_t); if (heap == NULL) { fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return NULL; } heap->freelist = NULL; fluid_mutex_init(heap->mutex); /* LOCK */ fluid_mutex_lock(heap->mutex); /* Allocate the event entries */ for (i = 0; i < nbEvents; i++) { tmp = FLUID_NEW(fluid_evt_entry); tmp->next = heap->freelist; heap->freelist = tmp; } /* UNLOCK */ fluid_mutex_unlock(heap->mutex); #else int i; fluid_evt_heap_t* heap; int siz = 2*sizeof(fluid_evt_entry *) + sizeof(fluid_evt_entry)*nbEvents; heap = (fluid_evt_heap_t *)FLUID_MALLOC(siz); if (heap == NULL) { fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return NULL; } FLUID_MEMSET(heap, 0, siz); /* link all heap events */ { fluid_evt_entry *tmp = &(heap->pool); for (i = 0 ; i < nbEvents - 1 ; i++) tmp[i].next = &(tmp[i+1]); tmp[nbEvents-1].next = NULL; /* set head & tail */ heap->tail = &(tmp[nbEvents-1]); heap->head = &(heap->pool); } #endif return (heap); }
fluid_tuning_t* new_fluid_tuning(char* name, int bank, int prog) { fluid_tuning_t* tuning; int i; tuning = FLUID_NEW(fluid_tuning_t); if (tuning == NULL) { FLUID_LOG(FLUID_PANIC, "Out of memory"); return NULL; } tuning->name = NULL; if (name != NULL) { tuning->name = FLUID_STRDUP(name); } tuning->bank = bank; tuning->prog = prog; for (i = 0; i < 128; i++) { tuning->pitch[i] = i * 100.0; } return tuning; }
/** * new_fluid_hashtable_full: * @hash_func: a function to create a hash value from a key. * @key_equal_func: a function to check two keys for equality. * @key_destroy_func: a function to free the memory allocated for the key * used when removing the entry from the #fluid_hashtable_t or %NULL if you * don't want to supply such a function. * @value_destroy_func: a function to free the memory allocated for the * value used when removing the entry from the #fluid_hashtable_t or %NULL if * you don't want to supply such a function. * * Creates a new #fluid_hashtable_t like fluid_hashtable_new() with a reference count * of 1 and allows to specify functions to free the memory allocated for the * key and value that get called when removing the entry from the #fluid_hashtable_t. * * Return value: a new #fluid_hashtable_t. **/ fluid_hashtable_t* new_fluid_hashtable_full (fluid_hash_func_t hash_func, fluid_equal_func_t key_equal_func, fluid_destroy_notify_t key_destroy_func, fluid_destroy_notify_t value_destroy_func) { fluid_hashtable_t *hashtable; hashtable = FLUID_NEW (fluid_hashtable_t); if (!hashtable) { FLUID_LOG (FLUID_ERR, "Out of memory"); return NULL; } hashtable->size = HASH_TABLE_MIN_SIZE; hashtable->nnodes = 0; hashtable->hash_func = hash_func ? hash_func : fluid_direct_hash; hashtable->key_equal_func = key_equal_func; hashtable->ref_count = 1; hashtable->key_destroy_func = key_destroy_func; hashtable->value_destroy_func = value_destroy_func; hashtable->nodes = FLUID_ARRAY (fluid_hashnode_t*, hashtable->size); FLUID_MEMSET (hashtable->nodes, 0, hashtable->size * sizeof (fluid_hashnode_t *)); return hashtable; }
static fluid_set_setting_t* new_fluid_set_setting(void) { fluid_set_setting_t* setting; setting = FLUID_NEW(fluid_set_setting_t); if (!setting) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } setting->node.type = FLUID_SET_TYPE; setting->hashtable = new_fluid_hashtable_full(fluid_str_hash, fluid_str_equal, fluid_settings_key_destroy_func, fluid_settings_value_destroy_func); if (!setting->hashtable) { FLUID_FREE (setting); return NULL; } return setting; }
/** * Register a sequencer client. * @param seq Sequencer object * @param name Name of sequencer client * @param callback Sequencer client callback or NULL for a source client. * @param data User data to pass to the \a callback * @return Unique sequencer ID or #FLUID_FAILED on error * * Clients can be sources or destinations of events. Sources don't need to * register a callback. */ short fluid_sequencer_register_client (fluid_sequencer_t* seq, const char *name, fluid_event_callback_t callback, void* data) { fluid_sequencer_client_t * client; char * nameCopy; client = FLUID_NEW(fluid_sequencer_client_t); if (client == NULL) { fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return FLUID_FAILED; } nameCopy = FLUID_STRDUP(name); if (nameCopy == NULL) { fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); FLUID_FREE(client); return FLUID_FAILED; } seq->clientsID++; client->name = nameCopy; client->id = seq->clientsID; client->callback = callback; client->data = data; seq->clients = fluid_list_append(seq->clients, (void *)client); return (client->id); }
fluid_rvoice_eventhandler_t* new_fluid_rvoice_eventhandler(int is_threadsafe, int queuesize, int finished_voices_size, int bufs, int fx_bufs, fluid_real_t sample_rate) { fluid_rvoice_eventhandler_t* eventhandler = FLUID_NEW(fluid_rvoice_eventhandler_t); if (eventhandler == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } eventhandler->mixer = NULL; eventhandler->queue = NULL; eventhandler->finished_voices = NULL; eventhandler->is_threadsafe = is_threadsafe; eventhandler->queue_stored = 0; eventhandler->finished_voices = new_fluid_ringbuffer(finished_voices_size, sizeof(fluid_rvoice_t*)); if (eventhandler->finished_voices == NULL) goto error_recovery; eventhandler->queue = new_fluid_ringbuffer(queuesize, sizeof(fluid_rvoice_event_t)); if (eventhandler->queue == NULL) goto error_recovery; eventhandler->mixer = new_fluid_rvoice_mixer(bufs, fx_bufs, sample_rate); if (eventhandler->mixer == NULL) goto error_recovery; fluid_rvoice_mixer_set_finished_voices_callback(eventhandler->mixer, finished_voice_callback, eventhandler); return eventhandler; error_recovery: delete_fluid_rvoice_eventhandler(eventhandler); return NULL; }
fluid_revmodel_t* new_fluid_revmodel(fluid_real_t sample_rate) { fluid_revmodel_t* rev; rev = FLUID_NEW(fluid_revmodel_t); if (rev == NULL) { return NULL; } fluid_set_revmodel_buffers(rev, sample_rate); /* Set default values */ fluid_allpass_setfeedback(&rev->allpassL[0], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[0], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[1], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[1], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[2], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[2], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[3], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[3], 0.5f); rev->gain = fixedgain; fluid_revmodel_set(rev,FLUID_REVMODEL_SET_ALL,initialroom,initialdamp,initialwidth,initialwet); return rev; }
/** * Open a MIDI file and return a new MIDI file handle. * @internal * @param filename Path of file to open. * @return New MIDI file handle or NULL on error. */ fluid_midi_file* new_fluid_midi_file(char* filename) { fluid_midi_file* mf; mf = FLUID_NEW(fluid_midi_file); if (mf == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET(mf, 0, sizeof(fluid_midi_file)); mf->c = -1; mf->running_status = -1; mf->fp = FLUID_FOPEN(filename, "rb"); if (mf->fp == NULL) { FLUID_LOG(FLUID_ERR, "Couldn't open the MIDI file"); FLUID_FREE(mf); return NULL; } if (fluid_midi_file_read_mthd(mf) != FLUID_OK) { FLUID_FREE(mf); return NULL; } return mf; }
/* * new_fluid_sndmgr_audio_driver * This implementation used the 16bit format. */ fluid_audio_driver_t* new_fluid_sndmgr_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) { fluid_sndmgr_audio_driver_t* dev = NULL; int period_size, periods, buffer_size; /* check the format */ if (!fluid_settings_str_equal(settings, "audio.sample-format", "16bits")) { FLUID_LOG(FLUID_ERR, "Unhandled sample format"); return NULL; } /* compute buffer size */ fluid_settings_getint(settings, "audio.period-size", &period_size); fluid_settings_getint(settings, "audio.periods", &periods); buffer_size = period_size*periods; /* allocated dev */ dev = FLUID_NEW(fluid_sndmgr_audio_driver_t); if (dev == NULL) { FLUID_LOG(FLUID_PANIC, "Out of memory"); return NULL; } FLUID_MEMSET(dev, 0, sizeof(fluid_sndmgr_audio_driver_t)); dev->callback_is_audio_func = false; dev->data = (void *)synth; dev->callback = NULL; if (start_fluid_sndmgr_audio_driver(settings, dev, buffer_size) != 0) { delete_fluid_sndmgr_audio_driver((fluid_audio_driver_t*)dev); return NULL; } return (fluid_audio_driver_t*)dev; }
/** * Create a new MIDI player. * @param synth Fluid synthesizer instance to create player for * @return New MIDI player instance or NULL on error (out of memory) */ fluid_player_t* new_fluid_player(fluid_synth_t* synth) { int i; fluid_player_t* player; player = FLUID_NEW(fluid_player_t); if (player == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } player->status = FLUID_PLAYER_READY; player->loop = 1; player->ntracks = 0; for (i = 0; i < MAX_NUMBER_OF_TRACKS; i++) { player->track[i] = NULL; } player->synth = synth; player->system_timer = NULL; player->sample_timer = NULL; player->playlist = NULL; player->currentfile = NULL; player->division = 0; player->send_program_change = 1; player->miditempo = 480000; player->deltatime = 4.0; player->cur_msec = 0; player->cur_ticks = 0; player->use_system_timer = fluid_settings_str_equal(synth->settings, "player.timing-source", "system"); fluid_settings_getint (synth->settings, "player.reset-synth", &i); player->reset_synth_between_songs = i; return player; }
/** * Create a new MIDI router rule. * @return Newly allocated router rule or NULL if out of memory. * @since 1.1.0 * * The new rule is a "unity" rule which will accept any values and wont modify * them. */ fluid_midi_router_rule_t * new_fluid_midi_router_rule (void) { fluid_midi_router_rule_t *rule; rule = FLUID_NEW (fluid_midi_router_rule_t); if (rule == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET (rule, 0, sizeof (fluid_midi_router_rule_t)); rule->chan_min = 0; rule->chan_max = 999999; rule->chan_mul = 1.0; rule->chan_add = 0; rule->par1_min = 0; rule->par1_max = 999999; rule->par1_mul = 1.0; rule->par1_add = 0; rule->par2_min = 0; rule->par2_max = 999999; rule->par2_mul = 1.0; rule->par2_add = 0; return rule; };
/** * Return a new MIDI file handle for parsing an already-loaded MIDI file. * @internal * @param buffer Pointer to full contents of MIDI file (borrows the pointer). * The caller must not free buffer until after the fluid_midi_file is deleted. * @param length Size of the buffer in bytes. * @return New MIDI file handle or NULL on error. */ fluid_midi_file * new_fluid_midi_file(const char* buffer, size_t length) { fluid_midi_file *mf; mf = FLUID_NEW(fluid_midi_file); if (mf == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET(mf, 0, sizeof(fluid_midi_file)); mf->c = -1; mf->running_status = -1; mf->buffer = buffer; mf->buf_len = length; mf->buf_pos = 0; mf->eof = FALSE; if (fluid_midi_file_read_mthd(mf) != FLUID_OK) { FLUID_FREE(mf); return NULL; } return mf; }
fluid_timer_t* new_fluid_timer (int msec, fluid_timer_callback_t callback, void* data, int new_thread, int auto_destroy, int high_priority) { fluid_timer_t *timer; timer = FLUID_NEW (fluid_timer_t); if (timer == NULL) { FLUID_LOG (FLUID_ERR, "Out of memory"); return NULL; } timer->msec = msec; timer->callback = callback; timer->data = data; timer->cont = TRUE ; timer->thread = NULL; timer->auto_destroy = auto_destroy; if (new_thread) { timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, FALSE); if (!timer->thread) { FLUID_FREE (timer); return NULL; } } else fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ return timer; }
fluid_revmodel_t* new_fluid_revmodel() { fluid_revmodel_t* rev; rev = FLUID_NEW(fluid_revmodel_t); if (rev == NULL) { return NULL; } /* Tie the components to their buffers */ fluid_comb_setbuffer(&rev->combL[0], rev->bufcombL1, combtuningL1); fluid_comb_setbuffer(&rev->combR[0], rev->bufcombR1, combtuningR1); fluid_comb_setbuffer(&rev->combL[1], rev->bufcombL2, combtuningL2); fluid_comb_setbuffer(&rev->combR[1], rev->bufcombR2, combtuningR2); fluid_comb_setbuffer(&rev->combL[2], rev->bufcombL3, combtuningL3); fluid_comb_setbuffer(&rev->combR[2], rev->bufcombR3, combtuningR3); fluid_comb_setbuffer(&rev->combL[3], rev->bufcombL4, combtuningL4); fluid_comb_setbuffer(&rev->combR[3], rev->bufcombR4, combtuningR4); fluid_comb_setbuffer(&rev->combL[4], rev->bufcombL5, combtuningL5); fluid_comb_setbuffer(&rev->combR[4], rev->bufcombR5, combtuningR5); fluid_comb_setbuffer(&rev->combL[5], rev->bufcombL6, combtuningL6); fluid_comb_setbuffer(&rev->combR[5], rev->bufcombR6, combtuningR6); fluid_comb_setbuffer(&rev->combL[6], rev->bufcombL7, combtuningL7); fluid_comb_setbuffer(&rev->combR[6], rev->bufcombR7, combtuningR7); fluid_comb_setbuffer(&rev->combL[7], rev->bufcombL8, combtuningL8); fluid_comb_setbuffer(&rev->combR[7], rev->bufcombR8, combtuningR8); fluid_allpass_setbuffer(&rev->allpassL[0], rev->bufallpassL1, allpasstuningL1); fluid_allpass_setbuffer(&rev->allpassR[0], rev->bufallpassR1, allpasstuningR1); fluid_allpass_setbuffer(&rev->allpassL[1], rev->bufallpassL2, allpasstuningL2); fluid_allpass_setbuffer(&rev->allpassR[1], rev->bufallpassR2, allpasstuningR2); fluid_allpass_setbuffer(&rev->allpassL[2], rev->bufallpassL3, allpasstuningL3); fluid_allpass_setbuffer(&rev->allpassR[2], rev->bufallpassR3, allpasstuningR3); fluid_allpass_setbuffer(&rev->allpassL[3], rev->bufallpassL4, allpasstuningL4); fluid_allpass_setbuffer(&rev->allpassR[3], rev->bufallpassR4, allpasstuningR4); /* Set default values */ fluid_allpass_setfeedback(&rev->allpassL[0], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[0], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[1], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[1], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[2], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[2], 0.5f); fluid_allpass_setfeedback(&rev->allpassL[3], 0.5f); fluid_allpass_setfeedback(&rev->allpassR[3], 0.5f); /* set values manually, since calling set functions causes update and all values should be initialized for an update */ rev->roomsize = initialroom * scaleroom + offsetroom; rev->damp = initialdamp * scaledamp; rev->wet = initialwet * scalewet; rev->width = initialwidth; rev->gain = fixedgain; /* now its okay to update reverb */ fluid_revmodel_update(rev); /* Clear all buffers */ fluid_revmodel_init(rev); return rev; }
fluid_midi_driver_t * new_fluid_sndio_midi_driver(fluid_settings_t *settings, handle_midi_event_func_t handler, void *data) { int err; fluid_sndio_midi_driver_t *dev; char *device; /* not much use doing anything */ if (handler == NULL) { FLUID_LOG(FLUID_ERR, "Invalid argument"); return NULL; } /* allocate the device */ dev = FLUID_NEW(fluid_sndio_midi_driver_t); if (dev == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET(dev, 0, sizeof(fluid_sndio_midi_driver_t)); dev->hdl = NULL; dev->driver.handler = handler; dev->driver.data = data; /* allocate one event to store the input data */ dev->parser = new_fluid_midi_parser(); if (dev->parser == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); goto error_recovery; } /* get the device name. if none is specified, use the default device. */ if (!fluid_settings_dupstr(settings, "midi.sndio.device", &device)) { device = NULL; } /* open the default hardware device. only use midi in. */ dev->hdl = mio_open(device, MIO_IN, 0); if (dev->hdl == NULL) { FLUID_LOG(FLUID_ERR, "Couldn't open sndio midi device"); goto error_recovery; } dev->status = FLUID_MIDI_READY; err = pthread_create(&dev->thread, NULL, fluid_sndio_midi_run, (void *)dev); if (err) { FLUID_LOG(FLUID_PANIC, "Couldn't create the midi thread."); goto error_recovery; } return (fluid_midi_driver_t *) dev; error_recovery: delete_fluid_sndio_midi_driver((fluid_midi_driver_t *)dev); return NULL; }
fluid_server_socket_t* new_fluid_server_socket(int port, fluid_server_func_t func, void* data) { fluid_server_socket_t* server_socket; struct sockaddr_in addr; fluid_socket_t sock; g_return_val_if_fail (func != NULL, NULL); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { FLUID_LOG(FLUID_ERR, "Failed to create server socket"); return NULL; } FLUID_MEMSET((char *)&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(port); if (bind(sock, (const struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { FLUID_LOG(FLUID_ERR, "Failed to bind server socket"); fluid_socket_close(sock); return NULL; } if (listen(sock, 10) == SOCKET_ERROR) { FLUID_LOG(FLUID_ERR, "Failed listen on server socket"); fluid_socket_close(sock); return NULL; } server_socket = FLUID_NEW(fluid_server_socket_t); if (server_socket == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); fluid_socket_close(sock); return NULL; } server_socket->socket = sock; server_socket->func = func; server_socket->data = data; server_socket->cont = 1; server_socket->thread = new_fluid_thread(fluid_server_socket_run, server_socket, 0, FALSE); if (server_socket->thread == NULL) { FLUID_FREE(server_socket); fluid_socket_close(sock); return NULL; } return server_socket; }
/* * new_fluid_midi_parser */ fluid_midi_parser_t* new_fluid_midi_parser() { fluid_midi_parser_t* parser; parser = FLUID_NEW(fluid_midi_parser_t); if (parser == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } parser->status = 0; /* As long as the status is 0, the parser won't do anything -> no need to initialize all the fields. */ return parser; }
/* * fluid_hashtable_insert_internal: * @hashtable: our #fluid_hashtable_t * @key: the key to insert * @value: the value to insert * @keep_new_key: if %TRUE and this key already exists in the table * then call the destroy notify function on the old key. If %FALSE * then call the destroy notify function on the new key. * * Implements the common logic for the fluid_hashtable_insert() and * fluid_hashtable_replace() functions. * * Do a lookup of @key. If it is found, replace it with the new * @value (and perhaps the new @key). If it is not found, create a * new node. */ static void fluid_hashtable_insert_internal (fluid_hashtable_t *hashtable, void *key, void *value, int keep_new_key) { fluid_hashnode_t **node_ptr, *node; unsigned int key_hash; fluid_return_if_fail (hashtable != NULL); fluid_return_if_fail (hashtable->ref_count > 0); node_ptr = fluid_hashtable_lookup_node (hashtable, key, &key_hash); if ((node = *node_ptr)) { if (keep_new_key) { if (hashtable->key_destroy_func) hashtable->key_destroy_func (node->key); node->key = key; } else { if (hashtable->key_destroy_func) hashtable->key_destroy_func (key); } if (hashtable->value_destroy_func) hashtable->value_destroy_func (node->value); node->value = value; } else { node = FLUID_NEW (fluid_hashnode_t); if (!node) { FLUID_LOG (FLUID_ERR, "Out of memory"); return; } node->key = key; node->value = value; node->key_hash = key_hash; node->next = NULL; *node_ptr = node; hashtable->nnodes++; fluid_hashtable_maybe_resize (hashtable); } }
BOOL CALLBACK fluid_dsound_enum_callback2(LPGUID guid, LPCTSTR description, LPCTSTR module, LPVOID context) { fluid_dsound_devsel_t* devsel = (fluid_dsound_devsel_t*) context; FLUID_LOG(FLUID_DBG, "Testing audio device: %s", description); if (FLUID_STRCASECMP(devsel->devname, description) == 0) { devsel->devGUID = FLUID_NEW(GUID); if(devsel->devGUID) { memcpy(devsel->devGUID, guid, sizeof(GUID)); FLUID_LOG(FLUID_DBG, "Selected audio device GUID: %p", devsel->devGUID); } } return TRUE; }
/** * Create a new sequencer event structure. * @return New sequencer event structure or NULL if out of memory */ fluid_event_t* new_fluid_event() { fluid_event_t* evt; evt = FLUID_NEW(fluid_event_t); if (evt == NULL) { fluid_log(FLUID_PANIC, "event: Out of memory\n"); return NULL; } fluid_event_clear(evt); return(evt); }
/* Private functions */ static fluid_samplecache_entry_t *new_samplecache_entry(SFData *sf, unsigned int sample_start, unsigned int sample_end, int sample_type) { fluid_samplecache_entry_t *entry; entry = FLUID_NEW(fluid_samplecache_entry_t); if (entry == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET(entry, 0, sizeof(*entry)); entry->filename = FLUID_STRDUP(sf->fname); if (entry->filename == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); goto error_exit; } if (fluid_get_file_modification_time(entry->filename, &entry->modification_time) == FLUID_FAILED) { FLUID_LOG(FLUID_WARN, "Unable to read modificaton time of soundfont file."); entry->modification_time = 0; } entry->sf_samplepos = sf->samplepos; entry->sf_samplesize = sf->samplesize; entry->sf_sample24pos = sf->sample24pos; entry->sf_sample24size = sf->sample24size; entry->sample_start = sample_start; entry->sample_end = sample_end; entry->sample_type = sample_type; entry->sample_count = fluid_sffile_read_sample_data(sf, sample_start, sample_end, sample_type, &entry->sample_data, &entry->sample_data24); if (entry->sample_count < 0) { goto error_exit; } return entry; error_exit: delete_samplecache_entry(entry); return NULL; }
/* * new_fluid_track */ fluid_track_t* new_fluid_track(int num) { fluid_track_t* track; track = FLUID_NEW(fluid_track_t); if (track == NULL) { return NULL; } track->name = NULL; track->num = num; track->first = NULL; track->cur = NULL; track->last = NULL; track->ticks = 0; return track; }
/** * Create a MIDI event structure. * @return New MIDI event structure or NULL when out of memory. */ fluid_midi_event_t* new_fluid_midi_event() { fluid_midi_event_t* evt; evt = FLUID_NEW(fluid_midi_event_t); if (evt == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } evt->dtime = 0; evt->type = 0; evt->channel = 0; evt->param1 = 0; evt->param2 = 0; evt->next = NULL; evt->paramptr = NULL; return evt; }
fluid_evt_entry* _fluid_seq_heap_get_free(fluid_evt_heap_t* heap) { #ifdef HEAP_WITH_DYNALLOC fluid_evt_entry* evt = NULL; /* LOCK */ fluid_mutex_lock(heap->mutex); #if !defined(MACOS9) if (heap->freelist == NULL) { heap->freelist = FLUID_NEW(fluid_evt_entry); if (heap->freelist != NULL) { heap->freelist->next = NULL; } } #endif evt = heap->freelist; if (evt != NULL) { heap->freelist = heap->freelist->next; evt->next = NULL; } /* UNLOCK */ fluid_mutex_unlock(heap->mutex); return evt; #else fluid_evt_entry* evt; if (heap->head == NULL) return NULL; /* take from head of the heap */ /* critical - should threadlock ? */ evt = heap->head; heap->head = heap->head->next; return evt; #endif }
/* * new_fluid_channel */ fluid_channel_t* new_fluid_channel(fluid_synth_t* synth, int num) { fluid_channel_t* chan; chan = FLUID_NEW(fluid_channel_t); if (chan == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } chan->synth = synth; chan->channum = num; chan->preset = NULL; fluid_channel_init(chan); fluid_channel_init_ctrl(chan); return chan; }
/* * new_fluid_sndmgr_audio_driver2 * * This implementation used the audio_func float format, with * conversion from float to 16bits in the driver. */ fluid_audio_driver_t* new_fluid_sndmgr_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data) { fluid_sndmgr_audio_driver_t* dev = NULL; int period_size, periods, buffer_size; /* compute buffer size */ fluid_settings_getint(settings, "audio.period-size", &period_size); fluid_settings_getint(settings, "audio.periods", &periods); buffer_size = period_size*periods; /* allocated dev */ dev = FLUID_NEW(fluid_sndmgr_audio_driver_t); if (dev == NULL) { FLUID_LOG(FLUID_PANIC, "Out of memory"); return NULL; } FLUID_MEMSET(dev, 0, sizeof(fluid_sndmgr_audio_driver_t)); /* allocate the conversion buffers */ dev->convbuffers[0] = FLUID_ARRAY(float, buffer_size); dev->convbuffers[1] = FLUID_ARRAY(float, buffer_size); if ((dev->convbuffers[0] == NULL) || (dev->convbuffers[1] == NULL)) { FLUID_LOG(FLUID_PANIC, "Out of memory"); goto error_recovery; } dev->callback_is_audio_func = true; dev->data = data; dev->callback = func; if (start_fluid_sndmgr_audio_driver(settings, dev, buffer_size) != 0) { goto error_recovery; } return (fluid_audio_driver_t*)dev; error_recovery: delete_fluid_sndmgr_audio_driver((fluid_audio_driver_t*)dev); return NULL; }
/** * Create a new thread. * @param func Function to execute in new thread context * @param data User defined data to pass to func * @param prio_level Priority level. If greater than 0 then high priority scheduling will * be used, with the given priority level (used by pthreads only). 0 uses normal scheduling. * @param detach If TRUE, 'join' does not work and the thread destroys itself when finished. * @return New thread pointer or NULL on error */ fluid_thread_t * new_fluid_thread (fluid_thread_func_t func, void *data, int prio_level, int detach) { GThread *thread; fluid_thread_info_t *info; GError *err = NULL; g_return_val_if_fail (func != NULL, NULL); /* Make sure g_thread_init has been called. * FIXME - Probably not a good idea in a shared library, * but what can we do *and* remain backwards compatible? */ if (!g_thread_supported ()) g_thread_init (NULL); if (prio_level > 0) { info = FLUID_NEW (fluid_thread_info_t); if (!info) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } info->func = func; info->data = data; info->prio_level = prio_level; thread = g_thread_create (fluid_thread_high_prio, info, detach == FALSE, &err); } else thread = g_thread_create ((GThreadFunc)func, data, detach == FALSE, &err); if (!thread) { FLUID_LOG(FLUID_ERR, "Failed to create the thread: %s", fluid_gerror_message (err)); g_clear_error (&err); } return thread; }
/** * Create a new sequencer object. * @param use_system_timer If TRUE, sequencer will advance at the rate of the * system clock. If FALSE, call fluid_sequencer_process() to advance * the sequencer. * @return New sequencer instance * @since 1.1.0 */ fluid_sequencer_t* new_fluid_sequencer2 (int use_system_timer) { fluid_sequencer_t* seq; seq = FLUID_NEW(fluid_sequencer_t); if (seq == NULL) { fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return NULL; } FLUID_MEMSET(seq, 0, sizeof(fluid_sequencer_t)); seq->scale = 1000; // default value seq->useSystemTimer = use_system_timer ? TRUE : FALSE; seq->startMs = seq->useSystemTimer ? fluid_curtime() : 0; seq->clients = NULL; seq->clientsID = 0; if (-1 == _fluid_seq_queue_init(seq, FLUID_SEQUENCER_EVENTS_MAX)) { FLUID_FREE(seq); fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return NULL; } #if FLUID_SEQ_WITH_TRACE seq->tracelen = 1024*100; seq->tracebuf = (char *)FLUID_MALLOC(seq->tracelen); if (seq->tracebuf == NULL) { _fluid_seq_queue_end(seq); FLUID_FREE(seq); fluid_log(FLUID_PANIC, "sequencer: Out of memory\n"); return NULL; } seq->traceptr = seq->tracebuf; #endif return(seq); }
/** * Create a new midi router. The default rules will pass all events unmodified. * @param settings Settings used to configure MIDI router * @param handler MIDI event callback. * @param event_handler_data Caller defined data pointer which gets passed to 'handler' * @return New MIDI router instance or NULL on error * * The MIDI handler callback should process the possibly filtered/modified MIDI * events from the MIDI router and forward them on to a synthesizer for example. * The function fluid_synth_handle_midi_event() can be used for \a handle and * a #fluid_synth_t passed as the \a event_handler_data parameter for this purpose. */ fluid_midi_router_t * new_fluid_midi_router(fluid_settings_t *settings, handle_midi_event_func_t handler, void *event_handler_data) { fluid_midi_router_t *router = NULL; int i; router = FLUID_NEW (fluid_midi_router_t); if (router == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } FLUID_MEMSET (router, 0, sizeof (fluid_midi_router_t)); /* Retrieve the number of MIDI channels for range limiting */ fluid_settings_getint(settings, "synth.midi-channels", &router->nr_midi_channels); fluid_mutex_init (router->rules_mutex); router->synth = (fluid_synth_t *)event_handler_data; router->event_handler = handler; router->event_handler_data = event_handler_data; /* Create default routing rules which pass all events unmodified */ for (i = 0; i < FLUID_MIDI_ROUTER_RULE_COUNT; i++) { router->rules[i] = new_fluid_midi_router_rule (); if (!router->rules[i]) goto error_recovery; } return router; error_recovery: delete_fluid_midi_router (router); return NULL; }
/** * Create a new thread. * @param func Function to execute in new thread context * @param data User defined data to pass to func * @param prio_level Priority level. If greater than 0 then high priority scheduling will * be used, with the given priority level (used by pthreads only). 0 uses normal scheduling. * @param detach If TRUE, 'join' does not work and the thread destroys itself when finished. * @return New thread pointer or NULL on error */ fluid_thread_t * new_fluid_thread (const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach) { GThread *thread; fluid_thread_info_t *info; GError *err = NULL; g_return_val_if_fail (func != NULL, NULL); #if OLD_GLIB_THREAD_API /* Make sure g_thread_init has been called. * FIXME - Probably not a good idea in a shared library, * but what can we do *and* remain backwards compatible? */ if (!g_thread_supported ()) g_thread_init (NULL); #endif if (prio_level > 0) { info = FLUID_NEW (fluid_thread_info_t); if (!info) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } info->func = func; info->data = data; info->prio_level = prio_level; #if NEW_GLIB_THREAD_API thread = g_thread_try_new (name, fluid_thread_high_prio, info, &err); #else thread = g_thread_create (fluid_thread_high_prio, info, detach == FALSE, &err); #endif } #if NEW_GLIB_THREAD_API else thread = g_thread_try_new (name, (GThreadFunc)func, data, &err); #else else thread = g_thread_create ((GThreadFunc)func, data, detach == FALSE, &err);