Skip to content
Myr

Add comment support to stb_vorbis

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Audino · committed by Audino · parent 052dce1 · Browse files · 1 file+77 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+77 added−1 removed

  • other:+77 added−1 removed

1 file+77 added−1 removed

modified:stb_vorbis.c+77 added-1 removed
128 unmodified lines
129130 int max_frame_size;131} stb_vorbis_info;132133typedef struct134{135 char *vendor;136137 int comment_list_length;138 char **comment_list;139} stb_vorbis_comment;140141// get general information about the file142extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f);143144// get ogg comments145extern stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f);146147// get the last error detected (clears it, too)148extern int stb_vorbis_get_error(stb_vorbis *f);149150// close an ogg vorbis file and free all memory in use
618 unmodified lines
769 unsigned int setup_memory_required;770 unsigned int temp_memory_required;771 unsigned int setup_temp_memory_required;772773 char *vendor;774 int comment_list_length;775 char **comment_list;776777 // input config778#ifndef STB_VORBIS_NO_STDIO779 FILE *f;780 uint32 f_start;
772 unmodified lines
1553 f->valid_bits = 0;1554 return x;1555}15561557static int get32_packet(vorb *f)1558{1559 uint32 x;1560 x = get8_packet(f);1561 x += get8_packet(f) << 8;1562 x += get8_packet(f) << 16;1563 x += (uint32) get8_packet(f) << 24;1564 return x;1565}15661567static void flush_packet(vorb *f)1568{1569 while (get8_packet_raw(f) != EOP);1570}
2084 unmodified lines
3655 if (!(x & 1)) return error(f, VORBIS_invalid_first_page);36563657 // second packet!3658 if (!start_page(f)) return FALSE;36343659 3660 if (!start_packet(f)) return FALSE;36613662 if (!next_segment(f)) return FALSE;36633664 if (get8_packet(f) != VORBIS_packet_comment) return error(f, VORBIS_invalid_setup);3665 for (i=0; i < 6; ++i) header[i] = get8_packet(f);3666 if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);3667 //file vendor3668 len = get32_packet(f);3669 f->vendor = (char*)setup_malloc(f, sizeof(char) * (len+1));3670 for(i=0; i < len; ++i) {3671 f->vendor[i] = get8_packet(f);3672 }3673 f->vendor[len] = (char)NULL;3674 //user comments3675 f->comment_list_length = get32_packet(f);3676 f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length));3677 3678 for(i=0; i < f->comment_list_length; ++i) {3679 len = get32_packet(f);3680 f->comment_list[i] = (char*)setup_malloc(f, sizeof(char) * (len+1));36813682 for(j=0; j < len; ++j) {3683 f->comment_list[i][j] = get8_packet(f);3684 }3685 f->comment_list[i][len] = (char)NULL;3686 }36873688 // framing_flag3689 x = get8_packet(f);3690 if (!(x & 1)) return error(f, VORBIS_invalid_setup);36913692 3693 skip(f, f->bytes_in_seg);3694 f->bytes_in_seg = 0;36953696 do {3697 len = next_segment(f);3698 skip(f, len);3699 f->bytes_in_seg = 0;
508 unmodified lines
42084209static void vorbis_deinit(stb_vorbis *p)4210{4211 int i,j;42124213 setup_free(p, p->vendor);4214 for (i=0; i < p->comment_list_length; ++i) {4215 setup_free(p, p->comment_list[i]);4216 }4217 setup_free(p, p->comment_list);42184219 if (p->residue_config) {4220 for (i=0; i < p->residue_count; ++i) {4221 Residue *r = p->residue_config+i;4222 if (r->classdata) {
91 unmodified lines
4314 d.max_frame_size = f->blocksize_1 >> 1;4315 return d;4316}43174318stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f)4319{4320 stb_vorbis_comment d;4321 d.vendor = f->vendor;4322 d.comment_list_length = f->comment_list_length;4323 d.comment_list = f->comment_list;4324 return d;4325}43264327int stb_vorbis_get_error(stb_vorbis *f)4328{4329 int e = f->error;4330 f->error = VORBIS__no_error;
1248 unmodified lines