Skip to content

Commit

Permalink
Added auto-play mode. Push select to enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitSith2 committed Sep 15, 2011
1 parent 4d40e54 commit 4386653
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 24 deletions.
Binary file modified NDS_Music_Player.nds
Binary file not shown.
10 changes: 10 additions & 0 deletions arm7/source/sndbase.arm.c
Expand Up @@ -6,6 +6,8 @@
static void sound_timer();
static void sndsysMsgHandler(int, void*);

volatile int seq_status=STATUS_STOPPED;

void InstallSoundSys()
{
/* Power sound on */
Expand Down Expand Up @@ -261,12 +263,20 @@ void sndsysMsgHandler(int bytes, void* user_data)
case SNDSYS_PLAYSEQ:
{
PlaySeq(&msg.seq, &msg.bnk, msg.war);
seq_status=STATUS_PLAYING;
return;
}

case SNDSYS_FADESEQ:
{
seq_status=STATUS_FADING;
return;
}

case SNDSYS_STOPSEQ:
{
StopSeq();
seq_status=STATUS_STOPPED;
return;
}
}
Expand Down
76 changes: 66 additions & 10 deletions arm7/source/sseq.arm.c
Expand Up @@ -179,6 +179,7 @@ typedef struct
int a,d,s,r;
int loopcount,looppos;
int track_ended;
int track_looped;
} trackstat_t;

int ntracks = 0;
Expand Down Expand Up @@ -209,7 +210,7 @@ int _Note(void* bnk, void** war, int instr, int note, int prio, playinfo_t* play
msg.count=2;
msg.data[0] = 0;
msg.data[1] = fRecord;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
return -1;
}
Expand Down Expand Up @@ -261,7 +262,7 @@ int _Note(void* bnk, void** war, int instr, int note, int prio, playinfo_t* play
msg.count=2;
msg.data[0] = 0;
msg.data[1] = fRecord;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
return -1;
}
Expand Down Expand Up @@ -308,6 +309,8 @@ void _NoteStop(int n)
#define SEQ_READ16(pos) ((u16)seqData[(pos)] | ((u16)seqData[(pos)+1] << 8))
#define SEQ_READ24(pos) ((u32)seqData[(pos)] | ((u32)seqData[(pos)+1] << 8) | ((u32)seqData[(pos)+2] << 16))

int message_send_flag=0;

void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
{
#ifdef SNDSYS_DEBUG
Expand Down Expand Up @@ -345,15 +348,15 @@ void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
#ifdef SNDSYS_DEBUG
msg.count=3;
msg.data[0] = 0x03;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
}
else
{
#ifdef SNDSYS_DEBUG
msg.count=4;
msg.data[0] = 0x04;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
pos = 3;
}
Expand All @@ -364,7 +367,7 @@ void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
msg.count=5;
msg.data[0] = 5;
msg.data[1] = i;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
memset(tracks + i, 0, sizeof(trackstat_t));
tracks[i].pos = SEQ_READ24(pos); pos += 3;
Expand All @@ -375,6 +378,8 @@ void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
tracks[i].playinfo.pitchb = 0;
tracks[i].playinfo.pitchr = 2;
tracks[i].prio = 64;
tracks[i].track_looped = 0;
tracks[i].track_ended = 0;
tracks[i].a = -1; tracks[i].d = -1; tracks[i].s = -1; tracks[i].r = -1;
}

Expand All @@ -383,7 +388,7 @@ void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
msg.count=5;
msg.data[0] = 5;
msg.data[1] = 0;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
//fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
memset(tracks + 0, 0, sizeof(trackstat_t));
tracks[0].pos = pos;
Expand All @@ -394,12 +399,16 @@ void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
tracks[0].playinfo.pitchb = 0;
tracks[0].playinfo.pitchr = 2;
tracks[0].prio = 64;
tracks[0].track_looped = 0;
tracks[0].track_ended = 0;
tracks[0].a = -1; tracks[0].d = -1; tracks[0].s = -1; tracks[0].r = -1;
seq_bpm = 120;
message_send_flag = 0;
}

void StopSeq()
{
returnMsg msg;
seq_bpm=0; //stop sound_timer
//v=0;

Expand All @@ -411,6 +420,11 @@ void StopSeq()
chstat->track = -1;
SCHANNEL_CR(i) = 0;
}
#ifdef SNDSYS_DEBUG
msg.count=1;
msg.data[0] = 6;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
#endif
}

