/*---------------------------------------------------------------------------* Project: Audio visualization tools File: DEMOAVX.c Copyright 2001 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: DEMOAVX.c,v $ Revision 2.0 2006/02/20 04:37:44 ceb Ported from revolution to cafe. Revision 1.2 2006/02/20 04:37:44 mitu Changed include path from dolphin/ to revolution/. Revision 1.1.1.1 2005/05/12 02:15:48 yasuh-to Ported from dolphin sheath tree. 1 2002/01/11 4:55p Eugene Cheesy method for snooping output from DSP/input to AI-FIFO. It is audio-system agnostic, however. $NoKeywords: $ *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* * Includes *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #define AVX_INTERNAL_NUM_FRAMES 10 // Buffer for up to 10 frames (in case the frame rate drops to around 20 fps). ALIGNED_VAR(static s16, 32, __AVX_internal_buffer[AVX_FRAME_SIZE_WORDS*AVX_INTERNAL_NUM_FRAMES]); static void (*__AVX_save_isr)(void); // AVX callback for the AI-FIFO DMA interrupt. static u32 __AVX_num_frames; // Number of audio frames to buffer. static u32 __AVX_num_filled; // Number of frames filled since the last user refresh. static u32 __AVX_curr_frame; static u16 *__AVX_buffer; // Internal AI-FIFO buffer. static s16 *__AVX_left_buffer; // Pointer to the caller's left-channel sample buffer. static s16 *__AVX_right_buffer; // Pointer to the caller's right-channel sample buffer. static u32 __AVX_write_ptr = 0; static u32 __AVX_buffer_size = 0; static OSMutex __AVX_mutex; /*---------------------------------------------------------------------------* * Name : * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ static BOOL flag = FALSE; static void __DEMOAVX_isr(void) { u32 frame_address; if (__AVX_save_isr) { (*__AVX_save_isr)(); // Get the current address of the current AI-FIFO DMA transaction. frame_address = AIGetDMAStartAddr(); // Freak out if the address is NULL ASSERTMSG(frame_address, "AVX: frame address is NULL!\n"); // Invalidate source (DSP output/AI-FIFO input) //DCInvalidateRange((void *)(frame_address), AVX_FRAME_SIZE_BYTES); // Copy output from DSP into the AVX buffer. memcpy((void *)(&__AVX_buffer[__AVX_curr_frame * AVX_FRAME_SIZE_WORDS]), (void *)(frame_address), AVX_FRAME_SIZE_BYTES); // Flush newly copied data from the cache. //DCFlushRange((void *)(&__AVX_buffer[__AVX_curr_frame * AVX_FRAME_SIZE_WORDS]), AVX_FRAME_SIZE_BYTES); // Increment the frame pointer. __AVX_curr_frame = (__AVX_curr_frame + 1) % __AVX_num_frames; // Increment the frame counter. __AVX_num_filled = (__AVX_num_filled + 1) % AVX_INTERNAL_NUM_FRAMES; if (__AVX_curr_frame > 4) flag = TRUE; } } // end __DEMOAVX_isr /*---------------------------------------------------------------------------* * Name : * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ u32 DEMOAVXGetNumFilled(void) { u32 tmp; OSLockMutex(&__AVX_mutex); tmp = __AVX_num_filled; __AVX_num_filled = 0; OSUnlockMutex(&__AVX_mutex); return(tmp); } // end DEMOAVXGetNumFilled() /*---------------------------------------------------------------------------* * Name : * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ u32 DEMOAVXGetFrameCounter(void) { return(__AVX_curr_frame); } // end DEMOAVXGetFrameCounter() /*---------------------------------------------------------------------------* * Name : * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ u32 DEMOAVXRefreshBuffer(u32 *start_index, u32 *end_index) { u32 num_filled; u32 curr_frame; u32 i; u32 j; if (flag) { OSLockMutex(&__AVX_mutex); // num_filled = DEMOAVXGetNumFilled(); // Rewind back through the AI buffer curr_frame = (__AVX_num_frames + DEMOAVXGetFrameCounter() - num_filled) % __AVX_num_frames; OSUnlockMutex(&__AVX_mutex); // Save the starting position in the final sample buffer. *start_index = __AVX_write_ptr; for (i=0; i