19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Library General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Library General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Library General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Audio interrupt variables and callback function
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Patrice Mandin
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h>
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <mint/osbind.h>
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <mint/falcon.h>
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <mint/mintbind.h>
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <mint/cookie.h>
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_audio.h"
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mintaudio.h"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mintaudio_stfa.h"
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The audio device */
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_AudioDevice *SDL_MintAudio_device;
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallUint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvolatile unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvolatile unsigned short SDL_MintAudio_mutex;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvolatile unsigned long SDL_MintAudio_clocktics;
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallcookie_stfa_t	*SDL_MintAudio_stfa;
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned short SDL_MintAudio_hasfpu;
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* MiNT thread variables */
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_bool SDL_MintAudio_mint_present;
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_bool SDL_MintAudio_quit_thread;
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_bool SDL_MintAudio_thread_finished;
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halllong SDL_MintAudio_thread_pid;
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The callback function, called by each driver whenever needed */
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_MintAudio_Callback(void)
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint8 *buffer;
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioDevice *audio = SDL_MintAudio_device;
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(buffer, audio->spec.silence, audio->spec.size);
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (audio->paused)
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (audio->convert.needed) {
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		int silence;
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( audio->convert.src_format == AUDIO_U8 ) {
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			silence = 0x80;
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			silence = 0;
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_memset(audio->convert.buf, silence, audio->convert.len);
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio->spec.callback(audio->spec.userdata,
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			(Uint8 *)audio->convert.buf,audio->convert.len);
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_ConvertAudio(&audio->convert);
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Add a new frequency/clock/predivisor to the current list */
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_MintAudio_AddFrequency(_THIS, Uint32 frequency, Uint32 clock,
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 prediv, int gpio_bits)
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i, p;
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (MINTAUDIO_freqcount==MINTAUDIO_maxfreqs) {
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Search where to insert the frequency (highest first) */
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for (p=0; p<MINTAUDIO_freqcount; p++) {
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (frequency > MINTAUDIO_frequencies[p].frequency) {
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Put all following ones farer */
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (MINTAUDIO_freqcount>0) {
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for (i=MINTAUDIO_freqcount; i>p; i--) {
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t));
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* And insert new one */
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	MINTAUDIO_frequencies[p].frequency = frequency;
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	MINTAUDIO_frequencies[p].masterclock = clock;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	MINTAUDIO_frequencies[p].predivisor = prediv;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	MINTAUDIO_frequencies[p].gpio_bits = gpio_bits;
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	MINTAUDIO_freqcount++;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Search for the nearest frequency */
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_MintAudio_SearchFrequency(_THIS, int desired_freq)
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i;
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Only 1 freq ? */
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (MINTAUDIO_freqcount==1) {
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return 0;
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Check the array */
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for (i=0; i<MINTAUDIO_freqcount; i++) {
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (desired_freq >= ((MINTAUDIO_frequencies[i].frequency+
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			MINTAUDIO_frequencies[i+1].frequency)>>1)) {
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return i;
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Not in the array, give the latest */
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return MINTAUDIO_freqcount-1;
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Check if FPU is present */
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_MintAudio_CheckFpu(void)
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	long cookie_fpu;
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_MintAudio_hasfpu = 0;
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (Getcookie(C__FPU, &cookie_fpu) != C_FOUND) {
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	switch ((cookie_fpu>>16)&0xfffe) {
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 2:
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 4:
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 6:
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 8:
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 16:
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_MintAudio_hasfpu = 1;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The thread function, used under MiNT with xbios */
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_MintAudio_Thread(long param)
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SndBufPtr	pointers;
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_bool	buffers_filled[2] = {SDL_FALSE, SDL_FALSE};
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_MintAudio_thread_finished = SDL_FALSE;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while (!SDL_MintAudio_quit_thread) {
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (Buffptr(&pointers)!=0)
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			continue;
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (( (unsigned long)pointers.play>=(unsigned long)SDL_MintAudio_audiobuf[0])
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			&& ( (unsigned long)pointers.play<=(unsigned long)SDL_MintAudio_audiobuf[1]))
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		{
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			/* DMA is reading buffer #0, setup buffer #1 if not already done */
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if (!buffers_filled[1]) {
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_MintAudio_numbuf = 1;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_MintAudio_Callback();
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				Setbuffer(0, SDL_MintAudio_audiobuf[1], SDL_MintAudio_audiobuf[1] + SDL_MintAudio_audiosize);
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffers_filled[1]=SDL_TRUE;
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffers_filled[0]=SDL_FALSE;
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			/* DMA is reading buffer #1, setup buffer #0 if not already done */
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if (!buffers_filled[0]) {
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_MintAudio_numbuf = 0;
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_MintAudio_Callback();
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				Setbuffer(0, SDL_MintAudio_audiobuf[0], SDL_MintAudio_audiobuf[0] + SDL_MintAudio_audiosize);
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffers_filled[0]=SDL_TRUE;
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				buffers_filled[1]=SDL_FALSE;
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		usleep(100);
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_MintAudio_thread_finished = SDL_TRUE;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_MintAudio_WaitThread(void)
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (!SDL_MintAudio_mint_present)
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (SDL_MintAudio_thread_finished)
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_MintAudio_quit_thread = SDL_TRUE;
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	while (!SDL_MintAudio_thread_finished) {
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		Syield();
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
216