/* format_new_match */ AsmFormat * format_new_match(char const * filename, FILE * fp) { char const path[] = LIBDIR "/" PACKAGE "/format"; DIR * dir; struct dirent * de; size_t len; #ifdef __APPLE__ char const ext[] = ".dylib"; #else char const ext[] = ".so"; #endif int hasflat = 0; AsmFormat * format = NULL; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, filename); #endif if((dir = opendir(path)) == NULL) { error_set_code(1, "%s: %s", path, strerror(errno)); return NULL; } while((de = readdir(dir)) != NULL) { if((len = strlen(de->d_name)) < sizeof(ext)) continue; if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0) continue; de->d_name[len - sizeof(ext) + 1] = '\0'; if(strcmp(de->d_name, "flat") == 0) hasflat = 1; if((format = format_new(de->d_name)) == NULL) continue; if(format_init(format, NULL, filename, fp) == 0 && format_match(format) == 1) break; format_delete(format); format = NULL; } closedir(dir); /* fallback on the "flat" format plug-in if necessary and available */ if(format == NULL && hasflat && (format = format_new("flat")) != NULL && format_init(format, NULL, filename, fp) != 0) { format_delete(format); format = NULL; } return format; }
sw_sounddata * sounddata_new_empty(gint nr_channels, gint sample_rate, gint sample_length) { sw_sounddata *s; sw_framecount_t len; s = g_malloc (sizeof(sw_sounddata)); if (!s) return NULL; s->refcount = 1; s->format = format_new (nr_channels, sample_rate); s->nr_frames = (sw_framecount_t) sample_length; if (sample_length > 0) { len = frames_to_bytes (s->format, sample_length); s->data = g_malloc0 ((size_t)len); if (!(s->data)) { fprintf(stderr, "Unable to allocate %" PRId64 " bytes for sample data.\n", len); g_free(s); return NULL; #ifdef DEBUG } else { g_print ("g_malloc0'd %d bytes for new sounddata\n", len); #endif } } else { s->data = NULL; } s->sels = NULL; g_mutex_init (&s->sels_mutex); g_mutex_init (&s->data_mutex); return s; }