Subversion Repositories Kolibri OS

Rev

Rev 577 | Rev 650 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 577 Rev 646
Line 16... Line 16...
16
#include "../kolibri.h"
16
#include "../kolibri.h"
17
#include "string.h"
17
#include "string.h"
18
#include "ac97wav.h"
18
#include "ac97wav.h"
19
#include "../mpg/mpg123.h"
19
#include "../mpg/mpg123.h"
20
#include "../sound.h"
20
#include "../sound.h"
21
 
-
 
-
 
21
#include "../ufmod-codec.h"                   /* uFMOD integration */
-
 
22
void exit();                                  /* uFMOD integration */
Line 22... Line 23...
22
 
23
 
23
#define MP3_ERROR_OUT_OF_BUFFER  5
24
#define MP3_ERROR_OUT_OF_BUFFER  5
Line 24... Line 25...
24
int m_last_error;
25
int m_last_error;
Line 29... Line 30...
29
 
30
 
30
void touch(char *buf, int size);
31
void touch(char *buf, int size);
31
int mp3FindSync(byte* buf, int size, int* sync);
32
int mp3FindSync(byte* buf, int size, int* sync);
Line -... Line 33...
-
 
33
int stream_read_raw(struct reader *rd,unsigned char *buf, int size);
-
 
34
 
-
 
35
int __cdecl _stricmp (const char * dst, const char * src);
32
int stream_read_raw(struct reader *rd,unsigned char *buf, int size);
36
char *__cdecl strrchr (const char * string,int ch);
Line 33... Line 37...
33
 
37
 
34
char *fname;
38
char *fname;
Line 41... Line 45...
41
SNDBUF hBuff;
45
SNDBUF hBuff;
Line 42... Line 46...
42
 
46
 
Line 43... Line 47...
43
CTRL_INFO info;
47
CTRL_INFO info;
-
 
48
 
-
 
49
FILEINFO   fileinfo;
Line 44... Line 50...
44
 
50
const char *filename;
45
FILEINFO   fileinfo;
51
const char *fileext;
46
 
52
 
47
int m_vol;
53
int m_vol;
Line 62... Line 68...
62
int outremain;
68
int outremain;
63
int totalout;
69
int totalout;
64
int done;
70
int done;
Line 65... Line 71...
65
 
71
 
-
 
72
char header[] = "AC97 MP3 player";
66
char header[] = "AC97 MP3 player";
73
char buttons_xm[]  = " Play    Stop                    Vol-    Vol+"; /* uFMOD integration */
-
 
74
char buttons_wav[] = " Play    Stop     <<      >>     Vol-    Vol+"; /* uFMOD integration */
Line -... Line 75...
-
 
75
char *buttons_text = buttons_wav;                                     /* uFMOD integration */
67
char buttons_text[]=" Play    Stop     <<      >>     Vol-    Vol+";
76
 
Line 68... Line 77...
68
 
77
void play_xm();                                                       /* uFMOD integration */
69
void (*snd_play)();
78
void (*snd_play)();
-
 
79
 
70
 
80
void draw_window()
Line 71... Line 81...
71
void draw_window()
81
{
Line 72... Line 82...
72
{
82
	int len;                                                          /* uFMOD integration */
Line 83... Line 93...
83
 
93
 
84
   make_button(7,41,286,11, 0x30|BT_HIDE|BT_NOFRAME,0x404040);
94
   make_button(7,41,286,11, 0x30|BT_HIDE|BT_NOFRAME,0x404040);
Line 85... Line 95...
85
   draw_bar(7,41,286,11,0x404040);
95
   draw_bar(7,41,286,11,0x404040);
86
 
96
 
-
 
97
   draw_bar(7,55,286,11,0x404040);
87
   draw_bar(7,55,286,11,0x404040);
98
	 len = strlen(filename);                                                /* uFMOD integration */
88
   write_text(12,58,0x004000|FONT0, fname, strlen(fname));
99
	 if(len > 47) len = 47;                                              /* uFMOD integration */
89
   write_text(11,57,0x00FF20|FONT0, fname, strlen(fname));
100
   write_text(11,57,0x00FF20|FONT0, filename, len);                        /* uFMOD integration */
90
 
101
 
91
   write_text(8,8,0xFFFFFF|FONT0, header, strlen(header));
102
   write_text(8,8,FONT0, header, sizeof(header)-1);                     /* uFMOD integration */
Line 92... Line 103...
92
   write_text(12,28,0x404040|FONT0,buttons_text,strlen(buttons_text));
103
   write_text(12,28,0x404040|FONT0,buttons_text,sizeof(buttons_wav)-1); /* uFMOD integration */
93
   write_text(11,27,0xA0FFA0|FONT0,buttons_text,strlen(buttons_text));
104
   write_text(11,27,0xA0FFA0|FONT0,buttons_text,sizeof(buttons_wav)-1); /* uFMOD integration */
Line 94... Line 105...
94
 
105
 
95
   EndDraw();
106
   EndDraw();
96
};
107
};
97
 
