Ejemplo n.º 1
0
BOOL MikMod_Reset(void)

/* Reset the driver using the new global variable settings. */
/* If the driver has not been initialized, it will be now. */

{
    if(!initialized) return MikMod_Init();
    if((md_driver->Reset == NULL) || (md_device != idevice))
    {   /* md_driver->Reset was NULL, or md_device was changed, */
        /* so do a full reset of the driver. */

        if(isplaying) md_driver->PlayStop();
        md_driver->Exit();
        if(MikMod_Init())
        {   MikMod_Exit();
            if(_mm_errorhandler!=NULL) _mm_errorhandler();
            return 1;
        }
        if(isplaying) md_driver->PlayStart();
    } else
    {   if(md_driver->Reset())
        {   MikMod_Exit();
            if(_mm_errorhandler!=NULL) _mm_errorhandler();
            return 1;
        }
    }

    return 0;
}
Ejemplo n.º 2
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");
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
static void
gst_mikmod_loop (GstElement * element)
{
  GstMikMod *mikmod;
  GstBuffer *buffer_in;

  g_return_if_fail (element != NULL);
  g_return_if_fail (GST_IS_MIKMOD (element));

  mikmod = GST_MIKMOD (element);
  srcpad = mikmod->srcpad;
  mikmod->Buffer = NULL;

  if (!mikmod->initialized) {
    while ((buffer_in = GST_BUFFER (gst_pad_pull (mikmod->sinkpad)))) {
      if (GST_IS_EVENT (buffer_in)) {
        GstEvent *event = GST_EVENT (buffer_in);

        if (GST_EVENT_TYPE (event) == GST_EVENT_EOS)
          break;
      } else {
        if (mikmod->Buffer) {
          mikmod->Buffer = gst_buffer_append (mikmod->Buffer, buffer_in);
        } else {
          mikmod->Buffer = buffer_in;
        }
      }
    }

    if (!GST_PAD_CAPS (mikmod->srcpad)) {
      if (GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (mikmod->srcpad))) {
        GST_ELEMENT_ERROR (mikmod, CORE, NEGOTIATION, (NULL), (NULL));
        return;
      }
    }

    MikMod_RegisterDriver (&drv_gst);
    MikMod_RegisterAllLoaders ();

    MikMod_Init ("");
    reader = GST_READER_new (mikmod);
    module = Player_LoadGeneric (reader, 64, 0);

    gst_buffer_unref (mikmod->Buffer);

    if (!Player_Active ())
      Player_Start (module);

    mikmod->initialized = TRUE;
  }

  if (Player_Active ()) {
    timestamp = (module->sngtime / 1024.0) * GST_SECOND;
    drv_gst.Update ();
  } else {
    gst_element_set_eos (GST_ELEMENT (mikmod));
    gst_pad_push (mikmod->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
  }
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    MikMod_RegisterAllDrivers();
    MikMod_Init("");

    MikMod_Exit();
    return 0;
}
Ejemplo n.º 8
0
/*-------------------------------------------------------------------------------------
// sdyMOD_Init - Initialize MikMod
// 
//	Called only from inside sdyMOD_Open() - see below.
//-------------------------------------------------------------------------------------*/
static int MOD_Init(void)
{
	MikMod_RegisterDriver(&drv_sdy);
	MikMod_RegisterAllLoaders();
	md_mixfreq = 44100;
	//md_mode |= DMODE_SOFT_MUSIC;
	md_mode |= DMODE_INTERP | DMODE_STEREO | DMODE_SURROUND;
	//md_reverb = 1;
	if(MikMod_Init("")) return -1;
	g_MikMod = TRUE;
	atexit(MikMod_Exit);
	return 0;
}
Ejemplo n.º 9
0
int main() {
  int i=0, x, y, t;
  const int COLOURS_LEN = sizeof(COLOURS) / sizeof(int);
  const int FLAG_LEN    = sizeof(FLAG)    / sizeof(char) - 1;

  // Extract module song payload
  char fname[] = "/tmp/file-XXXXXX";
  int fd = mkstemp(fname);
  if (write(fd, src_music_xm, src_music_xm_len) < 0)
    return -1;
  lseek(fd, 0, SEEK_SET);
  FILE *pFile = fdopen(fd, "rb");

  // Load and play the module song
  MODULE *module;
  MikMod_RegisterAllDrivers();
  MikMod_RegisterAllLoaders();
  md_mode |= DMODE_SOFT_MUSIC;
  MikMod_Init("");
  module = Player_LoadFP(pFile, 64, 0);
  module->wrap = 1;
  Player_Start(module);

  // Animation
  while (1) {
    MikMod_Update();
    for (y = 0; y < COLOURS_LEN; y++) { // line loop
      printf("\x1b[1;%dm", COLOURS[y]); // set rainbow line colour
      for (x = 0; x < WIDTH - ANGLE*(COLOURS_LEN-y); x++) // rainbow line
        putchar(FLAG[(x + (FLAG_LEN-y)+i) % FLAG_LEN]); // print rainbow character
      printf("\x1b[0m"); // clear colour
      for (t = ANGLE; t < ANGLE * (COLOURS_LEN-y); t++) // print distance holder
        putchar(' ');
      printf("\x1b[1m"); // set bright color for cat
      puts(CAT[y%COLOURS_LEN + (i%10<COLOURS_LEN ? 0 : COLOURS_LEN)]); // cat
    }

    if (_kbhit()) // key pressed?
      break;

    i++;
    usleep(DELAY); // wait x ms
    printf("\x1b[%dA", COLOURS_LEN); // move up before loop
  }

  puts("\x1b[0m"); // reset colours
  Player_Stop();
  Player_Free(module);
  MikMod_Exit();
  return 0;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
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));
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
OSL_SOUND *oslLoadSoundFileMOD(const char *filename, int stream)		{
    OSL_SOUND *s;
    UNIMOD *mf;

    if (!osl_modInitialized)		{
//		_mm_RegisterErrorHandler(my_error_handler);
        MikMod_RegisterAllLoaders();
        MikMod_RegisterDriver(drv_psp);

        //md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_MUSIC;
        MikMod_Init();

        osl_modInitialized = 1;
    }

    s = (OSL_SOUND*)malloc(sizeof(OSL_SOUND));
    if (s)			{
        //Never forget that! If any member is added to OSL_SOUND, it is assumed to be zero!
        memset(s, 0, sizeof(OSL_SOUND));
        mf = MikMod_LoadSong((char*)filename, 128);
        if (mf)		{
            s->data = (void*)mf;

            s->endCallback = NULL;
            s->volumeLeft = s->volumeRight = OSL_VOLUME_MAX;
            //No special format
            s->format = 0;
            //Always stereo output
            s->mono = 0;
            s->divider = OSL_FMT_44K;
            //MOD files are never streamed
            s->isStreamed = 0;
            //Use the default value
            s->numSamples = 0;

            /*	if (wav->fmt.sample_rate >= 44100)
            		s->divider = OSL_FMT_44K;
            	else if (wav->fmt.sample_rate >= 22050)
            		s->divider = OSL_FMT_22K;
            	else
            		s->divider = OSL_FMT_11K;*/

            s->audioCallback = oslAudioCallback_AudioCallback_MOD;
            s->playSound = oslAudioCallback_PlaySound_MOD;
            s->stopSound = oslAudioCallback_StopSound_MOD;
            s->standBySound = oslAudioCallback_StandBy_MOD;
            s->reactiveSound = oslAudioCallback_ReactiveSound_MOD;
            s->deleteSound = oslAudioCallback_DeleteSound_MOD;
        }
        else		{
            free(s);
            s = NULL;
        }
    }

    if (!s)
    {
        //oslHandleLoadNoFailError(filename);
    }
    return s;

    /*	VirtualFileRead(&bfh, sizeof(bfh), 1, f);
    	//Vérifie l'en-tête
    	if (strcmp(bfh.strVersion, "OSLBGM v01"))		{
    		free(s);
    		VirtualFileClose(f);
    		return NULL;
    	}
    	if (bfh.format == 1)		{
    		//Pour l'adpcm, dataplus contient la structure définissant les données
    		ad = (OSL_ADGlobals*)malloc(sizeof(OSL_ADGlobals));
    		if (!ad)		{
    			free(s);
    			VirtualFileClose(f);
    			return NULL;
    		}
    		s->dataplus = ad;
    	}
    	debut = VirtualFileTell(f);
    	s->baseoffset = debut;
    	VirtualFileSeek(f, 0, SEEK_END);
    	fin = VirtualFileTell(f);
    	if (fin-debut <= 0)			{
    		free(s);
    		if (ad)	free(ad);
    		VirtualFileClose(f);
    		return NULL;
    	}
    	VirtualFileSeek(f, 0, SEEK_SET);
    	s->isStreamed = stream;
    	if (s->isStreamed)			{
    		if (strlen(filename) >= sizeof(s->filename))
    			oslFatalError("Sound file name too long!");
    		strcpy(s->filename, filename);
    		s->suspendNumber = osl_suspendNumber;
    		s->data = (void*)f;
    	}
    	else		{
    		s->data = malloc(fin-debut);
    		if (!s->data)		{
    			free(s);
    			if (ad)	free(ad);
    			VirtualFileClose(f);
    			return NULL;
    		}
    		VirtualFileRead(s->data, fin-debut, 1, f);
    		VirtualFileClose(f);
    	}
    	s->endCallback = NULL;
    	s->format = bfh.format;
    	if (bfh.sampleRate == 44100)
    		s->divider = OSL_FMT_44K;
    	else if (bfh.sampleRate == 22050)
    		s->divider = OSL_FMT_22K;
    	else if (bfh.sampleRate == 11025)
    		s->divider = OSL_FMT_11K;
    	s->size = fin-debut;
    //	if (bfh.format & OSL_FMT_STEREO)
    //		s->mono = 0;				//OSL_AUDIO_FORMAT_STEREO
    //	else
    		s->mono = 0x10;				//OSL_AUDIO_FORMAT_MONO
    	s->volumeLeft = s->volumeRight = OSL_VOLUME_MAX;

    	s->audioCallback = oslAudioCallback_AudioCallback_BGM;
    	s->playSound = oslAudioCallback_PlaySound_BGM;
    	s->standBySound = oslAudioCallback_StandBy_BGM;
    	s->reactiveSound = oslAudioCallback_ReactiveSound_BGM;
    	s->deleteSound = oslAudioCallback_DeleteSound_BGM;

    	return s;*/
}
Ejemplo n.º 18
0
void MikModClass_Init()
{
	MikMod_Init(NULL);
	MikMod_RegisterAllLoaders();
	NodeRegisterClass(&MikMod);
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
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
Ejemplo n.º 21
0
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize audio and video */
    audio_init(44100,2);
    console_init();

    /* Initialize key detection */
    controller_init();

    MikMod_RegisterAllDrivers();
    MikMod_RegisterAllLoaders();

    md_mode |= DMODE_16BITS;
    md_mode |= DMODE_SOFT_MUSIC;
    md_mode |= DMODE_SOFT_SNDFX;
    //md_mode |= DMODE_STEREO;
                                            
    md_mixfreq = audio_get_frequency();

    MikMod_Init("");

    if(dfs_init( DFS_DEFAULT_LOCATION ) != DFS_ESUCCESS)
    {
        printf("Filesystem failed to start!\n");
    }
    else
    {
        direntry_t *list;
        int count = 0;
        int page = 0;
        int cursor = 0; 

        console_set_render_mode(RENDER_MANUAL);
        console_clear();

        list = populate_dir(&count);

        while(1)
        {
            console_clear();
            display_dir(list, cursor, page, MAX_LIST, count);
            console_render();

            controller_scan();
            struct controller_data keys = get_keys_down();

            if(keys.c[0].up)
            {
                cursor--;
                new_scroll_pos(&cursor, &page, MAX_LIST, count);
            }

            if(keys.c[0].down)
            {
                cursor++;
                new_scroll_pos(&cursor, &page, MAX_LIST, count);
            }

            if(keys.c[0].C_right && list[cursor].type == DT_REG)
            {
                /* Module playing loop */
                MODULE *module = NULL;

                /* Concatenate to make file */
                char path[512];

                strcpy( path, dir );
                strcat( path, list[cursor].filename );

                module = Player_Load(path, 256, 0);
                
                /* Ensure that first part of module doesn't get cut off */
                audio_write_silence();
                audio_write_silence();

                if(module)
                {
                    char c = '-';
                    int sw = 0;

                    Player_Start(module);

                    while(1)
                    {
                        if(sw == 5)
                        {
                            console_clear();
                            display_dir(list, cursor, page, MAX_LIST, count);

                            sw = 0;
                            switch(c)
                            {
                                case '-':
                                    c = '\\';
                                    break;
                                case '\\':
                                    c = '|';
                                    break;
                                case '|':
                                    c = '/';
                                    break;
                                case '/':
                                    c = '-';
                                    break;
                            }
    
                            printf("\n\n\n%c Playing module", c);                        
                            console_render();
                        }
                        else
                        {
                            sw++;
                        }

                        MikMod_Update();

                        controller_scan();
                        struct controller_data keys = get_keys_down();

                        if(keys.c[0].C_left || !Player_Active())
                        {
                            /* End playback */
                            audio_write_silence();
                            audio_write_silence();
                            audio_write_silence();
                            audio_write_silence();

                            break;
                        }
                    }
                
                    Player_Stop();
                    Player_Free(module);
                }
            }

            if(keys.c[0].L)
            {
                /* Open the SD card */
                strcpy( dir, "sd://" );

                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].R)
            {
                /* Open the ROM FS card */
                strcpy( dir, "rom://" );

                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].A && list[cursor].type == DT_DIR)
            {
                /* Change directories */
                chdir(list[cursor].filename);
       
                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].B)
            {
                /* Up! */
                chdir("..");
       
                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }
        }
    }

    while(1);

    return 0;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
