diff options
-rw-r--r-- | apps/codecs/asap.c | 12 | ||||
-rw-r--r-- | apps/metadata/asap.c | 99 |
2 files changed, 62 insertions, 49 deletions
diff --git a/apps/codecs/asap.c b/apps/codecs/asap.c index b549edad8b..c36a02369d 100644 --- a/apps/codecs/asap.c +++ b/apps/codecs/asap.c | |||
@@ -36,7 +36,8 @@ enum codec_status codec_main(void) | |||
36 | int song; | 36 | int song; |
37 | int duration; | 37 | int duration; |
38 | char* module; | 38 | char* module; |
39 | 39 | int bytesPerSample =2; | |
40 | |||
40 | /* Generic codec initialisation */ | 41 | /* Generic codec initialisation */ |
41 | ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); | 42 | ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); |
42 | 43 | ||
@@ -74,10 +75,15 @@ next_track: | |||
74 | ci->configure(DSP_SET_SAMPLE_DEPTH, 16); | 75 | ci->configure(DSP_SET_SAMPLE_DEPTH, 16); |
75 | /* Stereo or Mono output ? */ | 76 | /* Stereo or Mono output ? */ |
76 | if(asap.module_info.channels ==1) | 77 | if(asap.module_info.channels ==1) |
78 | { | ||
77 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | 79 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); |
80 | bytesPerSample = 2; | ||
81 | } | ||
78 | else | 82 | else |
83 | { | ||
79 | ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); | 84 | ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); |
80 | 85 | bytesPerSample = 4; | |
86 | } | ||
81 | /* reset eleapsed */ | 87 | /* reset eleapsed */ |
82 | ci->set_elapsed(0); | 88 | ci->set_elapsed(0); |
83 | 89 | ||
@@ -115,7 +121,7 @@ next_track: | |||
115 | n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE); | 121 | n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE); |
116 | #endif | 122 | #endif |
117 | 123 | ||
118 | ci->pcmbuf_insert(samples, NULL, n_bytes /2); | 124 | ci->pcmbuf_insert(samples, NULL, n_bytes /bytesPerSample); |
119 | 125 | ||
120 | bytes_done += n_bytes; | 126 | bytes_done += n_bytes; |
121 | ci->set_elapsed((bytes_done / 2) / 44.1); | 127 | ci->set_elapsed((bytes_done / 2) / 44.1); |
diff --git a/apps/metadata/asap.c b/apps/metadata/asap.c index 1ab972181c..9bd615afd1 100644 --- a/apps/metadata/asap.c +++ b/apps/metadata/asap.c | |||
@@ -33,18 +33,6 @@ | |||
33 | 33 | ||
34 | #define MAX_SONGS 32 | 34 | #define MAX_SONGS 32 |
35 | 35 | ||
36 | struct module_info | ||
37 | { | ||
38 | char name[255]; | ||
39 | char author[255]; | ||
40 | char date[255]; | ||
41 | int numSongs; | ||
42 | int defSong; | ||
43 | int numChannels; | ||
44 | int durations[32]; | ||
45 | int loops[32]; | ||
46 | }; | ||
47 | |||
48 | static bool parse_dec(int *retval, const char *p, int minval, int maxval) | 36 | static bool parse_dec(int *retval, const char *p, int minval, int maxval) |
49 | { | 37 | { |
50 | int r = 0; | 38 | int r = 0; |
@@ -116,7 +104,26 @@ static int ASAP_ParseDuration(const char *s) | |||
116 | return r; | 104 | return r; |
117 | } | 105 | } |
118 | 106 | ||
119 | static bool parse_sap_header(int fd,struct module_info* info,int file_len) | 107 | static bool read_asap_string(char* source,char** buf,char** buffer_end,char** dest) |
108 | { | ||
109 | if(parse_text(*buf,source) == false) return false; | ||
110 | |||
111 | /* set dest pointer */ | ||
112 | *dest = *buf; | ||
113 | |||
114 | /* move buf ptr */ | ||
115 | *buf += strlen(*buf)+1; | ||
116 | |||
117 | /* check size */ | ||
118 | if(*buf >= *buffer_end) | ||
119 | { | ||
120 | DEBUGF("Buffer full\n"); | ||
121 | return false; | ||
122 | } | ||
123 | return true; | ||
124 | } | ||
125 | |||
126 | static bool parse_sap_header(int fd,struct mp3entry* id3,int file_len) | ||
120 | { | 127 | { |
121 | int module_index = 0; | 128 | int module_index = 0; |
122 | int sap_signature = -1; | 129 | int sap_signature = -1; |
@@ -125,15 +132,20 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len) | |||
125 | int i; | 132 | int i; |
126 | 133 | ||
127 | /* set defaults */ | 134 | /* set defaults */ |
128 | 135 | int numSongs=1; | |
129 | info->numSongs=1; | 136 | int defSong=0; |
130 | info->defSong=0; | 137 | int numChannels=1; |
131 | info->numChannels=1; | 138 | int durations[MAX_SONGS]; |
139 | int loops[MAX_SONGS]; | ||
132 | for (i = 0; i < MAX_SONGS; i++) { | 140 | for (i = 0; i < MAX_SONGS; i++) { |
133 | info->durations[i] = -1; | 141 | durations[i] = -1; |
134 | info->loops[i] = 0; | 142 | loops[i] = 0; |
135 | } | 143 | } |
136 | 144 | ||
145 | /* use id3v2 buffer for our strings */ | ||
146 | char* buffer = id3->id3v2buf; | ||
147 | char* buffer_end = id3->id3v2buf + ID3V2_BUF_SIZE; | ||
148 | |||
137 | /* parse file */ | 149 | /* parse file */ |
138 | while (1) | 150 | while (1) |
139 | { | 151 | { |
@@ -166,7 +178,7 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len) | |||
166 | return false; | 178 | return false; |
167 | 179 | ||
168 | line[i] = '\0'; | 180 | line[i] = '\0'; |
169 | for (p = line; *p != '\0'; p++) { | 181 | for (p = line; *p != '\0'; p++) { |
170 | if (*p == ' ') { | 182 | if (*p == ' ') { |
171 | *p++ = '\0'; | 183 | *p++ = '\0'; |
172 | break; | 184 | break; |
@@ -180,71 +192,66 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len) | |||
180 | return false; | 192 | return false; |
181 | if (strcmp(line,"AUTHOR") == 0) | 193 | if (strcmp(line,"AUTHOR") == 0) |
182 | { | 194 | { |
183 | if (parse_text(info->author, p) == false ) | 195 | if(read_asap_string(p,&buffer,&buffer_end,&id3->artist) == false) |
184 | return false; | 196 | return false; |
185 | } | 197 | } |
186 | else if(strcmp(line,"NAME")==0) | 198 | else if(strcmp(line,"NAME")==0) |
187 | { | 199 | { |
188 | if (parse_text(info->name, p) == false) | 200 | if(read_asap_string(p,&buffer,&buffer_end,&id3->title) == false) |
189 | return false; | 201 | return false; |
190 | } | 202 | } |
191 | else if(strcmp(line,"DATE")==0) | 203 | else if(strcmp(line,"DATE")==0) |
192 | { | 204 | { |
193 | if (parse_text(info->date, p) == false) | 205 | if(read_asap_string(p,&buffer,&buffer_end,&id3->year_string) == false) |
194 | return false; | 206 | return false; |
195 | } | 207 | } |
196 | else if (strcmp(line,"SONGS")==0) | 208 | else if (strcmp(line,"SONGS")==0) |
197 | { | 209 | { |
198 | if (parse_dec(&info->numSongs, p,1,MAX_SONGS) == false ) | 210 | if (parse_dec(&numSongs, p,1,MAX_SONGS) == false ) |
199 | return false; | 211 | return false; |
200 | } | 212 | } |
201 | else if (strcmp(line,"DEFSONG")==0) | 213 | else if (strcmp(line,"DEFSONG")==0) |
202 | { | 214 | { |
203 | if (parse_dec(&info->defSong, p,0,MAX_SONGS) == false) | 215 | if (parse_dec(&defSong, p,0,MAX_SONGS) == false) |
204 | return false; | 216 | return false; |
205 | } | 217 | } |
206 | else if (strcmp(line,"STEREO")==0) | 218 | else if (strcmp(line,"STEREO")==0) |
207 | { | 219 | { |
208 | info->numChannels = 2; | 220 | numChannels = 2; |
209 | } | 221 | } |
210 | else if (strcmp(line,"TIME") == 0) | 222 | else if (strcmp(line,"TIME") == 0) |
211 | { | 223 | { |
212 | int duration = ASAP_ParseDuration(p); | 224 | int durationTemp = ASAP_ParseDuration(p); |
213 | if (duration < 0 || duration_index >= MAX_SONGS) | 225 | if (durationTemp < 0 || duration_index >= MAX_SONGS) |
214 | return false; | 226 | return false; |
215 | info->durations[duration_index] = duration; | 227 | durations[duration_index] = durationTemp; |
216 | if (strstr(p, "LOOP") != NULL) | 228 | if (strstr(p, "LOOP") != NULL) |
217 | info->loops[duration_index] = 1; | 229 | loops[duration_index] = 1; |
218 | duration_index++; | 230 | duration_index++; |
219 | } | 231 | } |
220 | } | 232 | } |
221 | 233 | ||
234 | /* set length: */ | ||
235 | int length = durations[defSong]; | ||
236 | if (length < 0) | ||
237 | length = 180 * 1000; | ||
238 | id3->length = length; | ||
239 | |||
222 | lseek(fd,0,SEEK_SET); | 240 | lseek(fd,0,SEEK_SET); |
223 | return true; | 241 | return true; |
224 | } | 242 | } |
225 | 243 | ||
226 | 244 | ||
227 | bool get_asap_metadata(int fd, struct mp3entry* id3) | 245 | bool get_asap_metadata(int fd, struct mp3entry* id3) |
228 | { | 246 | { |
229 | char *buf = id3->id3v2buf; | ||
230 | 247 | ||
231 | int filelength = filesize(fd); | 248 | int filelength = filesize(fd); |
232 | struct module_info *info; | ||
233 | info = (struct module_info *) (((intptr_t)buf + 3) & ~3); /* Align to 4 bytes */ | ||
234 | 249 | ||
235 | if(parse_sap_header(fd,info,filelength) == false) | 250 | if(parse_sap_header(fd,id3,filelength) == false) |
236 | { | 251 | { |
237 | DEBUGF("parse sap header failed.\n"); | 252 | DEBUGF("parse sap header failed.\n"); |
238 | return false; | 253 | return false; |
239 | } | 254 | } |
240 | |||
241 | id3->title = info->name; | ||
242 | id3->artist = info->author; | ||
243 | id3->year_string = info->date; | ||
244 | int length = info->durations[info->defSong]; | ||
245 | if (length < 0) | ||
246 | length = 180 * 1000; | ||
247 | id3->length = length; | ||
248 | 255 | ||
249 | id3->bitrate = 706; | 256 | id3->bitrate = 706; |
250 | id3->frequency = 44100; | 257 | id3->frequency = 44100; |