blob: dfffe39dd6fd30964faf13f8bd1d16618444c196 [file] [log] [blame]
Nils Wallménius0e496052007-09-24 15:57:32 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Stepan Moskovchenko
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#define FRACTSIZE 10
21
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000022#define BUF_SIZE 8192 /* 32 kB output buffers */
Nils Wallménius0e496052007-09-24 15:57:32 +000023#define NBUF 2
24
Nils Wallménius0e496052007-09-24 15:57:32 +000025#ifndef SIMULATOR
26
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000027#if (HW_SAMPR_CAPS & SAMPR_CAP_22) /* use 22050Hz if we can */
28#define SAMPLE_RATE SAMPR_22 /* 22050 */
Nils Wallménius0e496052007-09-24 15:57:32 +000029#else
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000030#define SAMPLE_RATE SAMPR_44 /* 44100 */
Nils Wallménius0e496052007-09-24 15:57:32 +000031#endif
32
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000033#ifdef CPU_PP /* the pp based targets can't handle too many voices
34 mainly because they have to use 44100Hz sample rate */
35#define MAX_VOICES 16
36#else
Stepan Moskovchenkod33645b2007-10-17 03:48:24 +000037#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000038#endif /* CPU_PP */
Nils Wallménius0e496052007-09-24 15:57:32 +000039
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000040#else /* Simulator requires 44100Hz, and we can afford to use more voices */
Nils Wallménius0e496052007-09-24 15:57:32 +000041
42#define SAMPLE_RATE SAMPR_44
43#define MAX_VOICES 48
44
45#endif
46
47#define BYTE unsigned char
48
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000049/* Data chunk ID types, returned by readID() */
Nils Wallménius0e496052007-09-24 15:57:32 +000050#define ID_UNKNOWN -1
51#define ID_MTHD 1
52#define ID_MTRK 2
53#define ID_EOF 3
54#define ID_RIFF 4
55
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000056/* MIDI Commands */
Nils Wallménius0e496052007-09-24 15:57:32 +000057#define MIDI_NOTE_OFF 128
58#define MIDI_NOTE_ON 144
59#define MIDI_AFTERTOUCH 160
60#define MIDI_CONTROL 176
61#define MIDI_PRGM 192
62#define MIDI_PITCHW 224
63
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000064/* MIDI Controllers */
Stepan Moskovchenko47d83232007-10-21 19:47:33 +000065#define CTRL_DATAENT_MSB 6
Stepan Moskovchenko1515ff82007-10-15 05:11:37 +000066#define CTRL_VOLUME 7
Nils Wallménius0e496052007-09-24 15:57:32 +000067#define CTRL_BALANCE 8
68#define CTRL_PANNING 10
Stepan Moskovchenko47d83232007-10-21 19:47:33 +000069#define CTRL_NONREG_LSB 98
70#define CTRL_NONREG_MSB 99
71#define CTRL_REG_LSB 100
72#define CTRL_REG_MSB 101
73
74#define REG_PITCHBEND_MSB 0
75#define REG_PITCHBEND_LSB 0
76
77
Nils Wallménius0e496052007-09-24 15:57:32 +000078#define CHANNEL 1
79
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000080/* Most of these are deprecated.. rampdown is used, maybe one other one too */
Nils Wallménius0e496052007-09-24 15:57:32 +000081#define STATE_ATTACK 1
82#define STATE_DECAY 2
83#define STATE_SUSTAIN 3
84#define STATE_RELEASE 4
85#define STATE_RAMPDOWN 5
86
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000087/* Loop states */
Nils Wallménius0e496052007-09-24 15:57:32 +000088#define STATE_LOOPING 7
89#define STATE_NONLOOPING 8
90
Nils Wallméniusca46a3d2007-10-04 21:01:40 +000091/* Various bits in the GUS mode byte */
Nils Wallménius0e496052007-09-24 15:57:32 +000092#define LOOP_ENABLED 4
93#define LOOP_PINGPONG 8
94#define LOOP_REVERSE 16
95
Nils Wallménius0e496052007-09-24 15:57:32 +000096struct MIDIfile
97{
98 int Length;
99 unsigned short numTracks;
100 unsigned short div; /* Time division, X ticks per millisecond */
101 struct Track * tracks[48];
102 unsigned char patches[128];
103 int numPatches;
104};
105
Nils Wallménius0e496052007-09-24 15:57:32 +0000106struct SynthObject
107{
108 struct GWaveform * wf;
109 int delta;
110 int decay;
111 unsigned int cp; /* unsigned int */
Nils Wallméniusab5a38d2007-10-18 13:43:13 +0000112 int state, loopState;
Nils Wallménius0e496052007-09-24 15:57:32 +0000113 int note, vol, ch, isUsed;
114 int curRate, curOffset, targetOffset;
115 int curPoint;
116 signed short int volscale;
117};
118
119struct Event
120{
121 unsigned int delta;
122 unsigned char status, d1, d2;
123 unsigned int len;
124 unsigned char * evData;
125};
126
127struct Track
128{
129 unsigned int size;
130 unsigned int numEvents;
131 unsigned int delta; /* For sequencing */
132 unsigned int pos; /* For sequencing */
133 void * dataBlock;
134};
135
136int printf(const char *fmt, ...);
Nils Wallménius0e496052007-09-24 15:57:32 +0000137unsigned char readChar(int file);
Nils Wallménius0e496052007-09-24 15:57:32 +0000138int readTwoBytes(int file);
139int readFourBytes(int file);
140int readVarData(int file);
141int eof(int fd);
142unsigned char * readData(int file, int len);
143void exit(int code);
144
145#define malloc(n) my_malloc(n)
146void * my_malloc(int size);
147
148extern struct SynthObject voices[MAX_VOICES];
149
150extern int chVol[16]; /* Channel volume */
Nils Wallméniuse1940b82007-10-04 19:36:42 +0000151extern int chPan[16]; /* Channel panning */
Nils Wallménius0e496052007-09-24 15:57:32 +0000152extern int chPat[16]; /* Channel patch */
153extern int chPW[16]; /* Channel pitch wheel, MSB only */
Stepan Moskovchenko1515ff82007-10-15 05:11:37 +0000154extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
Stepan Moskovchenkod33645b2007-10-17 03:48:24 +0000155extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
156extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
Stepan Moskovchenko47d83232007-10-21 19:47:33 +0000157extern unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
158extern unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
Nils Wallménius0e496052007-09-24 15:57:32 +0000159
160extern struct GPatch * gusload(char *);
161extern struct GPatch * patchSet[128];
162extern struct GPatch * drumSet[128];
163
164extern struct MIDIfile * mf;
165
166extern int numberOfSamples;
167extern long bpm;
168