Ejemplo n.º 1
0
/*** 
      gx_audio_Start

     This function restarts the audio engine
     This is called when coming back from Main Menu
 ***/
void gx_audio_Start(void)
{
  /* shutdown background music */
  PauseOgg(1);	
  StopOgg();	
  
  /* shutdown menu audio processing */
  ASND_Pause(1);
  ASND_End();
  AUDIO_StopDMA();
  AUDIO_RegisterDMACallback(NULL);
  DSP_Halt();

  /* DMA Interrupt callback */
  AUDIO_RegisterDMACallback(ai_callback);

  /* emulation is synchronized with audio hardware by default */
  audioSync = AUDIO_WAIT;

  /* reset emulation audio processing */
  memset(soundbuffer, 0, sizeof(soundbuffer));
  audioWait = 0;
  bufferSize = 0;
  bufferIndex = 0;
}
Ejemplo n.º 2
0
void
sound_lowlevel_end( void )
{
  sfifo_flush( &sound_fifo );
  sfifo_close( &sound_fifo );
  AUDIO_StopDMA();
}
Ejemplo n.º 3
0
static int init(int rate, int channels, int format, int flags)
{
	AUDIO_StopDMA();

	if(rate>32000) quality = AI_SAMPLERATE_48KHZ; 
	else quality = AI_SAMPLERATE_32KHZ;
	ao_data.samplerate = (quality==AI_SAMPLERATE_48KHZ) ? 48000 : 32000;
	ao_data.channels = clamp(channels, 2, 6);
	ao_data.format = AF_FORMAT_S16_NE;
	ao_data.bps = ao_data.channels * ao_data.samplerate * sizeof(s16);
	request_mult = (float)ao_data.channels / HW_CHANNELS;
	request_size = BUFFER_SIZE * request_mult;
	ao_data.buffersize = request_size * BUFFER_COUNT;
	ao_data.outburst = request_size;
	
	for (int counter = 0; counter < BUFFER_COUNT; counter++)
	{
		memset(buffers[counter], 0, BUFFER_SIZE);
		DCFlushRange(buffers[counter], BUFFER_SIZE);
	}

	memset(silence, 0, BUFFER_SIZE);
	DCFlushRange(silence, BUFFER_SIZE);

	buffer_fill = 0;
	buffer_play = 0;
	buffered = 0;

	playing = false;

	AUDIO_SetDSPSampleRate(quality);
	AUDIO_RegisterDMACallback(switch_buffers);

	return CONTROL_TRUE;
}
Ejemplo n.º 4
0
/*** 
      gx_audio_Update

     This function retrieves samples for the frame then set the next DMA parameters 
     Parameters will be taken in account only when current DMA operation is over
 ***/
void gx_audio_Update(void)
{
  /* retrieve audio samples */
  int size = audio_update() * 4;

  /* set next DMA soundbuffer */
  s16 *sb = (s16 *)(soundbuffer[mixbuffer]);
  DCFlushRange((void *)sb, size);
  AUDIO_InitDMA((u32) sb, size);
  mixbuffer ^= 1;

  /* Start Audio DMA */
  /* this is called once to kick-off DMA from external memory to audio interface        */
  /* DMA operation is automatically restarted when all samples have been sent.          */
  /* If DMA settings are not updated at that time, previous sound buffer will be used.  */
  /* Therefore we need to make sure frame emulation is completed before current DMA is  */
  /* completed, either by synchronizing frame emulation with DMA start or by syncing it */
  /* with Vertical Interrupt and outputing a suitable number of samples per frame.      */
  /*                                                                                    */
  /* In both cases, audio DMA need to be synchronized with VSYNC and therefore need to  */
  /* be resynchronized (restarted) every time video settings are changed (hopefully,    */
  /* this generally happens while no music is played.                                   */                    
  if (!audioStarted)
  {
    /* restart audio DMA */
    AUDIO_StopDMA();
    AUDIO_StartDMA();
    audioStarted = 1;

    /* resynchronize emulation */
    frameticker = 1;
  }
}
Ejemplo n.º 5
0
static void uninit(int immed)
{
	reset();
	AUDIO_RegisterDMACallback(NULL);
	while(AUDIO_GetDMABytesLeft() > 0)
		usleep(100);
	AUDIO_StopDMA();
}
Ejemplo n.º 6
0
void pauseAudio(void){
#ifdef THREADED_AUDIO
	// We just grab the audio_free 'lock' and don't let go
	//   when we have this lock, audio_thread must be waiting
	if(audioEnabled){
		LWP_SemWait(audio_free);
		audio_paused = 1;
	}
#endif
	AUDIO_StopDMA();
}
Ejemplo n.º 7
0
static void StartDMA(void)
{
    AUDIO_StopDMA();
    soundpos++;
    if (soundpos >= NUMSOUNDBLOCKS)
        soundpos = 0;

    AUDIO_InitDMA((u32)stereodata16[soundpos], soundtruelen * 4);
    DCFlushRange((void *)stereodata16[soundpos], soundtruelen * 4);
    AUDIO_StartDMA();
}
Ejemplo n.º 8
0
static void 
switch_buffers(void)
{
  AUDIO_StopDMA();
  
  cur_buffer ^= 1;

  AUDIO_InitDMA((u32)buffer[cur_buffer], buffer_size[cur_buffer]);
  AUDIO_StartDMA();

  LWP_ThreadSignal(audio_queue);
}
Ejemplo n.º 9
0
static void wii_audio_free(void *data)
{
   AUDIO_StopDMA();
   AUDIO_RegisterDMACallback(NULL);
   if (g_audio && g_audio->cond)
   {
      LWP_CloseQueue(g_audio->cond);
      g_audio->cond = 0;
   }
   if (data)
      free(data);
   g_audio = NULL;
}
Ejemplo n.º 10
0
/****************************************************************************
 * SwitchAudioMode
 *
 * Switches between menu sound and emulator sound
 ***************************************************************************/
