--- Joshua Kwan <joshk@triplehelix.org> wrote:> Well, I'm quite frankly stumped. I'm writing a program that recurses > into directories and reads (among others) FLAC files and should be > able > to read the vorbis comments ARTIST and TITLE from the file. > > A while back, I was popen()ing to metaflac, because I didn't want to > mess with libFLAC. But now, it's the weekend, so I can mess around > with > this. Here's the code in question:...> When I run this code, I get a SEGV during get_comment because > object_->data.vorbis_comment.comments is junk. Must I initialize it > somewhere? Note that vc.get_num_comments returns 14, which I imagine > is > a correct number. The documentation isn't overly clear about how this > works > and it would be cooler if some basic examples could be provided. > > Thanks in advance for any help that can be provided. Excuse my > ignorance! :(it's in the API docs; here's one link: http://flac.sourceforge.net/api/group__flac__metadata__level1.html#_details The C++ interface is a little simpler: FLAC::Metadata::SimpleIterator it; if (it.is_valid()) { if (it.init(filename, true, true)) { FLAC::Metadata::VorbisComment *vc = 0; do { if (it.get_block_type() =::FLAC__METADATA_TYPE_VORBIS_COMMENT) { vc dynamic_cast<FLAC::Metadata::VorbisComment*>(it.get_block()); assert(0 != vc); } } while (!vc && it.next()); //use vc delete vc; } } maybe I should add a shorthand function similar to flac__metadata_get_streaminfo() Josh __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree
Well, I'm quite frankly stumped. I'm writing a program that recurses into directories and reads (among others) FLAC files and should be able to read the vorbis comments ARTIST and TITLE from the file. A while back, I was popen()ing to metaflac, because I didn't want to mess with libFLAC. But now, it's the weekend, so I can mess around with this. Here's the code in question: bool getflac (struct Song* flac, const char* path) { FLAC__StreamMetadata *md = FLAC__metadata_object_new (FLAC__METADATA_TYPE_STREAMINFO); if (FLAC__metadata_get_streaminfo(path, md)) { unsigned nc = 0, i; FLAC::Metadata::VorbisComment vc (md); nc = vc.get_num_comments(); for (i = 0; i <= nc; i++) { FLAC::Metadata::VorbisComment::Entry e; e = vc.get_comment(i); if (!strcmp(e.get_field_name(), "ARTIST")) flac->artist = e.get_field_value(); else if (!strcmp(e.get_field_name(), "TITLE")) flac->title = e.get_field_value(); } return true; } else return false; } When I run this code, I get a SEGV during get_comment because object_->data.vorbis_comment.comments is junk. Must I initialize it somewhere? Note that vc.get_num_comments returns 14, which I imagine is a correct number. The documentation isn't overly clear about how this works and it would be cooler if some basic examples could be provided. Thanks in advance for any help that can be provided. Excuse my ignorance! :( -- Joshua Kwan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 827 bytes Desc: Digital signature Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20031107/fcbc8514/attachment.pgp
On Fri, 2003-11-07 at 22:56, Joshua Kwan wrote:> Well, I'm quite frankly stumped. I'm writing a program that recurses > into directories and reads (among others) FLAC files and should be able > to read the vorbis comments ARTIST and TITLE from the file. > > A while back, I was popen()ing to metaflac, because I didn't want to > mess with libFLAC. But now, it's the weekend, so I can mess around with > this. Here's the code in question: > > bool getflac (struct Song* flac, const char* path) > { > FLAC__StreamMetadata *md = FLAC__metadata_object_new (FLAC__METADATA_TYPE_STREAMINFO); > > if (FLAC__metadata_get_streaminfo(path, md)) > { > unsigned nc = 0, i; > FLAC::Metadata::VorbisComment vc (md);There are several different types of metadata blocks: you have obtained the STREAMINFO block and tried to treat it like a VORBISCOMMENT block by passing it to the VorbisComment constructor. You will need to iterate through the metadata blocks until you find a VORBISCOMMENT block. See http://flac.sourceforge.net/format.html for more information about the format, and more detail on the different kinds of metadata blocks. I have not used the C++ interface, but I think this is your problem. For an example of reading vorbiscomments from a FLAC file, you can see my vorbiscomment support for Rhythmbox. It uses the C interface, though, and uses the stream decoder instead of the metadata iterator interface (this is so it can support streams in addition to files): http://cvs.gnome.org/lxr/source/rhythmbox/monkey-media/stream-info-impl/flac-stream-info-impl.c See FLAC_stream_info_impl_open_stream() and FLAC_metadata_callback(). Josh
Hi me (2x - Haberman and Coalson), On Tue, Nov 11, 2003 at 03:51:42PM -0800, Josh Coalson wrote:> The C++ interface is a little simpler:[code follows] OK. Well, I found the C interface a little bit easier to understand, so I ended up using that instead of continuing to try to figure out the C++ interface. The one problem I have is that the values in block->data. vorbis_comment.comments tend to have trailing junk. For example: Breakpoint 1, get_flac(Song*, char const*) (flac=0x806b8a8, path=0x8068844 "/usr/share/mp3/01-dazed_and_confused.flac") at ftfuncs.cc:53 53 for (i = 0; i < e->length; i++) (gdb) p e->entry $6 = (FLAC__byte *) 0x8066118 "TITLE=Dazed And Confused8Ini\021" [...] This only seems to happen sometimes, and the only reliable way to prevent myself from treading into wild memory is to iterate e->length times over each character in e->entry every single time and not go one byte further. I'm obviously doing something slightly wrong I suppose. The offending code is at <http://cvs.triplehelix.org/tagreport/ftfuncs.cc>, function get_flac(). But thanks for all your help. I might change to the C++ interface later if I have time since the rest of the project is in C++ anyway. Thanks, -- Joshua Kwan -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 827 bytes Desc: not available Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20031111/49c10dca/attachment.pgp