⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 song_drv.lst

📁 该程序包含了MP3的全部源码。芯片选择MP3专用芯片
💻 LST
📖 第 1 页 / 共 2 页
字号:
 296          /*F**************************************************************************
 297          * NAME: song_init
 298          *----------------------------------------------------------------------------
 299          * PARAMS:
 300          *
 301          * return:
 302          *   header status:  SONG_NO_ERR:    header ok
C51 COMPILER V7.20   SONG_DRV                                                              11/14/2004 00:50:07 PAGE 6   

 303          *                   SONG_LAYER_ERR: not a layer 3 file
 304          *                   SONG_BR_ERR:    bit rate not supported
 305          *                   SONG_FS_ERR:    bad frequency sampling
 306          *                   SONG_SYNC_ERR:  no header found
 307          *----------------------------------------------------------------------------
 308          * PURPOSE: 
 309          *   Search frame header and initialize song playing according to this header
 310          *----------------------------------------------------------------------------
 311          * EXAMPLE:
 312          *----------------------------------------------------------------------------
 313          * NOTE:
 314          *   Header search is stopped when errors number exceeds 
 315          *----------------------------------------------------------------------------
 316          * REQUIREMENTS:
 317          *****************************************************************************/
 318          Byte song_init (void)
 319          {
 320   1      Byte    b, c;
 321   1      Byte    head_status;                        /* return error byte */
 322   1      Byte    err_count;                          /* error counter */
 323   1      bit     err_set;                            /* error flag */
 324   1      Byte    bit_rate;                           /* Bit Rate  */
 325   1      Byte    song_fs;                            /* Frequency sample */
 326   1      Byte    song_version;                       /* Song verison : MPEG1 or MPEG2 */
 327   1      Uint16  song_one_frame_size;                /* Size of one frame */
 328   1      
 329   1      
 330   1        head_status = SONG_NO_ERR;
 331   1        err_count = SONG_MAX_ERR;
 332   1        while (!Feof())
 333   1        {
 334   2          if (err_count != 0)
 335   2          { /* continue searching synchro */
 336   3            if (Fgetc() == MP3_SYNC_H)
 337   3            { /* high order sync found */
 338   4              b = Fgetc();
 339   4              if ((b & MP3_MSK_SYNC) == MP3_SYNC_L)
 340   4              { /* low order sync found */
 341   5                if ((b & MP3_MSK_LAYER) != MP3_LAYER_III)
 342   5                {
 343   6                  Fseek( (Int16) -1 );
 344   6                  head_status |= SONG_LAYER_ERR;  /* bad layer */
 345   6                  err_count--;
 346   6                }
 347   5                else
 348   5                {
 349   6                  c = Fgetc();
 350   6                  if (c & 0x02)
 351   6                    song_one_frame_size = 1;
 352   6                  else
 353   6                    song_one_frame_size = 0;
 354   6                  b = (b & MP3_MSK_VER) >> 1;       /* keep MPEG Version B3 -> B2 */
 355   6      
 356   6                  if (b)
 357   6                  {
 358   7                    song_version = 0;   /* Version MPEG1 */
 359   7                  }
 360   6                  else
 361   6                  {
 362   7                    song_version = 1;   /* Version MPEG2 */
 363   7                  }
 364   6                  bit_rate = c >> 4;
C51 COMPILER V7.20   SONG_DRV                                                              11/14/2004 00:50:07 PAGE 7   

 365   6                  song_fs = (c & MP3_MSK_FS) >> 2;
 366   6                  switch (song_fs)
 367   6                  {
 368   7                    case 0x00 :   /* 44100 Hz / 22050 Hz */
 369   7                      song_one_frame_size += song_tab_frame_size_00[song_version][bit_rate];
 370   7                      break;
 371   7                    case 0x01 :   /* 48000 Hz / 24000 Hz */
 372   7                      song_one_frame_size += song_tab_frame_size_01[song_version][bit_rate];
 373   7                      break;
 374   7                    case 0x10 :   /* 32000 Hz / 16000 Hz */
 375   7                      song_one_frame_size += song_tab_frame_size_10[song_version][bit_rate];
 376   7                      break;
 377   7                  }
 378   6                  song_frame_size = (song_tab_seek[song_version][bit_rate]) >> 3;
 379   6                  b |= (c & MP3_MSK_FS) >> 2;       /* read FS B3:2 -> B1:0 */
 380   6                  c &= MP3_MSK_BR;
 381   6      
 382   6                  
 383   6                              err_set = FALSE;
 384   6      
 385   6                  switch (b)
 386   6                  {
 387   7                    case MP3_FS_44:
 388   7                    case MP3_FS_48:
 389   7                    case MP3_FS_32:
 390   7                    case MP3_FS_22:
 391   7                    case MP3_FS_24:
 392   7                    case MP3_FS_16:
 393   7                    {
 394   8                      if (c == MP3_BR_FREE)
 395   8                      {
 396   9                        head_status |= SONG_BR_ERR; /* bad bit-rate */
 397   9                        err_count--;
 398   9                        err_set = TRUE;
 399   9                      }
 400   8                      break;
 401   8                    }
 402   7                    default:
 403   7                    {
 404   8                      head_status |= SONG_FS_ERR;   /* bad sampling frequency */
 405   8                      err_count--;
 406   8                      err_set = TRUE;
 407   8                      break;
 408   8                    }
 409   7                  }
 410   6                  if (!err_set)
 411   6                  {
 412   7                    Fseek((Int16)(song_one_frame_size) - 3);
 413   7                    if (Fgetc() == MP3_SYNC_H)                        /* first header byte */
 414   7                    { /* high order sync found */
 415   8                      b = Fgetc();                                    /* second header byte */  
 416   8                      if ((b & MP3_MSK_SYNC) == MP3_SYNC_L)
 417   8                      { /* low order sync found */
 418   9                        if ((b & MP3_MSK_LAYER) != MP3_LAYER_III)
 419   9                        {
 420  10                          head_status |= SONG_LAYER_ERR;  /* bad layer */
 421  10                          err_count--;
 422  10                          Fseek(-(Int16)(song_one_frame_size) - 1 );
 423  10                        }
 424   9                        else
 425   9                        {
 426  10                          c = Fgetc();                                /* third header byte */
C51 COMPILER V7.20   SONG_DRV                                                              11/14/2004 00:50:07 PAGE 8   

 427  10                          if ( song_fs == ((c & MP3_MSK_FS) >> 2) )
 428  10                          {
 429  11                            b = (b & MP3_MSK_VER) >> 1;       /* keep MPEG Version B3 -> B2 */
 430  11                            b |= (c & MP3_MSK_FS) >> 2;       /* read FS B3:2 -> B1:0 */ 
 431  11                            c &= MP3_MSK_BR;
 432  11                            song_audio_init();                /* init audio interface */
 433  11                            clock_song_init();  //b             /* program the song clocks */
 434  11                            Fseek(-(Int16)(song_one_frame_size) - 3);
 435  11                            return SONG_NO_ERR;
 436  11                          }
 437  10                          else    
 438  10                          { /* Frequency sample does not match */
 439  11                            Fseek(-(Int16)(song_one_frame_size) - 2);
 440  11                          }
 441  10                        }
 442   9                      }
 443   8                      else
 444   8                      { /* no low order synchro found */
 445   9                        Fseek(-(Int16)(song_one_frame_size) - 1);
 446   9                      }
 447   8                    }
 448   7                    else
 449   7                    { /* No high order synchro found */
 450   8                      Fseek(-(Int16)(song_one_frame_size));
 451   8                    }
 452   7                    
 453   7                  }
 454   6                              else
 455   6                              { /* bad bit-rate or bad sampling frequency */
 456   7                          Fseek( (Int16) -2 );
 457   7                              }
 458   6                }
 459   5              }
 460   4                      else
 461   4                      { /* No low order sync found */
 462   5                  Fseek( (Int16) -1 );
 463   5                      }
 464   4      
 465   4            }
 466   3          }
 467   2          else
 468   2          { /* too much error */
 469   3            return head_status;
 470   3          }
 471   2        }
 472   1        return (head_status | SONG_SYNC_ERR);
 473   1      }
 474          
 475          
 476          /*F**************************************************************************
 477          * NAME: song_audio_init
 478          *----------------------------------------------------------------------------
 479          * PARAMS:
 480          *
 481          * return:
 482          *----------------------------------------------------------------------------
 483          * PURPOSE: 
 484          *   Audio interface initialization in song mode
 485          *----------------------------------------------------------------------------
 486          * EXAMPLE:
 487          *----------------------------------------------------------------------------
 488          * NOTE:
C51 COMPILER V7.20   SONG_DRV                                                              11/14/2004 00:50:07 PAGE 9   

 489          *   DAC_NB_BIT defined in config.h
 490          *----------------------------------------------------------------------------
 491          * REQUIREMENTS:
 492          *****************************************************************************/
 493          void song_audio_init (void)
 494          {
 495   1        AUDCON0=AUDCON0&0xfe;  //HLR=0
 496   1        AUDCON0=AUDCON0|0x02;  //DSIZ=1
 497   1        AUDCON0=AUDCON0|0x04;  //POL=1
 498   1        AUDCON0=AUDCON0|((0x01<<3)&0xf4);  //JUST=1
 499   1        AUDCON1=AUDCON1&0x7f;  //SRC=0
 500   1      
 501   1        AUDCON1=AUDCON1|0x01;
 502   1        AUDCON1=AUDCON1|0x40;
 503   1       
 504   1       // Aud_set_pcm_32(18);
 505   1       // Aud_set_song();
 506   1       // Aud_enable();
 507   1       // Aud_disable_int();                        /* disable audio interrupt */
 508   1      }
 509          
 510          
 511          /*F**************************************************************************
 512          * NAME: song_start
 513          *----------------------------------------------------------------------------
 514          * PARAMS:
 515          *
 516          * return:
 517          *----------------------------------------------------------------------------
 518          * PURPOSE: 
 519          *   Start song playing
 520          *----------------------------------------------------------------------------
 521          * EXAMPLE:
 522          *----------------------------------------------------------------------------
 523          * NOTE:
 524          *----------------------------------------------------------------------------
 525          * REQUIREMENTS:
 526          *****************************************************************************/
 527          void song_start (void)
 528          {  
 529   1        Aud_song_play();                          /* start sample request */
 530   1        mp3_init();                               /* enable mp3 decoder */
 531   1      }
 532          
 533          
 534          /*F**************************************************************************
 535          * NAME: song_pause
 536          *----------------------------------------------------------------------------
 537          * PARAMS:
 538          *
 539          * return:
 540          *----------------------------------------------------------------------------
 541          * PURPOSE: 
 542          *   Stop song playing
 543          *----------------------------------------------------------------------------
 544          * EXAMPLE:
 545          *----------------------------------------------------------------------------
 546          * NOTE:
 547          *   clocks are not disabled by this functions
 548          *----------------------------------------------------------------------------
 549          * REQUIREMENTS:
 550          *****************************************************************************/
C51 COMPILER V7.20   SONG_DRV                                                              11/14/2004 00:50:07 PAGE 10  

 551          void song_pause (void)
 552          {
 553   1        Aud_song_pause();                         /* disable audio */
 554   1        mp3_stop();                               /* disable mp3 macrocell */
 555   1      }
 556          
 557          
 558          /*F**************************************************************************
 559          * NAME: song_stop
 560          *----------------------------------------------------------------------------
 561          * PARAMS:
 562          *
 563          * return:
 564          *----------------------------------------------------------------------------
 565          * PURPOSE: 
 566          *   Stop song playing
 567          *----------------------------------------------------------------------------
 568          * EXAMPLE:
 569          *----------------------------------------------------------------------------
 570          * NOTE:
 571          *----------------------------------------------------------------------------
 572          * REQUIREMENTS:
 573          *****************************************************************************/
 574          void song_stop (void)
 575          { 
 576   1        aud_stop();                               /* disable audio */
 577   1        mp3_stop();                               /* disable mp3 macrocell */
 578   1        clock_disable();                          /* disable clocks */
 579   1      }
 580          
 581          
 582          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    875    ----
   CONSTANT SIZE    =    256    ----
   XDATA SIZE       =      4       8
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   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 + -