mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-26 04:24:16 +01:00
rewrites of audio system
This commit is contained in:
parent
53958d97b0
commit
45b38cbb7e
@ -21,7 +21,50 @@ static int tail = 0;
|
|||||||
static u8 mixerdata[MIXBUFFSIZE];
|
static u8 mixerdata[MIXBUFFSIZE];
|
||||||
#define MIXERMASK ((MIXBUFFSIZE >> 2) - 1)
|
#define MIXERMASK ((MIXBUFFSIZE >> 2) - 1)
|
||||||
|
|
||||||
static u8 soundbuffer[3200] ATTRIBUTE_ALIGN(32);
|
static u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32);
|
||||||
|
extern int ConfigRequested;
|
||||||
|
static int whichab = 0;
|
||||||
|
int IsPlaying = 0;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* MIXER_GetSamples
|
||||||
|
***************************************************************************/
|
||||||
|
static int MIXER_GetSamples( u8 *dstbuffer, int maxlen )
|
||||||
|
{
|
||||||
|
u32 *src = (u32 *)mixerdata;
|
||||||
|
u32 *dst = (u32 *)dstbuffer;
|
||||||
|
u32 intlen = maxlen >> 2;
|
||||||
|
|
||||||
|
memset(dstbuffer, 0, maxlen);
|
||||||
|
|
||||||
|
while( ( head != tail ) && intlen )
|
||||||
|
{
|
||||||
|
*dst++ = src[tail++];
|
||||||
|
tail &= MIXERMASK;
|
||||||
|
intlen--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 3200;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* MIXER_GetSamples
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
static void AudioPlayer()
|
||||||
|
{
|
||||||
|
if ( !ConfigRequested )
|
||||||
|
{
|
||||||
|
int len = MIXER_GetSamples(soundbuffer[whichab], 3200);
|
||||||
|
DCFlushRange(soundbuffer[whichab],len);
|
||||||
|
AUDIO_InitDMA((u32)soundbuffer[whichab],len);
|
||||||
|
AUDIO_StartDMA();
|
||||||
|
whichab ^= 1;
|
||||||
|
IsPlaying = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IsPlaying = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* MIXER_AddSamples
|
* MIXER_AddSamples
|
||||||
@ -54,57 +97,44 @@ void MIXER_AddSamples( u8 *sampledata, int len )
|
|||||||
fixofs += fixinc;
|
fixofs += fixinc;
|
||||||
}
|
}
|
||||||
while( --intlen );
|
while( --intlen );
|
||||||
|
|
||||||
|
// Restart Sound Processing if stopped
|
||||||
|
if (IsPlaying == 0)
|
||||||
|
{
|
||||||
|
ConfigRequested = 0;
|
||||||
|
AudioPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* MIXER_GetSamples
|
* MIXER_GetSamples
|
||||||
****************************************************************************/
|
***************************************************************************/
|
||||||
int MIXER_GetSamples( u8 *dstbuffer, int maxlen )
|
|
||||||
{
|
|
||||||
u32 *src = (u32 *)mixerdata;
|
|
||||||
u32 *dst = (u32 *)dstbuffer;
|
|
||||||
u32 intlen = maxlen >> 2;
|
|
||||||
|
|
||||||
memset(dstbuffer, 0, maxlen);
|
|
||||||
|
|
||||||
while( ( head != tail ) && intlen )
|
|
||||||
{
|
|
||||||
*dst++ = src[tail++];
|
|
||||||
tail &= MIXERMASK;
|
|
||||||
intlen--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 3200;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AudioPlayer()
|
|
||||||
{
|
|
||||||
AUDIO_StopDMA();
|
|
||||||
MIXER_GetSamples(soundbuffer, 3200);
|
|
||||||
DCFlushRange(soundbuffer,3200);
|
|
||||||
AUDIO_InitDMA((u32)soundbuffer,3200);
|
|
||||||
AUDIO_StartDMA();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitialiseSound()
|
void InitialiseSound()
|
||||||
{
|
{
|
||||||
AUDIO_Init(NULL); // Start audio subsystem
|
AUDIO_Init(NULL); // Start audio subsystem
|
||||||
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
|
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
|
||||||
AUDIO_RegisterDMACallback(AudioPlayer);
|
AUDIO_RegisterDMACallback(AudioPlayer);
|
||||||
memset(soundbuffer, 0, 3200);
|
memset(soundbuffer, 0, 3840*2);
|
||||||
|
memset(mixerdata, 0, MIXBUFFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* MIXER_GetSamples
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
void ResetAudio()
|
void ResetAudio()
|
||||||
{
|
{
|
||||||
memset(soundbuffer, 0, 3200);
|
memset(soundbuffer, 0, 3840*2);
|
||||||
|
memset(mixerdata, 0, MIXBUFFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* MIXER_GetSamples
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
void StopAudio()
|
void StopAudio()
|
||||||
{
|
{
|
||||||
AUDIO_StopDMA();
|
AUDIO_StopDMA();
|
||||||
}
|
IsPlaying = 0;
|
||||||
|
|
||||||
void StartAudio()
|
|
||||||
{
|
|
||||||
AUDIO_StartDMA();
|
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,7 @@
|
|||||||
#define __AUDIOMIXER__
|
#define __AUDIOMIXER__
|
||||||
|
|
||||||
void MIXER_AddSamples( u8 *sampledata, int len );
|
void MIXER_AddSamples( u8 *sampledata, int len );
|
||||||
int MIXER_GetSamples( u8 *dstbuffer, int maxlen );
|
|
||||||
void StopAudio();
|
void StopAudio();
|
||||||
void StartAudio();
|
|
||||||
void ResetAudio();
|
void ResetAudio();
|
||||||
void InitialiseSound();
|
void InitialiseSound();
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "vba.h"
|
#include "vba.h"
|
||||||
#include "button_mapping.h"
|
#include "button_mapping.h"
|
||||||
|
#include "audio.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "tbtime.h"
|
#include "tbtime.h"
|
||||||
@ -298,6 +299,7 @@ u32 GetJoy(int pad)
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
StopAudio();
|
||||||
ConfigRequested = 1;
|
ConfigRequested = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -646,7 +646,6 @@ MainMenu (int selectedMenu)
|
|||||||
{
|
{
|
||||||
tb_t start,end;
|
tb_t start,end;
|
||||||
mftb(&start);
|
mftb(&start);
|
||||||
StopAudio();
|
|
||||||
|
|
||||||
int quit = 0;
|
int quit = 0;
|
||||||
int ret;
|
int ret;
|
||||||
@ -738,7 +737,6 @@ MainMenu (int selectedMenu)
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartAudio();
|
|
||||||
mftb(&end);
|
mftb(&end);
|
||||||
loadtimeradjust += tb_diff_msec(&end, &start);
|
loadtimeradjust += tb_diff_msec(&end, &start);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user