队列中的Lame编码iOS

队列中的Lame编码iOS,ios,lame,dispatch-async,Ios,Lame,Dispatch Async,我正在尝试使用LAME将WAV文件转换为MP3文件 我正在使用这个代码。 我想在后台(或队列中)执行此操作。由于输入文件很大,它可以完全控制它直到完成。有人能帮我吗 int read, write; FILE *pcm = fopen([mergeFile cStringUsingEncoding:1], "rb"); //source fseek(pcm, 4*1024, SEEK_CUR); //skip file hea

我正在尝试使用LAME将WAV文件转换为MP3文件

我正在使用这个代码。 我想在后台(或队列中)执行此操作。由于输入文件很大,它可以完全控制它直到完成。有人能帮我吗

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);

do {
    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);

我将使用串行NSOperationQueue进行编码

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
#ifdef __IPHONE_8_0
queue.qualityOfService = /* a NSQualityOfService */;
#endif
您可以添加如下作业:

[queue addOperationWithBlock:^{

    /* Encoding code goes here */

    dispatch_async(dispatch_get_main_queue(), ^{

        /* Report operation status on completion (delegate, notification, etc...)

    }];

}];

我将使用串行NSOperationQueue进行编码

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
#ifdef __IPHONE_8_0
queue.qualityOfService = /* a NSQualityOfService */;
#endif
您可以添加如下作业:

[queue addOperationWithBlock:^{

    /* Encoding code goes here */

    dispatch_async(dispatch_get_main_queue(), ^{

        /* Report operation status on completion (delegate, notification, etc...)

    }];

}];

你可以试着用积木来达到你的要求。你可以试着用积木来达到你的要求。你可以试着用积木来达到你的要求。