Пример #1
0
    MP3Encoder(UINT bitRate)
    {
        curBitRate = bitRate;

        lgf = lame_init();
        if(!lgf)
            CrashError(TEXT("Unable to open mp3 encoder"));

        lame_set_in_samplerate(lgf, App->GetSampleRateHz());
        lame_set_out_samplerate(lgf, App->GetSampleRateHz());
        lame_set_num_channels(lgf, 2);
        lame_set_mode(lgf, STEREO);
        lame_set_disable_reservoir(lgf, TRUE); //bit reservoir has to be disabled for seamless streaming
        lame_set_VBR(lgf, vbr_off);
        lame_set_brate(lgf, bitRate);
        lame_init_params(lgf);

        outputFrameSize = lame_get_framesize(lgf); //1152 usually
        dwMP3MaxSize = DWORD(1.25*double(outputFrameSize*audioBlockSize) + 7200.0);
        MP3OutputBuffer.SetSize(dwMP3MaxSize+1);
        MP3OutputBuffer[0] = 0x2f;

        bFirstPacket = true;

        Log(TEXT("------------------------------------------"));
        Log(TEXT("%s"), GetInfoString().Array());
    }
Пример #2
0
/* initialize the lame library */
static void mp3streamout_tilde_lame_init(t_mp3streamout *x)
{
    int    ret;
    x->lgfp = lame_init(); /* set default parameters for now */

#ifdef _WIN32
    /* load lame_enc.dll library */
    HINSTANCE dll;
    dll=LoadLibrary("lame_enc.dll");
    if(dll==NULL)
    {
        error("mp3streamout~: error loading lame_enc.dll");
        closesocket(x->x_fd);
        x->x_fd = -1;
        outlet_float(x->x_obj.ob_outlet, 0);
        post("mp3streamout~: connection closed");
        return;
    }
#endif
    {
        const char *lameVersion = get_lame_version();
        logpost(NULL, 4,  "mp3streamout~ : using lame version : %s", lameVersion );
    }

    /* setting lame parameters */
    lame_set_num_channels( x->lgfp, 2);
    lame_set_in_samplerate( x->lgfp, sys_getsr() );
    lame_set_out_samplerate( x->lgfp, x->x_samplerate );
    lame_set_brate( x->lgfp, x->x_bitrate );
    lame_set_mode( x->lgfp, x->x_mp3mode );
    lame_set_quality( x->lgfp, x->x_mp3quality );
    lame_set_emphasis( x->lgfp, 1 );
    lame_set_original( x->lgfp, 1 );
    lame_set_copyright( x->lgfp, 1 ); /* viva free music societies !!! */
    lame_set_disable_reservoir( x->lgfp, 0 );
    //lame_set_padding_type( x->lgfp, PAD_NO ); /* deprecated in LAME */
    ret = lame_init_params( x->lgfp );
    if ( ret<0 )
    {
        post( "mp3streamout~ : error : lame params initialization returned : %d", ret );
    }
    else
    {
        x->x_lame=1;
        /* magic formula copied from windows dll for MPEG-I */
        x->x_lamechunk = 2*1152;

        post( "mp3streamout~ : lame initialization done. (%d)", x->x_lame );
    }
    lame_init_bitstream( x->lgfp );
}
Пример #3
0
    /* initialize the lame library */
