📄 song_drv.c
字号:
/*C**************************************************************************
* $RCSfile: song_drv.c,v $
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE: $Name: DEMO_FAT_1_2_5 $
* REVISION: $Revision: 1.7 $
* FILE_CVSID: $Id: song_drv.c,v 1.7 2002/06/06 15:30:13 ffosse Exp $
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the song driver routines
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* system configuration */
#include "..\..\..\..\lib\aud\aud_drv.h" /* audio driver definition */
#include "..\..\..\..\lib\mp3\mp3_drv.h" /* mp3 driver definition */
#include "..\..\..\..\lib_demob\dac\dac_drv.h"/* dac driver definition */
#include "..\file\file.h" /* file definition */
#include "..\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 ________________________________________________*/
static Byte song_sound; /* save the selected sound */
/*_____ D E C L A R A T I O N ______________________________________________*/
static void song_audio_init (void);
/*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)
{
MP3VOL = VOLUME_MED;
MP3VOR = 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 (MP3VOL != VOLUME_MAX)
{
MP3VOL++;
MP3VOR = MP3VOL;
}
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;
}
}
}
/*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 (MP3VOL != VOLUME_MIN)
{
MP3VOL--;
MP3VOR = MP3VOL;
}
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;
}
}
}
/*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 (MP3VOL);
}
case SND_BASS:
{
return (MP3BAS);
}
case SND_MEDIUM:
{
return (MP3MED);
break;
}
case SND_TREBLE:
{
return (MP3TRE);
}
}
}
/*F**************************************************************************
* NAME: song_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* header status: SONG_NO_ERR: header ok
* SONG_LAYER_ERR: not a layer 3 file
* SONG_BR_ERR: bit rate not supported
* SONG_FS_ERR: bad frequency sampling
* SONG_SYNC_ERR: no header found
*----------------------------------------------------------------------------
* PURPOSE:
* Initialize song playing depending on the frame
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Byte song_init (void)
{
Byte b, c;
while (!Feof())
{
if (Fgetc() == MP3_SYNC_H)
{ /* high order sync found */
b = Fgetc();
if ((b & MP3_MSK_SYNC) == MP3_SYNC_L)
{ /* low order sync found */
if ((b & MP3_MSK_LAYER) != MP3_LAYER_III)
{
return SONG_LAYER_ERR; /* bad layer */
}
c = Fgetc();
b = (b & MP3_MSK_VER) >> 1; /* keep MPEG Version B3 -> B2 */
b |= (c & MP3_MSK_FS) >> 2; /* read FS B3:2 -> B1:0 */
c &= MP3_MSK_BR;
switch (b)
{
case MP3_FS_44:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_256))
{
return SONG_BR_ERR; /* bad bit-rate */
}
break;
}
case MP3_FS_48:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_320))
{
return SONG_BR_ERR; /* bad bit-rate */
}
break;
}
case MP3_FS_32:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_224))
{
return SONG_BR_ERR; /* bad bit-rate */
}
break;
}
case MP3_FS_22:
case MP3_FS_24:
case MP3_FS_16:
{
if (c == MP3_BR_FREE)
{
return SONG_BR_ERR; /* bad bit-rate */
}
break;
}
default:
{
return SONG_FS_ERR; /* bad sampling frequency */
}
}
song_audio_init(); /* init audio interface */
clock_song_init(b); /* program the song clocks */
Dac_emphasis(Fgetc() & MP3_MSK_EMP);/* config DAC emphasis */
return SONG_NO_ERR;
}
}
}
return SONG_SYNC_ERR; /* bad MP3 file */
}
/*F**************************************************************************
* NAME: song_audio_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Audio interface initialization in song mode
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* DAC_NB_BIT defined in config.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_audio_init (void)
{
Aud_set_pcm_32(DAC_NB_BIT);
Aud_set_song();
Aud_enable();
Aud_disable_int(); /* disable audio interrupt */
Dac_unmute();
}
/*F**************************************************************************
* NAME: song_start
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Start song playing
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_start (void)
{
Aud_song_play(); /* start sample request */
mp3_init(); /* enable mp3 decoder */
}
/*F**************************************************************************
* NAME: song_stop
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Stop song playing
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void song_stop (void)
{
Dac_mute(); /* silence */
aud_stop(); /* disable audio */
mp3_stop(); /* disable mp3 macrocell */
clock_disable(); /* disable clocks */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -