📄 song_drv.lst
字号:
288
289
290 /*F**************************************************************************
291 * NAME: song_init
292 *----------------------------------------------------------------------------
293 * PARAMS:
294 *
295 * return:
296 * header status: SONG_NO_ERR: header ok
297 * SONG_LAYER_ERR: not a layer 3 file
298 * SONG_BR_ERR: bit rate not supported
299 * SONG_FS_ERR: bad frequency sampling
300 * SONG_SYNC_ERR: no header found
C51 COMPILER V7.00 SONG_DRV 04/28/2004 09:31:56 PAGE 6
301 *----------------------------------------------------------------------------
302 * PURPOSE:
303 * Search frame header and initialize song playing according to this header
304 *----------------------------------------------------------------------------
305 * EXAMPLE:
306 *----------------------------------------------------------------------------
307 * NOTE:
308 * Header search is stopped when errors number exceeds
309 *----------------------------------------------------------------------------
310 * REQUIREMENTS:
311 *****************************************************************************/
312 Byte song_init (void)
313 {
314 1 Byte b, c;
315 1 Byte head_status; /* return error byte */
316 1 Byte err_count; /* error counter */
317 1 bit err_set; /* error flag */
318 1 Byte bit_rate; /* Bit Rate */
319 1 Byte song_fs; /* Frequency sample */
320 1 Byte song_version; /* Song verison : MPEG1 or MPEG2 */
321 1 Uint16 song_one_frame_size; /* Size of one frame */
322 1
323 1
324 1 head_status = SONG_NO_ERR;
325 1 err_count = SONG_MAX_ERR;
326 1 while (!Feof())
327 1 {
328 2 if (err_count != 0)
329 2 { /* continue searching synchro */
330 3 if (Fgetc() == MP3_SYNC_H)
331 3 { /* high order sync found */
332 4 b = Fgetc();
333 4 if ((b & MP3_MSK_SYNC) == MP3_SYNC_L)
334 4 { /* low order sync found */
335 5 if ((b & MP3_MSK_LAYER) != MP3_LAYER_III)
336 5 {
337 6 Fseek( (Int16) -1 );
338 6 head_status |= SONG_LAYER_ERR; /* bad layer */
339 6 err_count--;
340 6 }
341 5 else
342 5 {
343 6 c = Fgetc();
344 6 if (c & 0x02)
345 6 song_one_frame_size = 1;
346 6 else
347 6 song_one_frame_size = 0;
348 6 b = (b & MP3_MSK_VER) >> 1; /* keep MPEG Version B3 -> B2 */
349 6
350 6 if (b)
351 6 {
352 7 song_version = 0; /* Version MPEG1 */
353 7 }
354 6 else
355 6 {
356 7 song_version = 1; /* Version MPEG2 */
357 7 }
358 6 bit_rate = c >> 4;
359 6 song_fs = (c & MP3_MSK_FS) >> 2;
360 6 switch (song_fs)
361 6 {
362 7 case 0x00 : /* 44100 Hz / 22050 Hz */
C51 COMPILER V7.00 SONG_DRV 04/28/2004 09:31:56 PAGE 7
363 7 song_one_frame_size += song_tab_frame_size_00[song_version][bit_rate];
364 7 break;
365 7 case 0x01 : /* 48000 Hz / 24000 Hz */
366 7 song_one_frame_size += song_tab_frame_size_01[song_version][bit_rate];
367 7 break;
368 7 case 0x10 : /* 32000 Hz / 16000 Hz */
369 7 song_one_frame_size += song_tab_frame_size_10[song_version][bit_rate];
370 7 break;
371 7 }
372 6 song_frame_size = (song_tab_seek[song_version][bit_rate]) >> 3;
373 6 b |= (c & MP3_MSK_FS) >> 2; /* read FS B3:2 -> B1:0 */
374 6 c &= MP3_MSK_BR;
375 6
376 6
377 6 err_set = FALSE;
378 6
379 6 switch (b)
380 6 {
381 7 case MP3_FS_44:
382 7 case MP3_FS_48:
383 7 case MP3_FS_32:
384 7 case MP3_FS_22:
385 7 case MP3_FS_24:
386 7 case MP3_FS_16:
387 7 {
388 8 if (c == MP3_BR_FREE)
389 8 {
390 9 head_status |= SONG_BR_ERR; /* bad bit-rate */
391 9 err_count--;
392 9 err_set = TRUE;
393 9 }
394 8 break;
395 8 }
396 7 default:
397 7 {
398 8 head_status |= SONG_FS_ERR; /* bad sampling frequency */
399 8 err_count--;
400 8 err_set = TRUE;
401 8 break;
402 8 }
403 7 }
404 6 if (!err_set)
405 6 {
406 7 Fseek((Int16)(song_one_frame_size) - 3);
407 7 if (Fgetc() == MP3_SYNC_H) /* first header byte */
408 7 { /* high order sync found */
409 8 b = Fgetc(); /* second header byte */
410 8 if ((b & MP3_MSK_SYNC) == MP3_SYNC_L)
411 8 { /* low order sync found */
412 9 if ((b & MP3_MSK_LAYER) != MP3_LAYER_III)
413 9 {
414 10 head_status |= SONG_LAYER_ERR; /* bad layer */
415 10 err_count--;
416 10 Fseek(-(Int16)(song_one_frame_size) - 1 );
417 10 }
418 9 else
419 9 {
420 10 c = Fgetc(); /* third header byte */
421 10 if ( song_fs == ((c & MP3_MSK_FS) >> 2) )
422 10 {
423 11 b = (b & MP3_MSK_VER) >> 1; /* keep MPEG Version B3 -> B2 */
424 11 b |= (c & MP3_MSK_FS) >> 2; /* read FS B3:2 -> B1:0 */
C51 COMPILER V7.00 SONG_DRV 04/28/2004 09:31:56 PAGE 8
425 11 c &= MP3_MSK_BR;
426 11 song_audio_init(); /* init audio interface */
427 11 clock_song_init(b); /* program the song clocks */
428 11 Fseek(-(Int16)(song_one_frame_size) - 3);
429 11 return SONG_NO_ERR;
430 11 }
431 10 else
432 10 { /* Frequency sample does not match */
433 11 Fseek(-(Int16)(song_one_frame_size) - 2);
434 11 }
435 10 }
436 9 }
437 8 else
438 8 { /* no low order synchro found */
439 9 Fseek(-(Int16)(song_one_frame_size) - 1);
440 9 }
441 8 }
442 7 else
443 7 { /* No high order synchro found */
444 8 Fseek(-(Int16)(song_one_frame_size));
445 8 }
446 7
447 7 }
448 6 else
449 6 { /* bad bit-rate or bad sampling frequency */
450 7 Fseek( (Int16) -2 );
451 7 }
452 6 }
453 5 }
454 4 else
455 4 { /* No low order sync found */
456 5 Fseek( (Int16) -1 );
457 5 }
458 4
459 4 }
460 3 }
461 2 else
462 2 { /* too much error */
463 3 return head_status;
464 3 }
465 2 }
466 1 return (head_status | SONG_SYNC_ERR);
467 1 }
468
469
470 /*F**************************************************************************
471 * NAME: song_audio_init
472 *----------------------------------------------------------------------------
473 * PARAMS:
474 *
475 * return:
476 *----------------------------------------------------------------------------
477 * PURPOSE:
478 * Audio interface initialization in song mode
479 *----------------------------------------------------------------------------
480 * EXAMPLE:
481 *----------------------------------------------------------------------------
482 * NOTE:
483 * DAC_NB_BIT defined in config.h
484 *----------------------------------------------------------------------------
485 * REQUIREMENTS:
486 *****************************************************************************/
C51 COMPILER V7.00 SONG_DRV 04/28/2004 09:31:56 PAGE 9
487 void song_audio_init (void)
488 {
489 1 Aud_set_pcm_32(DAC_NB_BIT);
490 1 Aud_set_song();
491 1 Aud_enable();
492 1 Aud_disable_int(); /* disable audio interrupt */
493 1 }
494
495
496 /*F**************************************************************************
497 * NAME: song_start
498 *----------------------------------------------------------------------------
499 * PARAMS:
500 *
501 * return:
502 *----------------------------------------------------------------------------
503 * PURPOSE:
504 * Start song playing
505 *----------------------------------------------------------------------------
506 * EXAMPLE:
507 *----------------------------------------------------------------------------
508 * NOTE:
509 *----------------------------------------------------------------------------
510 * REQUIREMENTS:
511 *****************************************************************************/
512 void song_start (void)
513 {
514 1 Dac_unmute(); /* maestro please! */
515 1 Aud_song_play(); /* start sample request */
516 1 mp3_init(); /* enable mp3 decoder */
517 1 }
518
519
520 /*F**************************************************************************
521 * NAME: song_pause
522 *----------------------------------------------------------------------------
523 * PARAMS:
524 *
525 * return:
526 *----------------------------------------------------------------------------
527 * PURPOSE:
528 * Stop song playing
529 *----------------------------------------------------------------------------
530 * EXAMPLE:
531 *----------------------------------------------------------------------------
532 * NOTE:
533 * clocks are not disabled by this functions
534 *----------------------------------------------------------------------------
535 * REQUIREMENTS:
536 *****************************************************************************/
537 void song_pause (void)
538 {
539 1 Aud_song_pause(); /* disable audio */
540 1 mp3_stop(); /* disable mp3 macrocell */
541 1 }
542
543
544 /*F**************************************************************************
545 * NAME: song_stop
546 *----------------------------------------------------------------------------
547 * PARAMS:
548 *
C51 COMPILER V7.00 SONG_DRV 04/28/2004 09:31:56 PAGE 10
549 * return:
550 *----------------------------------------------------------------------------
551 * PURPOSE:
552 * Stop song playing
553 *----------------------------------------------------------------------------
554 * EXAMPLE:
555 *----------------------------------------------------------------------------
556 * NOTE:
557 *----------------------------------------------------------------------------
558 * REQUIREMENTS:
559 *****************************************************************************/
560 void song_stop (void)
561 {
562 1 Dac_mute(); /* silence please! */
563 1 aud_stop(); /* disable audio */
564 1 mp3_stop(); /* disable mp3 macrocell */
565 1 clock_disable(); /* disable clocks */
566 1 }
567
568
569
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 888 ----
CONSTANT SIZE = 256 ----
XDATA SIZE = 2 ----
PDATA SIZE = ---- ----
DATA SIZE = 2 8
IDATA SIZE = 1 ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -