예제 #1
0
void SgInitialise ()
{
    // MikMod Setup
    
    MikMod_RegisterAllLoaders();
    
    MikMod_RegisterDriver(&drv_alsa);
    MikMod_RegisterDriver(&drv_oss);
    MikMod_RegisterDriver(&drv_esd);
    MikMod_RegisterDriver(&drv_nos);

    if(MikMod_Init("") != 0){
        SgDebugPrintf("MikMod Driver error: %s.\n",MikMod_strerror(MikMod_errno));	
        return;
    }
    
    if(MikMod_InitThreads() != 1){
        SgDebugPrintf("MikMod Not Threadsafe: %s.\n",MikMod_strerror(MikMod_errno));	
        return;
    }
    
    if (MikMod_SetNumVoices(16,8) != 0) 
        SgDebugPrintf("SoundGarden WARNING: Failed to set the desired number of voices\n");
    
    MikMod_EnableOutput();
            
    // Start the Sound Thread

    if (pthread_create( &mikmod_update_thread, NULL, SgUpdateMikModThread, NULL ) != 0) 
        SgDebugPrintf("SoundGarden WARNING: Failed to create sound thread\n");
}
예제 #2
0
void my_error_handler(void)
{
	printf("_mm_critical %d\n", MikMod_critical);
	printf("_mm_errno %d\n", MikMod_errno);
	printf("%s\n", MikMod_strerror(MikMod_errno));
	return;
}
예제 #3
0
int Mix_OpenAudio(int frequency, uint16 format, int channels, int chunksize)
{
    /* register all the drivers */
    MikMod_RegisterAllDrivers();

    /* register all the module loaders */
    MikMod_RegisterAllLoaders();

    /* initialize the library */
    md_mode |= DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
    
    if (MikMod_Init("")) {
        printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
		return 1;
    }
    
    /* One for music and one for sfx */
    MikMod_SetNumVoices(-1,8);
    MikMod_EnableOutput();
    
    loaded = 1;
	gfrequency = frequency;
	gchannels = channels;
	
	thd_create(0, snd_thread, NULL);
	return 0;
}
예제 #4
0
static int mod_initMikMod() {
	if(mod_mikModInitError) return -1;

	if(!mod_mikModInitiated) {
		mod_mikModInitiated = 1;

		md_device = 0;
		md_reverb = 0;

		MikMod_RegisterDriver(&drv_mpd);
		MikMod_RegisterAllLoaders();
	}

	md_pansep = 64;
	md_mixfreq = 44100;
	md_mode = (DMODE_SOFT_MUSIC | DMODE_INTERP | DMODE_STEREO |
			DMODE_16BITS);

	if(MikMod_Init("")) {
		ERROR("Could not init MikMod: %s\n", 
			MikMod_strerror(MikMod_errno));
		mod_mikModInitError = 1;
		return -1;
	}

	return 0;
}
예제 #5
0
void UOpenALAudioSubsystem::RegisterMusic( UMusic* Music )
{
	guard(UOpenALAudioSubsystem::RegisterMusic);

	checkSlow(Music);
	if( !Music->Handle )
	{
		// Set the handle to avoid reentrance.
		Music->Handle = (void*)-1;

		// Load the data.
		Music->Data.Load();
		debugf( NAME_DevMusic, TEXT("Register music: %s (%i)"), Music->GetPathName(), Music->Data.Num() );
		check(Music->Data.Num()>0);

		// Load the module.
		MREADER* Reader = BuildMikModMemoryReader( &Music->Data(0), Music->Data.Num() );
		MODULE* Module = Player_LoadGeneric( Reader, 64, 0 );
		DestroyMikModMemoryReader( Reader );
		if( Module == NULL )
			appErrorf(
				TEXT("Couldn't load music '%s': %s"),
				Music->GetPathName(), MikMod_strerror( MikMod_errno )
			);
		Music->Handle = Module;

		// Enable looping and wrapping.
		Module->loop = Module->wrap = 1;

		// Unload the data.
		Music->Data.Unload();
	}

	unguard;
}
예제 #6
0
int
init_sound_engine (void)
{
  if (nosound) {
    nosfx = 1;
    return 0;
  }

  dmsg (D_SYSTEM | D_SOUND_TRACK, "initialize libMikMod");

  /* register all the drivers */
  MikMod_RegisterAllDrivers ();
  dmsg (D_SOUND_TRACK, "libMikMod driver registered");

  /* register the all module loader
     (the user can use something else than .xm) */
  MikMod_RegisterAllLoaders ();
  dmsg (D_SOUND_TRACK, "libMikMod loader registered");

  /* initialize the library */
  md_device = nth_driver;
  md_mode |= DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
  if (mono)
    md_mode &= ~DMODE_STEREO;
  if (bits8)
    md_mode &= ~DMODE_16BITS;
  if (hqmix)
    md_mode |= DMODE_HQMIXER;
  dmsg (D_SOUND_TRACK, "Opening audio device #%d, with %dbits, %s%s",
	nth_driver, (md_mode & DMODE_16BITS)?16:8,
	(md_mode & DMODE_STEREO)?"stereo":"mono",
	(md_mode & DMODE_HQMIXER)?"":", high quality mixer");
  if (driver_options)
    dmsg (D_SOUND_TRACK, "MikMod user options: %s", driver_options);
  if (MikMod_Init (driver_options ? driver_options : const_cast_string (""))) {
    wmsg (_("Could not initialize sound, reason: %s\n"
	    "Disabling sound output (use -S to suppress this message)."),
	  MikMod_strerror (MikMod_errno));
    nosfx = nosound = 1;
    MikMod_Exit ();
    return 0;
  }

  dmsg (D_SOUND_TRACK,"initialize MikMod thread");
  if (MikMod_InitThreads () != 1) {
    wmsg (_("Could not initialize sound, reason: "
	    "LibMikMod is not thread safe.\n"
	    "Disabling sound output (use -S to suppress this message)."));
    nosfx = nosound = 1;
    MikMod_Exit ();
    return 0;
  }

  sound_initialized = 1;

  pthread_mutex_init (&playing, 0);
  adjust_volume ();

  return 0;
}
예제 #7
0
파일: splay.c 프로젝트: idispatch/libmikmod
int main(int argc, char **argv)
{
	MODULE *module;

	if (argc<2) {
		fprintf(stderr, "Usage: ./splay1 file\n");
		return 1;
	}

	/* register all the drivers */
	MikMod_RegisterAllDrivers();

	/* register all the module loaders */
	MikMod_RegisterAllLoaders();

	/* init the library */
	md_mode |= DMODE_SOFT_MUSIC | DMODE_NOISEREDUCTION;
	if (MikMod_Init("")) {
		fprintf(stderr, "Could not initialize sound, reason: %s\n",
				MikMod_strerror(MikMod_errno));
		return 2;
	}

	/* load module */
	module = Player_Load(argv[1], 64, 0);	
	if (module) {
		/* */
		printf("Playing %s (%d chn) - SIMD: %s\n", module->songname, module->numchn,
			md_mode & DMODE_SIMDMIXER ? "yes" : "no");
		/* start module */
		Player_Start(module);

		while (Player_Active()) {
			MikMod_Sleep(10000);
			MikMod_Update();
		}

		Player_Stop();
		Player_Free(module);
	} else
		fprintf(stderr, "Could not load module, reason: %s\n",
				MikMod_strerror(MikMod_errno));

	MikMod_Exit();

	return 0;
}
예제 #8
0
int main(int argc, char** argv)
{       

	MODULE *module;

	/* register all the drivers */
	MikMod_RegisterAllDrivers();

	/* register all the module loaders */
	MikMod_RegisterAllLoaders();
	
	/* initialize the library */
	md_mode |= DMODE_SOFT_MUSIC;
	if (MikMod_Init("")) 
	{
		fprintf(stderr, "Could not initialize sound, reason: %s\n",
		MikMod_strerror(MikMod_errno));
		return -1;
	}
        
       
	/* load module */
	module = Player_Load("music.xm", 64, 0);
	printf ("module loaded\n");
	if (module)
	{
		/* start module */
		Player_Start(module);
		while (Player_Active()) 
		{
		        /* we're playing */
			gsKit_vsync_wait();
		}
	
		Player_Stop();
		Player_Free(module);
	} else
	fprintf(stderr, "Could not load module, reason: %s\n",
		MikMod_strerror(MikMod_errno));

	/* give up */
	MikMod_Exit();
	return 0;
}
예제 #9
0
Mix_Chunk *Mix_LoadWAV(char *file)
{
	SAMPLE *sample;
    /* load module */
    sample = Sample_Load(file);
    if (sample) {
		return (Mix_Chunk *) sample;
    }else
	{
        printf("Could not load sample, reason: %s\n", MikMod_strerror(MikMod_errno));
	}
	return NULL;
}
예제 #10
0
Mix_Music *Mix_LoadMUS(const char *file)
{
	MODULE *module;
    /* load module */
    module = Player_Load((char *)(file), 64, 0);
    if (module) {
		return (Mix_Music *) module;
    }else
	{
        printf("Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno));
	}
	return NULL;

}
예제 #11
0
void
load_soundtrack (char *ptr)
{
  if (nosound)
    return;
  dmsg (D_FILE|D_SOUND_TRACK,"loading sound track: %s", ptr);
  module = Player_Load (ptr, 16, 0);
  if (!module) {
    wmsg (_("Could not load %s, reason: %s"), ptr,
	  MikMod_strerror (MikMod_errno));
  } else {
    sound_track_loaded = 1;
  }
}
예제 #12
0
Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
{
	SAMPLE *sample;
   	struct MREADER* reader = _mm_new_rwops_reader (src);
   	if (reader) {
   		sample = Sample_LoadGeneric(reader);
		if(reader) free(reader);
		return (Mix_Music *) sample;
   	}
   	else
	{
        printf("Could not load sample, reason: %s\n", MikMod_strerror(MikMod_errno));
	}
	return NULL;
}
예제 #13
0
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ Initialise
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
void CMikModDriver::Initialise()
{
    MikMod_RegisterAllDrivers();

    MikMod_RegisterAllLoaders();

    if (MikMod_Init(""))
    {
    	unsigned char		errstr[256];
    	char				*err=MikMod_strerror(MikMod_errno);
		errstr[0]=std::strlen(err);
    	
    	BlockMove(err,&errstr[1],errstr[0]);
    	
		ThrowStr_(-1,errstr);
    }

	sInited=true;
}
예제 #14
0
static bool
moda_InitModule (int flags, const TFB_DecoderFormats* fmts)
{
    MikMod_RegisterDriver (&moda_mmout_drv);
    MikMod_RegisterAllLoaders ();

    if (flags & audio_QUALITY_HIGH)
    {
        md_mode = DMODE_HQMIXER|DMODE_STEREO|DMODE_16BITS|DMODE_INTERP|DMODE_SURROUND;
        md_mixfreq = 44100;
        md_reverb = 1;
    }
    else if (flags & audio_QUALITY_LOW)
    {
        md_mode = DMODE_SOFT_MUSIC|DMODE_STEREO|DMODE_16BITS;
#ifdef __SYMBIAN32__
        md_mixfreq = 11025;
#else
        md_mixfreq = 22050;
#endif
        md_reverb = 0;
    }
    else
    {
        md_mode = DMODE_SOFT_MUSIC|DMODE_STEREO|DMODE_16BITS|DMODE_INTERP;
        md_mixfreq = 44100;
        md_reverb = 0;
    }

    md_pansep = 64;

    if (MikMod_Init (""))
    {
        log_add (log_Error, "MikMod_Init() failed, %s",
                 MikMod_strerror (MikMod_errno));
        return false;
    }

    moda_formats = fmts;

    return true;
}
예제 #15
0
/* SDL_RWops compatibility */
Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw)
{
	//Sanity check: only MOD!
	if (detect_music_type(rw) != MUS_MOD){
		printf("Error: format not supported.\n");
		return NULL;
	}
	
	MODULE *module;
   	struct MREADER* reader = _mm_new_rwops_reader (rw);
   	if (reader) {
   		module = Player_LoadGeneric(reader,64,0);
		if(reader) free(reader);
		return (Mix_Music *) module;
   	}
   	else
	{
        printf("Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno));
	}
	return NULL;
}
예제 #16
0
파일: modex.c 프로젝트: andrewoesten/modex
int main(int p_argc, char * p_argv[])
{
	MikMod_RegisterAllLoaders();
//    MikMod_RegisterAllDrivers();
	MikMod_RegisterDriver(&drv_nos);
	
	if(p_argc < 2) {
		usage(p_argv[0]);
		return 1;
	}
	
	if(MikMod_Init("")) {
		printf("MikMod_Init: %s\n", MikMod_strerror(MikMod_errno));
		return 2;
	}
	
	extract(p_argv[1]);
	
	MikMod_Exit();
	
	return 0;
}
예제 #17
0
static qboolean S_MIKMOD_CodecInitialize (void)
{
	if (mikmod_codec.initialized)
		return true;

	/* set mode flags to only we like: */
	md_mode = 0;
	if ((shm->samplebits / 8) == 2)
		md_mode |= DMODE_16BITS;
	if (shm->channels == 2)
		md_mode |= DMODE_STEREO;
	md_mode |= DMODE_SOFT_MUSIC;	/* this is a software-only mixer */
	md_mode |= DMODE_HQMIXER;		/* high-quality mixer is OK */

	/* md_mixfreq is UWORD, so something like 96000 isn't OK */
	md_mixfreq = (shm->speed < 65536)? shm->speed : 48000;

	/* keeping md_device as 0 which is default (auto-detect: we
	 * only register drv_nos, and it will be the only one found.)
	 * md_pansep (stereo channels separation) default 128 is OK.
	 * no reverbation (md_reverb 0 (up to 15)) is OK.
	 * md_musicvolume and md_sndfxvolume defaults are 128: OK. */
	/* just tone down overall volume md_volume from 128 to 96? */
	md_volume = 96;

	MikMod_RegisterDriver(&drv_nos);	/* only need the "nosound" driver, none else */
	MikMod_RegisterAllLoaders();
	if (S_MIKMOD_initlib(NULL))
	{
		Con_DPrintf("Could not initialize MikMod: %s\n", MikMod_strerror(MikMod_errno));
		return false;
	}

	/* this can't get set with drv_nos, but whatever, be safe: */
	md_mode &= ~DMODE_SIMDMIXER;	/* SIMD mixer is buggy when combined with HQMIXER */

	mikmod_codec.initialized = true;
	return true;
}
예제 #18
0
static qboolean S_MIKMOD_CodecOpenStream (snd_stream_t *stream)
{
	mik_priv_t *priv;

	stream->priv = Z_Malloc(sizeof(mik_priv_t));
	priv = (mik_priv_t *) stream->priv;
	priv->reader.Seek = MIK_Seek;
	priv->reader.Tell = MIK_Tell;
	priv->reader.Read = MIK_Read;
	priv->reader.Get  = MIK_Get;
	priv->reader.Eof  = MIK_Eof;
	priv->fh = &stream->fh;

	priv->module = Player_LoadGeneric((MREADER *)stream->priv, 64, 0);
	if (!priv->module)
	{
		Con_DPrintf("Could not load module: %s\n", MikMod_strerror(MikMod_errno));
		Z_Free(stream->priv);
		return false;
	}

	/* keep default values of fadeout (0: don't fade out volume during when last
	 * position of the module is being played), extspd (1: do process Protracker
	 * extended speed effect), panflag (1: do process panning effects), wrap (0:
	 * don't wrap to restart position when module is finished) are OK with us as
	 * set internally by libmikmod::Player_Init(). */
	/* just change the loop setting to 0, i.e. don't process in-module loops: */
	priv->module->loop	= 0;
	Player_Start(priv->module);

	stream->info.rate	= md_mixfreq;
	stream->info.bits	= (md_mode & DMODE_16BITS)? 16: 8;
	stream->info.width	= stream->info.bits / 8;
	stream->info.channels	= (md_mode & DMODE_STEREO)? 2 : 1;
/*	Con_DPrintf("Playing %s (%d chn)\n", priv->module->songname, priv->module->numchn);*/

	return true;
}
예제 #19
0
void init_mikmod(struct config_info *conf)
{
  md_mixfreq = audio.output_frequency;
  md_mode = DMODE_16BITS;
  md_mode |= DMODE_STEREO;
  md_device = 0;
  md_volume = 96;
  md_musicvolume = 128;
  md_sndfxvolume = 128;
  md_pansep = 128;
  md_reverb = 0;
  md_mode |= DMODE_SOFT_MUSIC | DMODE_SURROUND;

  MikMod_RegisterDriver(&drv_nos);

  /* XM and AMF seem to be broken with Mikmod? */

  MikMod_RegisterLoader(&load_gdm);
  //MikMod_RegisterLoader(&load_xm);
  MikMod_RegisterLoader(&load_s3m);
  MikMod_RegisterLoader(&load_mod);
  MikMod_RegisterLoader(&load_med);
  MikMod_RegisterLoader(&load_mtm);
  MikMod_RegisterLoader(&load_stm);
  MikMod_RegisterLoader(&load_it);
  MikMod_RegisterLoader(&load_669);
  MikMod_RegisterLoader(&load_ult);
  MikMod_RegisterLoader(&load_dsm);
  MikMod_RegisterLoader(&load_far);
  MikMod_RegisterLoader(&load_okt);
  //MikMod_RegisterLoader(&load_amf);

  // FIXME: Should break a lot more here
  if(MikMod_Init(NULL))
    fprintf(stderr, "MikMod Init failed: %s", MikMod_strerror(MikMod_errno));
}
예제 #20
0
void SgPlaySound ( char *fullfilename, char *id, bool synchronised )
{
    SAMPLE *sample = NULL;
    char *sampleid = id ? id : fullfilename;

    if ( cache.LookupTree ( sampleid ) ) {

        // Sound sample already loaded into memory - start it playing
		
        sample = cache.GetData ( sampleid );
		
        if ( !sample ) {

            SgDebugPrintf ( "SoundGarden WARNING : Failed to load sound from cache : %s\n", fullfilename );
            cache.RemoveData ( sampleid );
            return;

        }

    }
    else {

        // Load sample and place into cache

        sample = Sample_Load( fullfilename );
        if ( !sample ) {
            SgDebugPrintf ( "SoundGarden WARNING : failed to load sound %s\n (%s)", fullfilename, MikMod_strerror(MikMod_errno) );
            return;
        }

        cache.PutData ( sampleid, sample );

    }
    
    int voice = Sample_Play(sample, 0, SFX_CRITICAL);
    
    Voice_SetVolume(voice,128);
    Voice_SetPanning(voice,PAN_CENTER);
    Voice_SetFrequency(voice,22000);

}
예제 #21
0
int main(void)
{
    /* sound effects */
    SAMPLE *sfx1, *sfx2;
    /* voices */
    int v1, v2;
    int i;

    /* register all the drivers */
    MikMod_RegisterAllDrivers();

    /* initialize the library */
    md_mode |= DMODE_SOFT_SNDFX;
    if (MikMod_Init("")) {
        fprintf(stderr, "Could not initialize sound, reason: %s\n",
                MikMod_strerror(MikMod_errno));
        return 1;
    }

    /* load samples */
    sfx1 = Load("first.wav");
    if (!sfx1) {
        MikMod_Exit();
        fprintf(stderr, "Could not load the first sound, reason: %s\n",
                MikMod_strerror(MikMod_errno));
        return 1;
    }
    sfx2 = Load("second.wav");
    if (!sfx2) {
        Sample_Free(sfx1);
        MikMod_Exit();
        fprintf(stderr, "Could not load the second sound, reason: %s\n",
                MikMod_strerror(MikMod_errno));
        return 1;
    }

    /* reserve 2 voices for sound effects */
    MikMod_SetNumVoices(-1, 2);

    /* get ready to play */
    MikMod_EnableOutput();

    /* play first sample */
    v1 = Sample_Play(sfx1, 0, 0);
    do {
        MikMod_Update();
        MikMod_Sleep(100000);
    } while (!Voice_Stopped(v1));

    for (i = 0; i < 10; i++) {
        MikMod_Update();
        MikMod_Sleep(100000);
    }

    /* half a second later, play second sample */
    v2 = Sample_Play(sfx2, 0, 0);
    do {
        MikMod_Update();
        MikMod_Sleep(100000);
    } while (!Voice_Stopped(v2));

    for (i = 0; i < 10; i++) {
        MikMod_Update();
        MikMod_Sleep(100000);
    }

    MikMod_DisableOutput();

    Sample_Free(sfx2);
    Sample_Free(sfx1);

    MikMod_Exit();

    return 0;
}
예제 #22
0
int main(void)
{
	SceCtrlData pad, lastpad;

	int maxchan = 128;
	BOOL outputEnabled;
	MODULE *mf = NULL;
	SAMPLE *sf = NULL;
	int voice = 0;
	int pan = 127;
	int vol = 127;
	int freq = 22000;

	pspDebugScreenInit();
	SetupCallbacks();

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(1);
	if (!MikMod_InitThreads()) {
		printf("MikMod thread init failed\n");
	}

	MikMod_RegisterErrorHandler(my_error_handler);
	/* register all the drivers */
	MikMod_RegisterAllDrivers();
	/* register all the module loaders */
	MikMod_RegisterAllLoaders();

	/* initialize the library */
	md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC; 
	md_reverb = 0;
	md_pansep = 128;
	if (MikMod_Init("")) {
		printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
		sceKernelExitGame();
		return 0;
	}

	MikMod_SetNumVoices(-1, 8);
	/* get ready to play */
	sf = Sample_Load("ms0:/sound.wav");

	printf("Starting.\n");
	MikMod_EnableOutput();
	outputEnabled = 1;

	if ((mikModThreadID = sceKernelCreateThread("MikMod" ,(void*)&AudioChannelThread,0x12,0x10000,0,NULL)) > 0) {
		sceKernelStartThread(mikModThreadID, 0 , NULL);
	}
	else {
		printf("Play thread create failed!\n");
	}

	sceCtrlReadBufferPositive(&lastpad, 1);
	do {
		sceCtrlReadBufferPositive(&pad, 1);

		if(pad.Buttons != lastpad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				voice = Sample_Play(sf,0,0);
				Voice_SetPanning(voice, pan);
			}

			if(pad.Buttons & PSP_CTRL_SQUARE) {
				outputEnabled = !outputEnabled;
				if(outputEnabled)
					MikMod_EnableOutput();
				else	MikMod_DisableOutput();
			}

			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				mf = Player_Load("ms0:/MUSIC.XM", maxchan, 0);
				if (NULL != mf) {
					mf->wrap = 1;
					Player_Start(mf);
				}
			}

			if(pad.Buttons & PSP_CTRL_TRIANGLE) {
				if (NULL != mf) {
					Player_Stop();
					Player_Free(mf); /* To stop the song for real, it needs to be freed. I know, weird... */
					mf = NULL;
				}
			}

			if(pad.Buttons & PSP_CTRL_SELECT)
				printf("Player is %s\n", Player_Active()?"On":"Off");

			lastpad = pad;
		}

		if(pad.Buttons & PSP_CTRL_LTRIGGER) {
			Voice_SetPanning(voice, (pan<2)?pan:--pan);
			printf("pan is %d\n", pan);
		}

		if(pad.Buttons & PSP_CTRL_RTRIGGER) {
			Voice_SetPanning(voice, (pan>254)?pan:++pan);
			printf("pan is %d\n", pan);
		}

		if(pad.Buttons & PSP_CTRL_UP) {
			Voice_SetVolume(voice, (vol>254)?vol:++vol);
			printf("vol is %d\n", vol);
		}

		if(pad.Buttons & PSP_CTRL_DOWN) {
			Voice_SetVolume(voice, (vol<2)?vol:--vol);
			printf("vol is %d\n", vol);
		}

		if(pad.Buttons & PSP_CTRL_LEFT) {
			Voice_SetFrequency(voice, (freq<1001)?freq:(freq -=1000));
			printf("freq is %d\n", freq);
		}

		if(pad.Buttons & PSP_CTRL_RIGHT) {
			Voice_SetFrequency(voice, (freq>44000)?freq:(freq +=1000));
			printf("freq is %d\n", freq);
		}
		sceDisplayWaitVblankStart();
		
	} while(!((pad.Buttons & PSP_CTRL_START) || done));

	printf("Stopping.\n");

	/* allow audio thread to terminate cleanly */
	done = 1;
	if (mikModThreadID > 0) {
		SceUInt timeout = 100000;
		sceKernelWaitThreadEnd(mikModThreadID, &timeout);
		/* not 100% sure if this is necessary after a clean exit,
		 * but just to make sure any resources are freed: */
		sceKernelDeleteThread(mikModThreadID);
	}
	Player_Stop();
	Player_Free(mf);
	MikMod_Exit();

	sceKernelExitGame();
	return 0;
}
예제 #23
0
/* Initialize the music players with a certain desired audio format */
int open_music(SDL_AudioSpec *mixer)
{
	int music_error;


	music_error = 0;
#ifdef WAV_MUSIC
	if ( WAVStream_Init(mixer) < 0 ) {
		++music_error;
	}
#endif
#ifdef MOD_MUSIC
	/* Set the MikMod music format */
	music_swap8 = 0;
	music_swap16 = 0;
	switch (mixer->format) {

		case AUDIO_U8:
		case AUDIO_S8: {
			if ( mixer->format == AUDIO_S8 ) {
				music_swap8 = 1;
			}
			md_mode = 0;
		}
		break;

		case AUDIO_S16LSB:
		case AUDIO_S16MSB: {
			/* See if we need to correct MikMod mixing */
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
			if ( mixer->format == AUDIO_S16MSB ) {
#else
			if ( mixer->format == AUDIO_S16LSB ) {
#endif
				music_swap16 = 1;
			}
			md_mode = DMODE_16BITS;
		}
		break;

		default: {
			Mix_SetError("Unknown hardware audio format");
			++music_error;
		}
	}
	if ( mixer->channels > 1 ) {
		if ( mixer->channels > 2 ) {
			Mix_SetError("Hardware uses more channels than mixer");
			++music_error;
		}
		md_mode |= DMODE_STEREO;
	}
	md_mixfreq	 = mixer->freq;
	md_device	  = 0;
	md_volume	  = 96;
	md_musicvolume = 128;
	md_sndfxvolume = 128;
	md_pansep	  = 128;
	md_reverb	  = 0;
	MikMod_RegisterAllLoaders();
	MikMod_RegisterAllDrivers();
	if ( MikMod_Init() ) {
		Mix_SetError("%s", MikMod_strerror(MikMod_errno));
		++music_error;
	}
#endif
#ifdef MID_MUSIC
#ifdef USE_TIMIDITY_MIDI
	samplesize = mixer->size / mixer->samples;
	if ( Timidity_Init(mixer->freq, mixer->format,
	                    mixer->channels, mixer->samples) == 0 ) {
		timidity_ok = 1;
	} else {
		timidity_ok = 0;
	}
#endif
#ifdef USE_NATIVE_MIDI
#ifdef USE_TIMIDITY_MIDI
	native_midi_ok = !timidity_ok;
	if ( native_midi_ok )
#endif
		native_midi_ok = native_midi_detect();
#endif
#endif
#ifdef OGG_MUSIC
	if ( OGG_init(mixer) < 0 ) {
		++music_error;
	}
#endif
#ifdef MP3_MUSIC
	/* Keep a copy of the mixer */
	used_mixer = *mixer;
#endif
	music_playing = NULL;
	music_stopped = 0;
	if ( music_error ) {
		return(-1);
	}
	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);

	/* Calculate the number of ms for each callback */
	ms_per_step = (int) (((float)mixer->samples * 1000.0) / mixer->freq);

	return(0);
}

