src/audio/mint/SDL_mintaudio_gsxb.c
changeset 961 185acc07127a
parent 769 b8d311d90021
child 962 176240cf4405
equal deleted inserted replaced
960:eec28a5278be 961:185acc07127a
    51 
    51 
    52 #define MINT_AUDIO_DRIVER_NAME "mint_gsxb"
    52 #define MINT_AUDIO_DRIVER_NAME "mint_gsxb"
    53 
    53 
    54 /* Debug print info */
    54 /* Debug print info */
    55 #define DEBUG_NAME "audio:gsxb: "
    55 #define DEBUG_NAME "audio:gsxb: "
    56 #if 0
    56 #if 1
    57 #define DEBUG_PRINT(what) \
    57 #define DEBUG_PRINT(what) \
    58 	{ \
    58 	{ \
    59 		printf what; \
    59 		printf what; \
    60 	}
    60 	}
    61 #else
    61 #else
   177 static void Mint_CloseAudio(_THIS)
   177 static void Mint_CloseAudio(_THIS)
   178 {
   178 {
   179 	/* Stop replay */
   179 	/* Stop replay */
   180 	Buffoper(0);
   180 	Buffoper(0);
   181 
   181 
   182 	DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
       
   183 
       
   184 	/* Uninstall interrupt */
   182 	/* Uninstall interrupt */
   185 	if (NSetinterrupt(2, SI_NONE, SDL_MintAudio_EmptyGsxbInterrupt)<0) {
   183 	if (NSetinterrupt(2, SI_NONE, SDL_MintAudio_EmptyGsxbInterrupt)<0) {
   186 		DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
   184 		DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
   187 	}
   185 	}
   188 
   186 
   189 	DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
       
   190 
       
   191 	/* Wait if currently playing sound */
   187 	/* Wait if currently playing sound */
   192 	while (SDL_MintAudio_mutex != 0) {
   188 	while (SDL_MintAudio_mutex != 0) {
   193 	}
   189 	}
   194 
       
   195 	DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
       
   196 
   190 
   197 	/* Clear buffers */
   191 	/* Clear buffers */
   198 	if (SDL_MintAudio_audiobuf[0]) {
   192 	if (SDL_MintAudio_audiobuf[0]) {
   199 		Mfree(SDL_MintAudio_audiobuf[0]);
   193 		Mfree(SDL_MintAudio_audiobuf[0]);
   200 		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   194 		SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   201 	}
   195 	}
   202 
       
   203 	DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
       
   204 
   196 
   205 	/* Unlock sound system */
   197 	/* Unlock sound system */
   206 	Unlocksnd();
   198 	Unlocksnd();
   207 }
   199 }
   208 
   200 
   276 			spec->format |= 0x1000;
   268 			spec->format |= 0x1000;
   277 		}
   269 		}
   278 	}
   270 	}
   279 	
   271 	
   280 	/* Calculate and select the closest frequency */
   272 	/* Calculate and select the closest frequency */
   281 	MINTAUDIO_sfreq=1;
   273 	MINTAUDIO_freqcount=0;
   282 	MINTAUDIO_nfreq=12;
   274 	for (i=1;i<4;i++) {
   283 	for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) {
   275 		SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, (1<<i)-1);
   284 		MINTAUDIO_hardfreq[i]=MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(i+1));
   276 	}
   285 		DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i]));
   277 
   286 	}
   278 #if 1
   287 
   279 	for (i=0; i<MINTAUDIO_freqcount; i++) {
   288 	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 1, spec->freq);
   280 		DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n",
   289 	spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq];
   281 			i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock,
       
   282 			MINTAUDIO_frequencies[i].predivisor
       
   283 		));
       
   284 	}
       
   285 #endif
       
   286 
       
   287 	MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq);
       
   288 	spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   290 
   289 
   291 	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
   290 	DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff));
   292 	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
   291 	DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0)));
   293 	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
   292 	DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0)));
   294 	DEBUG_PRINT(("channels=%d, ", spec->channels));
   293 	DEBUG_PRINT(("channels=%d, ", spec->channels));
   297 	return 0;
   296 	return 0;
   298 }
   297 }
   299 
   298 
   300 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
   299 static void Mint_InitAudio(_THIS, SDL_AudioSpec *spec)
   301 {
   300 {
   302 	int channels_mode;
   301 	int channels_mode, prediv;
   303 	void *buffer;
   302 	void *buffer;
   304 
   303 
   305 	/* Stop currently playing sound */
   304 	/* Stop currently playing sound */
   306 	Buffoper(0);
   305 	Buffoper(0);
   307 
   306 
   331 	}
   330 	}
   332 	if (Setmode(channels_mode)<0) {
   331 	if (Setmode(channels_mode)<0) {
   333 		DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
   332 		DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n"));
   334 	}
   333 	}
   335 
   334 
   336 	Devconnect(DMAPLAY, DAC, CLKEXT, MINTAUDIO_numfreq, 1);
   335 	prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
       
   336 	Devconnect(DMAPLAY, DAC, CLKEXT, prediv, 1);
   337 
   337 
   338 	/* Set buffer */
   338 	/* Set buffer */
   339 	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   339 	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   340 	if (Setbuffer(0, buffer, buffer + spec->size)<0) {
   340 	if (Setbuffer(0, buffer, buffer + spec->size)<0) {
   341 		DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
   341 		DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));