/*---------------------------------------------------------------------------* 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.4 2006/03/06 09:59:09 kawaset Eliminated warnings. Revision 1.3 02/21/2006 01:04:26 mitu modified am.h path. Revision 1.2 02/20/2006 04:13:12 mitu changed include path from dolphin/ to revolution/. Revision 1.1 02/03/2006 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 #ifndef HOLLYWOOD_REV #include #else #include #include #endif #include "axseq.h" static void CallbackAudioFrame(void); #ifndef HOLLYWOOD_REV static u32 AramMemArray[MAX_ARAM_BLOCKS]; #endif static SEQSEQUENCE Sequence; static u8 *Wavetable; static u8 *Pcm; static u8 *ZeroBase; static u8 *MidiFile; #ifdef HOLLYWOOD_REV #define ZEROBUFFER_BYTES 256 extern MEMHeapHandle __ExpHeap; #endif static void CallbackAudioFrame(void) { int old = OSEnableInterrupts(); // run the sequencer SEQRunAudioFrame(); // run the synth SYNRunAudioFrame(); // tell the mixer to update settings MIXUpdateSettings(); OSRestoreInterrupts(old); } #ifdef HOLLYWOOD_REV /*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*/ 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; } #endif void AXSeqSetup(void) { #ifndef HOLLYWOOD_REV u32 aramSize, aramBase; #endif #ifndef HOLLYWOOD_REV ARInit(AramMemArray, MAX_ARAM_BLOCKS); ARQInit(); #endif AXInit(); // initialize AX MIXInit(); // initialize mixer SYNInit(); // initialize synthesizer SEQInit(); // initialize sequencer AXRegisterCallback(&CallbackAudioFrame); #ifndef HOLLYWOOD_REV aramSize = ARGetSize() - ARGetBaseAddress(); aramBase = ARAlloc(aramSize); AMInit(aramBase, aramSize); Wavetable = AMLoadFile(GM_WT, NULL); Pcm = (u8*)AMPush(GM_PCM); ZeroBase = (u8*)AMGetZeroBuffer(); MidiFile = AMLoadFile(MIDI_FILE, NULL); #else Wavetable = LoadFileIntoRam(GM_WT); Pcm = LoadFileIntoRam(GM_PCM); MidiFile = LoadFileIntoRam(MIDI_FILE); ZeroBase = MEMAllocFromExpHeapEx(__ExpHeap, ZEROBUFFER_BYTES, 8); memset(ZeroBase, 0, ZEROBUFFER_BYTES); DCFlushRange(ZeroBase, ZEROBUFFER_BYTES); #endif SEQAddSequence( &Sequence, MidiFile, Wavetable, Pcm, ZeroBase, 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; } }