mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Move all of midiplay into its subdir and add a Makefile for it, add header files as necessary.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14841 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
e24975a35f
commit
0e49605aaa
15 changed files with 377 additions and 195 deletions
|
@ -122,7 +122,6 @@ nim.c
|
||||||
|
|
||||||
#if CONFIG_CODEC == SWCODEC /* software codec platforms */
|
#if CONFIG_CODEC == SWCODEC /* software codec platforms */
|
||||||
mp3_encoder.c
|
mp3_encoder.c
|
||||||
midiplay.c
|
|
||||||
wav2wv.c
|
wav2wv.c
|
||||||
#else /* hardware codec platforms */
|
#else /* hardware codec platforms */
|
||||||
#ifndef HAVE_MMC /* not for Ondio, has no remote control pin */
|
#ifndef HAVE_MMC /* not for Ondio, has no remote control pin */
|
||||||
|
|
|
@ -42,6 +42,7 @@ doom
|
||||||
|
|
||||||
/* For all the swcodec targets */
|
/* For all the swcodec targets */
|
||||||
#if CONFIG_CODEC == SWCODEC
|
#if CONFIG_CODEC == SWCODEC
|
||||||
|
midi
|
||||||
mpegplayer
|
mpegplayer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
74
apps/plugins/midi/Makefile
Normal file
74
apps/plugins/midi/Makefile
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
# __________ __ ___.
|
||||||
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
# \/ \/ \/ \/ \/
|
||||||
|
# $Id $
|
||||||
|
#
|
||||||
|
|
||||||
|
INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
|
||||||
|
-I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
|
||||||
|
CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET) $(EXTRA_DEFINES) \
|
||||||
|
-DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
|
||||||
|
|
||||||
|
ifdef APPEXTRA
|
||||||
|
INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
|
||||||
|
endif
|
||||||
|
|
||||||
|
LINKFILE := $(OBJDIR)/link.lds
|
||||||
|
DEPFILE = $(OBJDIR)/dep-midiplay
|
||||||
|
|
||||||
|
# This sets up 'SRC' based on the files mentioned in SOURCES
|
||||||
|
include $(TOOLSDIR)/makesrc.inc
|
||||||
|
|
||||||
|
SOURCES = $(SRC)
|
||||||
|
OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
|
||||||
|
DIRS = .
|
||||||
|
|
||||||
|
ifndef SIMVER
|
||||||
|
LDS := ../plugin.lds
|
||||||
|
OUTPUT = $(OUTDIR)/midiplay.rock
|
||||||
|
else ## simulators
|
||||||
|
OUTPUT = $(OUTDIR)/midiplay.rock
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: $(OUTPUT)
|
||||||
|
|
||||||
|
ifndef SIMVER
|
||||||
|
$(OBJDIR)/midiplay.elf: $(OBJS) $(LINKFILE) $(BITMAPLIBS)
|
||||||
|
$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) -o $@ $(OBJS) -L$(BUILDDIR) -lplugin -lgcc \
|
||||||
|
$(LINKBITMAPS) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/midiplay.map
|
||||||
|
|
||||||
|
$(OUTPUT): $(OBJDIR)/midiplay.elf
|
||||||
|
$(call PRINTS,OBJCOPY $(@F))$(OC) -O binary $< $@
|
||||||
|
else
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
# This is the SDL simulator version
|
||||||
|
|
||||||
|
$(OUTPUT): $(OBJS)
|
||||||
|
$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin $(LINKBITMAPS) -o $@
|
||||||
|
ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
|
||||||
|
# 'x' must be kept or you'll have "Win32 error 5"
|
||||||
|
# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
|
||||||
|
# #define ERROR_ACCESS_DENIED 5L
|
||||||
|
else
|
||||||
|
@chmod -x $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif # end of simulator section
|
||||||
|
|
||||||
|
include $(TOOLSDIR)/make.inc
|
||||||
|
|
||||||
|
# MEMORYSIZE should be passed on to this makefile with the chosen memory size
|
||||||
|
# given in number of MB
|
||||||
|
$(LINKFILE): $(LDS)
|
||||||
|
$(call PRINTS,build $(@F))cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) \
|
||||||
|
$(DEFINES) -E -P - >$@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call PRINTS,cleaning midiplay)rm -rf $(OBJDIR)/midiplay
|
||||||
|
$(SILENT)rm -f $(OBJDIR)/midiplay.* $(DEPFILE)
|
||||||
|
|
||||||
|
-include $(DEPFILE)
|
6
apps/plugins/midi/SOURCES
Normal file
6
apps/plugins/midi/SOURCES
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
midifile.c
|
||||||
|
midiutil.c
|
||||||
|
sequencer.c
|
||||||
|
guspat.c
|
||||||
|
synth.c
|
||||||
|
midiplay.c
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,7 +16,9 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "guspat.h"
|
||||||
|
#include "midiutil.h"
|
||||||
|
|
||||||
extern struct plugin_api * rb;
|
extern struct plugin_api * rb;
|
||||||
|
|
||||||
|
@ -119,8 +122,6 @@ struct GWaveform * loadWaveform(int file)
|
||||||
return wav;
|
return wav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int selectWaveform(struct GPatch * pat, int midiNote)
|
int selectWaveform(struct GPatch * pat, int midiNote)
|
||||||
{
|
{
|
||||||
/* We divide by 100 here because everyone's freq formula is slightly different */
|
/* We divide by 100 here because everyone's freq formula is slightly different */
|
||||||
|
@ -137,7 +138,6 @@ int selectWaveform(struct GPatch * pat, int midiNote)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct GPatch * gusload(char * filename)
|
struct GPatch * gusload(char * filename)
|
||||||
{
|
{
|
||||||
struct GPatch * gp = (struct GPatch *)malloc(sizeof(struct GPatch));
|
struct GPatch * gp = (struct GPatch *)malloc(sizeof(struct GPatch));
|
||||||
|
@ -196,3 +196,4 @@ struct GPatch * gusload(char * filename)
|
||||||
|
|
||||||
return gp;
|
return gp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,8 +16,8 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "midiutil.h"
|
||||||
|
|
||||||
extern struct plugin_api * rb;
|
extern struct plugin_api * rb;
|
||||||
|
|
||||||
|
@ -234,7 +235,6 @@ struct Track * readTrack(int file)
|
||||||
return trk;
|
return trk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int readID(int file)
|
int readID(int file)
|
||||||
{
|
{
|
||||||
char id[5];
|
char id[5];
|
||||||
|
@ -318,4 +318,3 @@ void unloadFile(struct MIDIfile * mf)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
21
apps/plugins/midi/midifile.h
Normal file
21
apps/plugins/midi/midifile.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct MIDIfile * loadFile(char * filename);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Karl Kurbjun based on midi2wav by Stepan Moskovchenko
|
* Copyright (C) 2005 Karl Kurbjun based on midi2wav by Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,8 +16,12 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
#include "../../plugin.h"
|
#include "guspat.h"
|
||||||
|
#include "midiutil.h"
|
||||||
|
#include "synth.h"
|
||||||
|
#include "sequencer.h"
|
||||||
|
#include "midifile.h"
|
||||||
|
|
||||||
PLUGIN_HEADER
|
PLUGIN_HEADER
|
||||||
PLUGIN_IRAM_DECLARE
|
PLUGIN_IRAM_DECLARE
|
||||||
|
@ -62,7 +67,6 @@ PLUGIN_IRAM_DECLARE
|
||||||
#define BTN_UP BUTTON_UP
|
#define BTN_UP BUTTON_UP
|
||||||
#define BTN_DOWN BUTTON_DOWN
|
#define BTN_DOWN BUTTON_DOWN
|
||||||
|
|
||||||
|
|
||||||
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
||||||
#define BTN_QUIT BUTTON_POWER
|
#define BTN_QUIT BUTTON_POWER
|
||||||
#define BTN_RIGHT BUTTON_RIGHT
|
#define BTN_RIGHT BUTTON_RIGHT
|
||||||
|
@ -77,32 +81,6 @@ PLUGIN_IRAM_DECLARE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define FRACTSIZE 10
|
|
||||||
|
|
||||||
#ifndef SIMULATOR
|
|
||||||
|
|
||||||
#if (HW_SAMPR_CAPS & SAMPR_CAP_22)
|
|
||||||
#define SAMPLE_RATE SAMPR_22 // 44100 22050 11025
|
|
||||||
#else
|
|
||||||
#define SAMPLE_RATE SAMPR_44 // 44100 22050 11025
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_VOICES 20 // Note: 24 midi channels is the minimum general midi
|
|
||||||
// spec implementation
|
|
||||||
|
|
||||||
#else // Simulator requires 44100, and we can afford to use more voices
|
|
||||||
|
|
||||||
#define SAMPLE_RATE SAMPR_44
|
|
||||||
#define MAX_VOICES 48
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define BUF_SIZE 256
|
|
||||||
#define NBUF 2
|
|
||||||
|
|
||||||
#undef SYNC
|
#undef SYNC
|
||||||
|
|
||||||
#ifdef SIMULATOR
|
#ifdef SIMULATOR
|
||||||
|
@ -114,13 +92,6 @@ struct MIDIfile * mf IBSS_ATTR;
|
||||||
int numberOfSamples IBSS_ATTR;
|
int numberOfSamples IBSS_ATTR;
|
||||||
long bpm IBSS_ATTR;
|
long bpm IBSS_ATTR;
|
||||||
|
|
||||||
#include "midi/midiutil.c"
|
|
||||||
#include "midi/guspat.h"
|
|
||||||
#include "midi/guspat.c"
|
|
||||||
#include "midi/sequencer.c"
|
|
||||||
#include "midi/midifile.c"
|
|
||||||
#include "midi/synth.c"
|
|
||||||
|
|
||||||
long gmbuf[BUF_SIZE*NBUF];
|
long gmbuf[BUF_SIZE*NBUF];
|
||||||
|
|
||||||
int quit=0;
|
int quit=0;
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,134 +16,23 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "midiutil.h"
|
||||||
#define BYTE unsigned char
|
|
||||||
|
|
||||||
//Data chunk ID types, returned by readID()
|
|
||||||
#define ID_UNKNOWN -1
|
|
||||||
#define ID_MTHD 1
|
|
||||||
#define ID_MTRK 2
|
|
||||||
#define ID_EOF 3
|
|
||||||
#define ID_RIFF 4
|
|
||||||
|
|
||||||
|
|
||||||
//MIDI Commands
|
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
//MIDI Controllers
|
|
||||||
#define CTRL_VOLUME 7
|
|
||||||
#define CTRL_BALANCE 8
|
|
||||||
#define CTRL_PANNING 10
|
|
||||||
#define CHANNEL 1
|
|
||||||
|
|
||||||
//Most of these are deprecated.. rampdown is used, maybe one other one too
|
|
||||||
#define STATE_ATTACK 1
|
|
||||||
#define STATE_DECAY 2
|
|
||||||
#define STATE_SUSTAIN 3
|
|
||||||
#define STATE_RELEASE 4
|
|
||||||
#define STATE_RAMPDOWN 5
|
|
||||||
|
|
||||||
//Loop states
|
|
||||||
#define STATE_LOOPING 7
|
|
||||||
#define STATE_NONLOOPING 8
|
|
||||||
|
|
||||||
//Various bits in the GUS mode byte
|
|
||||||
#define LOOP_ENABLED 4
|
|
||||||
#define LOOP_PINGPONG 8
|
|
||||||
#define LOOP_REVERSE 16
|
|
||||||
|
|
||||||
#define LOOPDIR_FORWARD 0
|
|
||||||
#define LOOPDIR_REVERSE 1
|
|
||||||
|
|
||||||
|
|
||||||
extern struct plugin_api * rb;
|
extern struct plugin_api * rb;
|
||||||
|
|
||||||
int printf(const char *fmt, ...);
|
|
||||||
|
|
||||||
int chVol[16] IBSS_ATTR; /* Channel volume */
|
int chVol[16] IBSS_ATTR; /* Channel volume */
|
||||||
int chPanLeft[16] IBSS_ATTR; /* Channel panning */
|
int chPanLeft[16] IBSS_ATTR; /* Channel panning */
|
||||||
int chPanRight[16] IBSS_ATTR;
|
int chPanRight[16] IBSS_ATTR;
|
||||||
int chPat[16] IBSS_ATTR; /* Channel patch */
|
int chPat[16] IBSS_ATTR; /* Channel patch */
|
||||||
int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
|
int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
|
||||||
|
|
||||||
|
|
||||||
struct GPatch * gusload(char *);
|
struct GPatch * gusload(char *);
|
||||||
struct GPatch * patchSet[128];
|
struct GPatch * patchSet[128];
|
||||||
struct GPatch * drumSet[128];
|
struct GPatch * drumSet[128];
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
unsigned int delta;
|
|
||||||
unsigned int decay;
|
|
||||||
unsigned int cp;
|
|
||||||
unsigned char state, loopState, loopDir;
|
|
||||||
unsigned char note, vol, ch, isUsed;
|
|
||||||
int curRate, curOffset, targetOffset;
|
|
||||||
unsigned int curPoint;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct SynthObject
|
|
||||||
{
|
|
||||||
struct GWaveform * wf;
|
|
||||||
int delta;
|
|
||||||
int decay;
|
|
||||||
unsigned int cp; /* unsigned int */
|
|
||||||
int state, loopState, loopDir;
|
|
||||||
int note, vol, ch, isUsed;
|
|
||||||
int curRate, curOffset, targetOffset;
|
|
||||||
int curPoint;
|
|
||||||
signed short int volscale;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SynthObject voices[MAX_VOICES] IBSS_ATTR;
|
struct SynthObject voices[MAX_VOICES] IBSS_ATTR;
|
||||||
|
|
||||||
void sendEvent(struct Event * ev);
|
|
||||||
inline void setPoint(struct SynthObject * so, int pt);
|
|
||||||
struct Event * getEvent(struct Track * tr, int evNum);
|
|
||||||
int readTwoBytes(int file);
|
|
||||||
int readFourBytes(int file);
|
|
||||||
int readVarData(int file);
|
|
||||||
int midimain(void * filename);
|
|
||||||
|
|
||||||
|
|
||||||
void *alloc(int size)
|
void *alloc(int size)
|
||||||
{
|
{
|
||||||
static char *offset = NULL;
|
static char *offset = NULL;
|
||||||
|
@ -180,7 +70,6 @@ void *alloc(int size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Rick's code */
|
/* Rick's code */
|
||||||
/*
|
/*
|
||||||
void *alloc(int size)
|
void *alloc(int size)
|
||||||
|
@ -267,3 +156,4 @@ void exit(int code)
|
||||||
{
|
{
|
||||||
code = code; /* Stub function, kill warning for now */
|
code = code; /* Stub function, kill warning for now */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
172
apps/plugins/midi/midiutil.h
Normal file
172
apps/plugins/midi/midiutil.h
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* 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
|
||||||
|
|
||||||
|
#define BUF_SIZE 256
|
||||||
|
#define NBUF 2
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SIMULATOR
|
||||||
|
|
||||||
|
#if (HW_SAMPR_CAPS & SAMPR_CAP_22)
|
||||||
|
#define SAMPLE_RATE SAMPR_22 // 44100 22050 11025
|
||||||
|
#else
|
||||||
|
#define SAMPLE_RATE SAMPR_44 // 44100 22050 11025
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_VOICES 20 // Note: 24 midi channels is the minimum general midi
|
||||||
|
// spec implementation
|
||||||
|
|
||||||
|
#else // Simulator requires 44100, and we can afford to use more voices
|
||||||
|
|
||||||
|
#define SAMPLE_RATE SAMPR_44
|
||||||
|
#define MAX_VOICES 48
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BYTE unsigned char
|
||||||
|
|
||||||
|
//Data chunk ID types, returned by readID()
|
||||||
|
#define ID_UNKNOWN -1
|
||||||
|
#define ID_MTHD 1
|
||||||
|
#define ID_MTRK 2
|
||||||
|
#define ID_EOF 3
|
||||||
|
#define ID_RIFF 4
|
||||||
|
|
||||||
|
//MIDI Commands
|
||||||
|
#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
|
||||||
|
|
||||||
|
//MIDI Controllers
|
||||||
|
#define CTRL_VOLUME 7
|
||||||
|
#define CTRL_BALANCE 8
|
||||||
|
#define CTRL_PANNING 10
|
||||||
|
#define CHANNEL 1
|
||||||
|
|
||||||
|
//Most of these are deprecated.. rampdown is used, maybe one other one too
|
||||||
|
#define STATE_ATTACK 1
|
||||||
|
#define STATE_DECAY 2
|
||||||
|
#define STATE_SUSTAIN 3
|
||||||
|
#define STATE_RELEASE 4
|
||||||
|
#define STATE_RAMPDOWN 5
|
||||||
|
|
||||||
|
//Loop states
|
||||||
|
#define STATE_LOOPING 7
|
||||||
|
#define STATE_NONLOOPING 8
|
||||||
|
|
||||||
|
//Various bits in the GUS mode byte
|
||||||
|
#define LOOP_ENABLED 4
|
||||||
|
#define LOOP_PINGPONG 8
|
||||||
|
#define LOOP_REVERSE 16
|
||||||
|
|
||||||
|
#define LOOPDIR_FORWARD 0
|
||||||
|
#define LOOPDIR_REVERSE 1
|
||||||
|
|
||||||
|
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;
|
||||||
|
unsigned int delta;
|
||||||
|
unsigned int decay;
|
||||||
|
unsigned int cp;
|
||||||
|
unsigned char state, loopState, loopDir;
|
||||||
|
unsigned char note, vol, ch, isUsed;
|
||||||
|
int curRate, curOffset, targetOffset;
|
||||||
|
unsigned int curPoint;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct SynthObject
|
||||||
|
{
|
||||||
|
struct GWaveform * wf;
|
||||||
|
int delta;
|
||||||
|
int decay;
|
||||||
|
unsigned int cp; /* unsigned int */
|
||||||
|
int state, loopState, loopDir;
|
||||||
|
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, ...);
|
||||||
|
int midimain(void * filename);
|
||||||
|
unsigned char readChar(int file);
|
||||||
|
void sendEvent(struct Event * ev);
|
||||||
|
inline void setPoint(struct SynthObject * so, int pt);
|
||||||
|
struct Event * getEvent(struct Track * tr, int evNum);
|
||||||
|
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 */
|
||||||
|
extern int chPanLeft[16]; /* Channel panning */
|
||||||
|
extern int chPanRight[16];
|
||||||
|
extern int chPat[16]; /* Channel patch */
|
||||||
|
extern int chPW[16]; /* Channel pitch wheel, MSB only */
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,6 +16,9 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "midiutil.h"
|
||||||
|
#include "guspat.h"
|
||||||
|
|
||||||
void setVolScale(int a);
|
void setVolScale(int a);
|
||||||
|
|
||||||
|
@ -22,7 +26,6 @@ extern struct plugin_api * rb;
|
||||||
|
|
||||||
long tempo=375000;
|
long tempo=375000;
|
||||||
|
|
||||||
|
|
||||||
inline void setVol(int ch, int vol)
|
inline void setVol(int ch, int vol)
|
||||||
{
|
{
|
||||||
int a=0;
|
int a=0;
|
||||||
|
@ -119,7 +122,6 @@ long pitchTbl[] ICONST_ATTR={
|
||||||
73297,73330,73363,73396,73429,73462,73495,73528
|
73297,73330,73363,73396,73429,73462,73495,73528
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void findDelta(struct SynthObject * so, int ch, int note)
|
void findDelta(struct SynthObject * so, int ch, int note)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -147,7 +149,6 @@ inline void setPW(int ch, int msb, int lsb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sets the volume scaling by channel volume and note volume */
|
/* Sets the volume scaling by channel volume and note volume */
|
||||||
/* This way we can do the multiplication/indexing once per */
|
/* This way we can do the multiplication/indexing once per */
|
||||||
/* MIDI event at the most, instead of once per sample. */
|
/* MIDI event at the most, instead of once per sample. */
|
||||||
|
@ -375,3 +376,4 @@ int tick(void)
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
apps/plugins/midi/sequencer.h
Normal file
23
apps/plugins/midi/sequencer.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int tick(void);
|
||||||
|
|
||||||
|
extern long tempo;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
* \/ \/ \/ \/ \/
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 Stepan Moskovchenko
|
* Copyright (C) 2005 Stepan Moskovchenko
|
||||||
*
|
*
|
||||||
|
@ -15,6 +16,10 @@
|
||||||
* KIND, either express or implied.
|
* KIND, either express or implied.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "plugin.h"
|
||||||
|
#include "guspat.h"
|
||||||
|
#include "midiutil.h"
|
||||||
|
#include "synth.h"
|
||||||
|
|
||||||
extern struct plugin_api * rb;
|
extern struct plugin_api * rb;
|
||||||
|
|
||||||
|
@ -43,8 +48,6 @@ void readTextBlock(int file, char * buf)
|
||||||
rb->lseek(file, -1, SEEK_CUR);
|
rb->lseek(file, -1, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Filename is the name of the config file */
|
/* Filename is the name of the config file */
|
||||||
/* The MIDI file should have been loaded at this point */
|
/* The MIDI file should have been loaded at this point */
|
||||||
int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
|
@ -400,34 +403,3 @@ signed short int synthVoice(struct SynthObject * so)
|
||||||
return s*so->volscale>>14;
|
return s*so->volscale>>14;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void synthSample(int * mixL, int * mixR)
|
|
||||||
{
|
|
||||||
register int dL=0;
|
|
||||||
register int dR=0;
|
|
||||||
register short sample=0;
|
|
||||||
register struct SynthObject *voicept=voices;
|
|
||||||
struct SynthObject *lastvoice=&voices[MAX_VOICES];
|
|
||||||
|
|
||||||
while(voicept!=lastvoice)
|
|
||||||
{
|
|
||||||
if(voicept->isUsed==1)
|
|
||||||
{
|
|
||||||
sample = synthVoice(voicept);
|
|
||||||
dL += (sample*chPanLeft[voicept->ch])>>7;
|
|
||||||
dR += (sample*chPanRight[voicept->ch])>>7;
|
|
||||||
}
|
|
||||||
voicept++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*mixL=dL;
|
|
||||||
*mixR=dR;
|
|
||||||
|
|
||||||
/* TODO: Automatic Gain Control, anyone? */
|
|
||||||
/* Or, should this be implemented on the DSP's output volume instead? */
|
|
||||||
|
|
||||||
return; /* No more ghetto lowpass filter.. linear intrpolation works well. */
|
|
||||||
}
|
|
||||||
|
|
50
apps/plugins/midi/synth.h
Normal file
50
apps/plugins/midi/synth.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig);
|
||||||
|
signed short int synthVoice(struct SynthObject * so);
|
||||||
|
|
||||||
|
static inline void synthSample(int * mixL, int * mixR)
|
||||||
|
{
|
||||||
|
register int dL=0;
|
||||||
|
register int dR=0;
|
||||||
|
register short sample=0;
|
||||||
|
register struct SynthObject *voicept=voices;
|
||||||
|
struct SynthObject *lastvoice=&voices[MAX_VOICES];
|
||||||
|
|
||||||
|
while(voicept!=lastvoice)
|
||||||
|
{
|
||||||
|
if(voicept->isUsed==1)
|
||||||
|
{
|
||||||
|
sample = synthVoice(voicept);
|
||||||
|
dL += (sample*chPanLeft[voicept->ch])>>7;
|
||||||
|
dR += (sample*chPanRight[voicept->ch])>>7;
|
||||||
|
}
|
||||||
|
voicept++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*mixL=dL;
|
||||||
|
*mixR=dR;
|
||||||
|
|
||||||
|
/* TODO: Automatic Gain Control, anyone? */
|
||||||
|
/* Or, should this be implemented on the DSP's output volume instead? */
|
||||||
|
|
||||||
|
return; /* No more ghetto lowpass filter.. linear intrpolation works well. */
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue