Lame Encoding iOS in queue -
i'm trying convert wav file mp3 file using lame.
i using code. want in background (or in queue). input file large, can take full control till finishing. can me so?
int read, write; file *pcm = fopen([mergefile cstringusingencoding:1], "rb"); //source fseek(pcm, 4*1024, seek_cur); //skip file header file *mp3 = fopen([mp3filepath cstringusingencoding:1], "wb"); //output const int pcm_size = 8192; const int mp3_size = 8192; short int pcm_buffer[pcm_size*2]; unsigned char mp3_buffer[mp3_size]; lame_t lame = lame_init(); lame_set_in_samplerate(lame, 44100); lame_set_vbr(lame, vbr_default); lame_init_params(lame); { read = fread(pcm_buffer, 2*sizeof(short int), pcm_size, pcm); nslog(@""); if (read == 0) write = lame_encode_flush(lame, mp3_buffer, mp3_size); else write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, mp3_size); } while (read != 0); lame_close(lame); fclose(mp3); fclose(pcm);
i use serial nsoperationqueue encoding.
nsoperationqueue *queue = [[nsoperationqueue alloc] init]; queue.maxconcurrentoperationcount = 1; #ifdef __iphone_8_0 queue.qualityofservice = /* nsqualityofservice */; #endif
you can add jobs this:
[queue addoperationwithblock:^{ /* encoding code goes here */ dispatch_async(dispatch_get_main_queue(), ^{ /* report operation status on completion (delegate, notification, etc...) }]; }];
Comments
Post a Comment