Re: lame_mp3_tags_fid and file access callbacks

2 messages Options
Embed this post
Permalink
Robert Hegemann

Re: lame_mp3_tags_fid and file access callbacks

Reply Threaded More More options
Print post
Permalink
Hi Aaron,

thank you very much for your patch, but I'll have to reject it.

Am Freitag, 8. Februar 2008 18:58 schrieb Aaron Patterson:

> Hi Robert,
>
> I've been working on Ruby bindings for LAME, and I've been having
> issues passing a file pointer to lame_mp3_tags_fid.  Sometimes I don't
> want to write to a file.  I was wondering if you would accept a patch
> to add a function that takes a struct of file access callbacks?
>
> I've attached the patch I wrote against lame (in CVS).  I hope you'll
> accept it!
>
> Thanks.

It's true, the lame_mp3_tags_fid function is really troublesome.
I had it on my todo list for a long time, but had no time to make
a workaround for it. As it seems I'm not the only one wanting a
solution for lame_mp3_tags_fid, I finally added some new API
functions to libmp3lame:

- to en-/dis- able automatic ID3 tag writing into audio stream (default on):

  void CDECL lame_set_write_id3tag_automatic(lame_global_flags * gfp, int);
  int CDECL lame_get_write_id3tag_automatic(lame_global_flags const* gfp);

- to query ID3 tags into a buffer:

  size_t CDECL lame_get_id3v1_tag(
        lame_global_flags * gfp, unsigned char* buffer, size_t size);
  size_t CDECL lame_get_id3v2_tag(
        lame_global_flags * gfp, unsigned char* buffer, size_t size);

- to query the final Xing/LAME tag frame into a buffer:

  size_t CDECL lame_get_lametag_frame(
        const lame_global_flags *, unsigned char* buffer, size_t size);

The LAME frontend program is using the new API functions too.


How to make the most out of it:

- before calling lame_init_param, disable automatic ID3 tag writing:

  lame_set_write_id3tag_automatic(gfp, 0);

- before writing any encoded audio data into file:

  imp3=lame_get_id3v2_tag(gfp, buffer, sizeof(buffer));
  fwrite(buffer, 1, imp3, outf);
  audio_pos=ftell(outf); // store beginning of audio data

- after encoding and flushing out all audio data:

  imp3=lame_get_id3v1_tag(gfp, buffer, sizeof(buffer));
  fwrite(buffer, 1, imp3, outf);

- now update the empty Xing/LAME tag frame in the beginning of audio stream:

  imp3=lame_get_lametag_frame(gfp, buffer, sizeof(buffer));
  fseek(outf,audio_pos,SEEK_SET); // remember beginning of audio data
  fwrite(buffer, 1, imp3, outf);

You want to add some error handling code, but I hope you get the idea of it.

If you have some more questions/suggestions, please let me know.


Ciao Robert


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Lame-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/lame-dev
Aaron Patterson-3

Re: lame_mp3_tags_fid and file access callbacks

Reply Threaded More More options
Print post
Permalink
On Sun, Feb 10, 2008 at 07:08:49PM +0100, Robert Hegemann wrote:

> Hi Aaron,
>
> thank you very much for your patch, but I'll have to reject it.
>
> Am Freitag, 8. Februar 2008 18:58 schrieb Aaron Patterson:
> > Hi Robert,
> >
> > I've been working on Ruby bindings for LAME, and I've been having
> > issues passing a file pointer to lame_mp3_tags_fid.  Sometimes I don't
> > want to write to a file.  I was wondering if you would accept a patch
> > to add a function that takes a struct of file access callbacks?
> >
> > I've attached the patch I wrote against lame (in CVS).  I hope you'll
> > accept it!
> >
> > Thanks.
>
> It's true, the lame_mp3_tags_fid function is really troublesome.
> I had it on my todo list for a long time, but had no time to make
> a workaround for it. As it seems I'm not the only one wanting a
> solution for lame_mp3_tags_fid, I finally added some new API
> functions to libmp3lame:
>
> - to en-/dis- able automatic ID3 tag writing into audio stream (default on):
>
>   void CDECL lame_set_write_id3tag_automatic(lame_global_flags * gfp, int);
>   int CDECL lame_get_write_id3tag_automatic(lame_global_flags const* gfp);
>
> - to query ID3 tags into a buffer:
>
>   size_t CDECL lame_get_id3v1_tag(
>         lame_global_flags * gfp, unsigned char* buffer, size_t size);
>   size_t CDECL lame_get_id3v2_tag(
>         lame_global_flags * gfp, unsigned char* buffer, size_t size);
>
> - to query the final Xing/LAME tag frame into a buffer:
>
>   size_t CDECL lame_get_lametag_frame(
>         const lame_global_flags *, unsigned char* buffer, size_t size);
>
> The LAME frontend program is using the new API functions too.
>
>
> How to make the most out of it:
>
> - before calling lame_init_param, disable automatic ID3 tag writing:
>
>   lame_set_write_id3tag_automatic(gfp, 0);
>
> - before writing any encoded audio data into file:
>
>   imp3=lame_get_id3v2_tag(gfp, buffer, sizeof(buffer));
>   fwrite(buffer, 1, imp3, outf);
>   audio_pos=ftell(outf); // store beginning of audio data
>
> - after encoding and flushing out all audio data:
>
>   imp3=lame_get_id3v1_tag(gfp, buffer, sizeof(buffer));
>   fwrite(buffer, 1, imp3, outf);
>
> - now update the empty Xing/LAME tag frame in the beginning of audio stream:
>
>   imp3=lame_get_lametag_frame(gfp, buffer, sizeof(buffer));
>   fseek(outf,audio_pos,SEEK_SET); // remember beginning of audio data
>   fwrite(buffer, 1, imp3, outf);
>
> You want to add some error handling code, but I hope you get the idea of it.
>
> If you have some more questions/suggestions, please let me know.

Perfect.  Thank you.  This looks like a better solution than mine, and
I'll start using it!

--
Aaron Patterson
http://tenderlovemaking.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Lame-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/lame-dev