/*---------------------------------------------------------------------------* Project: THP Simple Player File: axseq.c Copyright (C)2002-2006 Nintendo All Rights Reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: axseq.c,v $ Revision 1.7 2006/11/21 08:34:23 aka Removed the zero buffer. Revision 1.6 2006/10/23 02:12:13 aka Changed from AXInit() to AXInitSpecifyMem(). Changed from MIXInit() to MIXInitSpecifyMem(). Revision 1.5 2006/10/11 02:51:09 aka Revised AXInit() and MIXInit() and SYNInit(). Revision 1.4 2006/03/06 09:59:09 kawaset Eliminated warnings. Revision 1.3 2006/02/21 01:04:26 mitu modified am.h path. Revision 1.2 2006/02/20 04:13:12 mitu changed include path from dolphin/ to revolution/. Revision 1.1 2006/02/03 10:01:13 aka Imported from Dolphin tree. 1 02/02/28 6:39p Akagi Initial revision made by Suzuki-san (IRD). $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include "axseq.h" #define AXBUFFER_ON_MEM2 #undef AXBUFFER_ON_MEM2 static void CallbackAudioFrame(void); static SEQSEQUENCE Sequence; static u8 *Wavetable; static u8 *Pcm; static u8 *MidiFile; static void *axBuffer; static void *mixBuffer; static void *synBuffer; extern MEMHeapHandle __ExpHeap; static void CallbackAudioFrame(void) { int old = OSEnableInterrupts(); // run the sequencer SEQRunAudioFrame(); // run the synth SYNRunAudioFrame(); // tell the mixer to update settings MIXUpdateSettings(); OSRestoreInterrupts(old); } /*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*/ static void* LoadFileIntoRam(char *path) { DVDFileInfo handle; u32 round_length; s32 read_length; void *buffer; // Open File if (!DVDOpen(path, &handle)) { OSReport("WARNING! Failed to open %s\n", path); return NULL; } // Make sure file length is not 0 if (DVDGetLength(&handle) == 0) { OSReport("WARNING! File length is 0\n"); return NULL; } round_length = OSRoundUp32B(DVDGetLength(&handle)); buffer = MEMAllocFromExpHeapEx(__ExpHeap, round_length, 32); // Make sure we got a buffer if (buffer == NULL) { OSReport("WARNING! Unable to allocate buffer\n"); return NULL; } // Read Files read_length = DVDRead(&handle, buffer, (s32)(round_length), 0); // Make sure we read the file correctly if (read_length <= 0) { OSReport("WARNING! File lenght is wrong\n"); return NULL; } return buffer; } void AXSeqSetup(void) { #ifdef AXBUFFER_ON_MEM2 axBuffer = MEMAllocFromExpHeapEx(__ExpHeap, AXGetMemorySize(AX_MAX_VOICES), 32); #else axBuffer = OSAlloc(AXGetMemorySize(AX_MAX_VOICES)); #endif mixBuffer = MEMAllocFromExpHeap(__ExpHeap, MIXGetMemorySize(AX_MAX_VOICES)); synBuffer = MEMAllocFromExpHeap(__ExpHeap, SYNGetMemorySize(AX_MAX_VOICES)); AXInitSpecifyMem(AX_MAX_VOICES, axBuffer); // initialize AX MIXInitSpecifyMem(mixBuffer); // initialize mixer SYNInitSpecifyMem(synBuffer); // initialize synthesizer SEQInit(); // initialize sequencer AXRegisterCallback(&CallbackAudioFrame); Wavetable = LoadFileIntoRam(GM_WT); Pcm = LoadFileIntoRam(GM_PCM); MidiFile = LoadFileIntoRam(MIDI_FILE); SEQAddSequence( &Sequence, MidiFile, Wavetable, Pcm, NULL, 16, 15, 1 ); } void SeqPlay(void) { SEQSetState(&Sequence, SEQ_STATE_RUNLOOPED); return; } void SeqStop(void) { SEQSetState(&Sequence, SEQ_STATE_STOP); return; } BOOL GetSeqState(void) { if (SEQGetState(&Sequence) == SEQ_STATE_RUNLOOPED) { return TRUE; } else { return FALSE; } }