108
 
98
void draw_progress_bar()
109
void draw_progress_bar()
99
{  DWORD x;
110
{  DWORD x;
100
   x = 287.0f * (float)(rd.filepos-rd.strremain)/(float)fileinfo.size;
111
   x = (DWORD)(287.0f * (float)(rd.filepos-rd.strremain)/(float)fileinfo.size); /* uFMOD integration */
Line 117... Line 128...
117
   DWORD fmt;
128
   DWORD fmt;
118
   DWORD r_bytes;
129
   DWORD r_bytes;
119
   int retval;
130
   int retval;
120
   int err;
131
   int err;
121
   int ver;
132
   int ver;
-
 
133
   unsigned char *ttl, *cur;               /* uFMOD integration */
Line 122... Line 134...
122
    
134
    
123
   fname = argv[1];
135
   fname = argv[1];
124
   debug_out_str("\n\rPlay file ");
136
   debug_out_str("\n\rPlay file ");
125
   debug_out_str(fname); 
137
   debug_out_str(fname); 
Line 156... Line 168...
156
   touch(inpbuf, 0x10000);
168
   touch(inpbuf, 0x10000);
Line 157... Line 169...
157
   
169
   
158
   create_reader(&rd, inpbuf, 0x10000);
170
   create_reader(&rd, inpbuf, 0x10000);
Line 159... Line 171...
159
   init_reader(&rd,fname);
171
   init_reader(&rd,fname);
-
 
172
   
160
 
173
   filename = strrchr(fname,'/')+1;
-
 
174
   if( !(fileext = strrchr(filename,'.')))
-
 
175
     return 0;
161
   fmt = test_wav((WAVEHEADER*)testbuff);
176
     
162
   if (fmt != 0)
-
 
163
   {
-
 
164
     snd_play = &play_wave;
177
   if(!_stricmp(fileext,".mp3"))
165
     set_reader(&rd, 44);
178
   {
166
     outbuf = UserAlloc(32*1024);
179
			fmt = test_mp3(testbuff);              
167
     touch(outbuf, 32768);
-
 
168
   }   
180
			if(!fmt)
169
   else  
181
			{
-
 
182
        debug_out_str("\n\rInvalid MP3 file");
170
   { fmt = test_mp3(testbuff);
183
			  return 0;                     
171
     if(fmt ==0) return 0;
-
 
172
     snd_play = &play_mp3;
184
			};
173
      
185
			snd_play = &play_mp3;                  
174
     outremain = 0x40000 ;
186
			outremain = 0x40000;                   
175
     outbuf = UserAlloc(outremain);
187
			outbuf = UserAlloc(outremain);         
176
     touch(outbuf, outremain);
188
			touch(outbuf, outremain);              
177
     make_decode_tables(32767);
189
			make_decode_tables(32767);             
178
     init_layer2();
190
			init_layer2();                         
-
 
191
			init_layer3(32);                       
-
 
192
			fr.single = -1;
-
 
193
			goto play;                        
-
 
194
   };
-
 
195
     
-
 
196
   if(!_stricmp(fileext,".xm")) 
-
 
197
   {
-
 
198
	   if(uFMOD_LoadSong(fname))
-
 
199
	   {       
-
 
200
	      buttons_text = buttons_xm;               /* uFMOD integration */
-
 
201
	      fmt = PCM_2_16_48;                       /* uFMOD integration */
-
 
202
	      snd_play = &play_xm;                     /* uFMOD integration */
-
 
203
	      ttl = uFMOD_GetTitle();                  /* uFMOD integration */
-
 
204
	      cur = ttl;                               /* uFMOD integration */
-
 
205
	      err = 0;                                 /* uFMOD integration */
-
 
206
	      while(*cur && *cur++ != ' ') err++;      /* uFMOD integration */
-
 
207
	      if(err){                                 /* uFMOD integration */
-
 
208
	 	      cur = fname;                             /* uFMOD integration */
-
 
209
			     while(*cur) cur++;                       /* uFMOD integration */
-
 
210
			     *cur++ = ' ';                            /* uFMOD integration */
-
 
211
			     *cur++ = '|';                            /* uFMOD integration */
-
 
212
			     *cur++ = ' ';                            /* uFMOD integration */
-
 
213
			     while(*ttl) *cur++ = *ttl++;             /* uFMOD integration */
-
 
214
		    }
-
 
215
		    goto play; 
-
 
216
		 }   
-
 
217
		 debug_out_str("\n\rInvalid XM file");
-
 
218
     return 0;
-
 
219
	 };
-
 
220
	 
-
 
221
	 if(!_stricmp(fileext, ".wav"))
-
 
222
	 {
-
 
223
     fmt = test_wav((WAVEHEADER*)testbuff);
-
 
224
	   if(fmt)
-
 
225
		 {                                   
-
 
226
		   snd_play = &play_wave;            
-
 
227
		   set_reader(&rd, 44);              
-
 
228
		   outbuf = UserAlloc(32*1024);      
-
 
229
		   touch(outbuf, 32768);
-
 
230
		   goto play;                                  
-
 
231
		 }
179
     init_layer3(32);
232
     debug_out_str("\n\rInvalid WAV file");
Line -... Line 233...
-
 
233
     return 0;
-
 
234
	 };	
-
 
235
 
-
 
236
   debug_out_str("\n\rUsupported file");
-
 
237
   return 0;
180
     fr.single = -1;
238
 
Line 181... Line 239...
181
   };
239
play:
182
 
240
 
183
   status = ST_PLAY;
241
   status = ST_PLAY;
Line 204... Line 262...
204
           StopBuffer(hBuff);
262
           StopBuffer(hBuff);
205
           status = ST_DONE;
263
           status = ST_DONE;
206
           continue;
264
           continue;
Line 207... Line 265...
207
 
265
 
-
 
266
         case ST_EXIT:
208
         case ST_EXIT:
267
           uFMOD_StopSong();          /* uFMOD integration */
209
           StopBuffer(hBuff);
268
           StopBuffer(hBuff);
210
           DestroyBuffer(hBuff);
269
           DestroyBuffer(hBuff);
211
           return 0;
270
           return 0;
212
      };
271
      };