static void SwitchAudioMode(int mode)
{
	if(mode == 0) // emulator
	{
		ASND_Pause(1);
		AUDIO_StopDMA();
		WII_AudioStart();
	}
	else // menu
	{
		WII_AudioStop();
		ASND_Init();
		ASND_Pause(0);
	}
}
Ejemplo n.º 11
0
EXPORT void CALL
RomClosed( void )
{
#ifdef THREADED_AUDIO
	// Destroy semaphores and suspend the thread so audio can't play
	if(!thread_running) LWP_SemPost(first_audio);
	thread_running = 0;
	LWP_SemDestroy(buffer_full);
	LWP_SemDestroy(buffer_empty);
	LWP_SemDestroy(audio_free);
	LWP_SemDestroy(first_audio);
	LWP_JoinThread(audio_thread, NULL);
	audio_paused = 0;
#endif
	AUDIO_StopDMA(); // So we don't have a buzzing sound when we exit the game
}
Ejemplo n.º 12
0
void OSystem_Wii::deinitSfx() {
	if (_mixer)
		_mixer->setReady(false);

	AUDIO_StopDMA();
	AUDIO_RegisterDMACallback(NULL);

	if (sfx_thread_running) {
		sfx_thread_quit = true;
		LWP_ThreadBroadcast(sfx_queue);

		LWP_JoinThread(sfx_thread, NULL);
		LWP_CloseQueue(sfx_queue);

		free(sfx_stack);
		sfx_thread_running = false;

		for (u32 i = 0; i < SFX_BUFFERS; ++i)
			free(sound_buffer[i]);
	}
}
Ejemplo n.º 13
0
/*** 
      gx_audio_Start

     This function restart the audio engine
     This is called when coming back from Main Menu
 ***/
void gx_audio_Start(void)
{
  /* shutdown background music */
  PauseOgg(1);	
  StopOgg();	
  
  /* shutdown menu audio processing */
  ASND_Pause(1);
  AUDIO_StopDMA();
  AUDIO_RegisterDMACallback(NULL);
  DSP_Halt();

  /* when not using 60hz mode, frame emulation is synchronized with Audio Interface DMA */
  if (gc_pal | vdp_pal)
  {
    AUDIO_RegisterDMACallback(ai_callback);
  }

  /* reset emulation audio processing */
  memset(soundbuffer, 0, 2 * 3840);
  audioStarted = 0;
  mixbuffer = 0;
}
Ejemplo n.º 14
0
static void inline play_buffer(void){
#ifndef THREADED_AUDIO
	// We should wait for the other buffer to finish its DMA transfer first
	while( AUDIO_GetDMABytesLeft() );
	AUDIO_StopDMA();

#else // THREADED_AUDIO
	// Wait for a sample to actually be played to work around a deadlock
	LWP_SemWait(first_audio);
	
	// This thread will keep giving buffers to the audio as they come
	while(thread_running){

	// Wait for a buffer to be processed
	LWP_SemWait(buffer_full);
#endif

	// Make sure the buffer is in RAM, not the cache
	DCFlushRange(buffer[thread_buffer], buffer_size);

	// Actually send the buffer out to be played next
	AUDIO_InitDMA((unsigned int)&buffer[thread_buffer], buffer_size);

#ifdef THREADED_AUDIO
	// Wait for the audio interface to be free before playing
	LWP_SemWait(audio_free);
#endif

	// Start playing the buffer
	AUDIO_StartDMA();

#ifdef THREADED_AUDIO
	// Move the index to the next buffer
	NEXT(thread_buffer);
	}
#endif
}
Ejemplo n.º 15
0
static bool wii_audio_stop(void *data)
{
   (void)data;
   AUDIO_StopDMA();
   return true;
}
Ejemplo n.º 16
0
void SNDDMA_Shutdown(void)
{
	// Stop streaming.
	AUDIO_RegisterDMACallback(0);
	AUDIO_StopDMA();
}