This commit is contained in:
Daniel Borges
2012-11-16 09:18:57 +01:00
commit ea6f1ef80a
79 changed files with 3595 additions and 0 deletions

41
Player/Makefile Normal file
View File

@@ -0,0 +1,41 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
export TARGET := $(shell basename $(CURDIR))
export TOPDIR := $(CURDIR)
.PHONY: $(TARGET).arm7 $(TARGET).arm9
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all: $(TARGET).nds
#---------------------------------------------------------------------------------
$(TARGET).nds : $(TARGET).arm7 $(TARGET).arm9
ndstool -c $(TARGET).nds -7 $(TARGET).arm7 -9 $(TARGET).arm9
#---------------------------------------------------------------------------------
$(TARGET).arm7 : arm7/$(TARGET).elf
$(TARGET).arm9 : arm9/$(TARGET).elf
#---------------------------------------------------------------------------------
arm7/$(TARGET).elf:
$(MAKE) -C arm7
#---------------------------------------------------------------------------------
arm9/$(TARGET).elf:
$(MAKE) -C arm9
#---------------------------------------------------------------------------------
clean:
$(MAKE) -C arm9 clean
$(MAKE) -C arm7 clean
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9

132
Player/arm7/Makefile Normal file
View File

@@ -0,0 +1,132 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include build
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb-interwork -marm
CFLAGS := -g -Wall -O2\
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM7
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -Isource
LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map
LIBS := -ldswifi7 -lmm7 -lnds7
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM7BIN := $(TOPDIR)/$(TARGET).arm7
export ARM7ELF := $(CURDIR)/$(TARGET).arm7.elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM7BIN) : $(ARM7ELF)
@$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
$(ARM7ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@@ -0,0 +1,85 @@
#include "Envelope.h"
#include "InstrumentParameters.h"
#define MAX_VOLUME 512
void Envelope_Init(Envelope * pEnvelope)
{
pEnvelope->iTime = 0;
pEnvelope->iLastEnvelope = 0;
pEnvelope->iVelocity = 0;
pEnvelope->iState = RELEASE;
}
unsigned int Envelope_Compute(Envelope * pEnvelope, InstrumentParameters * pParameters)
{
unsigned int iEnvelope = 0;
int iAttack = pParameters->iAttack;
int iDecay = pParameters->iDecay;
int iSustain = pParameters->iSustain * MAX_VOLUME / 127;
int iRelease = pParameters->iRelease;
pEnvelope->iTime++;
switch ( pEnvelope->iState )
{
case ATTACK:
{
iEnvelope = (pEnvelope->iTime * MAX_VOLUME) / iAttack;
if ( pEnvelope->iTime >= iAttack ) {
pEnvelope->iTime = 0;
pEnvelope->iState = DECAY;
}
break;
}
case DECAY:
{
int s = MAX_VOLUME - iSustain;
iEnvelope = iSustain + s - ((pEnvelope->iTime * s) / iDecay);
if ( pEnvelope->iTime >= iDecay ) {
pEnvelope->iTime = 0;
pEnvelope->iState = SUSTAIN;
}
break;
}
case SUSTAIN:
{
iEnvelope = iSustain;
break;
}
case RELEASE:
{
if ( pEnvelope->iTime <= iRelease )
iEnvelope = pEnvelope->iLastEnvelope -
((pEnvelope->iTime * pEnvelope->iLastEnvelope) / iRelease);
break;
}
}
if ( pEnvelope->iState != RELEASE )
pEnvelope->iLastEnvelope = iEnvelope;
iEnvelope = iEnvelope * pEnvelope->iVelocity / 127;
return iEnvelope / (MAX_VOLUME / 128);
}
void Envelope_NoteOn(Envelope * pEnvelope, int v)
{
pEnvelope->iVelocity = v;
pEnvelope->iTime = 0;
pEnvelope->iState = ATTACK;
}
void Envelope_NoteOff(Envelope * pEnvelope)
{
if ( pEnvelope->iState != RELEASE )
{
pEnvelope->iTime = 0;
pEnvelope->iState = RELEASE;
}
}

View File

@@ -0,0 +1,31 @@
#ifndef _ENVELOPE_H_
#define _ENVELOPE_H_
#include "InstrumentParameters.h"
typedef enum
{
ATTACK,
DECAY,
SUSTAIN,
RELEASE
}
EnvelopeState;
typedef struct
{
int iTime;
int iLastEnvelope;
int iVelocity;
EnvelopeState iState;
}
Envelope;
void Envelope_Init(Envelope * pEnvelope);
unsigned int Envelope_Compute(Envelope * pEnvelope, InstrumentParameters * pParameters);
void Envelope_NoteOn(Envelope * pEnvelope, int velocity);
void Envelope_NoteOff(Envelope * pEnvelope);
#endif // _ENVELOPE_H_

View File

@@ -0,0 +1,109 @@
#include "Instrument.h"
#include "Utils.h"
#include <nds.h>
#define SOUND_PSG_DUTY(duty) ((duty)<<24)
void Instrument_Init(Instrument* pInstrument, int iChannel, InstrumentParameters* pParameters)
{
pInstrument->pParameters = pParameters;
pInstrument->iChannel = iChannel;
pInstrument->iLastFrequency = 0;
pInstrument->pFrequencies[0] = 1;
pInstrument->iFrequency = 0;
pInstrument->iNbFrequencies = 0;
pInstrument->iEffectTimer = 0;
pInstrument->iSweepFrequency = 0;
pInstrument->iModulationAmplitude = 0;
pInstrument->iPortamentoFrequency = 0;
pInstrument->iArpeggioTimer = 0;
Envelope_Init(&pInstrument->oEnvelope);
}
void Instrument_Compute(Instrument* pInstrument)
{
InstrumentParameters* pParameters = pInstrument->pParameters;
int iVolume = pParameters->iVolume;
if ( pParameters->iTremoloAmplitude != 0 )
{
int iSin = Sinus(pInstrument->iEffectTimer * 12868 * pParameters->iTremoloFrequency / 256) / 2 + 2048;
int iAmplitude = pParameters->iTremoloAmplitude * pParameters->iVolume / 255;
iVolume -= iSin * iAmplitude / 4096;
}
iVolume = Envelope_Compute(& pInstrument->oEnvelope, pParameters) * iVolume / 127;
if ( pParameters->iArpeggio > 0 )
{
pInstrument->iArpeggioTimer++;
if ( pInstrument->iArpeggioTimer >= pParameters->iArpeggio )
{
pInstrument->iArpeggioTimer = 0;
pInstrument->iFrequency++;
if ( pInstrument->iFrequency >= pInstrument->iNbFrequencies )
pInstrument->iFrequency = 0;
}
}
pInstrument->iEffectTimer++;
int iSweep = 0;
if ( pParameters->iSweepLength != 0
&& pInstrument->iEffectTimer < pParameters->iSweepLength )
iSweep = pInstrument->iSweepFrequency - (pInstrument->iEffectTimer * pInstrument->iSweepFrequency) / pParameters->iSweepLength;
int iModulation = Sinus(pInstrument->iEffectTimer * 12868 * pParameters->iModulationFrequency / 256) * pInstrument->iModulationAmplitude / 4096;
int iPortamento = 0;
if ( pParameters->iPortamentoLength != 0 && pInstrument->iEffectTimer < pParameters->iPortamentoLength )
iPortamento = pInstrument->iPortamentoFrequency - (pInstrument->iEffectTimer * pInstrument->iPortamentoFrequency) / pParameters->iPortamentoLength;
pInstrument->iLastFrequency = pInstrument->pFrequencies[pInstrument->iFrequency] + iSweep + iModulation + iPortamento;
if ( pInstrument->iLastFrequency <= 0 )
pInstrument->iLastFrequency = 1;
SCHANNEL_CR(pInstrument->iChannel) = SCHANNEL_ENABLE
| SOUND_VOL(iVolume)
| SOUND_PAN(pParameters->iPanning)
| SOUND_FORMAT_PSG
| SOUND_PSG_DUTY(pParameters->iDuty)
;
SCHANNEL_TIMER(pInstrument->iChannel) = SOUND_FREQ(pInstrument->iLastFrequency * 8);
}
void Instrument_NoteOn(Instrument* pInstrument, int iNote, int iVelocity)
{
int n = iNote + pInstrument->pParameters->iDetune;
Envelope_NoteOn(& pInstrument->oEnvelope, iVelocity);
if ( pInstrument->iEffectTimer < 3
&& pInstrument->iNbFrequencies <= sizeof(pInstrument->pFrequencies)/sizeof(pInstrument->pFrequencies[0]) )
{
// Arpeggio !
pInstrument->pFrequencies[pInstrument->iNbFrequencies++] = MidiNoteToFrequency(n);
}
else
{
pInstrument->pFrequencies[0] = MidiNoteToFrequency(n);
pInstrument->iNbFrequencies = 1;
pInstrument->iArpeggioTimer = 0;
pInstrument->iEffectTimer = 0;
pInstrument->iFrequency = 0;
if ( pInstrument->iLastFrequency == 0 )
pInstrument->iLastFrequency = pInstrument->pFrequencies[0];
pInstrument->iPortamentoFrequency = pInstrument->iLastFrequency - pInstrument->pFrequencies[0];
pInstrument->iSweepFrequency = MidiNoteToFrequency(n + pInstrument->pParameters->iSweepOffset) - pInstrument->pFrequencies[0];
pInstrument->iModulationAmplitude = MidiNoteToFrequency(n + pInstrument->pParameters->iModulationAmplitude) - pInstrument->pFrequencies[0];
}
}
void Instrument_NoteOff(Instrument* pInstrument)
{
Envelope_NoteOff(& pInstrument->oEnvelope);
}

View File

@@ -0,0 +1,60 @@
#ifndef _INSTRUMENT_H_
#define _INSTRUMENT_H_
#include "Envelope.h"
#include "InstrumentParameters.h"
enum {
VOLUME,
PANNING,
DETUNE,
ENVELOPE_ATTACK,
ENVELOPE_DECAY,
ENVELOPE_SUSTAIN,
ENVELOPE_RELEASE,
DUTY,
PORTAMENTO_LENGTH,
ARPEGGIO,
SWEEP_LENGTH,
SWEEP_OFFSET,
MODULATION_AMPLITUDE,
MODULATION_FREQUENCY,
TREMOLO_AMPLITUDE,
TREMOLO_FREQUENCY,
LAST,
NOTEON = 29, // for export
NOTEOFF = 30, // for export
END = 31 // for export
};
struct sInstrument {
InstrumentParameters * pParameters;
int iChannel;
Envelope oEnvelope;
float fTime;
int iLastFrequency;
unsigned int pFrequencies[8];
unsigned int iNbFrequencies;
unsigned int iFrequency;
unsigned int iArpeggioTimer;
int iEffectTimer;
int iSweepFrequency;
int iModulationAmplitude;
int iPortamentoFrequency;
};
typedef struct sInstrument Instrument;
void Instrument_Init(Instrument * pInstrument, int iChannel, InstrumentParameters * pParameters);
void Instrument_Compute(Instrument * pInstrument);
void Instrument_NoteOn(Instrument * pInstrument, int iNote, int iVelocity);
void Instrument_NoteOff(Instrument * pInstrument);
void Instrument_SetParameters(Instrument * pInstrument, InstrumentParameters * p);
#endif // _INSTRUMENT_H_

View File

@@ -0,0 +1,21 @@
#include "InstrumentParameters.h"
void InstrumentParameters_Init(InstrumentParameters * pParameters)
{
pParameters->iVolume = 64;
pParameters->iPanning = 64;
pParameters->iDetune = 0;
pParameters->iDuty = 0;
pParameters->iPortamentoLength = 0;
pParameters->iAttack = 2;
pParameters->iDecay = 16;
pParameters->iSustain = 64;
pParameters->iRelease = 5;
pParameters->iTremoloAmplitude = 0;
pParameters->iTremoloFrequency = 0;
pParameters->iSweepOffset = 0;
pParameters->iSweepLength = 0;
pParameters->iModulationAmplitude = 0;
pParameters->iModulationFrequency = 0;
pParameters->iArpeggio = 0;
}

View File

@@ -0,0 +1,35 @@
#ifndef _INSTRUMENTPARAMETERS_H_
#define _INSTRUMENTPARAMETERS_H_
struct sInstrumentParameters
{
unsigned char iVolume;
unsigned char iPanning;
signed char iDetune;
unsigned char iDuty;
unsigned char iAttack; // 1..255
unsigned char iDecay; // 1..255
unsigned char iSustain; // 0..127
unsigned char iRelease; // 1..255
unsigned char iTremoloAmplitude;
unsigned char iTremoloFrequency;
unsigned char iPortamentoLength;
unsigned char iSweepLength;
signed short iSweepOffset;
unsigned char iModulationAmplitude;
unsigned char iModulationFrequency;
unsigned char iArpeggio;
unsigned char pad;
};
typedef struct sInstrumentParameters InstrumentParameters;
void InstrumentParameters_Init(InstrumentParameters * pParameters);
#endif // _INSTRUMENTPARAMETERS_H_

155
Player/arm7/source/Player.c Normal file
View File

@@ -0,0 +1,155 @@
#include "Player.h"
#include "Utils.h"
#include <nds.h>
void Player_Handler(u32 iCommand, void* pUserdata)
{
Player* pPlayer = (Player *) pUserdata;
if ( iCommand == 0 )
Player_Stop(pPlayer);
else
Player_Play(pPlayer, (unsigned char *) iCommand);
}
void Player_Init(Player* pPlayer)
{
int i;
for ( i = 0 ; i < 8 ; i++ )
{
InstrumentParameters_Init(& pPlayer->pParameters[i]);
Instrument_Init(& pPlayer->pInstruments[i], i + 8, & pPlayer->pParameters[i]);
}
pPlayer->pCommand = 0;
pPlayer->iTimer = 0;
fifoSetValue32Handler(FIFO_USER_01, Player_Handler, pPlayer);
}
void Player_Play(Player* pPlayer, unsigned char* pData)
{
MemCopy(pPlayer->pParameters, pData, sizeof(InstrumentParameters)*8);
pPlayer->pCommand = (Command *) (pData + sizeof(InstrumentParameters)*8);
pPlayer->iTimer = 0;
}
void Player_Stop(Player* pPlayer)
{
pPlayer->pCommand = 0;
int i;
for ( i = 0 ; i < 8 ; i++ )
Instrument_NoteOff(& pPlayer->pInstruments[i]);
}
void Player_Execute(Player* pPlayer)
{
int i;
if ( pPlayer->pCommand != 0 )
{
int iCommand = pPlayer->pCommand->iCommand;
while ( iCommand != END && pPlayer->iTimer == pPlayer->pCommand->iFrame )
{
Instrument* pInstrument = & pPlayer->pInstruments[pPlayer->pCommand->iChannel];
InstrumentParameters* pParameters = & pPlayer->pParameters[pPlayer->pCommand->iChannel];
int iValue = pPlayer->pCommand->iValue;
switch ( iCommand )
{
case VOLUME:
pParameters->iVolume = iValue;
break;
case PANNING:
pParameters->iPanning = iValue;
break;
case DETUNE:
pParameters->iDetune = iValue;
break;
case ENVELOPE_ATTACK:
pParameters->iAttack = iValue;
break;
case ENVELOPE_DECAY:
pParameters->iDecay = iValue;
break;
case ENVELOPE_SUSTAIN:
pParameters->iSustain = iValue;
break;
case ENVELOPE_RELEASE:
pParameters->iRelease = iValue;
break;
case DUTY:
pParameters->iDuty = iValue;
break;
case PORTAMENTO_LENGTH:
pParameters->iPortamentoLength = iValue;
break;
case SWEEP_LENGTH:
pParameters->iSweepLength = iValue;
break;
case SWEEP_OFFSET:
pParameters->iSweepOffset = iValue;
break;
case MODULATION_AMPLITUDE:
pParameters->iModulationAmplitude = iValue;
break;
case MODULATION_FREQUENCY:
pParameters->iModulationFrequency = iValue;
break;
case TREMOLO_AMPLITUDE:
pParameters->iTremoloAmplitude = iValue;
break;
case TREMOLO_FREQUENCY:
pParameters->iTremoloFrequency = iValue;
break;
case ARPEGGIO:
pParameters->iArpeggio = iValue;
break;
case NOTEON:
Instrument_NoteOn(pInstrument,
iValue & 0xFFFF,
iValue >> 16);
break;
case NOTEOFF:
Instrument_NoteOff(pInstrument);
break;
}
pPlayer->pCommand++;
pPlayer->iTimer = 0;
iCommand = pPlayer->pCommand->iCommand;
}
if ( pPlayer->pCommand->iCommand == END )
{
for ( i = 0 ; i < 8 ; i++ )
Instrument_NoteOff(& pPlayer->pInstruments[i]);
pPlayer->pCommand = 0;
}
pPlayer->iTimer++;
}
for ( i = 0 ; i < 8 ; i++ )
Instrument_Compute(& pPlayer->pInstruments[i]);
}

View File

@@ -0,0 +1,25 @@
#ifndef _PLAYER_H_
#define _PLAYER_H_
#include "Instrument.h"
typedef struct {
unsigned int iFrame : 24;
unsigned int iChannel : 3;
unsigned int iCommand : 5; // see Instrument.h
int iValue;
} Command;
typedef struct {
Instrument pInstruments[8];
InstrumentParameters pParameters[8];
Command * pCommand;
int iTimer;
} Player;
void Player_Init(Player * pPlayer);
void Player_Play(Player * pPlayer, unsigned char * pData);
void Player_Stop(Player * pPlayer);
void Player_Execute(Player * pPlayer);
#endif // _PLAYER_H_

174
Player/arm7/source/Utils.c Normal file
View File

@@ -0,0 +1,174 @@
#include "Utils.h"
unsigned short MidiNoteToFrequency(int note)
{
static const unsigned short pFrequencies[] =
{
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,
12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,
14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,
15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,
18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,
19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,
20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,
21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,23,
23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,
24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,
25,26,26,26,26,26,26,26,26,26,26,27,27,27,27,27,
27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,29,
29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,
30,30,31,31,31,31,31,31,31,31,32,32,32,32,32,32,
32,32,32,33,33,33,33,33,33,33,33,34,34,34,34,34,
34,34,34,35,35,35,35,35,35,35,35,36,36,36,36,36,
36,36,36,37,37,37,37,37,37,37,38,38,38,38,38,38,
38,39,39,39,39,39,39,39,40,40,40,40,40,40,40,41,
41,41,41,41,41,41,42,42,42,42,42,42,43,43,43,43,
43,43,43,44,44,44,44,44,44,45,45,45,45,45,45,46,
46,46,46,46,46,47,47,47,47,47,47,48,48,48,48,48,
48,49,49,49,49,49,50,50,50,50,50,50,51,51,51,51,
51,52,52,52,52,52,53,53,53,53,53,54,54,54,54,54,
55,55,55,55,55,56,56,56,56,56,57,57,57,57,57,58,
58,58,58,58,59,59,59,59,59,60,60,60,60,61,61,61,
61,61,62,62,62,62,63,63,63,63,64,64,64,64,64,65,
65,65,65,66,66,66,66,67,67,67,67,68,68,68,68,69,
69,69,69,70,70,70,70,71,71,71,71,72,72,72,72,73,
73,73,73,74,74,74,75,75,75,75,76,76,76,76,77,77,
77,78,78,78,78,79,79,79,80,80,80,80,81,81,81,82,
82,82,83,83,83,83,84,84,84,85,85,85,86,86,86,86,
87,87,87,88,88,88,89,89,89,90,90,90,91,91,91,92,
92,92,93,93,93,94,94,94,95,95,95,96,96,96,97,97,
97,98,98,99,99,99,100,100,100,101,101,101,102,102,103,103,
103,104,104,104,105,105,106,106,106,107,107,108,108,108,109,109,
110,110,110,111,111,112,112,112,113,113,114,114,114,115,115,116,
116,116,117,117,118,118,119,119,119,120,120,121,121,122,122,123,
123,123,124,124,125,125,126,126,127,127,128,128,128,129,129,130,
130,131,131,132,132,133,133,134,134,135,135,136,136,137,137,138,
138,139,139,140,140,141,141,142,142,143,143,144,144,145,145,146,
146,147,147,148,148,149,150,150,151,151,152,152,153,153,154,155,
155,156,156,157,157,158,158,159,160,160,161,161,162,163,163,164,
164,165,166,166,167,167,168,169,169,170,170,171,172,172,173,173,
174,175,175,176,177,177,178,179,179,180,181,181,182,183,183,184,
184,185,186,187,187,188,189,189,190,191,191,192,193,193,194,195,
195,196,197,198,198,199,200,201,201,202,203,203,204,205,206,206,
207,208,209,209,210,211,212,212,213,214,215,216,216,217,218,219,
220,220,221,222,223,224,224,225,226,227,228,228,229,230,231,232,
233,233,234,235,236,237,238,239,239,240,241,242,243,244,245,246,
246,247,248,249,250,251,252,253,254,255,256,256,257,258,259,260,
261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,
277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,
293,294,295,296,297,299,300,301,302,303,304,305,306,307,308,310,
311,312,313,314,315,316,317,319,320,321,322,323,324,326,327,328,
329,330,332,333,334,335,336,338,339,340,341,342,344,345,346,347,
349,350,351,353,354,355,356,358,359,360,362,363,364,366,367,368,
369,371,372,374,375,376,378,379,380,382,383,384,386,387,389,390,
391,393,394,396,397,399,400,402,403,404,406,407,409,410,412,413,
415,416,418,419,421,422,424,425,427,429,430,432,433,435,436,438,
440,441,443,444,446,448,449,451,452,454,456,457,459,461,462,464,
466,467,469,471,472,474,476,478,479,481,483,485,486,488,490,492,
493,495,497,499,501,502,504,506,508,510,512,513,515,517,519,521,
523,525,527,528,530,532,534,536,538,540,542,544,546,548,550,552,
554,556,558,560,562,564,566,568,570,572,574,576,578,581,583,585,
587,589,591,593,595,598,600,602,604,606,608,611,613,615,617,620,
622,624,626,629,631,633,635,638,640,642,645,647,649,652,654,656,
659,661,664,666,668,671,673,676,678,681,683,685,688,690,693,695,
698,700,703,706,708,711,713,716,718,721,724,726,729,732,734,737,
739,742,745,748,750,753,756,758,761,764,767,769,772,775,778,781,
783,786,789,792,795,798,801,804,806,809,812,815,818,821,824,827,
830,833,836,839,842,845,848,851,854,858,861,864,867,870,873,876,
880,883,886,889,892,896,899,902,905,909,912,915,918,922,925,928,
932,935,939,942,945,949,952,956,959,963,966,970,973,977,980,984,
987,991,994,998,1002,1005,1009,1013,1016,1020,1024,1027,1031,1035,1038,1042,
1046,1050,1054,1057,1061,1065,1069,1073,1077,1081,1084,1088,1092,1096,1100,1104,
1108,1112,1116,1120,1124,1128,1133,1137,1141,1145,1149,1153,1157,1162,1166,1170,
1174,1178,1183,1187,1191,1196,1200,1204,1209,1213,1217,1222,1226,1231,1235,1240,
1244,1249,1253,1258,1262,1267,1271,1276,1280,1285,1290,1294,1299,1304,1309,1313,
1318,1323,1328,1332,1337,1342,1347,1352,1357,1362,1366,1371,1376,1381,1386,1391,
1396,1401,1407,1412,1417,1422,1427,1432,1437,1443,1448,1453,1458,1464,1469,1474,
1479,1485,1490,1496,1501,1506,1512,1517,1523,1528,1534,1539,1545,1551,1556,1562,
1567,1573,1579,1585,1590,1596,1602,1608,1613,1619,1625,1631,1637,1643,1649,1655,
1661,1667,1673,1679,1685,1691,1697,1703,1709,1716,1722,1728,1734,1741,1747,1753,
1760,1766,1772,1779,1785,1792,1798,1805,1811,1818,1824,1831,1837,1844,1851,1857,
1864,1871,1878,1884,1891,1898,1905,1912,1919,1926,1933,1940,1947,1954,1961,1968,
1975,1982,1989,1997,2004,2011,2018,2026,2033,2040,2048,2055,2062,2070,2077,2085,
2093,2100,2108,2115,2123,2131,2138,2146,2154,2162,2169,2177,2185,2193,2201,2209,
2217,2225,2233,2241,2249,2257,2266,2274,2282,2290,2298,2307,2315,2324,2332,2340,
2349,2357,2366,2374,2383,2392,2400,2409,2418,2426,2435,2444,2453,2462,2471,2480,
2489,2498,2507,2516,2525,2534,2543,2552,2561,2571,2580,2589,2599,2608,2618,2627,
2637,2646,2656,2665,2675,2685,2694,2704,2714,2724,2733,2743,2753,2763,2773,2783,
2793,2803,2814,2824,2834,2844,2855,2865,2875,2886,2896,2907,2917,2928,2938,2949,
2959,2970,2981,2992,3003,3013,3024,3035,3046,3057,3068,3079,3091,3102,3113,3124,
3135,3147,3158,3170,3181,3193,3204,3216,3227,3239,3251,3263,3274,3286,3298,3310,
3322,3334,3346,3358,3370,3382,3395,3407,3419,3432,3444,3457,3469,3482,3494,3507,
3520,3532,3545,3558,3571,3584,3597,3610,3623,3636,3649,3662,3675,3689,3702,3715,
3729,3742,3756,3769,3783,3797,3810,3824,3838,3852,3866,3880,3894,3908,3922,3936,
3951,3965,3979,3994,4008,4023,4037,4052,4066,4081,4096,4111,4125,4140,4155,4170,
4186,4201,4216,4231,4246,4262,4277,4293,4308,4324,4339,4355,4371,4387,4403,4418,
4434,4450,4467,4483,4499,4515,4532,4548,4564,4581,4597,4614,4631,4648,4664,4681,
4698,4715,4732,4749,4766,4784,4801,4818,4836,4853,4871,4888,4906,4924,4942,4960,
4978,4996,5014,5032,5050,5068,5087,5105,5123,5142,5161,5179,5198,5217,5236,5255,
5274,5293,5312,5331,5350,5370,5389,5409,5428,5448,5467,5487,5507,5527,5547,5567,
5587,5607,5628,5648,5668,5689,5710,5730,5751,5772,5793,5814,5835,5856,5877,5898,
5919,5941,5962,5984,6006,6027,6049,6071,6093,6115,6137,6159,6182,6204,6226,6249,
6271,6294,6317,6340,6363,6386,6409,6432,6455,6479,6502,6526,6549,6573,6597,6620,
6644,6668,6693,6717,6741,6765,6790,6814,6839,6864,6889,6914,6939,6964,6989,7014,
7040,7065,7091,7116,7142,7168,7194,7220,7246,7272,7298,7325,7351,7378,7404,7431,
7458,7485,7512,7539,7567,7594,7621,7649,7677,7704,7732,7760,7788,7817,7845,7873,
7902,7930,7959,7988,8017,8046,8075,8104,8133,8163,8192,8222,8251,8281,8311,8341,
8372,8402,8432,8463,8493,8524,8555,8586,8617,8648,8679,8711,8742,8774,8806,8837,
8869,8901,8934,8966,8998,9031,9064,9096,9129,9162,9195,9229,9262,9296,9329,9363,
9397,9431,9465,9499,9533,9568,9603,9637,9672,9707,9742,9777,9813,9848,9884,9920,
9956,9992,10028,10064,10100,10137,10174,10210,10247,10284,10322,10359,10396,10434,10472,10510,
10548,10586,10624,10662,10701,10740,10779,10818,10857,10896,10935,10975,11015,11054,11094,11135,
11175,11215,11256,11296,11337,11378,11420,11461,11502,11544,11586,11628,11670,11712,11754,11797,
11839,11882,11925,11968,12012,12055,12099,12142,12186,12230,12275,12319,12364,12408,12453,12498,
12543,12589,12634,12680,12726,12772,12818,12864,12911,12958,13004,13052,13099,13146,13194,13241,
};
if ( note < 0 )
note = 0;
if ( note > 127*16 )
note = 127*16;
return pFrequencies[note];
}
int Abs(int x)
{
if ( x < 0 )
return -x;
return x;
}
int Sinus(int x)
{
// translate x into [-pi, pi].f12
while ( x > 12868 )
x -= 25736;
while ( x < -12868 )
x += 25736;
// compute sin(x)
// see http://www.devmaster.net/forums/showthread.php?t=5784
const int B = 5215;
const int C = -1660;
return (B*x + ((C*x)>>12)*Abs(x))>>12;
}
void MemCopy(void * dst, void * src, int len)
{
unsigned char * d = (unsigned char *) dst;
unsigned char * s = (unsigned char *) src;
while ( len-- )
*d++ = *s++;
}

View File

@@ -0,0 +1,9 @@
#ifndef _MIDI_H_
#define _MIDI_H_
unsigned short MidiNoteToFrequency(int note);
int Abs(int x);
int Sinus(int x); // fixed point .12
void MemCopy(void * pDestination, void * pSource, int iSize);
#endif // _MIDI_H_

View File

@@ -0,0 +1,8 @@
.text
.align 4
.thumb
.global swiWaitVBL
.thumb_func
swiWaitVBL:
swi 0x05
bx lr

41
Player/arm7/source/main.c Normal file
View File

@@ -0,0 +1,41 @@
#include <nds.h>
#include <dswifi7.h>
#include <maxmod7.h>
#include "Player.h"
void VCountHandler()
{
inputGetAndSend();
}
int main()
{
irqInit();
fifoInit();
readUserSettings();
initClockIRQ();
SetYtrigger(80);
installSystemFIFO();
irqSet(IRQ_VCOUNT, VCountHandler);
irqSet(IRQ_VBLANK, 0);
irqEnable(IRQ_VBLANK|IRQ_VCOUNT|IRQ_NETWORK);
powerOn(POWER_SOUND);
REG_SOUNDCNT = SOUND_ENABLE | SOUND_VOL(127);
static Player oPlayer;
Player_Init(& oPlayer);
while ( 1 )
{
swiWaitForVBlank();
Player_Execute(& oPlayer);
}
return 0;
}

132
Player/arm9/Makefile Normal file
View File

@@ -0,0 +1,132 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := source
INCLUDES := include
DATA :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s -I$(CURDIR)/../source
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lnds9
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export ARM9BIN := $(TOPDIR)/$(TARGET).arm9
export ARM9ELF := $(CURDIR)/$(TARGET).arm9.elf
export DEPSDIR := $(CURDIR)/$(BUILD)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(ARM9BIN) : $(ARM9ELF)
@$(OBJCOPY) -O binary $< $@
@echo built ... $(notdir $@)
$(ARM9ELF) : $(OFILES)
@echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

Binary file not shown.

View File

@@ -0,0 +1,34 @@
#include <nds.h>
#include <stdio.h>
extern unsigned char basicloop[];
int main()
{
powerOn(POWER_ALL);
videoSetMode(MODE_0_2D);
consoleDemoInit();
BG_PALETTE[0] = RGB15(0, 0, 0);
while ( 1 )
{
swiWaitForVBlank();
scanKeys();
if ( keysDown() & KEY_X )
{
fifoSendValue32(FIFO_USER_01, (u32)(& basicloop[0]));
BG_PALETTE[0] = RGB15(15, 0, 0);
}
else if ( keysHeld() & KEY_B )
{
fifoSendValue32(FIFO_USER_01, 0);
BG_PALETTE[0] = RGB15(0, 0, 0);
}
}
return 0;
}

View File

@@ -0,0 +1,5 @@
.section .rodata
.balign 4
.global basicloop
basicloop:
.incbin "test"