diff options
Diffstat (limited to 'apps/plugins/midi2wav.c')
-rw-r--r-- | apps/plugins/midi2wav.c | 232 |
1 files changed, 0 insertions, 232 deletions
diff --git a/apps/plugins/midi2wav.c b/apps/plugins/midi2wav.c deleted file mode 100644 index 241d56defb..0000000000 --- a/apps/plugins/midi2wav.c +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2005 Stepan Moskovchenko | ||
10 | * | ||
11 | * All files in this archive are subject to the GNU General Public License. | ||
12 | * See the file COPYING in the source tree root for full license agreement. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #define SAMPLE_RATE 22050 | ||
20 | #define MAX_VOICES 100 | ||
21 | |||
22 | |||
23 | /* Only define LOCAL_DSP on Simulator or else we're asking for trouble */ | ||
24 | #if defined(SIMULATOR) | ||
25 | /*Enable this to write to the soundcard via a /dsv/dsp symlink in */ | ||
26 | // #define LOCAL_DSP | ||
27 | #endif | ||
28 | |||
29 | |||
30 | #if defined(LOCAL_DSP) | ||
31 | /* This is for writing to the DSP directly from the Simulator */ | ||
32 | #include <stdio.h> | ||
33 | #include <stdlib.h> | ||
34 | #include <linux/soundcard.h> | ||
35 | #include <sys/ioctl.h> | ||
36 | #endif | ||
37 | |||
38 | #include "../../firmware/export/system.h" | ||
39 | |||
40 | #include "../../plugin.h" | ||
41 | |||
42 | #include "lib/xxx2wav.h" | ||
43 | |||
44 | int numberOfSamples IDATA_ATTR; | ||
45 | long bpm; | ||
46 | |||
47 | #include "midi/midiutil.c" | ||
48 | #include "midi/guspat.h" | ||
49 | #include "midi/guspat.c" | ||
50 | #include "midi/sequencer.c" | ||
51 | #include "midi/midifile.c" | ||
52 | #include "midi/synth.c" | ||
53 | |||
54 | |||
55 | |||
56 | |||
57 | int fd=-1; /* File descriptor where the output is written */ | ||
58 | |||
59 | extern long tempo; /* The sequencer keeps track of this */ | ||
60 | |||
61 | |||
62 | struct plugin_api * rb; | ||
63 | |||
64 | |||
65 | |||
66 | |||
67 | |||
68 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
69 | { | ||
70 | TEST_PLUGIN_API(api); | ||
71 | rb = api; | ||
72 | TEST_PLUGIN_API(api); | ||
73 | (void)parameter; | ||
74 | rb = api; | ||
75 | |||
76 | if(parameter == NULL) | ||
77 | { | ||
78 | rb->splash(HZ*2, true, " Play .MID file "); | ||
79 | return PLUGIN_OK; | ||
80 | } | ||
81 | |||
82 | rb->splash(HZ, true, parameter); | ||
83 | if(midimain(parameter) == -1) | ||
84 | { | ||
85 | return PLUGIN_ERROR; | ||
86 | } | ||
87 | rb->splash(HZ*3, true, "FINISHED PLAYING"); | ||
88 | return PLUGIN_OK; | ||
89 | } | ||
90 | |||
91 | signed char outputBuffer[3000] IDATA_ATTR; /* signed char.. gonna run out of iram ... ! */ | ||
92 | |||
93 | |||
94 | int currentSample IDATA_ATTR; | ||
95 | int outputBufferPosition IDATA_ATTR; | ||
96 | int outputSampleOne IDATA_ATTR; | ||
97 | int outputSampleTwo IDATA_ATTR; | ||
98 | |||
99 | |||
100 | int midimain(void * filename) | ||
101 | { | ||
102 | |||
103 | printf("\nHello.\n"); | ||
104 | |||
105 | rb->splash(HZ/5, true, "LOADING MIDI"); | ||
106 | |||
107 | struct MIDIfile * mf = loadFile(filename); | ||
108 | |||
109 | rb->splash(HZ/5, true, "LOADING PATCHES"); | ||
110 | if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) | ||
111 | { | ||
112 | return -1; | ||
113 | } | ||
114 | |||
115 | /* | ||
116 | * This lets you hear the music through the sound card if you are on Simulator | ||
117 | * Make a symlink, archos/dsp.raw and make it point to /dev/dsp or whatever | ||
118 | * your sound device is. | ||
119 | */ | ||
120 | |||
121 | #if defined(LOCAL_DSP) | ||
122 | fd=rb->open("/dsp.raw", O_WRONLY); | ||
123 | int arg, status; | ||
124 | int bit, samp, ch; | ||
125 | |||
126 | arg = 16; /* sample size */ | ||
127 | status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg); | ||
128 | status = ioctl(fd, SOUND_PCM_READ_BITS, &arg); | ||
129 | bit=arg; | ||
130 | |||
131 | |||
132 | arg = 2; /* Number of channels, 1=mono */ | ||
133 | status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg); | ||
134 | status = ioctl(fd, SOUND_PCM_READ_CHANNELS, &arg); | ||
135 | ch=arg; | ||
136 | |||
137 | arg = SAMPLE_RATE; /* Yeah. sampling rate */ | ||
138 | status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg); | ||
139 | status = ioctl(fd, SOUND_PCM_READ_RATE, &arg); | ||
140 | samp=arg; | ||
141 | #else | ||
142 | file_info_struct file_info; | ||
143 | file_info.samplerate = SAMPLE_RATE; | ||
144 | file_info.infile = fd; | ||
145 | file_info.channels = 2; | ||
146 | file_info.bitspersample = 16; | ||
147 | local_init("/miditest.tmp", "/miditest.wav", &file_info, rb); | ||
148 | fd = file_info.outfile; | ||
149 | #endif | ||
150 | |||
151 | |||
152 | rb->splash(HZ/5, true, " I hope this works... "); | ||
153 | |||
154 | |||
155 | |||
156 | |||
157 | /* | ||
158 | * tick() will do one MIDI clock tick. Then, there's a loop here that | ||
159 | * will generate the right number of samples per MIDI tick. The whole | ||
160 | * MIDI playback is timed in terms of this value.. there are no forced | ||
161 | * delays or anything. It just produces enough samples for each tick, and | ||
162 | * the playback of these samples is what makes the timings right. | ||
163 | * | ||
164 | * This seems to work quite well. | ||
165 | */ | ||
166 | |||
167 | printf("\nOkay, starting sequencing"); | ||
168 | |||
169 | |||
170 | currentSample=0; /* Sample counting variable */ | ||
171 | outputBufferPosition = 0; | ||
172 | |||
173 | |||
174 | bpm=mf->div*1000000/tempo; | ||
175 | numberOfSamples=SAMPLE_RATE/bpm; | ||
176 | |||
177 | |||
178 | |||
179 | /* Tick() will return 0 if there are no more events left to play */ | ||
180 | while(tick(mf)) | ||
181 | { | ||
182 | /* | ||
183 | * Tempo recalculation moved to sequencer.c to be done on a tempo event only | ||
184 | * | ||
185 | */ | ||
186 | for(currentSample=0; currentSample<numberOfSamples; currentSample++) | ||
187 | { | ||
188 | |||
189 | synthSample(&outputSampleOne, &outputSampleTwo); | ||
190 | |||
191 | |||
192 | /* | ||
193 | * 16-bit audio because, well, it's better | ||
194 | * But really because ALSA's OSS emulation sounds extremely | ||
195 | * noisy and distorted when in 8-bit mode. I still do not know | ||
196 | * why this happens. | ||
197 | */ | ||
198 | |||
199 | outputBuffer[outputBufferPosition]=outputSampleOne&0XFF; // Low byte first | ||
200 | outputBufferPosition++; | ||
201 | outputBuffer[outputBufferPosition]=outputSampleOne>>8; //High byte second | ||
202 | outputBufferPosition++; | ||
203 | |||
204 | outputBuffer[outputBufferPosition]=outputSampleTwo&0XFF; // Low byte first | ||
205 | outputBufferPosition++; | ||
206 | outputBuffer[outputBufferPosition]=outputSampleTwo>>8; //High byte second | ||
207 | outputBufferPosition++; | ||
208 | |||
209 | |||
210 | /* | ||
211 | * As soon as we produce 2000 bytes of sound, | ||
212 | * write it to the sound card. Why 2000? I have | ||
213 | * no idea. It's 1 AM and I am dead tired. | ||
214 | */ | ||
215 | if(outputBufferPosition>=2000) | ||
216 | { | ||
217 | rb->write(fd, outputBuffer, 2000); | ||
218 | outputBufferPosition=0; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | printf("\n"); | ||
224 | |||
225 | #if !defined(LOCAL_DSP) | ||
226 | |||
227 | close_wav(&file_info); | ||
228 | #else | ||
229 | rb->close(fd); | ||
230 | #endif | ||
231 | return 0; | ||
232 | } | ||