Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
 
2
#include "mpg123/mpg123.h"
3
#include <stdlib.h>
4
 
5
/* stub */
6
FILE *http_open (char *url)
7
{
8
  return NULL;
9
}
10
 
11
 
12
 
13
static long rates[3][3] = {
14
 { 32000,44100,48000 } ,
15
 { 16000,22050,24000 } ,
16
 {  8000,11025,12000 }
17
};
18
 
19
int supported_rates = 0;
20
 
21
int outmode = DECODE_AUDIO;
22
 
23
char *listname = NULL;
24
long outscale  = 32768;
25
int checkrange = FALSE;
26
int tryresync  = TRUE;
27
int quiet      = FALSE;
28
int verbose    = 0;
29
int doublespeed= 0;
30
int halfspeed  = 0;
31
int shuffle = 0;
32
int change_always = 1;
33
int force_8bit = 0;
34
int force_frequency = -1;
35
long numframes = -1;
36
long startFrame= 0;
37
int usebuffer  = 0;
38
int frontend_type = 0;
39
int remote     = 0;
40
int buffer_fd[2];
41
int buffer_pid;
42
 
43
 
44
static int intflag = FALSE;
45
static int remflag = FALSE;
46
 
47
 
48
static char remote_buffer[1024];
49
static struct frame fr;
50
static struct audio_info_struct ai;
51
txfermem *buffermem;
52
#define FRAMEBUFUNIT (18 * 64 * 4)
53
 
54
void init_output(void)
55
{
56
  static int init_done = FALSE;
57
 
58
  if (init_done)
59
    return;
60
  init_done = TRUE;
61
 
62
  if (!(pcm_sample = (unsigned char *) malloc(audiobufsize * 2))) {
63
    perror ("malloc()");
64
    l1_exit (1);
65
 
66
  }
67
 
68
  if(outmode==DECODE_AUDIO) {
69
    //if(audio_open(&ai) < 0) {
70
    //  perror("audio");
71
    //  exit(1);
72
    // }
73
    /* audio_set_rate (&ai);  should already be done in audio_open() [OF] */
74
  }
75
}
76
 
77
static void reset_audio_samplerate(void)
78
{
79
 
80
  //if (outmode == DECODE_AUDIO) {
81
    /* audio_reset_parameters(&ai); */
82
    /*   close and re-open in order to flush
83
     *   the device's internal buffer before
84
     *   changing the sample rate.   [OF]
85
     */
86
  //audio_close (&ai);
87
    //if (audio_open(&ai) < 0) {
88
  //  perror("audio");
89
  //   exit(1);
90
  // }
91
  // }
92
}
93
 
94
void play_frame(int init,struct frame *fr)
95
{
96
  int clip;
97
 
98
  if((fr->header_change && change_always) || init) {
99
    int reset_audio = 0;
100
 
101
    if(remote)
102
      print_rheader(fr);
103
 
104
    if (!quiet && init) {
105
      if (verbose)
106
        print_header(fr);
107
      else
108
        print_header_compact(fr);
109
    }
110
 
111
    if(force_frequency < 0) {
112
      if(ai.rate != freqs[fr->sampling_frequency]>>(fr->down_sample)) {
113
        ai.rate = freqs[fr->sampling_frequency]>>(fr->down_sample);
114
        reset_audio = 1;
115
      }
116
    }
117
    else if(ai.rate != force_frequency) {
118
      ai.rate = force_frequency;
119
      reset_audio = 1;
120
    }
121
 
122
    init_output();
123
 
124
    if(reset_audio) {
125
      reset_audio_samplerate();
126
      if (intflag)
127
        return;
128
    }
129
  }
130
 
131
  if (fr->error_protection) {
132
    getbits(16); /* crc */
133
  }
134
 
135
  clip = (fr->do_layer)(fr,outmode,&ai);
136
 
137
  /*
138
  if(clip > 0 && checkrange)
139
    fprintf(stderr,"%d samples clipped\n", clip);
140
  */
141
}
142
 
143
void audio_info_struct_init(struct audio_info_struct *ai)
144
{
145
  ai->rate = -1;
146
  ai->gain = -1;
147
  ai->output = -1;
148
  ai->device = NULL;
149
  ai->channels = -1;
150
  ai->format = -1;
151
}
152
 
153
int audio_play_samples(struct audio_info_struct *ai, unsigned char *buf, int n)
154
{
155
  return 0;
156
}
157
 
158
 
159
int main(int argc,char *argv[])
160
{
161
  static char *fname="/MOSSE.MP3";
162
  int result;
163
  unsigned long frameNum = 0;
164
  //struct timeval start_time, now;
165
  unsigned long secdiff;
166
  int init;
167
 
168
 
169
  quiet=0;
170
  verbose=1;
171
 
172
  // DECODE_STDOUT stampa to 1
173
  // DECODE_AUDIO chiama la audio_play_samples
174
  // DECODE_BUFFER scrive su buffer_fd[1]
175
  outmode = DECODE_AUDIO;
176
 
177
  audio_info_struct_init(&ai);
178
 
179
  fr.single = -1; /* both channels */
180
  fr.synth = synth_1to1;
181
  fr.down_sample = 0;
182
 
183
  make_decode_tables(outscale);
184
  init_layer2();
185
  init_layer3(fr.down_sample);
186
 
187
  open_stream(fname,-1);
188
 
189
  //gettimeofday (&start_time, NULL);
190
  read_frame_init();
191
 
192
  init = 1;
193
  for(frameNum=0;read_frame(&fr) && numframes && !intflag;frameNum++) {
194
    if(frameNum < startFrame || (doublespeed && (frameNum % doublespeed))) {
195
      if(fr.lay == 3)
196
        set_pointer(512);
197
      continue;
198
    }
199
    numframes--;
200
    play_frame(init,&fr);
201
    init = 0;
202
      if (!(frameNum & 0xf))
203
        fprintf(stderr, "\r{%4lu} ",frameNum);
204
  }
205
 
206
  close_stream();
207
 
208
  {
209
    /* This formula seems to work at least for
210
     * MPEG 1.0/2.0 layer 3 streams.
211
     */
212
    int sfd = freqs[fr.sampling_frequency] * (fr.lsf + 1);
213
    int secs = (frameNum * (fr.lay==1 ? 384 : 1152) + sfd / 2) / sfd;
214
    fprintf(stderr,"[%d:%02d] Decoding of %s finished.\n", secs / 60,
215
            secs % 60, fname);
216
  }
217
 
218
}
219