Line 215... Line 274...
215
};
274
};
Line 216... Line 275...
216
 
275
 
217
void touch(char *buf, int size)
276
void touch(char *buf, int size)
218
{ int i;
277
{ int i;
219
   char a;
278
   char a;
220
    for ( i = 0;i < size; i+=4096)
279
    for ( i = 0;i < size; i+=4096)     //alloc all pages
221
      a = buf[i]; 
280
      a = buf[i]; 
Line 222... Line 281...
222
};
281
};
223
 
282
 
Line 229... Line 288...
229
    {  if(rd.filepos > 102400)
288
    {  if(rd.filepos > 102400)
230
          return 0; 
289
          return 0; 
231
        if(!rd.head_read(&rd,&hdr))
290
        if(!rd.head_read(&rd,&hdr))
232
                        return 0;
291
                        return 0;
233
        if(!decode_header(&fr,hdr))
292
        if(!decode_header(&fr,hdr))
-
 
293
        { 
-
 
294
         if((hdr & 0xffffff00) == 0x49443300)
-
 
295
 	      {
-
 
296
 		    int id3length = 0;
-
 
297
		    id3length = parse_new_id3(&rd, hdr);
-
 
298
		    continue;
-
 
299
	      };
234
        {  rd.strpos-=3;
300
          rd.strpos-=3;
235
            rd.stream-=3;
301
          rd.stream-=3;
236
            rd.strremain+=3;
302
          rd.strremain+=3;
237
            continue;
303
          continue;
238
        };
304
        };
239
        break;
305
        break;
Line 243... Line 309...
243
          
309
          
244
    whdr.riff_id = 0x46464952;
310
    whdr.riff_id = 0x46464952;
245
    whdr.riff_format = 0x45564157;
311
    whdr.riff_format = 0x45564157;
246
    whdr.wFormatTag = 0x01;
312
    whdr.wFormatTag = 0x01;
247
    whdr.nSamplesPerSec = freqs[fr.sampling_frequency];
313
    whdr.nSamplesPerSec = freqs[fr.sampling_frequency];
248
    whdr.nChannels = 2; //mpginfo.channels;
314
    whdr.nChannels = 2; 
Line 249... Line 315...
249
    whdr.wBitsPerSample = 16;
315
    whdr.wBitsPerSample = 16;
250
    
316
    
Line 322... Line 388...
322
    if(status != ST_EXIT)
388
    if(status != ST_EXIT)
323
      status =  ST_STOP;
389
      status =  ST_STOP;
324
};
390
};
Line 325... Line 391...
325
 