static int mp3write_tilde_lame_init(t_mp3write *x)
{
  time_t now;

    int    ret;
    x->lgfp = lame_init(); /* set default parameters for now */

#ifndef UNIX
    /* load lame_enc.dll library */
    HINSTANCE dll;
    dll=LoadLibrary("lame_enc.dll");
    if(dll==NULL)
    {
        error("mp3write~: error loading lame_enc.dll");
        closesocket(x->x_fd);
        x->x_fd = -1;
        post("mp3write~: connection closed");
        return -1;
    }
#endif
    {
       const char *lameVersion = get_lame_version();
       post( "mp3write~ : using lame version : %s", lameVersion );
    }

        /* setting lame parameters */
    lame_set_num_channels( x->lgfp, 2);
    lame_set_in_samplerate( x->lgfp, sys_getsr() );
    lame_set_out_samplerate( x->lgfp, x->x_samplerate );
    lame_set_brate( x->lgfp, x->x_bitrate );
    lame_set_mode( x->lgfp, x->x_mp3mode );
    lame_set_quality( x->lgfp, x->x_mp3quality );
    lame_set_emphasis( x->lgfp, 1 );
    lame_set_original( x->lgfp, 1 );
    lame_set_copyright( x->lgfp, 1 ); /* viva free music societies !!! */
    lame_set_disable_reservoir( x->lgfp, 0 );
    lame_set_padding_type( x->lgfp, PAD_NO );
    ret = lame_init_params( x->lgfp );
    if ( ret<0 ) {
       post( "mp3write~ : error : lame params initialization returned : %d", ret );
       return -1;
    } else {
       x->x_lame=1;
       /* magic formula copied from windows dll for MPEG-I */
       x->x_lamechunk = 2*1152;

       post( "mp3write~ : lame initialization done. (%d)", x->x_lame );
    }
    lame_init_bitstream( x->lgfp );

    /* setting tag information */
    id3tag_init(x->lgfp);
    id3tag_v1_only(x->lgfp);
    id3tag_space_v1(x->lgfp);
    id3tag_set_artist(x->lgfp, "Pd Session");
    now=time(NULL);
    sprintf( x->x_title, "Started at %s", ctime(&now) );
    id3tag_set_title(x->lgfp, x->x_title );
    
    return 0;

}
bool AUDMEncoder_Lame::initialize (void)
{

  int ret;
  MPEG_mode_e mmode;
  uint32_t frequence;



  lameFlags = lame_init ();
  if (lameFlags == NULL)
    return false;

  if (_incoming->getInfo ()->channels > 2)
    {
      printf ("[Lame]Too many channels\n");
      return false;
    }

  // recompute output length


  ret = lame_set_in_samplerate (MYFLAGS, wavheader.frequency);
  ret = lame_set_num_channels (MYFLAGS,  wavheader.channels);


  frequence = wavheader.frequency;
  printf ("[Lame] output frequency : %"PRIu32"\n", frequence);
  ret = lame_set_out_samplerate (MYFLAGS, frequence);

  ret = lame_set_quality (MYFLAGS, 2);

  if (wavheader.channels == 2)
    {

          mmode = STEREO;
    }
  else
    {
      mmode = MONO;
      printf ("[Lame] mono audio mp3");
    }

  ret = lame_set_brate (MYFLAGS, _config.bitrate);
  ret = lame_set_mode (MYFLAGS, mmode);	// 0 stereo 1 jstero
  ret = lame_set_quality (MYFLAGS, _config.quality);	// 0 stereo 1 jstero
  ret = lame_set_disable_reservoir (MYFLAGS, _config.disableBitReservoir);
  printf ("[Lame]Using quality of %d\n", lame_get_quality (MYFLAGS));
  // update bitrate in header
  wavheader.byterate = (_config.bitrate >> 3) * 1000;
#define BLOCK_SIZE 1152
  // configure CBR/ABR/...

  switch (_config.preset)
    {
    default:
    case ADM_LAME_PRESET_CBR:
        ADM_info("Lame : CBR Mode\n");
      break;
    case ADM_LAME_PRESET_ABR:
        ADM_info("Lame : ABR Mode\n");

      lame_set_preset (MYFLAGS, _config.bitrate);
      wavheader.blockalign = BLOCK_SIZE;
      break;
    case ADM_LAME_PRESET_EXTREME:
        ADM_info("Lame : Extreme Mode\n");
      wavheader.blockalign = BLOCK_SIZE;
      lame_set_preset (MYFLAGS, EXTREME);
      break;


    }
  ret = lame_init_params (MYFLAGS);
  if (ret == -1)
    {
        printf("[Lame] Init params failes %d\n",ret);
        return false;
    }

  lame_print_config (MYFLAGS);
  lame_print_internals (MYFLAGS);
  _chunk = BLOCK_SIZE * wavheader.channels;

  return true;
}
//________________________________________________
//   Init lame encoder
// frequence    : Impose frequency , 0 means reuse the incoming fq
// mode                         : ADM_STEREO etc...
// bitrate              : Bitrate in kbps (96,192...)
// return 0 : init failed
//                              1 : init succeeded
//_______________________________________________
uint8_t AUDMEncoder_Lame::init(ADM_audioEncoderDescriptor *config)
{
  int ret;
  MPEG_mode_e mmode;
  uint32_t frequence;
  LAME_encoderParam *lameConf=(LAME_encoderParam *)config->param;
      ADM_assert(config->paramSize==sizeof(LAME_encoderParam));

      lameFlags = lame_init();
      if (lameFlags == NULL)
          return 0;
      
      if(_incoming->getInfo()->channels>2)
      {
        printf("Too many channels\n");
        return 0; 
      }

	// recompute output length
	
      
      ret = lame_set_in_samplerate(MYFLAGS, _wavheader->frequency);
      ret = lame_set_num_channels(MYFLAGS, _wavheader->channels);

    
      frequence = _wavheader->frequency;
    printf("\n output frequency : %lu\n", frequence);
    ret = lame_set_out_samplerate(MYFLAGS, frequence);

    ret = lame_set_quality(MYFLAGS, 2);
    
    if (_wavheader->channels == 2)
      {
        switch (lameConf->mode)
	    {
	    case ADM_STEREO:
		mmode = STEREO;
		break;
	    case ADM_JSTEREO:
		mmode = JOINT_STEREO;
		break;
	    default:
		printf("\n **** unknown mode ***\n");
		mmode = STEREO;
		break;

	    }
    } else
    {
		mmode = MONO;
     	printf("\n mono audio mp3");
  	}

        ret = lame_set_brate(MYFLAGS, config->bitrate);
        ret = lame_set_mode(MYFLAGS, mmode);	// 0 stereo 1 jstero
        ret = lame_set_quality(MYFLAGS, lameConf->quality);	// 0 stereo 1 jstero
        ret = lame_set_disable_reservoir(MYFLAGS,lameConf->disableReservoir);
        printf("[Lame]Using quality of %d\n",lame_get_quality(MYFLAGS));
        ret = lame_init_params(MYFLAGS);
    if (ret == -1)
	return 0;
    // update bitrate in header
    _wavheader->byterate = (config->bitrate >> 3) * 1000;
#define BLOCK_SIZE 1152
    // configure CBR/ABR/...
    _preset=lameConf->preset;
    switch(_preset)
    {
    	default:
    	case ADM_LAME_PRESET_CBR: 
          break;
	case ADM_LAME_PRESET_ABR:
	  
          lame_set_preset( MYFLAGS, config->bitrate);
	  _wavheader->blockalign=BLOCK_SIZE;
	 break;
	case ADM_LAME_PRESET_EXTREME: 
	  _wavheader->blockalign=BLOCK_SIZE;
          lame_set_preset( MYFLAGS, EXTREME);	
	break;
    
    
    }

    lame_print_config(MYFLAGS);
    lame_print_internals(MYFLAGS);
    _chunk=BLOCK_SIZE*_wavheader->channels;
    return 1;
}