Allocate audio buffer for application mixing in FastRAM if available. Contributed by Daniel Illgen.
--HG-- branch : SDL-1.2
This commit is contained in:
parent
f156e90deb
commit
260c066bcc
2 changed files with 40 additions and 21 deletions
|
@ -80,7 +80,13 @@ int SDL_MintAudio_InitBuffers(SDL_AudioSpec *spec)
|
||||||
SDL_CalculateAudioSpec(spec);
|
SDL_CalculateAudioSpec(spec);
|
||||||
MINTAUDIO_audiosize = spec->size * MAX_DMA_BUF;
|
MINTAUDIO_audiosize = spec->size * MAX_DMA_BUF;
|
||||||
|
|
||||||
/* Allocate memory for audio buffers in DMA-able RAM */
|
/* Allocate audio buffer memory for application in FastRAM */
|
||||||
|
MINTAUDIO_fastrambuf = Atari_SysMalloc(MINTAUDIO_audiosize, MX_TTRAM);
|
||||||
|
if (MINTAUDIO_fastrambuf) {
|
||||||
|
SDL_memset(MINTAUDIO_fastrambuf, spec->silence, MINTAUDIO_audiosize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate audio buffers memory for hardware in DMA-able RAM */
|
||||||
MINTAUDIO_audiobuf[0] = Atari_SysMalloc(2 * MINTAUDIO_audiosize, MX_STRAM);
|
MINTAUDIO_audiobuf[0] = Atari_SysMalloc(2 * MINTAUDIO_audiosize, MX_STRAM);
|
||||||
if (MINTAUDIO_audiobuf[0]==NULL) {
|
if (MINTAUDIO_audiobuf[0]==NULL) {
|
||||||
SDL_SetError("SDL_MintAudio_OpenAudio: Not enough memory for audio buffer");
|
SDL_SetError("SDL_MintAudio_OpenAudio: Not enough memory for audio buffer");
|
||||||
|
@ -104,6 +110,10 @@ void SDL_MintAudio_FreeBuffers(void)
|
||||||
{
|
{
|
||||||
SDL_AudioDevice *this = SDL_MintAudio_device;
|
SDL_AudioDevice *this = SDL_MintAudio_device;
|
||||||
|
|
||||||
|
if (MINTAUDIO_fastrambuf) {
|
||||||
|
Mfree(MINTAUDIO_fastrambuf);
|
||||||
|
MINTAUDIO_fastrambuf = NULL;
|
||||||
|
}
|
||||||
if (MINTAUDIO_audiobuf[0]) {
|
if (MINTAUDIO_audiobuf[0]) {
|
||||||
Mfree(MINTAUDIO_audiobuf[0]);
|
Mfree(MINTAUDIO_audiobuf[0]);
|
||||||
MINTAUDIO_audiobuf[0] = MINTAUDIO_audiobuf[1] = NULL;
|
MINTAUDIO_audiobuf[0] = MINTAUDIO_audiobuf[1] = NULL;
|
||||||
|
@ -156,12 +166,12 @@ static void SDL_MintAudio_Callback(void)
|
||||||
Uint8 *buffer;
|
Uint8 *buffer;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
buffer = MINTAUDIO_audiobuf[SDL_MintAudio_numbuf];
|
buffer = (MINTAUDIO_fastrambuf ?
|
||||||
|
MINTAUDIO_fastrambuf :
|
||||||
|
MINTAUDIO_audiobuf[SDL_MintAudio_numbuf]);
|
||||||
SDL_memset(buffer, this->spec.silence, this->spec.size * SDL_MintAudio_max_buf);
|
SDL_memset(buffer, this->spec.silence, this->spec.size * SDL_MintAudio_max_buf);
|
||||||
|
|
||||||
if (this->paused)
|
if (!this->paused) {
|
||||||
return;
|
|
||||||
|
|
||||||
for (i=0; i<SDL_MintAudio_max_buf; i++) {
|
for (i=0; i<SDL_MintAudio_max_buf; i++) {
|
||||||
if (this->convert.needed) {
|
if (this->convert.needed) {
|
||||||
int silence;
|
int silence;
|
||||||
|
@ -179,13 +189,20 @@ static void SDL_MintAudio_Callback(void)
|
||||||
|
|
||||||
buffer += this->convert.len_cvt;
|
buffer += this->convert.len_cvt;
|
||||||
} else {
|
} else {
|
||||||
this->spec.callback(this->spec.userdata, buffer, this->spec.size);
|
this->spec.callback(this->spec.userdata, buffer,
|
||||||
|
this->spec.size);
|
||||||
|
|
||||||
buffer += this->spec.size;
|
buffer += this->spec.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MINTAUDIO_fastrambuf) {
|
||||||
|
SDL_memcpy(MINTAUDIO_audiobuf[SDL_MintAudio_numbuf], MINTAUDIO_fastrambuf,
|
||||||
|
this->spec.size * SDL_MintAudio_max_buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a new frequency/clock/predivisor to the current list */
|
/* Add a new frequency/clock/predivisor to the current list */
|
||||||
void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
|
void SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
|
||||||
Uint32 prediv, int gpio_bits)
|
Uint32 prediv, int gpio_bits)
|
||||||
|
|
|
@ -52,6 +52,7 @@ struct SDL_PrivateAudioData {
|
||||||
int numfreq; /* Number of selected frequency */
|
int numfreq; /* Number of selected frequency */
|
||||||
|
|
||||||
Uint8 *audiobuf[2]; /* DMA buffers */
|
Uint8 *audiobuf[2]; /* DMA buffers */
|
||||||
|
Uint8 *fastrambuf; /* Intermediate buffer to be filled by application */
|
||||||
int audiosize; /* and their size, variable depending on latency */
|
int audiosize; /* and their size, variable depending on latency */
|
||||||
|
|
||||||
void (*swapbuf)(Uint8 *nextbuf, int nextsize); /* Routine to swap DMA buffers */
|
void (*swapbuf)(Uint8 *nextbuf, int nextsize); /* Routine to swap DMA buffers */
|
||||||
|
@ -64,6 +65,7 @@ struct SDL_PrivateAudioData {
|
||||||
#define MINTAUDIO_numfreq (this->hidden->numfreq)
|
#define MINTAUDIO_numfreq (this->hidden->numfreq)
|
||||||
#define MINTAUDIO_swapbuf (this->hidden->swapbuf)
|
#define MINTAUDIO_swapbuf (this->hidden->swapbuf)
|
||||||
#define MINTAUDIO_audiobuf (this->hidden->audiobuf)
|
#define MINTAUDIO_audiobuf (this->hidden->audiobuf)
|
||||||
|
#define MINTAUDIO_fastrambuf (this->hidden->fastrambuf)
|
||||||
#define MINTAUDIO_audiosize (this->hidden->audiosize)
|
#define MINTAUDIO_audiosize (this->hidden->audiosize)
|
||||||
|
|
||||||
/* _MCH cookie (values>>16) */
|
/* _MCH cookie (values>>16) */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue