我正在尝试使用 Objective-C 创建 LAME mp3 编码器 GUI。我从 iTunes-LAME.app 中学到了很多东西并复制了很多代码。这次,我从 iTunes-LAME.app 中复制并修改了 id3tag 写入函数。但是在复制和修改功能中,我得到了 2byte 语言的损坏字符。我认为它可能有问题,但我不知道出了什么问题。这是功能。请帮我!!
编辑:我修改后的 id3tag 写入函数适用于单字节语言和数值。
struct id3_tag *id3tag;
struct id3_frame *frame = NULL;
frame = id3_frame_new(ID3_FRAME_TITLE);
id3tag = id3_tag_new();
id3_tag_attachframe(id3tag, frame);
id3_ucs4_t *ucs4 = id3_utf8_ucs4duplicate((const id3_utf8_t*)@"日本語".UTF8String);
if (id3_field_setstrings(&frame->fields[1], 1, &ucs4) == -1) {
NSLog(@"Unable to set frame %s",ID3_FRAME_TITLE);
id3_frame_delete(frame);
}
id3tag->options = 0;
id3tag->flags |= ID3_TAG_FLAG_FOOTERPRESENT;
id3_length_t len = id3_tag_render(id3tag, NULL);
char *buf = (char*)malloc(len);
len = id3_tag_render(id3tag, (id3_byte_t *)buf);
const char *filename=@"/Users/wayfarer/Desktop/01 ヴィーナスは眠れない.mp3".UTF8String;
int fd = open(filename, O_RDWR, 0644);
long fsize = lseek(fd, 0, SEEK_END);
long p = fsize;
int chunkSize = 1024 * 128;
buf = (char*)malloc(chunkSize);
while (p > 0) {
p -= chunkSize;
if (p < 0) {
chunkSize += p;
p = 0;
}
pread(fd, buf, chunkSize, p);
pwrite(fd, buf, chunkSize, p+len);
}
lseek(fd, 0, SEEK_SET);
write(fd, buf, len);
free(buf);
close(fd);
id3_tag_delete(id3tag);