iphone - How to convert FLAC file to wav file in ios? -


i want create audio player support flac format of audio files.for tried implement algorithm of flac wav conversion follow

please me.

all time gives me error

error: initializing decoder: flac__stream_decoder_init_status_error_opening_file

static flac__bool write_little_endian_uint16(file *f, flac__uint16 x) { return fputc(x, f) != eof && fputc(x >> 8, f) != eof ; }  static flac__bool write_little_endian_int16(file *f, flac__int16 x) { return write_little_endian_uint16(f, (flac__uint16)x); }  static flac__bool write_little_endian_uint32(file *f, flac__uint32 x) { return fputc(x, f) != eof && fputc(x >> 8, f) != eof && fputc(x >> 16, f) != eof && fputc(x >> 24, f) != eof ; }  int main(int argc, char *argv[]) { const char *input = "demo_audio_shaer.flac"; printf("aa[0]====%s",argv[0]);  flac__bool ok = true; flac__streamdecoder *decoder = 0; flac__streamdecoderinitstatus init_status; file *fout;  if((fout = fopen(argv[2], "wb")) == null) {     fprintf(stderr, "error: opening %s output\n", argv[2]);     return 1; }  if((decoder = flac__stream_decoder_new()) == null) {     fprintf(stderr, "error: allocating decoder\n");     fclose(fout);     return 1; }  (void)flac__stream_decoder_set_md5_checking(decoder, true); init_status = flac__stream_decoder_init_file(decoder, input, write_callback, metadata_callback, error_callback, /*client_data=*/fout); if(init_status != flac__stream_decoder_init_status_ok) {     fprintf(stderr, "error: initializing decoder: %s\n", flac__streamdecoderinitstatusstring[init_status]);     ok = false; }  if(ok) {     ok = flac__stream_decoder_process_until_end_of_stream(decoder);     fprintf(stderr, "decoding: %s\n", ok? "succeeded" : "failed");      fprintf(stderr, "   state: %s\n", flac__streamdecoderstatestring[flac__stream_decoder_get_state(decoder)]); }  flac__stream_decoder_delete(decoder); fclose(fout);  return 0; }  flac__streamdecoderwritestatus write_callback(const flac__streamdecoder *decoder, const                 flac__frame *frame, const flac__int32 * const buffer[], void *client_data) { file *f = (file*)client_data; const flac__uint32 total_size = (flac__uint32)(total_samples * channels * (bps/8)); size_t i;  (void)decoder;  if(total_samples == 0) {     fprintf(stderr, "error: example works flac files have total_samples count in streaminfo\n");     return flac__stream_decoder_write_status_abort; } if(channels != 2 || bps != 16) {     fprintf(stderr, "error: example supports 16bit stereo streams\n");     return flac__stream_decoder_write_status_abort; }  /* write wave header before write first frame */ if(frame->header.number.sample_number == 0) {     if(        fwrite("riff", 1, 4, f) < 4 ||        !write_little_endian_uint32(f, total_size + 36) ||        fwrite("wavefmt ", 1, 8, f) < 8 ||        !write_little_endian_uint32(f, 16) ||        !write_little_endian_uint16(f, 1) ||        !write_little_endian_uint16(f, (flac__uint16)channels) ||        !write_little_endian_uint32(f, sample_rate) ||        !write_little_endian_uint32(f, sample_rate * channels * (bps/8)) ||        !write_little_endian_uint16(f, (flac__uint16)(channels * (bps/8))) || /* block align */        !write_little_endian_uint16(f, (flac__uint16)bps) ||        fwrite("data", 1, 4, f) < 4 ||        !write_little_endian_uint32(f, total_size)        )     {         fprintf(stderr, "error: write error\n");         return flac__stream_decoder_write_status_abort;     } }  /* write decoded pcm samples */ for(i = 0; < frame->header.blocksize; i++) {     if(        !write_little_endian_int16(f, (flac__int16)buffer[0][i]) ||  /* left channel */        !write_little_endian_int16(f, (flac__int16)buffer[1][i])     /* right channel */        ) {         fprintf(stderr, "error: write error\n");         return flac__stream_decoder_write_status_abort;     } }  return flac__stream_decoder_write_status_continue; }  void metadata_callback(const flac__streamdecoder *decoder, const flac__streammetadata *metadata, void *client_data) { (void)decoder, (void)client_data;  /* print stats */ if(metadata->type == flac__metadata_type_streaminfo) {     /* save later */     total_samples = metadata->data.stream_info.total_samples;     sample_rate = metadata->data.stream_info.sample_rate;     channels = metadata->data.stream_info.channels;     bps = metadata->data.stream_info.bits_per_sample;      fprintf(stderr, "sample rate    : %u hz\n", sample_rate);     fprintf(stderr, "channels       : %u\n", channels);     fprintf(stderr, "bits per sample: %u\n", bps); #ifdef _msc_ver     fprintf(stderr, "total samples  : %i64u\n", total_samples); #else     fprintf(stderr, "total samples  : %llu\n", total_samples); #endif } }  void error_callback(const flac__streamdecoder *decoder, flac__streamdecodererrorstatus status, void *client_data) { (void)decoder, (void)client_data;  fprintf(stderr, "got error callback: %s\n", flac__streamdecodererrorstatusstring[status]); } 

i can suggest solution. https://github.com/krivoblotsky/ksaudioplayer

it supports *.flac , many other file formats.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -