view test/loopwave.c @ 1302:94643e9bad18

Date: Sat, 14 Jan 2006 15:16:01 -0500 From: Andrew Fuller Subject: [SDL] [PATCH] ML-8866 PS2->USB converter This converter seems to go by several names -- Super Dual Box, Dual USB Joypad, and who knows what else. Also branded differently with different colour cases, etc. But it seems to all be the same internals. It is a common converter used for StepMania, with several posts Googleable trying to make it work in Linux. I got mine yesterday and wanted to play stepmania, so I went ahead and made a crude patch for libsdl to split this baby into two logical joysticks. A couple notes about the patch: This patch works well for two dance mats hooked up and playing stepmania, however the mapping of the other buttons may be off. I have no joystick which uses all the buttons the converter reports, so I have no way of testing them. The name I used 0925:8866 which is the USB ID, and what SDLjoytest-GL reported is the name, even though lsusb shows Wisegroup, Ltd MP-8866 Dual USB Joypad, and the existing virtual joystick mapping uses the Wisegroup... name. Not sure why the discrepency. I'm not subscribed to this mailing list, so please CC me on any comments to this. -Andrew
author Sam Lantinga <slouken@libsdl.org>
date Tue, 31 Jan 2006 14:59:43 +0000
parents be9c9c8f6d53
children 0394f8ebc42d
line wrap: on
line source


/* Program to load a wave file and loop playing it using SDL sound */

/* loopwaves.c is much more robust in handling WAVE files -- 
	This is only for simple WAVEs
*/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include "SDL.h"
#include "SDL_audio.h"

struct {
	SDL_AudioSpec spec;
	Uint8   *sound;			/* Pointer to wave data */
	Uint32   soundlen;		/* Length of wave data */
	int      soundpos;		/* Current play position */
} wave;


/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void quit(int rc)
{
	SDL_Quit();
	exit(rc);
}


void fillerup(void *unused, Uint8 *stream, int len)
{
	Uint8 *waveptr;
	int    waveleft;

	/* Set up the pointers */
	waveptr = wave.sound + wave.soundpos;
	waveleft = wave.soundlen - wave.soundpos;

	/* Go! */
	while ( waveleft <= len ) {
		SDL_MixAudio(stream, waveptr, waveleft, SDL_MIX_MAXVOLUME);
		stream += waveleft;
		len -= waveleft;
		waveptr = wave.sound;
		waveleft = wave.soundlen;
		wave.soundpos = 0;
	}
	SDL_MixAudio(stream, waveptr, len, SDL_MIX_MAXVOLUME);
	wave.soundpos += len;
}

static int done = 0;
void poked(int sig)
{
	done = 1;
}

int main(int argc, char *argv[])
{
	char name[32];

	/* Load the SDL library */
	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(1);
	}

	if ( argv[1] == NULL ) {
		fprintf(stderr, "Usage: %s <wavefile>\n", argv[0]);
		quit(1);
	}

	/* Load the wave file into memory */
	if ( SDL_LoadWAV(argv[1],
			&wave.spec, &wave.sound, &wave.soundlen) == NULL ) {
		fprintf(stderr, "Couldn't load %s: %s\n",
						argv[1], SDL_GetError());
		quit(1);
	}
	wave.spec.callback = fillerup;

	/* Set the signals */
#ifdef SIGHUP
	signal(SIGHUP, poked);
#endif
	signal(SIGINT, poked);
#ifdef SIGQUIT
	signal(SIGQUIT, poked);
#endif
	signal(SIGTERM, poked);

	/* Initialize fillerup() variables */
	if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) {
		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
		SDL_FreeWAV(wave.sound);
		quit(2);
	}
	SDL_PauseAudio(0);

	/* Let the audio run */
	printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
	while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
		SDL_Delay(1000);

	/* Clean up on signal */
	SDL_CloseAudio();
	SDL_FreeWAV(wave.sound);
	SDL_Quit();
	return(0);
}