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

📄 song_drv.c

📁 c51snd1c硬盘播放器全部资料.源码.线路图.protel99se的pcb图
💻 C
📖 第 1 页 / 共 2 页
字号:
/*C**************************************************************************
* NAME:         song_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.20     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the song driver routines
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/

#include "config.h"                         /* system configuration */
#include "dac\dac_drv.h"                    /* dac driver definition */
#include "lib_mcu\aud\aud_drv.h"            /* audio driver definition */
#include "lib_mcu\mp3\mp3_drv.h"            /* mp3 driver definition */
#include "modules\file\file.h"              /* file definition */
#include "lib_mcu\clock\clock.h"            /* clock definition */
#include "song_drv.h"                       /* song driver definition */


/*_____ M A C R O S ________________________________________________________*/


/*_____ D E F I N I T I O N ________________________________________________*/

        Byte    song_sound;                 /* save the selected sound */
        Byte    mp3_volume;
xdata   Uint16  song_frame_size;            /* Frame size value for one second  */
idata   Byte    sound_volume;               /* save actual sound level          */

/*_____ D E C L A R A T I O N ______________________________________________*/

static  void    song_audio_init (void);

code Uint16 song_tab_frame_size_00 [2][16] =
    {/* 44.1 KHz MPEG1 */
      {0, 104, 130, 156, 182, 208, 261, 313, 365, 417, 522, 626, 731, 835, 1044, 0},
     /* 22.05 KHz MPEG2 */
      {0,  26, 52, 78, 104, 130, 156, 182, 208,  261,  313, 365, 417, 470, 522, 0}
    };

code Uint16 song_tab_frame_size_01 [2][16] =
    {
    /* 48 Khz MPEG1 */
      {0, 96, 120, 144, 168, 192, 240, 288, 336, 384, 480, 576, 672, 768, 960, 0},
    /* 24 Khz MPEG2 */
      {0,  24, 48, 72, 96, 120, 144, 168, 192, 240, 288, 336, 384, 432, 480, 0}
    };

code Uint16 song_tab_frame_size_10 [2][16] =

    {/* 32 Khz MPEG1  */
      {0, 144, 180, 216, 252, 288, 360, 432, 504, 576, 720, 864, 1008, 1152, 1440, 0},
     /* 16 Khz MPEG2  */
      {0,  36, 72, 108, 144, 180, 216, 252, 288, 360, 432, 504, 576, 648, 720, 0}
    };
    

code Uint16 song_tab_seek [2][16]=
{
  {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0},
  {0,  8, 16, 24, 32, 40, 48, 56,  64,  80,  96, 112, 128, 144, 160, 0}
  
};


/*F**************************************************************************
* NAME: song_snd_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Sound control initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   Initializes the sound controls to their medium value
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_snd_init (void)
{
  dac_init();
  dac_set_vol(mp3_volume = VOLUME_MED);
  MP3BAS = BASS_MED;
  MP3MED = MEDIUM_MED;
  MP3TRE = TREBLE_MED;

  song_sound = SND_VOLUME;          /* volume control selected by default */
}



/*F**************************************************************************
* NAME: song_snd_inc
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Increment the selected sound control
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   The number of the current selected sound control is stored in the
*   variable snd_select (0.Volume; 1.Bass; 2.Medium; 3. Trebble)
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_snd_inc (void)
{
  switch (song_sound)
  {
    case SND_VOLUME:
    if (mp3_volume != VOLUME_MAX)
    {
        if ((MP3CON&MSK_MPBBST) && (MP3VOL > VOLUME_MED || MP3VOR > VOLUME_MED)) Mp3_clr_bass_boost(); /* should be less than -15dB */
        dac_set_vol(++mp3_volume);
      }
      break;

    case SND_BASS:
    {
      if (MP3BAS != BASS_MAX)
        MP3BAS++;
      break;
    }

    case SND_MEDIUM:
    {
      if (MP3MED != MEDIUM_MAX)
        MP3MED++;
      break;
    }

    case SND_TREBLE:
    {
      if (MP3TRE != TREBLE_MAX)
        MP3TRE++;
      break;
    }

    case SND_BBOOST:
    if(MP3VOL > VOLUME_MED || MP3VOR > VOLUME_MED) /* should be less than -15dB */
      dac_set_vol(VOLUME_MED);
    Mp3_set_bass_boost();
    break;
  }
}


/*F**************************************************************************
* NAME: song_snd_dec
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Decrement the selected sound control
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   The number of the current selected sound control is stored in the
*   variable snd_select (0.Volume; 1.Bass; 2.Medium; 3. Trebble)
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_snd_dec (void)
{
  switch (song_sound)
  {
    case SND_VOLUME:
    if (mp3_volume != VOLUME_MIN) dac_set_vol(--mp3_volume);
      break;

    case SND_BASS:
    {
      if (MP3BAS != BASS_MIN)
        MP3BAS--;
      break;
    }

    case SND_MEDIUM:
    {
      if (MP3MED != MEDIUM_MIN)
        MP3MED--;
      break;
    }

    case SND_TREBLE:
    {
      if (MP3TRE != TREBLE_MIN)
        MP3TRE--;
      break;
    }

    case SND_BBOOST:
    Mp3_clr_bass_boost();
    break;
  }
}


/*F**************************************************************************
* NAME: song_snd_select
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Select next sound control
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_snd_select (void)
{
  song_sound = (song_sound + 1) % NB_SOUND;
}


/*F**************************************************************************
* NAME: song_get_sound
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*   sound selected: SND_VOLUME, SND_BASS, SND_MEDIUM, SND_TREBLE
*----------------------------------------------------------------------------
* PURPOSE: 
*   Returns selected sound control
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Byte song_get_sound (void)
{
  return (song_sound);
}


/*F**************************************************************************
* NAME: song_get_level
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*   level of sound selected
*----------------------------------------------------------------------------
* PURPOSE:
*   Returns selected sound level
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Byte song_get_level (void)
{
  switch (song_sound)
  {
    case SND_VOLUME: return mp3_volume;
    case SND_BASS:   return MP3BAS;
    case SND_MEDIUM: return MP3MED;
    case SND_TREBLE: return MP3TRE;
    case SND_BBOOST: return (MP3CON&MSK_MPBBST)?1:0;
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -