[flac-dev] Writing seektable using libFLAC++

Bastiaan Timmer basjetimmer at yahoo.com
Tue Apr 24 07:41:28 PDT 2012


Hi! I've been using a little C++ program I've written to encode flac files. The program does this in the usual way (I think), by inheriting a class from FLAC::Encoder::File, and passing it chunks of raw samples through process_interleaved()... Anyway, the program works beautifully, and I've now decided to try and add some metadata to the encoded flacs. Eventually, there will be vorbis comments, but right now I'm just trying to add a seektable. From some code examples I've managed to get it working  using the libFLAC C API like this:

  FLAC__StreamMetadata *md[1];
  md[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);  // THIS LEAKS
  FLAC__metadata_object_seektable_template_append_spaced_points(md[0], 13, d_bytestotal / 4);
  FLAC__metadata_object_seektable_template_sort(md[0], true);
  set_metadata(md, 1);

Now, I have several questions:

1. Most importantly: How can I get this to work with the libFLAC++ API? Do I not _need_ the template-methods, and are they not missing from the C++ API? I've also tried getting just half the metadata code from the C++ API and using the C API for the template-functions, like this:

  FLAC::Metadata::Prototype *md[1];
  FLAC__StreamMetadata *seektable = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
  FLAC__metadata_object_seektable_template_append_spaced_points(seektable, 13, d_bytestotal / 4);
  FLAC__metadata_object_seektable_template_sort(seektable, true);
  md[0] = new FLAC::Metadata::SeekTable(seektable);
  set_metadata(md, 1);

But that does not seem to work. Checking md[0]->type(), and md[0]->is_valid() and md[0]->is_legal() all return expected values, but the resulting flac has no seektable, but instead a 0-length metadata block of type 56 (UNKNOWN). So what am I doing wrong? And can I get rid of the C API calls altogether? Also, as you can see I'm arbitrarily creating 13 seekpoints, this is just for testing. But what is a good amount of seekpoints, how does the official flac binary determine a default?

2. I noticed while reading the source that all FLAC::Metadata::Prototype child classes have default constructors, that seem to do what you'd expect. They are not mentioned in the API docs (for example: http://flac.sourceforge.net/api/classFLAC_1_1Metadata_1_1SeekTable.html). Can this be considered a bug?

3. Assuming the FLAC__metadata_object_seektable_template_* functions are necessary for creating a proper seektable, and that these functions don't exist in the C++ API, would it be appreciated if I wrote some wrappers for these functions as members of the FLAC::Metadata::Seektable class? I'm assuming these functions would just be one-liners, so I should be capable and willing to do that. The same goes for all other FLAC__metadata_object_* functions not already wrapped in the appropriate FLAC::Metadata::Prototype children.

Sorry for the long message... but thanks for reading!

bepaald



More information about the flac-dev mailing list