1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "general.h"
6 #include "fileoutput.h"
7
8 /*
9
10 Ringtone Tools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
11 This falls under the Kohnian license. Please read
12 it at http://ringtonetools.mikekohn.net/
13
14 This program is NOT opensourced. You may not use any part
15 of this program for your own software.
16
17 */
18
write_long(FILE * out,int n)19 int write_long(FILE *out, int n)
20 {
21 putc((n&255),out);
22 putc(((n>>8)&255),out);
23 putc(((n>>16)&255),out);
24 putc(((n>>24)&255),out);
25
26 return 0;
27 }
28
write_word(FILE * out,int n)29 int write_word(FILE *out, int n)
30 {
31 putc((n&255),out);
32 putc(((n>>8)&255),out);
33
34 return 0;
35 }
36
read_long(FILE * in)37 int read_long(FILE *in)
38 {
39 int c;
40
41 c=getc(in);
42 c=c|(getc(in)<<8);
43 c=c|(getc(in)<<16);
44 c=c|(getc(in)<<24);
45
46 return c;
47 }
48
read_word(FILE * in)49 int read_word(FILE *in)
50 {
51 int c;
52
53 c=getc(in);
54 c=c|(getc(in)<<8);
55
56 return c;
57 }
58
write_long_b(FILE * out,int n)59 int write_long_b(FILE *out, int n)
60 {
61 putc(((n>>24)&255),out);
62 putc(((n>>16)&255),out);
63 putc(((n>>8)&255),out);
64 putc((n&255),out);
65
66 return 0;
67 }
68
write_word_b(FILE * out,int n)69 int write_word_b(FILE *out, int n)
70 {
71 putc(((n>>8)&255),out);
72 putc((n&255),out);
73
74 return 0;
75 }
76
read_long_b(FILE * in)77 int read_long_b(FILE *in)
78 {
79 int c;
80
81 c=getc(in);
82 c=(c<<8)|getc(in);
83 c=(c<<8)|getc(in);
84 c=(c<<8)|getc(in);
85
86 return c;
87 }
88
read_word_b(FILE * in)89 int read_word_b(FILE *in)
90 {
91 int c;
92
93 c=getc(in);
94 c=(c<<8)|getc(in);
95
96 return c;
97 }
98
read_chars(FILE * in,char * s,int count)99 int read_chars(FILE *in, char *s, int count)
100 {
101 int t;
102
103 for (t=0; t<count; t++)
104 {
105 s[t]=getc(in);
106 }
107
108 s[t]=0;
109
110 return 0;
111 }
112
write_chars(FILE * out,char * s)113 int write_chars(FILE *out, char *s)
114 {
115 int t;
116
117 t=0;
118 while(s[t]!=0 && t<255)
119 {
120 putc(s[t++],out);
121 }
122
123 return 0;
124 }
125
126 /* Routing */
127
header_route(FILE * out,struct note_t * note,int in_type,int out_type)128 int header_route(FILE *out, struct note_t *note, int in_type, int out_type)
129 {
130 if (out_type==0)
131 { write_wav_header(out,note); }
132 else
133 if (out_type==1)
134 { write_kws_header(out,note); }
135 else
136 if (out_type==2)
137 { write_mot_header(out,note); }
138 else
139 if (out_type==4)
140 { write_nokia_header(out,note); }
141 else
142 if (out_type==5)
143 { write_rtttl_header(out,note); }
144 else
145 if (out_type==6 || out_type==7)
146 { write_samsung_header(out,note); }
147 else
148 if (out_type==8)
149 { write_midi_header(out,note); }
150 else
151 if (out_type==9)
152 { write_siemens_header(out,note); }
153 else
154 if (out_type==10)
155 { write_mot_key_header(out,note); }
156 else
157 if (out_type==11)
158 { write_emelody_header(out,note); }
159 else
160 if (out_type==12)
161 { write_imelody_header(out,note); }
162 else
163 if (out_type==15)
164 { write_3210_header(out,note); }
165 #ifdef DSP
166 else
167 if (out_type==19)
168 { write_dsp_header(out,note); }
169 #endif
170
171 return 0;
172 }
173
note_route(FILE * out,struct note_t * note,int in_type,int out_type)174 int note_route(FILE *out, struct note_t *note, int in_type, int out_type)
175 {
176 if (out_type==0)
177 { write_wav_note(out,note); }
178 else
179 if (out_type==1)
180 { write_kws_note(out,note); }
181 else
182 if (out_type==2)
183 { write_mot_note(out,note); }
184 else
185 if (out_type==4)
186 { write_nokia_note(out,note); }
187 else
188 if (out_type==5)
189 { write_rtttl_note(out,note); }
190 else
191 if (out_type==6)
192 { write_samsung1_note(out,note); }
193 else
194 if (out_type==7)
195 { write_samsung2_note(out,note); }
196 else
197 if (out_type==8)
198 { write_midi_note(out,note); }
199 else
200 if (out_type==9)
201 { write_siemens_note(out,note); }
202 else
203 if (out_type==10)
204 { write_mot_key_note(out,note); }
205 else
206 if (out_type==11)
207 { write_emelody_note(out,note); }
208 else
209 if (out_type==12)
210 { write_imelody_note(out,note); }
211 else
212 if (out_type==15)
213 { write_3210_note(out,note); }
214 #ifdef DSP
215 else
216 if (out_type==19)
217 { write_dsp_note(out,note); }
218 #endif
219
220 note->note_count++;
221
222 return 0;
223 }
224
footer_route(FILE * out,struct note_t * note,int in_type,int out_type)225 int footer_route(FILE *out, struct note_t *note, int in_type, int out_type)
226 {
227 if (out_type==0)
228 { write_wav_footer(out,note); }
229 else
230 if (out_type==1)
231 { write_kws_footer(out,note); }
232 else
233 if (out_type==2)
234 { write_mot_footer(out,note); }
235 else
236 if (out_type==4)
237 { write_nokia_footer(out,note); }
238 else
239 if (out_type==5)
240 { write_rtttl_footer(out,note); }
241 else
242 if (out_type==6 || out_type==7)
243 { write_samsung_footer(out,note); }
244 else
245 if (out_type==8)
246 { write_midi_footer(out,note); }
247 else
248 if (out_type==9)
249 { write_siemens_footer(out,note); }
250 else
251 if (out_type==10)
252 { write_mot_key_footer(out,note); }
253 else
254 if (out_type==11)
255 { write_emelody_footer(out,note); }
256 else
257 if (out_type==12)
258 { write_imelody_footer(out,note); }
259 else
260 if (out_type==15)
261 { write_3210_footer(out,note); }
262 #ifdef DSP
263 else
264 if (out_type==19)
265 { write_dsp_footer(out,note); }
266 #endif
267
268 return 0;
269 }
270
logo_header_route(FILE * out,struct note_t * note,int out_type)271 int logo_header_route(FILE *out, struct note_t *note, int out_type)
272 {
273 if (note->width>MAX_WIDTH || note->height>MAX_HEIGHT)
274 {
275 printf("Logos are limited to %d x %d. Image is too big.\n",MAX_WIDTH,MAX_HEIGHT);
276 return -1;
277 }
278
279 note->picture=malloc(note->width*note->height*sizeof(int));
280 memset(note->picture,0,note->width*note->height*sizeof(int));
281
282 if (out_type==4) write_nokia_logo_header(out,note);
283 else
284 if (out_type==14) write_ems_logo_header(out,note);
285 else
286 if (out_type==17) write_bmp_header(out,note);
287 else
288 if (out_type==18) { }
289 else
290 if (out_type==20 || out_type==21) write_ngg_logo_header(out,note);
291 else
292 if (out_type==22) write_wbmp_header(out,note);
293 else
294 if (out_type==23) write_icon_header(out,note);
295 else
296 if (out_type==24) write_gif_header(out,note);
297 else
298 {
299 printf("This file cannot be converted to this output file type\n");
300 return -1;
301 }
302
303 return 0;
304 }
305
logo_footer_route(FILE * out,struct note_t * note,int out_type)306 int logo_footer_route(FILE *out, struct note_t *note, int out_type)
307 {
308 int f,u,c;
309
310 if ((note->bmp_flags&1)==1)
311 {
312 f=note->width*note->height;
313
314 for(u=0; u<f; u++)
315 {
316 c=note->picture[u];
317 c=(255-(c&255))+((255-((c>>8)&255))<<8)+((255-((c>>16)&255))<<16);
318 note->picture[u]=c;
319 }
320 }
321
322 #ifdef DEBUG
323 debug_logo(note);
324 #endif
325
326 if (out_type==4) write_nokia_logo_footer(out,note);
327 else
328 if (out_type==14) write_ems_logo_footer(out,note);
329 else
330 if (out_type==17) write_bmp_footer(out,note);
331 else
332 if (out_type==18) write_text_footer(out,note);
333 else
334 if (out_type==20 || out_type==21) write_ngg_logo_footer(out,note);
335 else
336 if (out_type==22) write_wbmp_footer(out,note);
337 else
338 if (out_type==23) write_icon_footer(out,note);
339 else
340 if (out_type==24) write_gif_footer(out,note);
341
342 free(note->picture);
343
344 return 0;
345 }
346
tempo_route(FILE * out,struct note_t * note,int in_type,int out_type)347 int tempo_route(FILE *out, struct note_t *note, int in_type, int out_type)
348 {
349 if (out_type==4)
350 { write_nokia_bpm(out,note); }
351 else
352 if (out_type==8)
353 { write_midi_bpm(out,note); }
354 else
355 if (out_type==5 && note->channels==1)
356 { write_rtx_bpm(out,note); }
357
358 return 0;
359 }
360
volume_route(FILE * out,struct note_t * note,int in_type,int out_type)361 int volume_route(FILE *out, struct note_t *note, int in_type, int out_type)
362 {
363 if (out_type==4)
364 { write_nokia_volume(out,note); }
365
366 return 0;
367 }
368
369
370
371