int ad_info_sndfile(WfDecoder* d) { SndfileDecoder* sf = d->d; if (!sf) return -1; int16_t bit_depth = parse_bit_depth(sf->sfinfo.format); d->info = (WfAudioInfo){ .channels = sf->sfinfo.channels, .frames = sf->sfinfo.frames, .sample_rate = sf->sfinfo.samplerate, .length = sf->sfinfo.samplerate ? (sf->sfinfo.frames * 1000) / sf->sfinfo.samplerate : 0, .bit_depth = bit_depth, .bit_rate = bit_depth * sf->sfinfo.channels * sf->sfinfo.samplerate, .meta_data = NULL, }; return 0; } static gboolean ad_open_sndfile(WfDecoder* decoder, const char* filename) { SndfileDecoder* priv = decoder->d = g_new0(SndfileDecoder, 1); priv->sfinfo.format = 0; if(!(priv->sffile = sf_open(filename, SFM_READ, &priv->sfinfo))){ dbg(1, "unable to open file '%s': %i: %s", filename, sf_error(NULL), sf_strerror(NULL)); g_free(priv); return FALSE; } ad_info_sndfile(decoder); return TRUE; }
static void *ad_open_sndfile(const char *fn, struct adinfo *nfo) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) calloc(1, sizeof(sndfile_audio_decoder)); priv->sfinfo.format=0; if(!(priv->sffile = sf_open(fn, SFM_READ, &priv->sfinfo))){ dbg(0, "unable to open file '%s'.", fn); puts(sf_strerror(NULL)); int e = sf_error(NULL); dbg(0, "error=%i", e); free(priv); return NULL; } ad_info_sndfile(priv, nfo); return (void*) priv; }