/* Portable case-insensitive string compare function */
int MIX_string_equals(const char *str1, const char *str2)
{
	while ( *str1 && *str2 ) {
		if ( toupper((unsigned char)*str1) !=
		     toupper((unsigned char)*str2) )
			break;
		++str1;
		++str2;
	}
	return (!*str1 && !*str2);
}

/* Load a music file */
Mix_Music *Mix_LoadMUS(const char *file)
{
	char *ext;
	Uint8 magic[5];
	Mix_Music *music;
	SDL_RWops *src; //maks

	/* Figure out what kind of file this is */
	/*fp = fopen(file, "rb"); //maks
	if ( (fp == NULL) || !fread(magic, 4, 1, fp) ) {
		if ( fp != NULL ) {
			fclose(fp);
		}
		Mix_SetError("Couldn't read from '%s'", file);
		return(NULL);
	}
	magic[4] = '\0';
	fclose(fp);*/

	src = SDL_RWFromFile(file, "rb"); //maks
	if ( (src == NULL) || !SDL_RWread(src, magic, 4, 1) ) {
		if ( src != NULL ) {
			SDL_RWclose(src);
		}
		Mix_SetError("Couldn't read from '%s'", file);
		return(NULL);
	}
	magic[4] = '\0';
	SDL_RWclose(src);

	/* Figure out the file extension, so we can determine the type */
	ext = strrchr(file, '.');
	if ( ext ) ++ext; /* skip the dot in the extension */

	/* Allocate memory for the music structure */
	music = (Mix_Music *)malloc(sizeof(Mix_Music));
	if ( music == NULL ) {
		Mix_SetError("Out of memory");
		return(NULL);
	}
	music->error = 0;

#ifdef CMD_MUSIC
	if ( music_cmd ) {
		music->type = MUS_CMD;
		music->data.cmd = MusicCMD_LoadSong(music_cmd, file);
		if ( music->data.cmd == NULL ) {
			music->error = 1;
		}
	} else
#endif
#ifdef WAV_MUSIC
	/* WAVE files have the magic four bytes "RIFF"
	   AIFF files have the magic 12 bytes "FORM" XXXX "AIFF"
	 */
	if ( (ext && MIX_string_equals(ext, "WAV")) ||
	     (strcmp((char *)magic, "RIFF") == 0) ||
	     (strcmp((char *)magic, "FORM") == 0) ) {
		music->type = MUS_WAV;
		music->data.wave = WAVStream_LoadSong(file, (char *)magic);
		if ( music->data.wave == NULL ) {
		  	Mix_SetError("Unable to load WAV file");
			music->error = 1;
		}
	} else
#endif

#ifndef _WIN32_WCE

#ifdef MID_MUSIC
	/* MIDI files have the magic four bytes "MThd" */
	if ( (ext && MIX_string_equals(ext, "MID")) ||
	     (ext && MIX_string_equals(ext, "MIDI")) ||
	     strcmp((char *)magic, "MThd") == 0 ) {
		music->type = MUS_MID;
#ifdef USE_NATIVE_MIDI
  		if ( native_midi_ok ) {
  			music->data.nativemidi = native_midi_loadsong((char *)file);
	  		if ( music->data.nativemidi == NULL ) {
		  		Mix_SetError("%s", native_midi_error());
			  	music->error = 1;
			}
	  	} MIDI_ELSE
#endif
#ifdef USE_TIMIDITY_MIDI
		if ( timidity_ok ) {
			music->data.midi = Timidity_LoadSong((char *)file);
			if ( music->data.midi == NULL ) {
				Mix_SetError("%s", Timidity_Error());
				music->error = 1;
			}
		} else {
			Mix_SetError("%s", Timidity_Error());
			music->error = 1;
		}
#endif
	} else
예제 #24
0
void SgPlayMod ( char *fullfilename )
{
    SgStopMod ();
    
    if ( !currentmod ) {

        currentmod=Player_Load(fullfilename, 16, 0);

        /* didn't work -> exit with errormsg. */

        if(currentmod==NULL){
            SgDebugPrintf("SoundGarden WARNING : Failed to load music file %s\n (%s)\n", fullfilename, MikMod_strerror(MikMod_errno));
            return;
        }

        /*  start playing the module: */
        
        Player_Start(currentmod);
        Player_SetVolume(playerVolume);
        
        SgDebugPrintf ( "SoundGarden Playing Music : %s (%d channels)\n", fullfilename, currentmod->numchn );

    }
}
예제 #25
0
파일: modex.c 프로젝트: andrewoesten/modex
int extract(const char * p_filename)
{
	MODULE * module;
	int i;
	signed short ** s = NULL;
	
 	module = Player_Load(p_filename, 64, 0);
	if (!module) {
		printf("Player_Load: %s\n", MikMod_strerror(MikMod_errno));
		return 1;
	}

	printf("Filename:        %s\n",    p_filename);
	printf("Songname:        %s\n",    module->songname);
	printf("No. of channels: %d\n",    module->numchn);
	printf("No. of insts:    %d\n",    module->numins);
	printf("No. of samps:    %d\n",    module->numsmp);
	
	// Init MikMod Interop
	printf("SampleExIOP:     ");
	
	s = VC1_GetSamples();
	if(!s) {
		s = VC2_GetSamples();
		if(!s) {
			printf("Error\n");
			return 2;
		}
		printf("VC2 (HQ)\n");
	} else {
		printf("VC1 (Default)\n");
	}
	
	printf("Saving Samples ...\n");
	for(i = 0; i < module->numsmp; i++) {
		char fn[256];
		SF_INFO sfi;
		SNDFILE * sf;
				
		if(!module->samples[i].length) continue;
				
		sprintf(fn, "%02d.wav", i);
		
		memset(&sfi, 0, sizeof(SF_INFO));
		sfi.samplerate = 22500;
		sfi.channels = module->samples[i].flags & SF_STEREO ? 2 : 1;
		sfi.format = SF_FORMAT_WAV;
		if(module->samples[i].flags & SF_16BITS) {
			sfi.format |= SF_FORMAT_PCM_16;
		} else {
			sfi.format |= SF_FORMAT_PCM_S8;
		}
		
		sf = sf_open(fn, SFM_WRITE, &sfi);
		
		sf_write_short(sf, s[module->samples[i].handle], (int)module->samples[i].length);
		
		sf_close(sf);
		
		printf("%03d: %-40s (%06d nsmps [* = %p]) | %02d | %c | %s | %s\n", 
			i, 
			module->samples[i].samplename, 
			(int)module->samples[i].length, 
			s[module->samples[i].handle],
			module->samples[i].flags & SF_16BITS     ? 16 : 8,
			module->samples[i].flags & SF_STEREO     ? 'S' : 'M', 
			module->samples[i].flags & SF_BIG_ENDIAN ? "BE" : "LE",
			module->samples[i].flags & SF_LOOP       ? "Loop" : "NoLoop");
		
		/**
		 * Test RAW Output
		 
		int j;
		FILE * f;
		char fn[256];
				
		sprintf(fn, "%02d.raw", i);
		f = fopen(fn, "wb");
		for(j = 0; j < module->samples[i].length; j++) {
			if(module->samples[i].inflags & SF_16BITS) {
				signed short * sss = (signed short *)s[module->samples[i].handle];
				
				if(module->samples[i].inflags & SF_STEREO) {
					fwrite(&sss[j], 2, 1, f);
				} else {
					fwrite(&sss[j], 1, 1, f);
				}
			} else {
				signed char * ssc = (signed char *)s[module->samples[i].handle];
				
				fwrite(&ssc[(j * 2)+1], 1, 1, f);
				if(module->samples[i].inflags & SF_STEREO) {
					j++;
					fwrite(&ssc[(j * 2)+1], 1, 1, f);
				}
			}
		}
		fclose(f);
		 */
		 
		
	}
	
	
	Player_Free(module);
	
	
	return 0;
}
예제 #26
0
UBOOL UOpenALAudioSubsystem::Init()
{
	guard(UOpenALAudioSubsystem::Init);

	INT Rate = GetActualOutputRate();


	// OpenAL / ALURE initialization
	ALCint ContextAttrs[] = { ALC_FREQUENCY, Rate, 0 };
	if( alureInitDevice( NULL, ContextAttrs ) == AL_FALSE )
		appErrorf( TEXT("Couldn't initialize OpenAL: %s"), alureGetErrorString() );

	alDistanceModel( AL_LINEAR_DISTANCE_CLAMPED );
	CheckALErrorFlag( TEXT("alDistanceModel") );

	alDopplerFactor( DopplerFactor );
	CheckALErrorFlag( TEXT("alDopplerFactor") );

	// Metre per second to units per second, where units per meter is 52.5.
	// Taken from: http://wiki.beyondunreal.com/Legacy:General_Scale_And_Dimensions
	alSpeedOfSound( 343.3f * 52.5f );
	CheckALErrorFlag( TEXT("alSpeedOfSound") );

	ALuint* NewSources = new ALuint[NumSources + 1];
	Sources = new FAudioSource[NumSources];
	alGenSources( NumSources + 1, NewSources );
	CheckALErrorFlag( TEXT("alGenSources") );
	MusicSource = NewSources[0];
	for( INT i=0; i<NumSources; i++ )
		Sources[i].Id = NewSources[i+1];
	delete[] NewSources;

	// Fix the music source to 0 values
	alSource3f(	MusicSource, AL_POSITION,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_VELOCITY,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_DIRECTION,			0.f, 0.f, 0.f );
	alSourcef(	MusicSource, AL_ROLLOFF_FACTOR,		0.f );
	alSourcei(	MusicSource, AL_SOURCE_RELATIVE,	AL_TRUE );

	SetVolumes();
	CheckALErrorFlag( TEXT("SetVolumes") );


	// MikMod initialization
	//kipz - remove this because it breaks on new mikmod
	//MikMod_RegisterDriver( &MusicDriver );
	MikMod_RegisterAllDrivers();
	// Register only formats that are known to be supported by UT.
	// Taken from: http://wiki.beyondunreal.com/Music
	MikMod_RegisterLoader( &load_mod );
	MikMod_RegisterLoader( &load_s3m );
	MikMod_RegisterLoader( &load_stm );
	MikMod_RegisterLoader( &load_it  );
	MikMod_RegisterLoader( &load_xm  );
	MikMod_RegisterLoader( &load_far );
	MikMod_RegisterLoader( &load_669 );

	md_mixfreq = Rate;
	if ( HighQualityMusic )
		md_mode |= DMODE_HQMIXER;
	if( MikMod_Init( "" ) )
		appErrorf( TEXT("Couldn't initialize MikMod: %s"), MikMod_strerror( MikMod_errno ) );


	// Initialized!
	USound::Audio = this;
	UMusic::Audio = this;
	Initialized = 1;

	return 1;
	unguard;
}