Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed


#include "mpg123/mpg123.h"
#include <stdlib.h>

/* stub */
FILE *http_open (char *url)
{
  return NULL;
}



static long rates[3][3] = {
 { 32000,44100,48000 } ,
 { 16000,22050,24000 } ,
 {  8000,11025,12000 }
};

int supported_rates = 0;

int outmode = DECODE_AUDIO;

char *listname = NULL;
long outscale  = 32768;
int checkrange = FALSE;
int tryresync  = TRUE;
int quiet      = FALSE;
int verbose    = 0;
int doublespeed= 0;
int halfspeed  = 0;
int shuffle = 0;
int change_always = 1;
int force_8bit = 0;
int force_frequency = -1;
long numframes = -1;
long startFrame= 0;
int usebuffer  = 0;
int frontend_type = 0;
int remote     = 0;
int buffer_fd[2];
int buffer_pid;


static int intflag = FALSE;
static int remflag = FALSE;


static char remote_buffer[1024];
static struct frame fr;
static struct audio_info_struct ai;
txfermem *buffermem;
#define FRAMEBUFUNIT (18 * 64 * 4)

void init_output(void)
{
  static int init_done = FALSE;

  if (init_done)
    return;
  init_done = TRUE;

  if (!(pcm_sample = (unsigned char *) malloc(audiobufsize * 2))) {
    perror ("malloc()");
    l1_exit (1);

  }

  if(outmode==DECODE_AUDIO) {
    //if(audio_open(&ai) < 0) {
    //  perror("audio");
    //  exit(1);
    // }
    /* audio_set_rate (&ai);  should already be done in audio_open() [OF] */
  }
}

static void reset_audio_samplerate(void)
{

  //if (outmode == DECODE_AUDIO) {
    /* audio_reset_parameters(&ai); */
    /*   close and re-open in order to flush
     *   the device's internal buffer before
     *   changing the sample rate.   [OF]
     */

  //audio_close (&ai);
    //if (audio_open(&ai) < 0) {
  //  perror("audio");
  //   exit(1);
  // }
  // }
}

void play_frame(int init,struct frame *fr)
{
  int clip;

  if((fr->header_change && change_always) || init) {
    int reset_audio = 0;

    if(remote)
      print_rheader(fr);

    if (!quiet && init) {
      if (verbose)
        print_header(fr);
      else
        print_header_compact(fr);
    }

    if(force_frequency < 0) {
      if(ai.rate != freqs[fr->sampling_frequency]>>(fr->down_sample)) {
        ai.rate = freqs[fr->sampling_frequency]>>(fr->down_sample);
        reset_audio = 1;
      }
    }
    else if(ai.rate != force_frequency) {
      ai.rate = force_frequency;
      reset_audio = 1;
    }

    init_output();

    if(reset_audio) {
      reset_audio_samplerate();
      if (intflag)
        return;
    }
  }

  if (fr->error_protection) {
    getbits(16); /* crc */
  }

  clip = (fr->do_layer)(fr,outmode,&ai);

  /*
  if(clip > 0 && checkrange)
    fprintf(stderr,"%d samples clipped\n", clip);
  */

}

void audio_info_struct_init(struct audio_info_struct *ai)
{
  ai->rate = -1;
  ai->gain = -1;
  ai->output = -1;
  ai->device = NULL;
  ai->channels = -1;
  ai->format = -1;
}

int audio_play_samples(struct audio_info_struct *ai, unsigned char *buf, int n)
{
  return 0;
}


int main(int argc,char *argv[])
{
  static char *fname="/MOSSE.MP3";
  int result;
  unsigned long frameNum = 0;
  //struct timeval start_time, now;
  unsigned long secdiff;
  int init;


  quiet=0;
  verbose=1;

  // DECODE_STDOUT stampa to 1
  // DECODE_AUDIO chiama la audio_play_samples
  // DECODE_BUFFER scrive su buffer_fd[1]
  outmode = DECODE_AUDIO;

  audio_info_struct_init(&ai);

  fr.single = -1; /* both channels */
  fr.synth = synth_1to1;
  fr.down_sample = 0;
 
  make_decode_tables(outscale);
  init_layer2();
  init_layer3(fr.down_sample);

  open_stream(fname,-1);
     
  //gettimeofday (&start_time, NULL);
  read_frame_init();

  init = 1;
  for(frameNum=0;read_frame(&fr) && numframes && !intflag;frameNum++) {
    if(frameNum < startFrame || (doublespeed && (frameNum % doublespeed))) {
      if(fr.lay == 3)
        set_pointer(512);
      continue;
    }
    numframes--;
    play_frame(init,&fr);
    init = 0;
      if (!(frameNum & 0xf))
        fprintf(stderr, "\r{%4lu} ",frameNum);
  }

  close_stream();

  {
    /* This formula seems to work at least for
     * MPEG 1.0/2.0 layer 3 streams.
     */

    int sfd = freqs[fr.sampling_frequency] * (fr.lsf + 1);
    int secs = (frameNum * (fr.lay==1 ? 384 : 1152) + sfd / 2) / sfd;
    fprintf(stderr,"[%d:%02d] Decoding of %s finished.\n", secs / 60,
            secs % 60, fname);
  }

}