src/audio/mint/SDL_mintaudio.c
author Patrice Mandin <patmandin@gmail.com>
Mon, 07 Jul 2003 19:16:03 +0000
changeset 644 594422ab8f9f
parent 557 0ce5a68278fd
child 704 c4803992e09c
permissions -rw-r--r--
Atari MiNT: added more audio drivers
slouken@398
     1
/*
patmandin@644
     2
    SDL - Simple DirectMedia Layer
patmandin@644
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@398
     4
patmandin@644
     5
    This library is free software; you can redistribute it and/or
patmandin@644
     6
    modify it under the terms of the GNU Library General Public
patmandin@644
     7
    License as published by the Free Software Foundation; either
patmandin@644
     8
    version 2 of the License, or (at your option) any later version.
patmandin@644
     9
patmandin@644
    10
    This library is distributed in the hope that it will be useful,
patmandin@644
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
patmandin@644
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
patmandin@644
    13
    Library General Public License for more details.
patmandin@644
    14
patmandin@644
    15
    You should have received a copy of the GNU Library General Public
patmandin@644
    16
    License along with this library; if not, write to the Free
patmandin@644
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
patmandin@644
    18
patmandin@644
    19
    Sam Lantinga
patmandin@644
    20
    slouken@libsdl.org
patmandin@644
    21
*/
patmandin@644
    22
patmandin@644
    23
/*
patmandin@644
    24
	Audio interrupt variables and callback function
patmandin@644
    25
patmandin@644
    26
	Patrice Mandin
patmandin@644
    27
*/
patmandin@644
    28
slouken@398
    29
#include <string.h>
slouken@398
    30
patmandin@644
    31
#include "SDL_types.h"
slouken@398
    32
#include "SDL_audio.h"
slouken@398
    33
slouken@398
    34
#include "SDL_mintaudio.h"
patmandin@644
    35
#include "SDL_mintaudio_stfa.h"
slouken@398
    36
patmandin@644
    37
/* The audio device */
slouken@398
    38
patmandin@644
    39
SDL_AudioDevice *SDL_MintAudio_device;
patmandin@644
    40
Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
patmandin@644
    41
long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
patmandin@644
    42
long SDL_MintAudio_numbuf;		/* Buffer to play */
patmandin@644
    43
long SDL_MintAudio_mutex;
patmandin@644
    44
cookie_stfa_t	*SDL_MintAudio_stfa;
slouken@398
    45
patmandin@644
    46
/* The callback function, called by each driver whenever needed */
slouken@398
    47
slouken@398
    48
void SDL_MintAudio_Callback(void)
slouken@398
    49
{
slouken@398
    50
	Uint8 *buffer;
slouken@398
    51
slouken@398
    52
 	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
patmandin@644
    53
	memset(buffer, SDL_MintAudio_device->spec.silence, SDL_MintAudio_device->spec.size);
slouken@398
    54
patmandin@644
    55
	if ( ! SDL_MintAudio_device->paused ) {
patmandin@644
    56
		if ( SDL_MintAudio_device->convert.needed ) {
patmandin@644
    57
			SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata,
patmandin@644
    58
				(Uint8 *)SDL_MintAudio_device->convert.buf,SDL_MintAudio_device->convert.len);
patmandin@644
    59
			SDL_ConvertAudio(&SDL_MintAudio_device->convert);
patmandin@644
    60
			memcpy(buffer, SDL_MintAudio_device->convert.buf, SDL_MintAudio_device->convert.len_cvt);
slouken@398
    61
		} else {
patmandin@644
    62
			SDL_MintAudio_device->spec.callback(SDL_MintAudio_device->spec.userdata, buffer, SDL_MintAudio_device->spec.size);
slouken@398
    63
		}
slouken@398
    64
	}
slouken@398
    65
}
slouken@398
    66
patmandin@644
    67
/* Simple function to search for the nearest frequency */
patmandin@644
    68
int SDL_MintAudio_SearchFrequency(_THIS, int falcon_codec, int desired_freq)
slouken@398
    69
{
slouken@398
    70
	int i;
slouken@398
    71
patmandin@644
    72
	/* Only 1 freq ? */
patmandin@644
    73
	if (MINTAUDIO_nfreq==1) {
patmandin@644
    74
		return(MINTAUDIO_sfreq);
slouken@398
    75
	}
slouken@398
    76
patmandin@644
    77
	/* Check the array */
patmandin@644
    78
	for (i=MINTAUDIO_sfreq; i<MINTAUDIO_nfreq-1; i++) {
patmandin@644
    79
		/* Remove unusable falcon codec frequencies */
patmandin@644
    80
		if (falcon_codec) {
patmandin@644
    81
			if ((i==6) || (i==8) || (i==10)) {
patmandin@644
    82
				continue;
patmandin@644
    83
			}
patmandin@644
    84
		}
slouken@398
    85
patmandin@644
    86
		if (desired_freq >= ((MINTAUDIO_hardfreq[i]+MINTAUDIO_hardfreq[i+1])>>1)) {
patmandin@644
    87
			return i;
slouken@398
    88
		}
slouken@398
    89
	}
slouken@398
    90
patmandin@644
    91
	/* Not in the array, give the latest */
patmandin@644
    92
	return MINTAUDIO_nfreq-1;
slouken@398
    93
}