/** * ca_context_change_device: * @c: the context to change the backend device for * @device: the backend device to use, in a format that is specific to the backend. * * Specify the backend device to use. This function may be called not be called after * ca_context_open() suceeded. This function might suceed even when * the specified driver backend is not available. Use * ca_context_open() to find out whether the backend is available * * Depending on the backend use this might or might not cause all * currently playing event sounds to be moved to the new device.. * * Returns: 0 on success, negative error code on error. */ int ca_context_change_device(ca_context *c, const char *device) { char *n; int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); if (!device) n = NULL; else if (!(n = ca_strdup(device))) { ret = CA_ERROR_OOM; goto fail; } ret = c->opened ? driver_change_device(c, n) : CA_SUCCESS; if (ret == CA_SUCCESS) { ca_free(c->device); c->device = n; } else ca_free(n); fail: ca_mutex_unlock(c->mutex); return ret; }
/** * ca_context_destroy: * @c: the context to destroy. * * Destroy a (connected or unconnected) context object. * * Returns: 0 on success, negative error code on error. */ int ca_context_destroy(ca_context *c) { int ret = CA_SUCCESS; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); /* There's no locking necessary here, because the application is * broken anyway if it destructs this object in one thread and * still is calling a method of it in another. */ if (c->opened) ret = driver_destroy(c); if (c->props) ca_assert_se(ca_proplist_destroy(c->props) == CA_SUCCESS); if (c->mutex) ca_mutex_free(c->mutex); ca_free(c->driver); ca_free(c->device); ca_free(c); return ret; }
void free_integral(Integral *integral) { free_ratfun(&integral->integrand); free_ratfun(&integral->rational_part); free_coefficient(&integral->poly_part); ca_free(&integral->Qi); ca_free(&integral->Si); }
void ca_sound_file_close(ca_sound_file *f) { ca_assert(f); if (f->wav) ca_wav_close(f->wav); if (f->vorbis) ca_vorbis_close(f->vorbis); ca_free(f->filename); ca_free(f); }
int ca_sound_file_open(ca_sound_file **_f, const char *fn) { FILE *file; ca_sound_file *f; int ret; ca_return_val_if_fail(_f, CA_ERROR_INVALID); ca_return_val_if_fail(fn, CA_ERROR_INVALID); if (!(f = ca_new0(ca_sound_file, 1))) return CA_ERROR_OOM; if (!(f->filename = ca_strdup(fn))) { ret = CA_ERROR_OOM; goto fail; } if (!(file = fopen(fn, "r"))) { ret = errno == ENOENT ? CA_ERROR_NOTFOUND : CA_ERROR_SYSTEM; goto fail; } if ((ret = ca_wav_open(&f->wav, file)) == CA_SUCCESS) { f->nchannels = ca_wav_get_nchannels(f->wav); f->rate = ca_wav_get_rate(f->wav); f->type = ca_wav_get_sample_type(f->wav); *_f = f; return CA_SUCCESS; } if (ret == CA_ERROR_CORRUPT) { if (fseek(file, 0, SEEK_SET) < 0) { ret = CA_ERROR_SYSTEM; goto fail; } if ((ret = ca_vorbis_open(&f->vorbis, file)) == CA_SUCCESS) { f->nchannels = ca_vorbis_get_nchannels(f->vorbis); f->rate = ca_vorbis_get_rate(f->vorbis); f->type = CA_SAMPLE_S16NE; *_f = f; return CA_SUCCESS; } } fail: ca_free(f->filename); ca_free(f); return ret; }
/** * ca_context_set_driver: * @c: the context to change the backend driver for * @driver: the backend driver to use (e.g. "alsa", "pulse", "null", ...) * * Specify the backend driver used. This function may not be called again after * ca_context_open() suceeded. This function might suceed even when * the specified driver backend is not available. Use * ca_context_open() to find out whether the backend is available. * * Returns: 0 on success, negative error code on error. */ int ca_context_set_driver(ca_context *c, const char *driver) { char *n; int ret; ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED); ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_mutex_lock(c->mutex); ca_return_val_if_fail_unlock(!c->opened, CA_ERROR_STATE, c->mutex); if (!driver) n = NULL; else if (!(n = ca_strdup(driver))) { ret = CA_ERROR_OOM; goto fail; } ca_free(c->driver); c->driver = n; ret = CA_SUCCESS; fail: ca_mutex_unlock(c->mutex); return ret; }
static void free_ca_ubrep (void *ap) { CAUnboundRepeat *ca = (CAUnboundRepeat *) ap; if ( ca != NULL ) { ca_free(ca->mask); xfree(ca->dim); xfree(ca->rep_dim); xfree(ca); } }
bool cave_generate_map(struct dm_map *map, struct random *r, enum dm_dungeon_type type, coord_t *ul, coord_t *dr) { FIX_UNUSED(type); /* initialise cellular automata */ coord_t size = { .x = dr->x - ul->x, .y = dr->y - ul->y, }; struct ca_map *cmap = ca_init(&size); /* fill the map randomly with floors */ coord_t p; for (p.y = 0; p.y < size.y; p.y++) { for (p.x = 0; p.x < size.x; p.x++) { ca_set_coord(cmap, &p, randpick(r, 45) ); } } /* Fill the map with large caves */ for (int i = 0; i < 4; i++) { ca_generation(cmap, 16, 8, 2); } /* Do a few passes to make them less smooth */ for (int i = 0; i < 2; i++) { int ri = (random_int32(r) % 4) +2; ca_generation(cmap, 5, ri, 1); } /* translate the ca_map to the real map */ for(p.y = 0; p.y < size.y; p.y++) { for(p.x = 0; p.x < size.x; p.x++) { coord_t c = cd_add(ul, &p); /* check if the cell is alive or dead */ if (ca_get_coord(cmap, &p) == CA_ALIVE) { /* fill the tile with the specified type */ if(random_int32(r)%100 < 1) { dm_get_map_me(&c,map)->tile = ts_get_tile_specific(TILE_ID_MAD_CAP_FUNGUS); } else dm_get_map_me(&c,map)->tile = ts_get_tile_specific(TILE_ID_CONCRETE_FLOOR); } } } /* cleanup and return */ ca_free(cmap); return true; }
int ca_vorbis_open(ca_vorbis **_v, FILE *f) { int ret, or; ca_vorbis *v; int64_t n; ca_return_val_if_fail(_v, CA_ERROR_INVALID); ca_return_val_if_fail(f, CA_ERROR_INVALID); if (!(v = ca_new0(ca_vorbis, 1))) return CA_ERROR_OOM; if ((or = ov_open(f, &v->ovf, NULL, 0)) < 0) { ret = convert_error(or); goto fail; } if ((n = ov_pcm_total(&v->ovf, -1)) < 0) { ret = convert_error(or); ov_clear(&v->ovf); goto fail; } if (((off_t) n * (off_t) sizeof(int16_t)) > FILE_SIZE_MAX) { ret = CA_ERROR_TOOBIG; ov_clear(&v->ovf); goto fail; } v->size = (off_t) n * (off_t) sizeof(int16_t) * ca_vorbis_get_nchannels(v); *_v = v; return CA_SUCCESS; fail: ca_free(v); return ret; }
void ca_vorbis_close(ca_vorbis *v) { ca_assert(v); ov_clear(&v->ovf); ca_free(v); }