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");
}
Beispiel #2
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;
}
Beispiel #3
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)));
  }
}
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
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;
}
Beispiel #7
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;
}
Beispiel #8
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));
}
Beispiel #9
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;
}
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;*/
}
Beispiel #11
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
	MikMod_RegisterDriver( &MusicDriver );

	// 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;
}