volatile int seq_bpm = 0;
Expand All @@ -420,6 +434,8 @@ void track_tick(int n);
void seq_tick()
{
int i;
int looped_twice=0;
int ended=0;
#ifdef LOG_SEQ
nocashMessage("Tick!");
#endif
Expand All @@ -436,7 +452,43 @@ void seq_tick()
}

for (i = 0; i < ntracks; i ++)
{
track_tick(i);
if(tracks[i].track_looped >= 2)
looped_twice++;
if(tracks[i].track_ended > 0)
ended++;
}
#ifdef SNDSYS_DEBUG
returnMsg msg;
if(!message_send_flag)
{
if(looped_twice == ntracks)
{
message_send_flag = 1;
msg.count = 1;
msg.data[0] = 7;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
return;
}
if(ended == ntracks)
{
message_send_flag = 1;
msg.count = 1;
msg.data[0] = 8;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
return;
}
if((looped_twice + ended) >= ntracks)
{
message_send_flag = 1;
msg.count = 1;
msg.data[0] = 7;
fifoSendDatamsg(FIFO_RETURN, sizeof(msg), (u8*)&msg);
return;
}
}
#endif
}

int read_vl(int* pos)
Expand Down Expand Up @@ -547,6 +599,8 @@ void track_tick(int n)
msg.count=1;
msg.data[0] = cmd;
#endif
if(track->pos > SEQ_READ24(track->pos))
track->track_looped++;
track->pos = SEQ_READ24(track->pos);
break;
}
Expand Down Expand Up @@ -610,7 +664,7 @@ void track_tick(int n)
nocashMessage("DUMMY1");
#endif
#ifdef SNDSYS_DEBUG
msg.count=2;
//msg.count=2;
msg.data[0] = cmd;
msg.data[1] = SEQ_READ8(track->pos); track->pos++;
#else
Expand Down Expand Up @@ -716,6 +770,8 @@ void track_tick(int n)
shouldRepeat = --track->loopcount;
if (shouldRepeat)
track->pos = track->looppos;
if((shouldRepeat == 1) && (track->loopcount == 0))
track->track_looped++;
break;
}
case 0xD5: // EXPR
Expand All @@ -735,7 +791,7 @@ void track_tick(int n)
nocashMessage("DUMMY2");
#endif
#ifdef SNDSYS_DEBUG
msg.count=3;
//msg.count=3;
msg.data[0] = cmd;
msg.data[1] = SEQ_READ8(track->pos); track->pos++;
msg.data[2] = SEQ_READ8(track->pos); track->pos++;
Expand Down Expand Up @@ -769,7 +825,7 @@ void track_tick(int n)
track->pos --;
return;
}
default:
/*default:
{
#ifdef SNDSYS_DEBUG
msg.count=3;
Expand All @@ -779,7 +835,7 @@ void track_tick(int n)
msg.data[3] = SEQ_READ8(track->pos+2);
#endif
break;
}
}*/
}
#ifdef SNDSYS_DEBUG
if(msg.count)
Expand Down
15 changes: 15 additions & 0 deletions arm7/source/template.c
Expand Up @@ -54,6 +54,7 @@ void powerButtonCB() {

//---------------------------------------------------------------------------------
int main() {
u32 i=0;
//---------------------------------------------------------------------------------
readUserSettings();

Expand Down Expand Up @@ -85,6 +86,20 @@ int main() {
exitflag = true;
}
swiWaitForVBlank();
if(seq_status==STATUS_FADING)
{
if(i<24)
{
i+=10;
}
else
{
i-=24;
ADSR_mastervolume--;
if(!ADSR_mastervolume)
StopSeq();
}
}
}
return 0;
}
7 changes: 7 additions & 0 deletions arm9/source/sndbase.c
Expand Up @@ -159,6 +159,13 @@ void StopSeq()
fifoSendDatamsg(FIFO_SNDSYS, sizeof(msg), (u8*) &msg);
}

void FadeSeq()
{
sndsysMsg msg;
msg.msg = SNDSYS_FADESEQ;
fifoSendDatamsg(FIFO_SNDSYS, sizeof(msg), (u8*) &msg);
}

void PlaySeqNDS(const char* ndsFile, const u32 SSEQOffset, const u32 SSEQSize, const u32 BANKOffset, const u32 BANKSize, const u32 WAVEARC1Offset, const u32 WAVEARC1Size, const u32 WAVEARC2Offset, const u32 WAVEARC2Size, const u32 WAVEARC3Offset, const u32 WAVEARC3Size, const u32 WAVEARC4Offset, const u32 WAVEARC4Size)
{
StopSeq();
Expand Down

0 comments on commit 4386653

Please sign in to comment.