391
 
326
void play_wave()
392
void play_wave()
Line 327... Line 393...
327
{  int retval;
393
{  int count;
328
 
-
 
329
   set_reader(&rd,44); 
394
 
330
   retval = 0;
395
   set_reader(&rd,44); 
331
   while(1)
396
   while(1)
332
   {
397
   {
Line 333... Line 398...
333
      if(status!=ST_PLAY)
398
      if(status!=ST_PLAY)
-
 
399
        break;
-
 
400
 
-
 
401
      if( count=stream_read_raw(&rd,outbuf,32768))
-
 
402
      {
334
        break;
403
        WaveOut(hBuff,outbuf,count);
335
 
404
        continue;
336
      if( !stream_read_raw(&rd,outbuf,32768))
405
      }
337
      {  done = 1;
-
 
338
          break; 
-
 
Line 339... Line 406...
339
      }; 
406
      done = 1;
340
      WaveOut(hBuff,outbuf,32768);
407
      break; 
341
   };
408
   };
Line -... Line 409...
-
 
409
 
-
 
410
   if(status != ST_EXIT)
-
 
411
     status =  ST_STOP;
-
 
412
};
-
 
413
 
-
 
414
void play_xm(){                             /* uFMOD integration */
-
 
415
	while(status == ST_PLAY){                 /* uFMOD integration */
-
 
416
		uFMOD_WaveOut(hBuff);                   /* uFMOD integration */
342
 
417
		delay(8);                               /* uFMOD integration */
343
   if(status != ST_EXIT)
418
	}                                         /* uFMOD integration */
344
    status =  ST_STOP;
419
	if(status != ST_EXIT) status = ST_STOP;   /* uFMOD integration */
345
};
420
}                                           /* uFMOD integration */
Line 517... Line 592...
517
    int   0x40
592
    int   0x40
518
  };  
593
  };  
519
};
594
};
Line 520... Line 595...
520
 
595
 
521
///*********
596
///*********
522
void *memmove ( void * dst, void * src, int count)
597
void *memmove ( void * dst, void * src, unsigned int count)  /* uFMOD integration */
523
{ void *ret;
598
{ void *ret;
Line 524... Line 599...
524
  ret = dst;
599
  ret = dst;
525
 
600
 
Line 553... Line 628...
553
          src = (char *)src + 1;
628
          src = (char *)src + 1;
554
      };
629
      };
555
      return(ret);
630
      return(ret);
556
}
631
}
Line -... Line 632...
-
 
632
 
-
 
633
char * __cdecl strrchr (const char * string,int ch)
-
 
634
{
-
 
635
        char *start = (char *)string;
-
 
636
 
-
 
637
        while (*string++)                       /* find end of string */
-
 
638
                ;
-
 
639
                                                /* search towards front */
-
 
640
        while (--string != start && *string != (char)ch)
-
 
641
                ;
-
 
642
 
-
 
643
        if (*string == (char)ch)                /* char found ? */
-
 
644
                return( (char *)string );
-
 
645
 
-
 
646
        return(NULL);
-
 
647
}
-
 
648
 
-
 
649
int __cdecl _stricmp (const char * dst, const char * src)
-
 
650
{
-
 
651
    int f, l;
-
 
652
 
-
 
653
    do
-
 
654
    {
-
 
655
        if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
-
 
656
            f -= 'A' - 'a';
-
 
657
        if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
-
 
658
            l -= 'A' - 'a';
-
 
659
    }
-
 
660
    while ( f && (f == l) );
-
 
661
 
-
 
662
    return(f - l);
-
 
663
}
-
 
664
 
-
 
665
 
557
 
666
 
558
//   debug_out_str(formats[fmt]);
667
//   debug_out_str(formats[fmt]);
Line 559... Line 668...
559
//   debug_out_str("\x0D\x0A\x00");
668
//   debug_out_str("\x0D\x0A\x00");
560
 
669
 
Line 582... Line 691...
582
//   debug_out_hex(whdr.nSamplesPerSec);
691
//   debug_out_hex(whdr.nSamplesPerSec);
583
//   debug_out_str("\x0D\x0A\x00");
692
//   debug_out_str("\x0D\x0A\x00");
Line 584... Line 693...
584
 
693
 
585
//   debug_out_hex(fmt);
694
//   debug_out_hex(fmt);
586
//   debug_out_str("\x0D\x0A\x00");
-
 
587
-
 
588
-