diff options
Diffstat (limited to 'apps/codecs/asap.c')
-rw-r--r-- | apps/codecs/asap.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/apps/codecs/asap.c b/apps/codecs/asap.c new file mode 100644 index 0000000000..f6fa68f4f4 --- /dev/null +++ b/apps/codecs/asap.c | |||
@@ -0,0 +1,131 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: asap.c 17847 2008-06-28 18:10:04Z domonoky $ | ||
9 | * | ||
10 | * Copyright (C) 2008 Dominik Wenger | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "codeclib.h" | ||
23 | #include "asap/asap.h" | ||
24 | |||
25 | CODEC_HEADER | ||
26 | |||
27 | #define CHUNK_SIZE (1024*8) | ||
28 | |||
29 | static byte samples[CHUNK_SIZE]; /* The sample buffer */ | ||
30 | static ASAP_State asap; /* asap codec state */ | ||
31 | |||
32 | /* this is the codec entry point */ | ||
33 | enum codec_status codec_main(void) | ||
34 | { | ||
35 | int n_bytes; | ||
36 | int song; | ||
37 | int duration; | ||
38 | char* module; | ||
39 | |||
40 | /* Generic codec initialisation */ | ||
41 | ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); | ||
42 | |||
43 | next_track: | ||
44 | if (codec_init()) { | ||
45 | DEBUGF("codec init failed\n"); | ||
46 | return CODEC_ERROR; | ||
47 | } | ||
48 | |||
49 | while (!*ci->taginfo_ready && !ci->stop_codec) | ||
50 | ci->sleep(1); | ||
51 | |||
52 | codec_set_replaygain(ci->id3); | ||
53 | |||
54 | int bytes_done =0; | ||
55 | int filesize; | ||
56 | ci->seek_buffer(0); | ||
57 | module = ci->request_buffer(&filesize, ci->filesize); | ||
58 | if (!module || (size_t)filesize < (size_t)ci->filesize) | ||
59 | { | ||
60 | DEBUGF("loading error\n"); | ||
61 | return CODEC_ERROR; | ||
62 | } | ||
63 | |||
64 | /*Init ASAP */ | ||
65 | if (!ASAP_Load(&asap, ci->id3->path, module, filesize)) | ||
66 | { | ||
67 | DEBUGF("%s: format not supported",ci->id3->path); | ||
68 | return CODEC_ERROR; | ||
69 | } | ||
70 | |||
71 | /* Make use of 44.1khz */ | ||
72 | ci->configure(DSP_SET_FREQUENCY, 44100); | ||
73 | /* Sample depth is 16 bit little endian */ | ||
74 | ci->configure(DSP_SET_SAMPLE_DEPTH, 16); | ||
75 | /* Stereo or Mono output ? */ | ||
76 | if(asap.module_info.channels ==1) | ||
77 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | ||
78 | else | ||
79 | ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); | ||
80 | |||
81 | /* reset eleapsed */ | ||
82 | ci->set_elapsed(0); | ||
83 | |||
84 | song = asap.module_info.default_song; | ||
85 | duration = asap.module_info.durations[song]; | ||
86 | if (duration < 0) | ||
87 | duration = 180 * 1000; | ||
88 | |||
89 | ASAP_PlaySong(&asap, song, duration); | ||
90 | ASAP_MutePokeyChannels(&asap, 0); | ||
91 | |||
92 | /* The main decoder loop */ | ||
93 | while (1) { | ||
94 | ci->yield(); | ||
95 | if (ci->stop_codec || ci->new_track) | ||
96 | break; | ||
97 | |||
98 | if (ci->seek_time) { | ||
99 | /* New time is ready in ci->seek_time */ | ||
100 | |||
101 | /* seek to pos */ | ||
102 | ASAP_Seek(&asap,ci->seek_time); | ||
103 | /* update elapsed */ | ||
104 | ci->set_elapsed(ci->seek_time); | ||
105 | /* update bytes_done */ | ||
106 | bytes_done = ci->seek_time*44.1*2; | ||
107 | /* seek ready */ | ||
108 | ci->seek_complete(); | ||
109 | } | ||
110 | |||
111 | /* Generate a buffer full of Audio */ | ||
112 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
113 | n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_LE); | ||
114 | #else | ||
115 | n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE); | ||
116 | #endif | ||
117 | |||
118 | ci->pcmbuf_insert(samples, NULL, n_bytes /2); | ||
119 | |||
120 | bytes_done += n_bytes; | ||
121 | ci->set_elapsed((bytes_done / 2) / 44.1); | ||
122 | |||
123 | if(n_bytes != sizeof(samples)) | ||
124 | break; | ||
125 | } | ||
126 | |||
127 | if (ci->request_next_track()) | ||
128 | goto next_track; | ||
129 | |||
130 | return CODEC_OK; | ||
131 | } | ||