blob: 6968c83c9aeaecc9e12c6d881aceea6d080f3d5e [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
22#define BUF_SIZE 256
23#define NBUF 2
24
25
26#ifndef SIMULATOR
27
28#if (HW_SAMPR_CAPS & SAMPR_CAP_22)
29#define SAMPLE_RATE SAMPR_22 // 44100 22050 11025
30#else
31#define SAMPLE_RATE SAMPR_44 // 44100 22050 11025
32#endif
33
Stepan Moskovchenko1ed54f42007-09-30 09:04:39 +000034#define MAX_VOICES 23 // Note: 24 midi channels is the minimum general midi
Nils Wallménius0e496052007-09-24 15:57:32 +000035 // spec implementation
36
37#else // Simulator requires 44100, and we can afford to use more voices
38
39#define SAMPLE_RATE SAMPR_44
40#define MAX_VOICES 48
41
42#endif
43
44#define BYTE unsigned char
45
46//Data chunk ID types, returned by readID()
47#define ID_UNKNOWN -1
48#define ID_MTHD 1
49#define ID_MTRK 2
50#define ID_EOF 3
51#define ID_RIFF 4
52
53//MIDI Commands
54#define MIDI_NOTE_OFF 128
55#define MIDI_NOTE_ON 144
56#define MIDI_AFTERTOUCH 160
57#define MIDI_CONTROL 176
58#define MIDI_PRGM 192
59#define MIDI_PITCHW 224
60
61//MIDI Controllers
62#define CTRL_VOLUME 7
63#define CTRL_BALANCE 8
64#define CTRL_PANNING 10
65#define CHANNEL 1
66
67//Most of these are deprecated.. rampdown is used, maybe one other one too
68#define STATE_ATTACK 1
69#define STATE_DECAY 2
70#define STATE_SUSTAIN 3
71#define STATE_RELEASE 4
72#define STATE_RAMPDOWN 5
73
74//Loop states
75#define STATE_LOOPING 7
76#define STATE_NONLOOPING 8
77
78//Various bits in the GUS mode byte
79#define LOOP_ENABLED 4
80#define LOOP_PINGPONG 8
81#define LOOP_REVERSE 16
82
83#define LOOPDIR_FORWARD 0
84#define LOOPDIR_REVERSE 1
85
86struct MIDIfile
87{
88 int Length;
89 unsigned short numTracks;
90 unsigned short div; /* Time division, X ticks per millisecond */
91 struct Track * tracks[48];
92 unsigned char patches[128];
93 int numPatches;
94};
95
96/*
97struct SynthObject
98{
99 struct GWaveform * wf;
100 unsigned int delta;
101 unsigned int decay;
102 unsigned int cp;
103 unsigned char state, loopState, loopDir;
104 unsigned char note, vol, ch, isUsed;
105 int curRate, curOffset, targetOffset;
106 unsigned int curPoint;
107};
108*/
109
110struct SynthObject
111{
112 struct GWaveform * wf;
113 int delta;
114 int decay;
115 unsigned int cp; /* unsigned int */
116 int state, loopState, loopDir;
117 int note, vol, ch, isUsed;
118 int curRate, curOffset, targetOffset;
119 int curPoint;
120 signed short int volscale;
121};
122
123struct Event
124{
125 unsigned int delta;
126 unsigned char status, d1, d2;
127 unsigned int len;
128 unsigned char * evData;
129};
130
131struct Track
132{
133 unsigned int size;
134 unsigned int numEvents;
135 unsigned int delta; /* For sequencing */
136 unsigned int pos; /* For sequencing */
137 void * dataBlock;
138};
139
140int printf(const char *fmt, ...);
Nils Wallménius0e496052007-09-24 15:57:32 +0000141unsigned char readChar(int file);
Nils Wallménius0e496052007-09-24 15:57:32 +0000142int readTwoBytes(int file);
143int readFourBytes(int file);
144int readVarData(int file);
145int eof(int fd);
146unsigned char * readData(int file, int len);
147void exit(int code);
148
149#define malloc(n) my_malloc(n)
150void * my_malloc(int size);
151
152extern struct SynthObject voices[MAX_VOICES];
153
154extern int chVol[16]; /* Channel volume */
155extern int chPanLeft[16]; /* Channel panning */
156extern int chPanRight[16];
157extern int chPat[16]; /* Channel patch */
158extern int chPW[16]; /* Channel pitch wheel, MSB only */
159
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