2007-09-24 15:57:32 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Stepan Moskovchenko
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define FRACTSIZE 10
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
#define BUF_SIZE 8192 /* 32 kB output buffers */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define NBUF 2
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
#if (HW_SAMPR_CAPS & SAMPR_CAP_22) /* use 22050Hz if we can */
|
|
|
|
#define SAMPLE_RATE SAMPR_22 /* 22050 */
|
2007-09-24 15:57:32 +00:00
|
|
|
#else
|
2007-10-04 21:01:40 +00:00
|
|
|
#define SAMPLE_RATE SAMPR_44 /* 44100 */
|
2007-09-24 15:57:32 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
#ifdef CPU_PP /* the pp based targets can't handle too many voices
|
|
|
|
mainly because they have to use 44100Hz sample rate */
|
|
|
|
#define MAX_VOICES 16
|
|
|
|
#else
|
2007-10-17 03:48:24 +00:00
|
|
|
#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
|
2007-10-04 21:01:40 +00:00
|
|
|
#endif /* CPU_PP */
|
2007-09-24 15:57:32 +00:00
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
#else /* Simulator requires 44100Hz, and we can afford to use more voices */
|
2007-09-24 15:57:32 +00:00
|
|
|
|
|
|
|
#define SAMPLE_RATE SAMPR_44
|
|
|
|
#define MAX_VOICES 48
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BYTE unsigned char
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* Data chunk ID types, returned by readID() */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define ID_UNKNOWN -1
|
|
|
|
#define ID_MTHD 1
|
|
|
|
#define ID_MTRK 2
|
|
|
|
#define ID_EOF 3
|
|
|
|
#define ID_RIFF 4
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* MIDI Commands */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define MIDI_NOTE_OFF 128
|
|
|
|
#define MIDI_NOTE_ON 144
|
|
|
|
#define MIDI_AFTERTOUCH 160
|
|
|
|
#define MIDI_CONTROL 176
|
|
|
|
#define MIDI_PRGM 192
|
|
|
|
#define MIDI_PITCHW 224
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* MIDI Controllers */
|
2007-10-15 05:11:37 +00:00
|
|
|
#define CTRL_PWDEPTH 6
|
|
|
|
#define CTRL_VOLUME 7
|
2007-09-24 15:57:32 +00:00
|
|
|
#define CTRL_BALANCE 8
|
|
|
|
#define CTRL_PANNING 10
|
|
|
|
#define CHANNEL 1
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* Most of these are deprecated.. rampdown is used, maybe one other one too */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define STATE_ATTACK 1
|
|
|
|
#define STATE_DECAY 2
|
|
|
|
#define STATE_SUSTAIN 3
|
|
|
|
#define STATE_RELEASE 4
|
|
|
|
#define STATE_RAMPDOWN 5
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* Loop states */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define STATE_LOOPING 7
|
|
|
|
#define STATE_NONLOOPING 8
|
|
|
|
|
2007-10-04 21:01:40 +00:00
|
|
|
/* Various bits in the GUS mode byte */
|
2007-09-24 15:57:32 +00:00
|
|
|
#define LOOP_ENABLED 4
|
|
|
|
#define LOOP_PINGPONG 8
|
|
|
|
#define LOOP_REVERSE 16
|
|
|
|
|
|
|
|
struct MIDIfile
|
|
|
|
{
|
|
|
|
int Length;
|
|
|
|
unsigned short numTracks;
|
|
|
|
unsigned short div; /* Time division, X ticks per millisecond */
|
|
|
|
struct Track * tracks[48];
|
|
|
|
unsigned char patches[128];
|
|
|
|
int numPatches;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SynthObject
|
|
|
|
{
|
|
|
|
struct GWaveform * wf;
|
|
|
|
int delta;
|
|
|
|
int decay;
|
|
|
|
unsigned int cp; /* unsigned int */
|
2007-10-18 13:43:13 +00:00
|
|
|
int state, loopState;
|
2007-09-24 15:57:32 +00:00
|
|
|
int note, vol, ch, isUsed;
|
|
|
|
int curRate, curOffset, targetOffset;
|
|
|
|
int curPoint;
|
|
|
|
signed short int volscale;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Event
|
|
|
|
{
|
|
|
|
unsigned int delta;
|
|
|
|
unsigned char status, d1, d2;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned char * evData;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Track
|
|
|
|
{
|
|
|
|
unsigned int size;
|
|
|
|
unsigned int numEvents;
|
|
|
|
unsigned int delta; /* For sequencing */
|
|
|
|
unsigned int pos; /* For sequencing */
|
|
|
|
void * dataBlock;
|
|
|
|
};
|
|
|
|
|
|
|
|
int printf(const char *fmt, ...);
|
|
|
|
unsigned char readChar(int file);
|
|
|
|
int readTwoBytes(int file);
|
|
|
|
int readFourBytes(int file);
|
|
|
|
int readVarData(int file);
|
|
|
|
int eof(int fd);
|
|
|
|
unsigned char * readData(int file, int len);
|
|
|
|
void exit(int code);
|
|
|
|
|
|
|
|
#define malloc(n) my_malloc(n)
|
|
|
|
void * my_malloc(int size);
|
|
|
|
|
|
|
|
extern struct SynthObject voices[MAX_VOICES];
|
|
|
|
|
|
|
|
extern int chVol[16]; /* Channel volume */
|
2007-10-04 19:36:42 +00:00
|
|
|
extern int chPan[16]; /* Channel panning */
|
2007-09-24 15:57:32 +00:00
|
|
|
extern int chPat[16]; /* Channel patch */
|
|
|
|
extern int chPW[16]; /* Channel pitch wheel, MSB only */
|
2007-10-15 05:11:37 +00:00
|
|
|
extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
|
2007-10-17 03:48:24 +00:00
|
|
|
extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
|
|
|
|
extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
|
|
|
|
|
|
|
|
|
2007-09-24 15:57:32 +00:00
|
|
|
|
|
|
|
extern struct GPatch * gusload(char *);
|
|
|
|
extern struct GPatch * patchSet[128];
|
|
|
|
extern struct GPatch * drumSet[128];
|
|
|
|
|
|
|
|
extern struct MIDIfile * mf;
|
|
|
|
|
|
|
|
extern int numberOfSamples;
|
|
|
|
extern long bpm;
|
|
|
|
|