Allocate audio buffer for application mixing in FastRAM if available. Contributed by Daniel Illgen. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Fri, 17 Apr 2015 21:41:11 +0200
branchSDL-1.2
changeset 95659f8a2b28f61d
parent 9564 b87c22915505
child 9900 453dce726f24
Allocate audio buffer for application mixing in FastRAM if available. Contributed by Daniel Illgen.
src/audio/mint/SDL_mintaudio.c
src/audio/mint/SDL_mintaudio.h
     1.1 --- a/src/audio/mint/SDL_mintaudio.c	Fri Apr 17 21:32:45 2015 +0200
     1.2 +++ b/src/audio/mint/SDL_mintaudio.c	Fri Apr 17 21:41:11 2015 +0200
     1.3 @@ -80,7 +80,13 @@
     1.4  	SDL_CalculateAudioSpec(spec);
     1.5  	MINTAUDIO_audiosize = spec->size * MAX_DMA_BUF;
     1.6  
     1.7 -	/* Allocate memory for audio buffers in DMA-able RAM */
     1.8 +	/* Allocate audio buffer memory for application in FastRAM */
     1.9 +	MINTAUDIO_fastrambuf = Atari_SysMalloc(MINTAUDIO_audiosize, MX_TTRAM);
    1.10 +	if (MINTAUDIO_fastrambuf) {
    1.11 +		SDL_memset(MINTAUDIO_fastrambuf, spec->silence, MINTAUDIO_audiosize);
    1.12 +	}
    1.13 +
    1.14 +	/* Allocate audio buffers memory for hardware in DMA-able RAM */
    1.15  	MINTAUDIO_audiobuf[0] = Atari_SysMalloc(2 * MINTAUDIO_audiosize, MX_STRAM);
    1.16  	if (MINTAUDIO_audiobuf[0]==NULL) {
    1.17  		SDL_SetError("SDL_MintAudio_OpenAudio: Not enough memory for audio buffer");
    1.18 @@ -104,6 +110,10 @@
    1.19  {
    1.20  	SDL_AudioDevice *this = SDL_MintAudio_device;
    1.21  
    1.22 +	if (MINTAUDIO_fastrambuf) {
    1.23 +		Mfree(MINTAUDIO_fastrambuf);
    1.24 +		MINTAUDIO_fastrambuf = NULL;
    1.25 +	}
    1.26  	if (MINTAUDIO_audiobuf[0]) {
    1.27  		Mfree(MINTAUDIO_audiobuf[0]);
    1.28  		MINTAUDIO_audiobuf[0] = MINTAUDIO_audiobuf[1] = NULL;
    1.29 @@ -156,33 +166,40 @@
    1.30  	Uint8 *buffer;
    1.31  	int i;
    1.32  
    1.33 - 	buffer = MINTAUDIO_audiobuf[SDL_MintAudio_numbuf];
    1.34 + 	buffer = (MINTAUDIO_fastrambuf ?
    1.35 +		MINTAUDIO_fastrambuf :
    1.36 +		MINTAUDIO_audiobuf[SDL_MintAudio_numbuf]);
    1.37  	SDL_memset(buffer, this->spec.silence, this->spec.size * SDL_MintAudio_max_buf);
    1.38  
    1.39 -	if (this->paused)
    1.40 -		return;
    1.41 +	if (!this->paused) {
    1.42 +		for (i=0; i<SDL_MintAudio_max_buf; i++) {
    1.43 +			if (this->convert.needed) {
    1.44 +				int silence;
    1.45  
    1.46 -	for (i=0; i<SDL_MintAudio_max_buf; i++) {
    1.47 -		if (this->convert.needed) {
    1.48 -			int silence;
    1.49 +				if ( this->convert.src_format == AUDIO_U8 ) {
    1.50 +					silence = 0x80;
    1.51 +				} else {
    1.52 +					silence = 0;
    1.53 +				}
    1.54 +				SDL_memset(this->convert.buf, silence, this->convert.len);
    1.55 +				this->spec.callback(this->spec.userdata,
    1.56 +					(Uint8 *)this->convert.buf,this->convert.len);
    1.57 +				SDL_ConvertAudio(&this->convert);
    1.58 +				SDL_memcpy(buffer, this->convert.buf, this->convert.len_cvt);
    1.59  
    1.60 -			if ( this->convert.src_format == AUDIO_U8 ) {
    1.61 -				silence = 0x80;
    1.62 +				buffer += this->convert.len_cvt;
    1.63  			} else {
    1.64 -				silence = 0;
    1.65 +				this->spec.callback(this->spec.userdata, buffer,
    1.66 +					this->spec.size);
    1.67 +
    1.68 +				buffer += this->spec.size;
    1.69  			}
    1.70 -			SDL_memset(this->convert.buf, silence, this->convert.len);
    1.71 -			this->spec.callback(this->spec.userdata,
    1.72 -				(Uint8 *)this->convert.buf,this->convert.len);
    1.73 -			SDL_ConvertAudio(&this->convert);
    1.74 -			SDL_memcpy(buffer, this->convert.buf, this->convert.len_cvt);
    1.75 +		}
    1.76 +	}
    1.77  
    1.78 -			buffer += this->convert.len_cvt;
    1.79 -		} else {
    1.80 -			this->spec.callback(this->spec.userdata, buffer, this->spec.size);
    1.81 -
    1.82 -			buffer += this->spec.size;
    1.83 -		}
    1.84 +	if (MINTAUDIO_fastrambuf) {
    1.85 +		SDL_memcpy(MINTAUDIO_audiobuf[SDL_MintAudio_numbuf], MINTAUDIO_fastrambuf,
    1.86 +			this->spec.size * SDL_MintAudio_max_buf);
    1.87  	}
    1.88  }
    1.89  
     2.1 --- a/src/audio/mint/SDL_mintaudio.h	Fri Apr 17 21:32:45 2015 +0200
     2.2 +++ b/src/audio/mint/SDL_mintaudio.h	Fri Apr 17 21:41:11 2015 +0200
     2.3 @@ -52,6 +52,7 @@
     2.4  	int	numfreq;	/* Number of selected frequency */
     2.5  
     2.6  	Uint8	*audiobuf[2];	/* DMA buffers */
     2.7 +	Uint8	*fastrambuf;	/* Intermediate buffer to be filled by application */
     2.8  	int	audiosize;	/* and their size, variable depending on latency */
     2.9  
    2.10  	void (*swapbuf)(Uint8 *nextbuf, int nextsize);	/* Routine to swap DMA buffers */
    2.11 @@ -64,6 +65,7 @@
    2.12  #define MINTAUDIO_numfreq	(this->hidden->numfreq)
    2.13  #define MINTAUDIO_swapbuf	(this->hidden->swapbuf)
    2.14  #define MINTAUDIO_audiobuf	(this->hidden->audiobuf)
    2.15 +#define MINTAUDIO_fastrambuf	(this->hidden->fastrambuf)
    2.16  #define MINTAUDIO_audiosize	(this->hidden->audiosize)
    2.17  
    2.18  /* _MCH cookie (values>>16) */