static void tick_temp(const char *filename, int chan) { int i; for (i = 0; i < tempfiles_size; i++) { tempfile_ctr *tmp; tmp = tempfiles[i]; if ((tmp) && (mus_strcmp(filename, tmp->name))) { tmp->ticks[chan]++; return; } } }
void remember_temp(const char *filename, int chans) { int i, old_size; tempfile_ctr *tmp = NULL; if (tempfiles_size == 0) { tempfiles_size = 8; tempfiles = (tempfile_ctr **)calloc(tempfiles_size, sizeof(tempfile_ctr *)); i = 0; } else { for (i = 0; i < tempfiles_size; i++) if ((tempfiles[i]) && (mus_strcmp(filename, tempfiles[i]->name))) return; for (i = 0; i < tempfiles_size; i++) if (tempfiles[i] == NULL) break; if (i >= tempfiles_size) { old_size = tempfiles_size; tempfiles_size += 8; tempfiles = (tempfile_ctr **)realloc(tempfiles, tempfiles_size * sizeof(tempfile_ctr *)); for (i = old_size; i < tempfiles_size; i++) tempfiles[i] = NULL; i = old_size; } } tmp = (tempfile_ctr *)calloc(1, sizeof(tempfile_ctr)); tempfiles[i] = tmp; tmp->name = mus_strdup(filename); tmp->chans = chans; tmp->ticks = (int *)calloc(chans, sizeof(int)); }
void forget_temp(const char *filename, int chan) { int i, j; for (i = 0; i < tempfiles_size; i++) { tempfile_ctr *tmp; tmp = tempfiles[i]; if ((tmp) && (mus_strcmp(filename, tmp->name))) { tmp->ticks[chan]--; for (j = 0; j < tmp->chans; j++) if (tmp->ticks[j] > 0) return; snd_remove(tmp->name, REMOVE_FROM_CACHE); free(tmp->name); free(tmp->ticks); free(tmp); tempfiles[i] = NULL; return; } } }
int mus_sound_forget(const char *name) { /* apparently here we want to forget either name or the expanded or contracted forms of name -- as many as we find! */ int i, len, len2, short_len = 0; bool free_name = false; char *short_name = NULL; sound_file **sound_table; int sound_table_size, index; char c; if (name == NULL) return(MUS_ERROR); len = strlen(name); if (len > 6) len2 = len - 6; else len2 = len / 2; c = name[len2]; if (name[0] == '/') { for (i = 0; i < len; i++) if (name[i] == '/') short_name = (char *)(name + i + 1); } else { short_name = mus_expand_filename(name); free_name = true; } if (short_name) short_len = strlen(short_name); index = sound_file_hash_index(name, len); sound_table = sound_tables[index]; sound_table_size = sound_table_sizes[index]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (sound_table[i]->file_name_length == len) && (sound_table[i]->file_name[len2] == c) && (mus_strcmp(name, sound_table[i]->file_name))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; } if (short_name) { if (short_len > 6) len2 = short_len - 6; else len2 = short_len / 2; c = short_name[len2]; index = sound_file_hash_index(short_name, short_len); sound_table = sound_tables[index]; sound_table_size = sound_table_sizes[index]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (sound_table[i]->file_name_length == short_len) && (sound_table[i]->file_name[len2] == c) && (mus_strcmp(short_name, sound_table[i]->file_name))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; } } if (free_name) free(short_name); return(MUS_NO_ERROR); }