+1








f3e61a31aa
* buffers: refresh 15 and revert to base decomp * behavior script * color helper functions * extended bounds * egeo_layout * fixed model ids * camera conf improved * message panel ucode small * graph node * level script * mathutil updates * mathutil updates (allow unused funcs) * behaviors a - beta_fish * Add librtc and fix some data declarations * Move GRUCODE define to proper location in makefile * Refresh 15 * extra * Make ROM name smaller and change messages printed on build a bit * Fix console (lol) * Update UNF to latest master * Make ucode load from .o's (and also fix Super3D) * Fix crash with rumble + custom mario model * graph node and mathutil * removed behaviors * Ldtob documentation * _Putfld labeling * area * behavior actions * camera * debug updates * bubbles * envfx snow * farcall helpers * game init * geo misc * hud * only check if VC on render init * ingame menu * revert goddard to base decomp * insn disasm * interaction documentation * level geo * level update defines * macro special objects formatting changes * main.h documentation * map parser documentation & formatting * airborne documentation * mario actions automatic documentation * mario actions cutscene documentation * mario actions moving documentation and options * mario actions object documentation and options * mario stationary documentation * mario submerged documentation * mario misc documentation * mario step: ledge grab fixes and documentation * mario documentation * memory.h documentation * moving textures * object behaviors * object collision * fix flamethrower bug * object helpers * object list processor documentation * paintings * platform displacement * print / printf * puppycam absf * puppyprint updates and formatting changes * rendering graph node performance optimizations * rumble opt and doc * hqvm back to ultrasm64 * save file documentation and unlock defines * s2d engine * reset various files to ultrasm64 * file select * intro geo documentation * screen transition documentation * segment2.h * shadow overhaul * skybox refactor * sound init: clean up define usage + documentation * spawn object optimizations and documentation * spawn sound cleanup * sram to ultrasm64 * star select cleanup * title screen cleanup * dialogs / text * rename stomp smoke * stomp smoke -> small water splash * updated README * compilation flags * optimized file positions + support function/data sections * surface collision performance improvements * surface load optimizations * camera conf documentation * Allow easier command for opening puppyprint debug * Rearranged framebuffers & fixed puppyprint console printing * Fix shadow scaling and shifting * Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit. * Fixed build with BETTER_HANGING off * Clean up OBJECTS_REJ ifdefs * Fix duplicate comment & graph render layers/flags bitmask * Fixed build with BETTER_HANGING off * Fix Fast64 importing by reverting sSegmentTable change * Readded missing functions that caused build errors with Mario head enabled * Fixed clang compilation issues * Add INTER mode for geo_update_layer_transparency * Fix build warnings * bugfix: miscalculation in obj_turn_toward_object * Some puppytech fixes * Further Puppycamera fixes * Fix BUGFIX_DIALOG_TIME_STOP Fixes #136 * Fix sliding platform bparams * Add LEGACY_SHADOW_IDS define for Fast64 compatibility * Apply suggested changes * Better find_in_bounds_yaw_wdw_bob_thi ifdef * Fix build warnings for unused functions * Fixed stale reference bug from obj_mark_for_deletion change * Fixed incorrect digit for 100s #145 * Change groundpound-fix define and functionality to just disable bonking * Fixed puppyroll #134 * Adjust height value for terrain angle to kick in * fixed hi score flashing * Remove menudata backup (#131) Not considered important enough to keep * Fix fread() build warning * Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init * Fix approach_s16 return value * Use boolean defines for oCapDoScaleVertically * Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled. * Move flames to LAYER_TRANSPARENT_INTER * Resolved some compiler warnings and added FALL_THROUGH define (#168) * Address some more compiler warnings with different define toggles * Remove unnecessary fallthrough attribute * fixed geo_process_billboard floating point exception * Allow water to face any direction * Initialize focOffset so that BBH doesn't crash * Removed superfluous RDP commands when switching microcodes which would override scissor * Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage * Fix rumble build * Fixed UNLOCK_FPS strobing * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Fix LEGACY_SHADOW_IDS id conflict * Use the vanilla default value for rotating fire bars if bparam2 is 0 * START_LEVEL safeguard * Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE * Fix rumble build * Fixed spline poll code using the wrong values for keyframes * Update readme with better credits Better credits for individual contributors * add arthur * added falco and moose * add fazana * le funny typo * added S2DEX engine to credits * silhouette + axo + ratio * remove specific callouts + add auto col distance * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Revert formatting changes to match vanilla decomp * Re-implement Y buffer for find_ceil * Re-implement POWER_STARS_HEAL for normal Power Stars * Start level comment & exit course comment/collapse * utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT * Fix "MAX_REFERENCED_WALLS" typo * Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213) * Revert stop_and_set_height_to_floor to vanilla Fixes #208 * Fixed sAudioEnabled so that it disables audio CPU processing as well * Fixed puppyprint debug RDP us calculations * Renamed sAudioEnabled to gAudioEnabled * Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE * Moved extended bounds and world scale configuration to a new config_world.h file * Default all objects to non-rej (#227) Fixes #221 (Default all objects to non-rej) * Fix #221 * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211) * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled * Change vtl decrement in visual_surface_display from 6 to 3 Fixes #207 * Make area in SL igloo wider to prevent a softlock (#233) Fixes #210 * Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232) Fixes #201 * Make UNLOCK_ALL apply to more things * Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init * Change chain chomp load/unload distances depending on number of segments (#237) Fixes #192 * added WATER_PLUNGE_UPWARP define * Add reonucam patch (#239) * added reonucam patch Fixes #218 * Fix how shadows handle water/transparency/height (#228) * Fix how shadows handle water/transparency/height * Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check Fixes #179 * added reonucam credit * delete unnecesary patches * Apply suggested changes * murdered more patches * UNLOCK_ALL unlocks the cap boxes * UNLOCK_ALL unlocks cap boxes (slightly more epic edition) * revert ceil buffer * Renamed HD_INTRO_TEXTURES define, separated intro floombas * prevent double definition of floombas * actually prevent floomba redefinition * Develop/refactor default defines (#242) * Changed default config options * Added build dir to includePaths for pngs * disable NO_SLEEP by default * Disable puppyprint by default Sorry fazana 😔 * fix typos * add comment about BETTER_REVERB console perf * disable blue coin switch retry by default * Update config_audio.h Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * revert air step line to vanilla to fix bitfs scaling platform issue (#247) Fixes #200 * Fix stuttering on thin slopes (#248) * Fix stuttering on thin slopes * Revert vec3f_find_ceil calls to vanilla * Rename vec3f_find_ceil to find_mario_ceil * Update src/engine/surface_collision.h Fixes #249 * Swap static and dynamic surface checks back to vanilla order (#253) * Swap static and dynamic surface checks back to vanilla order * re-enable DISABLE_ALL config Fixes #251 #252 * Fixed save and quitting while in widescreen (#257) * Fixed save and quitting while in widescreen * use define for the level * all my homies hate ifdefs * skip wall offsets < 0 (#255) Fixes #255 * #264: Document non-stop stars' issues (#267) * #264: Document non-stop stars' issues * Update include/config/config_game.h * nonstop vanilla comment * derive margin_radius from radius after capping at 200 (#266) Fixes #259 * Config cleanup/refactor (#269) * Moved puppyprint define to graphics / rearranged some debug defines for ease of access * Moved compatibility safeguards to config_safeguards.h * spacing and comment formatting * #272 Move GFX_POOL_SIZE to config_graphics.h * disable EASIER_DIALOG_TRIGGER by default * prevent redefining warnings * small ifdef typo * changed ifndef to undefs Fixes #262 Fixes #272 * Improved movement config documentation related to turning around (#271) Fixes #270 * rename CUSTOM_DEBUG, add comments (#275) * Update README.md (#277) * v2.0.0 Co-authored-by: CrashOveride95 <crashoveride953@gmail.com> Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com> Co-authored-by: n64 <n64> Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com> Co-authored-by: aglab2 <aglab3@gmail.com> Co-authored-by: gheskett <gheskett@gmail.com> Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
518 lines
18 KiB
C
518 lines
18 KiB
C
#include <ultra64.h>
|
|
#include <HVQM2File.h>
|
|
#include "hvqm.h"
|
|
#include "audio/data.h"
|
|
#include "buffers/framebuffers.h"
|
|
|
|
/***********************************************************************
|
|
* Timekeeper thread
|
|
***********************************************************************/
|
|
static OSThread tkThread;
|
|
static u64 tkStack[STACKSIZE/sizeof(u64)];
|
|
|
|
/***********************************************************************
|
|
* Audio DA counter thread
|
|
***********************************************************************/
|
|
static OSThread daCounterThread;
|
|
static u64 daCounterStack[STACKSIZE/sizeof(u64)];
|
|
|
|
/***********************************************************************
|
|
* Timekeeper's command message queue
|
|
***********************************************************************/
|
|
static OSMesgQueue tkCmdMesgQ;
|
|
static OSMesg tkCmdMesgBuf;
|
|
|
|
/***********************************************************************
|
|
* Message queue for responses from timekeeper
|
|
***********************************************************************/
|
|
static OSMesgQueue tkResMesgQ;
|
|
static OSMesg tkResMesgBuf;
|
|
|
|
/***********************************************************************
|
|
* Timekeeper's command structure
|
|
***********************************************************************/
|
|
typedef struct {
|
|
tkRewindProc rewind; /* Pointer to stream rewind function */
|
|
u32 samples_per_sec; /* Audio sampling rate */
|
|
} TKCMD;
|
|
|
|
/***********************************************************************
|
|
* VI event (retrace) message queue
|
|
***********************************************************************/
|
|
#define VI_MSG_SIZE 2
|
|
static OSMesgQueue viMessageQ;
|
|
static OSMesg viMessages[VI_MSG_SIZE];
|
|
|
|
/***********************************************************************
|
|
* AI event (FIFO free) message queue
|
|
***********************************************************************/
|
|
#define AI_MSG_SIZE 2
|
|
static OSMesgQueue aiMessageQ;
|
|
static OSMesg aiMessages[AI_MSG_SIZE];
|
|
|
|
/***********************************************************************
|
|
* Ring buffer for reserving display of image
|
|
*
|
|
* As soon as image (frame buffer) is complete, put into this
|
|
* ring buffer, wait for display time to come and set in VI.
|
|
***********************************************************************/
|
|
#define VIDEO_RING_SIZE NUM_CFBs
|
|
|
|
static struct {
|
|
u64 disptime; /* Display time */
|
|
void *vaddr; /* Frame buffer address */
|
|
u32 *statP; /* Pointer to frame buffer state flag */
|
|
} videoRing[VIDEO_RING_SIZE];
|
|
|
|
static int videoRingCount; /* Amount of data remaining in ring buffer */
|
|
static int videoRingWrite; /* Ring buffer write index */
|
|
static int videoRingRead; /* Ring buffer read index */
|
|
|
|
/***********************************************************************
|
|
* Ring buffer for reserving playback of audio
|
|
*
|
|
* As soon as audio (PCM data) is complete, put into this
|
|
* ring buffer and push as soon as AI FIFO is free.
|
|
***********************************************************************/
|
|
#define AUDIO_RING_BUFFER_SIZE NUM_PCMBUFs
|
|
|
|
static struct {
|
|
void *buf; /* PCM data buffer */
|
|
u32 len; /* PCM data length */
|
|
} audioRing[AUDIO_RING_BUFFER_SIZE];
|
|
|
|
static int audioRingCount; /* Amount of data remaining in ring buffer */
|
|
static int audioRingWrite; /* Ring buffer write index */
|
|
static int audioRingRead; /* Ring buffer read index */
|
|
|
|
/***********************************************************************
|
|
* PCM data buffer information
|
|
***********************************************************************/
|
|
static int pcmBufferCount; /* Number of PCM data buffers being used */
|
|
static u32 aiFIFOsamples; /* Number of PCM samples waiting in AI FIFO */
|
|
static u32 aiDAsamples; /* Number of samples AI is DMA transferring to DA */
|
|
|
|
/***********************************************************************
|
|
* Buffer for matching PCM transfer data length to PCM_ALIGN
|
|
***********************************************************************/
|
|
static s16 pcmModBuf[(PCM_ALIGN-1)*PCM_CHANNELS];
|
|
|
|
/***********************************************************************
|
|
* Flag enabling measurement of passage of time
|
|
***********************************************************************/
|
|
static int clock_alive;
|
|
|
|
/***********************************************************************
|
|
* Audio sampling rate
|
|
***********************************************************************/
|
|
static u32 samples_per_sec;
|
|
|
|
/***********************************************************************
|
|
* Number of PCM samples that have finished playing
|
|
*
|
|
* Strictly the number samples that have finished playing. Does not
|
|
* include samples in FIFO nor the sample playing in the DA buffer.
|
|
*
|
|
* From this value you get the amount of time that has passed
|
|
* since the start of play of the HVQM2 stream.
|
|
***********************************************************************/
|
|
static u64 samples_played;
|
|
|
|
/***********************************************************************
|
|
* The time samples_played was first updated ( osGetTime() )
|
|
*
|
|
* Time measured beyond this point is supplemented with osGetTime().
|
|
***********************************************************************/
|
|
static OSTime last_time;
|
|
|
|
/***********************************************************************
|
|
*
|
|
* u64 tkGetTime(void)
|
|
*
|
|
* Explanation
|
|
* The time that has passed since the start of HVQM2 movie playback
|
|
* is calculated back from the number of samples that have finished
|
|
* playing (samples_played) and the sampling rate (samples_per_sec).
|
|
* The time after samples_played was first updated is supplemented
|
|
* with osGetTime().
|
|
*
|
|
* Returned value
|
|
* The time that has passed since playback of the HVQM2 movie started
|
|
*
|
|
***********************************************************************/
|
|
u64 tkGetTime(void){
|
|
u64 retval;
|
|
|
|
if (!clock_alive) return 0;
|
|
|
|
retval = OS_CYCLES_TO_USEC((u64)osGetTime() - last_time);
|
|
if (samples_per_sec) retval += samples_played * 1000000LL / samples_per_sec;
|
|
return retval;
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void tkClockDisable(void)
|
|
*
|
|
* Explanation
|
|
* Disable measurement of time from start of HVQM2 movie playback
|
|
*
|
|
***********************************************************************/
|
|
static void tkClockDisable(void)
|
|
{
|
|
clock_alive = 0;
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void tkClockStart(void)
|
|
*
|
|
* Explanation
|
|
* Start measurement of time from start of HVQM2 movie playback
|
|
*
|
|
***********************************************************************/
|
|
static void tkClockStart(void)
|
|
{
|
|
samples_played = 0;
|
|
last_time = osGetTime();
|
|
clock_alive = 1;
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* daCounterProc - Audio DA counter thread procedure
|
|
*
|
|
* Counts the number of audio samples that have finished playing.
|
|
*
|
|
***********************************************************************/
|
|
static void daCounterProc(void UNUSED*argument)
|
|
{
|
|
for ( ; ; ) {
|
|
osRecvMesg( &aiMessageQ, NULL, OS_MESG_BLOCK );
|
|
last_time = osGetTime();
|
|
if ( aiDAsamples > 0 ) --pcmBufferCount;
|
|
samples_played += aiDAsamples;
|
|
aiDAsamples = aiFIFOsamples;
|
|
aiFIFOsamples = 0;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* timekeeperProc - Timekeeper thread procedure
|
|
*
|
|
* Plays the HVQM2 movie's audio records and takes charge of
|
|
* completed frame buffers, displaying them at the scheduled times.
|
|
*
|
|
***********************************************************************/
|
|
static void timekeeperProc(void UNUSED*argument) {
|
|
TKCMD *cmd;
|
|
void *showing_cfb = NULL; /* Frame buffer being displayed */
|
|
u32 *showing_cfb_statP = NULL; /* Pointer to state flag of the frame buffer being displayed */
|
|
s32 video_started; /* Flag indicating start of video display */
|
|
s32 audio_started; /* Flag indicating start of audio playback */
|
|
s32 video_done; /* Flag indicating end of video decoding */
|
|
s32 audio_done; /* Flag indicating end of audio decoding */
|
|
void *pushed_cfb; /* Frame buffer reserved for swap */
|
|
u32 *pushed_cfb_statP; /* Pointer to state flag of frame buffer reserved for swap */
|
|
s32 next_pcmbufno; /* The number of the PCM buffer to use next */
|
|
s32 pcm_mod_samples; /* The number of PCM samples left over */
|
|
tkAudioProc audioproc;
|
|
OSTime present_vtime;
|
|
|
|
/* Acquire retrace event */
|
|
osCreateMesgQueue( &viMessageQ, viMessages, VI_MSG_SIZE );
|
|
osViSetEvent( &viMessageQ, 0, 1 );
|
|
|
|
/* Acquire AI event*/
|
|
osCreateMesgQueue( &aiMessageQ, aiMessages, AI_MSG_SIZE );
|
|
osSetEventMesg( OS_EVENT_AI, &aiMessageQ, (OSMesg *)1 );
|
|
|
|
/*
|
|
* Create and start audio DA counter thread
|
|
*/
|
|
osCreateThread(&daCounterThread, DA_COUNTER_THREAD_ID, daCounterProc,
|
|
NULL, daCounterStack + (STACKSIZE/sizeof(u64)),
|
|
(OSPri)DA_COUNTER_PRIORITY);
|
|
osStartThread(&daCounterThread);
|
|
|
|
osRecvMesg(&tkCmdMesgQ, (OSMesg *)&cmd, OS_MESG_BLOCK);
|
|
|
|
/*
|
|
* Wait for movie playback command
|
|
*/
|
|
while ( cmd == NULL ) {
|
|
osSendMesg( &tkResMesgQ, NULL, OS_MESG_BLOCK );
|
|
osRecvMesg( &tkCmdMesgQ, (OSMesg *)&cmd, OS_MESG_BLOCK );
|
|
}
|
|
|
|
tkClockDisable();
|
|
audioproc = (cmd->rewind)();
|
|
|
|
samples_per_sec = cmd->samples_per_sec;
|
|
if (samples_per_sec) osAiSetFrequency(samples_per_sec);
|
|
|
|
pcmBufferCount = 0;
|
|
|
|
aiDAsamples = 0;
|
|
aiFIFOsamples = 0;
|
|
|
|
audioRingRead = audioRingWrite = 0;
|
|
audioRingCount = 0;
|
|
|
|
videoRingRead = videoRingWrite = 0;
|
|
videoRingCount = 0;
|
|
|
|
video_started = 0;
|
|
audio_started = 0;
|
|
video_done = 0;
|
|
audio_done = 0;
|
|
pushed_cfb = NULL;
|
|
pushed_cfb_statP = NULL;
|
|
next_pcmbufno = 0;
|
|
pcm_mod_samples = 0;
|
|
|
|
osSendMesg( &tkResMesgQ, NULL, OS_MESG_BLOCK ); /* Notification that playback preparations are finished */
|
|
|
|
present_vtime = osGetTime();
|
|
|
|
while (!video_done || videoRingCount > 0 || pushed_cfb != NULL ||
|
|
!audio_done || audioRingCount > 0 || aiFIFOsamples > 0) {
|
|
u64 present_time;
|
|
OSTime last_vtime;
|
|
/*
|
|
* Block until retrace comes
|
|
*/
|
|
osRecvMesg(&viMessageQ, NULL, OS_MESG_BLOCK);
|
|
|
|
last_vtime = present_vtime;
|
|
present_vtime = osGetTime();
|
|
present_time = tkGetTime() + OS_CYCLES_TO_USEC(present_vtime - last_vtime);
|
|
|
|
if (pushed_cfb != NULL) {
|
|
/* The display has switched from showing_cfb to pushed_cfb (it should have) */
|
|
if (!video_started) {
|
|
/* Display of the first frame has begun (the audio will begin from here) */
|
|
video_started = 1;
|
|
if (!audio_started && audio_done) {
|
|
audio_started = 1;
|
|
tkClockStart();
|
|
}
|
|
}
|
|
|
|
/* Release showing_cfb */
|
|
if (showing_cfb_statP != NULL && showing_cfb != pushed_cfb) {
|
|
*showing_cfb_statP &= ~CFB_SHOWING;
|
|
}
|
|
|
|
/* Update showing_cfb, pushed_cfb */
|
|
showing_cfb = pushed_cfb;
|
|
showing_cfb_statP = pushed_cfb_statP;
|
|
pushed_cfb = NULL;
|
|
pushed_cfb_statP = NULL;
|
|
}
|
|
|
|
/*
|
|
* Push the next frame buffer to the VI
|
|
*
|
|
* Before the start of video display (video_started == 0),
|
|
* wait until audio data is prepared for playback
|
|
* (audioRingCount > 0).
|
|
*/
|
|
if ( video_started || audioRingCount > 0 || audio_done ) {
|
|
while ( videoRingCount ) {
|
|
if ( videoRing[videoRingRead].disptime > present_time ) break;
|
|
if ( pushed_cfb_statP != NULL ) *pushed_cfb_statP &= ~CFB_SHOWING;
|
|
pushed_cfb = videoRing[videoRingRead].vaddr;
|
|
pushed_cfb_statP = videoRing[videoRingRead].statP;
|
|
*pushed_cfb_statP |= CFB_SHOWING;
|
|
osViSwapBuffer( pushed_cfb );
|
|
if ( ++videoRingRead == VIDEO_RING_SIZE ) videoRingRead = 0;
|
|
--videoRingCount;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Push the next PCM data to the AI
|
|
*
|
|
* Before the start of video display (video_started == 0)
|
|
* wait until the display of the first image frame
|
|
* has begun (video_started == 1).
|
|
*/
|
|
if ( video_started ) {
|
|
osSetThreadPri( NULL, (OSPri)(DA_COUNTER_PRIORITY + 1) );
|
|
while ( audioRingCount > 0 && aiFIFOsamples == 0 ) {
|
|
void *buffer = audioRing[audioRingRead].buf;
|
|
u32 length = audioRing[audioRingRead].len;
|
|
if ( osAiGetStatus() & AI_STATUS_FIFO_FULL ) break;
|
|
if ( osAiSetNextBuffer( buffer, length ) == -1 ) break;
|
|
aiFIFOsamples = length >> PCM_BYTES_PER_SAMPLE_SHIFT;
|
|
if ( ! audio_started ) {
|
|
/*
|
|
* Audio playback has begun.
|
|
* Here the time count starts to synchronize audio and video
|
|
*/
|
|
audio_started = 1;
|
|
tkClockStart();
|
|
}
|
|
if ( ++audioRingRead == AUDIO_RING_BUFFER_SIZE ) audioRingRead = 0;
|
|
--audioRingCount;
|
|
}
|
|
osSetThreadPri( NULL, (OSPri)TIMEKEEPER_PRIORITY );
|
|
}
|
|
/*
|
|
* Prepare the next PCM data
|
|
*/
|
|
if ( ! audio_done && audioRingCount < AUDIO_RING_BUFFER_SIZE && pcmBufferCount < NUM_PCMBUFs ) {
|
|
u32 samples;
|
|
u32 length;
|
|
void *buffer;
|
|
s16 *sp, *dp;
|
|
int i;
|
|
|
|
samples = audioproc( &gAiBuffers[next_pcmbufno][pcm_mod_samples<<PCM_CHANNELS_SHIFT] );
|
|
|
|
if ( samples > 0 ) {
|
|
++pcmBufferCount;
|
|
|
|
sp = pcmModBuf;
|
|
dp = (s16 *)((u8 *)gAiBuffers[next_pcmbufno]);
|
|
i = pcm_mod_samples << PCM_CHANNELS_SHIFT;
|
|
while ( i-- ) *dp++ = *sp++;
|
|
samples += pcm_mod_samples;
|
|
samples -= (pcm_mod_samples = samples & (PCM_ALIGN-1));
|
|
length = samples << PCM_BYTES_PER_SAMPLE_SHIFT;
|
|
buffer = gAiBuffers[next_pcmbufno];
|
|
osWritebackDCache( buffer, length );
|
|
audioRing[audioRingWrite].buf = buffer;
|
|
audioRing[audioRingWrite].len = length;
|
|
if ( ++audioRingWrite == AUDIO_RING_BUFFER_SIZE ) audioRingWrite = 0;
|
|
++audioRingCount;
|
|
|
|
sp = (s16 *)((u8 *)(gAiBuffers[next_pcmbufno]) + length);
|
|
dp = pcmModBuf;
|
|
i = pcm_mod_samples << PCM_CHANNELS_SHIFT;
|
|
while ( i-- ) *dp++ = *sp++;
|
|
|
|
if ( ++next_pcmbufno >= NUM_PCMBUFs ) next_pcmbufno = 0;
|
|
}
|
|
else audio_done = 1;
|
|
}
|
|
|
|
if ( osRecvMesg( &tkCmdMesgQ, (OSMesg *)&cmd, OS_MESG_NOBLOCK ) == 0 )
|
|
{
|
|
/*
|
|
* tkStop() or tkStart() has been executed
|
|
*
|
|
* Set 1 in video_done and end this playback loop
|
|
* after playback of the current movie's video and
|
|
* and audio has completely finished.
|
|
*/
|
|
video_done = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void createTimekeeper(void)
|
|
*
|
|
* Explanation
|
|
* Creates and starts the timekeeper thread
|
|
*
|
|
***********************************************************************/
|
|
void
|
|
createTimekeeper(void)
|
|
{
|
|
osCreateMesgQueue( &tkCmdMesgQ, &tkCmdMesgBuf, 1 );
|
|
osCreateMesgQueue( &tkResMesgQ, &tkResMesgBuf, 1 );
|
|
osCreateThread( &tkThread, TIMEKEEPER_THREAD_ID, timekeeperProc,
|
|
NULL, tkStack + (STACKSIZE/sizeof(u64)),
|
|
(OSPri)TIMEKEEPER_PRIORITY );
|
|
osStartThread( &tkThread );
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void tkStart(tkRewindProc rewind, u32 samples_per_sec)
|
|
*
|
|
* Argument
|
|
* rewind Pointer to movie rewind callback function
|
|
*
|
|
* Explanation
|
|
* Directs the timekeeper to play a new movie. Playback of the
|
|
* movie starts after callback of "rewind" by the timekeeper. After
|
|
* this, the HVQM2 video records are read and decoded and the
|
|
* completed frame buffers are handed over to the timekeeper by
|
|
* tkPushVideoframe() in succession to play the video part of the movie.
|
|
* As for the audio, the timekeeper itself calls the callback
|
|
* function (the value returned by rewind) that gets the PCM data as
|
|
* needed to playback the audio.
|
|
*
|
|
***********************************************************************/
|
|
void
|
|
tkStart( tkRewindProc rewind, u32 samples_per_sec )
|
|
{
|
|
TKCMD tkcmd;
|
|
tkcmd.samples_per_sec = samples_per_sec;
|
|
tkcmd.rewind = rewind;
|
|
osSendMesg( &tkCmdMesgQ, (OSMesg *)&tkcmd, OS_MESG_BLOCK );
|
|
osRecvMesg( &tkResMesgQ, (OSMesg *)NULL, OS_MESG_BLOCK );
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void tkStop(void)
|
|
*
|
|
* Explanation
|
|
* Stops the timekeeper. However, the timekeeper continues to
|
|
* run until playback of the audio of the playing movie is complete.
|
|
* To stop the stream in mid-stream, make 0 the value returned by
|
|
* the callback function that reads audio and is called from the
|
|
* timekeeper, and then execute tkStop().
|
|
*
|
|
* To immediately start the playback of a new movie, it is OK to
|
|
* to execute tkStart() without executing tkStop().
|
|
*
|
|
***********************************************************************/
|
|
void
|
|
tkStop( void )
|
|
{
|
|
osSendMesg( &tkCmdMesgQ, (OSMesg *)NULL, OS_MESG_BLOCK );
|
|
osRecvMesg( &tkResMesgQ, (OSMesg *)NULL, OS_MESG_BLOCK );
|
|
}
|
|
|
|
/***********************************************************************
|
|
*
|
|
* void tkPushVideoframe(void *vaddr, u32 *statP, u64 disptime)
|
|
*
|
|
* Argument
|
|
* vaddr Frame buffer address
|
|
* statP Pointer to state flag data regarding vaddr
|
|
* disptime Display time
|
|
*
|
|
* Explanation
|
|
* Entrusts the completed frame buffer vaddr to the timekeeper.
|
|
* The timekeeper displays the frame buffer after waiting for the
|
|
* "disptime" amount of time to pass from the start of the movie.
|
|
*
|
|
* To wait for the display of the vaddr frame buffer or to
|
|
* indicate that something is being displayed, the CFB_SHOWING
|
|
* flag is set in the u32 type data pointed to by the statP pointer.
|
|
* At the time when display of vaddr is finished, (once its display
|
|
* is over and display has switched to another frame buffer) this
|
|
* flag is cleared by the timekeeper.
|
|
*
|
|
***********************************************************************/
|
|
void
|
|
tkPushVideoframe( void *vaddr, u32 *statP, u64 disptime )
|
|
{
|
|
*statP |= CFB_SHOWING;
|
|
while ( videoRingCount >= VIDEO_RING_SIZE ) osYieldThread();
|
|
videoRing[videoRingWrite].disptime = disptime;
|
|
videoRing[videoRingWrite].vaddr = vaddr;
|
|
videoRing[videoRingWrite].statP = statP;
|
|
if ( ++videoRingWrite == VIDEO_RING_SIZE ) videoRingWrite = 0;
|
|
++videoRingCount;
|
|
}
|