/**
**  Load MikMod.
**
**  @param name   Filename of the module.
**  @param flags  Unused.
**
**  @return       Returns the loaded sample.
*/
CSample *LoadMikMod(const char *name, int flags)
{
	CSample *sample;
	MikModData *data;
	MODULE *module;
	CFile *f;
	char s[256];
	static int registered = 0;

	md_mode |= DMODE_STEREO | DMODE_INTERP | DMODE_SURROUND | DMODE_HQMIXER;
	MikMod_RegisterDriver(&drv_nos);
	if (!registered) {
		MikMod_RegisterAllLoaders();
		registered = 1;
	}

	strcpy_s(s, sizeof(s), name);
	f = new CFile;
	if (f->open(name, CL_OPEN_READ) == -1) {
		delete f;
		return NULL;
	}
	CurrentFile = f;

	MikMod_Init("");
	module = Player_LoadGeneric(&MReader, 64, 0);
	if (!module) {
		MikMod_Exit();
		f->close();
		delete f;
		return NULL;
	}

	if (flags & PlayAudioStream) {
		sample = new CSampleMikModStream;
		data = &((CSampleMikModStream *)sample)->Data;
	} else {
		sample = new CSampleMikMod;
		data = &((CSampleMikMod *)sample)->Data;
	}
	data->MikModFile = f;
	data->MikModModule = module;
	sample->Channels = 2;
	sample->SampleSize = 16;
	sample->Frequency = 44100;
	sample->Pos = 0;

	if (flags & PlayAudioStream) {
		sample->Len = 0;
		sample->Buffer = new unsigned char[SOUND_BUFFER_SIZE];

		Player_Start(data->MikModModule);
	} else {
		int read;
		int pos;

		// FIXME: need to find the correct length
		sample->Len = 55000000;
		sample->Buffer = new unsigned char[sample->Len];

		pos = 0;
		Player_Start(data->MikModModule);
		while (Player_Active()) {
			read = VC_WriteBytes((SBYTE *)sample->Buffer + pos,
				 sample->Len - pos);
			pos += read;
		}

		Player_Stop();
		Player_Free(data->MikModModule);
		MikMod_Exit();

		data->MikModFile->close();
		delete data->MikModFile;
	}

	return sample;
}