#include "config.h" #include "include/dac_drv.h" #include "include/aud_drv.h" #include "include/mp3_drv.h" #include "include/clock.h" #include "include/audio.h" #include "include/mp3_buffer.h" /* Frame size value for one second */ __xdata Uint16 song_frame_size; static void snd_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} }; /* initialize sound controls */ void snd_init (void) { MP3VOL = VOLUME_MED; MP3VOR = VOLUME_MED; MP3BAS = BASS_MED; MP3MED = MEDIUM_MED; MP3TRE = TREBLE_MED; } void snd_vol_inc(void) { if (MP3VOL != VOLUME_MAX) { MP3VOL++; MP3VOR = MP3VOL; } } void snd_bas_inc(void) { if (MP3BAS != BASS_MAX) { MP3BAS++; } } void snd_med_inc(void) { if (MP3MED != MEDIUM_MAX) { MP3MED++; } } void snd_tre_inc(void) { if (MP3TRE != TREBLE_MAX) { MP3TRE++; } } void snd_vol_dec(void) { if (MP3VOL != VOLUME_MIN) { MP3VOL--; MP3VOR = MP3VOL; } } void snd_bas_dec(void) { if (MP3BAS != BASS_MIN) { MP3BAS--; } } void snd_med_dec(void) { if (MP3MED != MEDIUM_MIN) { MP3MED--; } } void snd_tre_dec(void) { if (MP3TRE != TREBLE_MIN) { MP3TRE--; } } /* this searches a frame header and initializes audio playing accordingly. it returns 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 */ Byte audio_init (void) { Byte b, c; while (!mp3_buffer_eof()) { /* continue searching synchro */ if (mp3_buffer_getc() == MP3_SYNC_H) { /* high order sync found */ b = mp3_buffer_getc(); if ((b & MP3_MSK_SYNC) == MP3_SYNC_L) { /* low order sync found */ c = mp3_buffer_getc(); /* keep MPEG Version B3 -> B2 */ b = (b & MP3_MSK_VER) >> 1; /* read FS B3:2 -> B1:0 */ b |= (c & MP3_MSK_FS) >> 2; c &= MP3_MSK_BR; /* init audio interface */ snd_audio_init(); /* program the song clocks */ clock_song_init(b); return SONG_NO_ERR; } } } return SONG_SYNC_ERR; } void snd_audio_init (void) { Aud_set_pcm_32(DAC_NB_BIT); Aud_set_song(); Aud_enable(); /* disable audio interrupt */ Aud_disable_int(); } void snd_start (void) { /* maestro please! */ Dac_unmute(); /* start sample request */ Aud_song_play(); /* enable mp3 decoder */ mp3_init(); } void snd_pause (void) { /* disable audio */ Aud_song_pause(); /* disable mp3 macrocell */ mp3_stop(); } void snd_stop (void) { /* silence please! */ Dac_mute(); /* disable audio */ aud_stop(); /* disable mp3 macrocell */ mp3_stop(); }