0

I'm trying to create LAME mp3 encoder GUI with Objective-C. I've learned many thing and copied many codes from iTunes-LAME.app. This time, I copied and modified id3tag writing function from iTunes-LAME.app. But in the copied and modified function, I got corrupted characters with 2byte language. I think may be something wrong with it but I can't figure out what is wrong. Here's the function. Please help me!!

EDIT: My modified id3tag writing function is works fine for single-byte language and numeric values.

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);
xanadu6291
  • 931
  • 10
  • 20
  • Could you provide reference for that library? I almost sure it have methods, that take unicode-strings in arguments. – Cy-4AH Sep 26 '14 at 13:37
  • Sorry since I am inexperienced with Objective-c, I can't understand what is the reference mean. Dose it mean a documentation for the function? If so, there are no documentation with libid3tag. That is the reason of my headache. Or do you mean reference counter or something? How can I provide it for you? – xanadu6291 Sep 26 '14 at 17:18
  • I've found that there is header file of libid3tag "id3tag.h" but this is not online. if you need "id3tag.h", I can provide it personally. i.e. via E-mail or something. – xanadu6291 Sep 27 '14 at 16:07
  • Sorry! I found the online one. [id3tag.h](https://gitorious.org/linux-nios2/uclinux-dist/source/bc0184418725e80ded340026e0f043c380b24d2b:lib/libid3tag/libid3tag-0.15.1b/id3tag.h#L233) – xanadu6291 Sep 27 '14 at 16:19

1 Answers1

1

By adding

id3_field_settextencoding(&frame->fields[0], ID3_FIELD_TEXTENCODING_UTF_8);

below line

id3_ucs4_t *ucs4 = id3_utf8_ucs4duplicate((const id3_utf8_t*)@"日本語".UTF8String);

I can solve the problem. I don't know why iTunes-LAME.app can handle multibyte language without "id3_field_settextencoding". But anyway the problem was gone. I'm very happy!!

xanadu6291
  • 931
  • 10
  • 20