예제 #1
0
파일: layer3.c 프로젝트: dariaphoebe/shine
/* Compute default encoding values. */
shine_global_config *shine_initialise(shine_config_t *pub_config)
{
  double avg_slots_per_frame;
  shine_global_config *config;

  config = calloc(1,sizeof(shine_global_config));
  if (config == NULL)
    return config;

  shine_subband_initialise(config);
  shine_mdct_initialise(config);
  shine_loop_initialise(config);
  shine_formatbits_initialise(config);
  shine_bitstream_initialise(config );

  /* Copy public config. */
  config->wave.channels   = pub_config->wave.channels;
  config->wave.samplerate = pub_config->wave.samplerate; 
  config->mpeg.mode       = pub_config->mpeg.mode;     
  config->mpeg.bitr       = pub_config->mpeg.bitr; 
  config->mpeg.emph       = pub_config->mpeg.emph; 
  config->mpeg.copyright  = pub_config->mpeg.copyright;  
  config->mpeg.original   = pub_config->mpeg.original; 

  /* Set default values. */
  config->ResvMax        = 0;
  config->ResvSize       = 0;
  config->mpeg.crc       = 0;
  config->mpeg.ext       = 0;
  config->mpeg.mode_ext  = 0;

  config->mpeg.bits_per_slot     = 8;

  /* Figure average number of 'slots' per frame. */
  avg_slots_per_frame = ((double)samp_per_frame /
                        ((double)config->wave.samplerate/1000)) *
                        ((double)config->mpeg.bitr /
                         (double)config->mpeg.bits_per_slot);

  config->mpeg.whole_slots_per_frame  = (int)avg_slots_per_frame;

  config->mpeg.frac_slots_per_frame  = avg_slots_per_frame - (double)config->mpeg.whole_slots_per_frame;
  config->mpeg.slot_lag              = -config->mpeg.frac_slots_per_frame;

  if(config->mpeg.frac_slots_per_frame==0)
    config->mpeg.padding = 0;

  config->mpeg.samplerate_index = shine_find_samplerate_index(config->wave.samplerate);
  config->mpeg.bitrate_index    = shine_find_bitrate_index(config->mpeg.bitr)+1;

  shine_open_bit_stream(&config->bs, BUFFER_SIZE);

  memset((char *)&config->side_info,0,sizeof(shine_side_info_t));

  config->sideinfo_len = (config->wave.channels==1) ? 168 : 288;

  return config;
}
예제 #2
0
/* Compute default encoding values. */
shine_global_config *shine_initialise(shine_config_t *pub_config)
{
  double avg_slots_per_frame;
  shine_global_config *config;

  if (shine_check_config(pub_config->wave.samplerate, pub_config->mpeg.bitr) < 0)
    return NULL;

  config = calloc(1,sizeof(shine_global_config));
  if (config == NULL)
    return config;

  shine_subband_initialise(config);
  shine_mdct_initialise(config);
  shine_loop_initialise(config);
  shine_formatbits_initialise(config);
  shine_bitstream_initialise(config );

  /* Copy public config. */
  config->wave.channels   = pub_config->wave.channels;
  config->wave.samplerate = pub_config->wave.samplerate; 
  config->mpeg.mode       = pub_config->mpeg.mode;     
  config->mpeg.bitr       = pub_config->mpeg.bitr; 
  config->mpeg.emph       = pub_config->mpeg.emph; 
  config->mpeg.copyright  = pub_config->mpeg.copyright;  
  config->mpeg.original   = pub_config->mpeg.original; 

  /* Set default values. */
  config->ResvMax             = 0;
  config->ResvSize            = 0;
  config->mpeg.layer          = LAYER_III;
  config->mpeg.crc            = 0;
  config->mpeg.ext            = 0;
  config->mpeg.mode_ext       = 0;
  config->mpeg.bits_per_slot  = 8;

  config->mpeg.samplerate_index   = shine_find_samplerate_index(config->wave.samplerate);
  config->mpeg.version            = shine_mpeg_version(config->mpeg.samplerate_index);
  config->mpeg.bitrate_index      = shine_find_bitrate_index(config->mpeg.bitr, config->mpeg.version);
  config->mpeg.granules_per_frame = granules_per_frame[config->mpeg.version];

  /* Figure average number of 'slots' per frame. */
  avg_slots_per_frame = ((double)config->mpeg.granules_per_frame * GRANULE_SIZE /
                        ((double)config->wave.samplerate)) *
                        (1000*(double)config->mpeg.bitr /
                         (double)config->mpeg.bits_per_slot);

  config->mpeg.whole_slots_per_frame  = (int)avg_slots_per_frame;

  config->mpeg.frac_slots_per_frame  = avg_slots_per_frame - (double)config->mpeg.whole_slots_per_frame;
  config->mpeg.slot_lag              = -config->mpeg.frac_slots_per_frame;

  if(config->mpeg.frac_slots_per_frame==0)
    config->mpeg.padding = 0;

  shine_open_bit_stream(&config->bs, BUFFER_SIZE);

  memset((char *)&config->side_info,0,sizeof(shine_side_info_t));

  /* determine the mean bitrate for main data */
  if (config->mpeg.granules_per_frame == 2) /* MPEG 1 */
    config->sideinfo_len = 8 * ((config->wave.channels==1) ? 4 + 17 : 4 + 32);
  else                /* MPEG 2 */
    config->sideinfo_len = 8 * ((config->wave.channels==1) ? 4 + 9 : 4 + 17);

  return config;
}