> 
> On Mon, Jan 31, 2000 at 12:36:36PM +0100, Felix von Leitner wrote:
> > PS: This is my first email to this list, so I should also mention that I
> > submitted the RTP patch to lame (in case anyone wants to ask me
> > anything about it).
> 

I have been using mp3rtp.c as an example of the 'correct' way to use
the lame encoding library.  The rtp code is included with the LAME
source, but it must be compiled separately (make mp3rtp).  With a
few changes to the makefile, this program can be compiled by linking
to libmp3lame.a, and it requires no special hooks or modifications
into the lame source code, and only needs to include "lame.h".

The lame library interface is still undergoing a lot of changes, so
for any library developers or library users out there, suggestions and
comments are welcome :-)

The biggest change right now is that the core fuctions do no
file i/o of any kind.  You are now required to do your own mp3 file
output (as shown below).  You can do your own PCM input, or use
lame_init_infile(), lame_readframe()

Mark






Here is a section from main() of mp3rtp.c:


  /* initialize encoder */
  gf=lame_init();

  /* Remove the arguments that are rtp related, and then 
   * parse the command line arguments, setting various flags in the
   * struct pointed to by 'gf'.  If you want to parse your own arguments,
   * or call libmp3lame from a program which uses a GUI to set arguments,
   * skip this call and set the values of interest in the gf-> struct.  
   * (see lame.h for documentation about these parameters)
   */
  for (i=1; i<argc-1; i++)  /* remove first argument, it was for rtp */
    argv[i]=argv[i+1];
  lame_parse_args(argc-1, argv); 

  /* open the output file.  Filename was parsed into gf->inPath */
  if (!strcmp(gf->outPath, "-")) {
    outf = stdout;
  } else {
    if ((outf = fopen(gf->outPath, "wb")) == NULL) {
      fprintf(stderr,"Could not create \"%s\".\n", gf->outPath);
      exit(1);
    }
  }


  /* open the wav/aiff/raw pcm or mp3 input file.  This call will
   * open the file with name gf->inFile, try to parse the headers and
   * set gf->samplerate, gf->num_channels, gf->num_samples.
   * if you want to do your own file input, skip this call and set
   * these values yourself.  
   */
  lame_init_infile();


  /* Now that all the options are set, lame needs to analyze them and
   * set some more options 
   */
  lame_init_params();
  lame_print_config();   /* print usefull information about options being used */


  samples_to_encode = gf->encoder_delay + 288;
  /* encode until we hit eof */
  do {
    /* read in gf->framesize samples.  If you are doing your own file input
     * replace this by a call to fill Buffer with exactly gf->framesize sampels */
    iread=lame_readframe(Buffer);
    imp3=lame_encode(Buffer,mp3buffer);  /* encode the frame */
    fwrite(mp3buffer,1,imp3,outf);       /* write the MP3 output to file  */
    rtp_output(mp3buffer,imp3);          /* write MP3 output to RTP port */    
    samples_to_encode += iread - gf->framesize;
  } while (iread);
  
  /* encode until we flush internal buffers.  (Buffer=0 at this point */
  while (samples_to_encode > 0) {
    imp3=lame_encode(Buffer,mp3buffer);
    fwrite(mp3buffer,1,imp3,outf);
    rtp_output(mp3buffer,imp3);
    samples_to_encode -= gf->framesize;
  }
  

  imp3=lame_encode_finish(mp3buffer);   /* may return one more mp3 frame */
  fwrite(mp3buffer,1,imp3,outf);  
  rtp_output(mp3buffer,imp3);
  fclose(outf);
  lame_mp3_tags();                /* add id3 or VBR tags to mp3 file */


--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to