📄 song_drv.c
字号:
/*C**************************************************************************
* $RCSfile: song_drv.c,v $
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE: $Name: DEMO_FAT_1_9_9 $
* REVISION: $Revision: 1.9 $
* FILE_CVSID: $Id: song_drv.c,v 1.9 2002/09/06 12:59:11 njourdan 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:
* Search frame header and initialize song playing according to this header
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Header search is stopped when errors number exceeds
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Byte song_init (void)
{
Byte b, c;
Byte head_status; /* return error byte */
Byte err_count; /* error counter */
bit err_set; /* error flag */
err_set = FALSE;
head_status = SONG_NO_ERR;
err_count = SONG_MAX_ERR;
while (!Feof())
{
if (err_count != 0)
{ /* continue searching synchro */
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)
{
head_status |= SONG_LAYER_ERR; /* bad layer */
err_count--;
}
else
{
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)
{
#if (0)
case MP3_FS_44:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_256))
{
head_status |= SONG_BR_ERR; /* bad bit-rate */
err_count--;
err_set = TRUE;
}
break;
}
case MP3_FS_48:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_320))
{
head_status |= SONG_BR_ERR; /* bad bit-rate */
err_count--;
err_set = TRUE;
}
break;
}
case MP3_FS_32:
{
if ((c == MP3_BR_FREE) || (c > MP3_BR_224))
{
head_status |= SONG_BR_ERR; /* bad bit-rate */
err_count--;
err_set = TRUE;
}
break;
}
#endif
case MP3_FS_44:
case MP3_FS_48:
case MP3_FS_32:
case MP3_FS_22:
case MP3_FS_24:
case MP3_FS_16:
{
if (c == MP3_BR_FREE)
{
head_status |= SONG_BR_ERR; /* bad bit-rate */
err_count--;
err_set = TRUE;
}
break;
}
default:
{
head_status |= SONG_FS_ERR; /* bad sampling frequency */
err_count--;
err_set = TRUE;
break;
}
}
if (!err_set)
{
err_set = FALSE;
song_audio_init(); /* init audio interface */
clock_song_init(b); /* program the song clocks */
// Dac_emphasis(Fgetc() & MP3_MSK_EMP);/* config DAC emphasis */
Dac_unmute(); /* maestro please! */
// Fseek(-4); /* return to beginning of stream */
Fseek(-3);
return SONG_NO_ERR;
}
}
}
}
}
else
{ /* too much error */
return head_status;
}
}
return (head_status | SONG_SYNC_ERR);
}
/*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 */
}
/*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 please! */
aud_stop(); /* disable audio */
mp3_stop(); /* disable mp3 macrocell */
clock_disable(); /* disable clocks */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -