2008-12-11 18:38:29 +01:00
|
|
|
/****************************************************************************
|
2008-12-12 16:38:04 +01:00
|
|
|
* ogc_audio.c
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* Genesis Plus GX audio support
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* code by Softdev (2006), Eke-Eke (2007,2008)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
/* global datas */
|
|
|
|
unsigned char soundbuffer[16][3840] ATTRIBUTE_ALIGN(32);
|
2008-12-10 19:16:30 +01:00
|
|
|
int mixbuffer = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
static int playbuffer = 0;
|
|
|
|
static int IsPlaying = 0;
|
|
|
|
|
|
|
|
/*** AudioSwitchBuffers
|
|
|
|
Genesis Plus only provides sound data on completion of each frame.
|
|
|
|
To try to make the audio less choppy, this function is called from both the
|
|
|
|
DMA completion and update_audio.
|
|
|
|
Testing for data in the buffer ensures that there are no clashes.
|
|
|
|
***/
|
|
|
|
static void AudioSwitchBuffers()
|
|
|
|
{
|
|
|
|
if (ConfigRequested)
|
|
|
|
{
|
|
|
|
IsPlaying = 0;
|
|
|
|
return;
|
|
|
|
}
|
2008-12-10 19:16:30 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
u32 dma_len = (vdp_pal) ? 3840 : 3200;
|
|
|
|
|
|
|
|
/* restart audio DMA with current soundbuffer */
|
|
|
|
AUDIO_InitDMA((u32) soundbuffer[playbuffer], dma_len);
|
|
|
|
DCFlushRange(soundbuffer[playbuffer], dma_len);
|
|
|
|
AUDIO_StartDMA();
|
2008-12-10 19:16:30 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* increment soundbuffers index */
|
2008-12-12 14:27:38 +01:00
|
|
|
playbuffer++;
|
|
|
|
playbuffer &= 0xf;
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
if (playbuffer == mixbuffer)
|
|
|
|
{
|
|
|
|
playbuffer--;
|
|
|
|
if ( playbuffer < 0 ) playbuffer = 15;
|
|
|
|
}
|
|
|
|
IsPlaying = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ogc_audio__init(void)
|
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
AUDIO_Init (NULL);
|
|
|
|
AUDIO_SetDSPSampleRate (AI_SAMPLERATE_48KHZ);
|
|
|
|
AUDIO_RegisterDMACallback (AudioSwitchBuffers);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ogc_audio__reset(void)
|
|
|
|
{
|
|
|
|
AUDIO_StopDMA ();
|
|
|
|
IsPlaying = 0;
|
|
|
|
mixbuffer = 0;
|
|
|
|
playbuffer = 0;
|
2008-12-14 13:38:52 +01:00
|
|
|
memset(soundbuffer, 0, 16 * 3840);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ogc_audio__update(void)
|
|
|
|
{
|
|
|
|
/* restart Audio DMA if needed */
|
2008-12-07 20:31:50 +01:00
|
|
|
if (!IsPlaying) AudioSwitchBuffers();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|