Example #1
0
static void S_MIKMOD_CodecCloseStream (snd_stream_t *stream)
{
	Player_Stop();
	Player_Free(((mik_priv_t *)stream->priv)->module);
	Z_Free(stream->priv);
	S_CodecUtilClose(&stream);
}
Example #2
0
void Mix_FreeMusic(Mix_Music *music)
{
	Player_Stop(); //Just in case!
	MODULE *module; //Casting needed
	module = (MODULE *)music;
	
    Player_Free(module);
}
void SgStopMod ()
{
    if (currentmod) {
        Player_Stop();              /* stop playing */
        Player_Free(currentmod);   /* and free the module */
        currentmod = NULL;
    }
}
Example #4
0
static void
moda_Close (THIS_PTR)
{
    TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This;

    if (moda->module)
    {
        Player_Free (moda->module);
        moda->module = NULL;
    }
}
Example #5
0
/**
**  Type member function to free sample
*/
CSampleMikModStream::~CSampleMikModStream()
{
	CurrentFile = this->Data.MikModFile;

	Player_Stop();
	Player_Free(this->Data.MikModModule);
	MikMod_Exit();
	this->Data.MikModFile->close();
	delete this->Data.MikModFile;
	delete[] this->Buffer;
}
Example #6
0
static int l_MusicRelease(lua_State * lState)
{
	Music ** music = toMusic(lState, 1);
	if(*music)
	{
		l_MusicStop(lState);
		Player_Free(*music);
		*music = NULL;
	}

	return 0;
}
Example #7
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;
}
Example #8
0
void UOpenALAudioSubsystem::UnregisterMusic( UMusic* Music )
{
	guard(UOpenALAudioSubsystem::UnregisterMusic);

	check(Music);
	if( Music->Handle )
	{
		debugf( NAME_DevMusic, TEXT("Unregister music: %s"), Music->GetFullName() );

		MODULE* Module = (MODULE*)Music->Handle;
		Player_Free( Module );
	}

	unguard;
}
Example #9
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;
}
Example #10
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;
}
Example #11
0
/*-------------------------------------------------------------------------------------
// -
//-------------------------------------------------------------------------------------*/
sdyBool SDYSTRMAPI MOD_Close(void	*pMOD)
{
	if(!pMOD) return sdyFalse;
	
	Player_Stop();
	Player_Free(pMOD);
	
	g_nRefs--;
	
/*	if(g_nRefs <= 0)
	{
		MikMod_Exit();
		g_MikMod = sdyFalse;
		g_nRefs = 0;
	}*/
	
	//if(pMOD->pFile)
	//	pMOD->sdyIO.close_func(pMOD->pFile);
	
	return sdyTrue;
}
Example #12
0
MpdTag * modTagDup(char * file) {
	MpdTag * ret = NULL;
	MODULE * moduleHandle;
	char * title;

	if(mod_initMikMod() < 0) return NULL;

	if(!(moduleHandle = Player_Load(file, 128, 0))) goto fail;

	Player_Free(moduleHandle);

	ret = newMpdTag();

	ret->time = 0;
 	title = strdup(Player_LoadTitle(file));
 	if(title) addItemToMpdTag(ret, TAG_ITEM_TITLE, title);

fail:
	MikMod_Exit();

	return ret;
}
Example #13
0
void
unload_soundtrack (void)
{
  if (nosound)
    return;
  if (sound_track_playing) {
    dmsg (D_SOUND_TRACK, "joining playing thread");
    pthread_mutex_unlock (&playing);
    pthread_join (polling_thread, 0);
    Player_Stop ();
    sound_track_playing = 0;
  }
  if (sound_track_loaded) {
    dmsg (D_SOUND_TRACK, "unloading sound track");
    Player_Free (module);
    module = 0;
    soundtrack_title = 0;
    soundtrack_author = 0;
    FREE_SPRITE0 (soundtrack_title_sprite);
    FREE_SPRITE0 (soundtrack_author_sprite);
    sound_track_loaded = 0;
  }
}
Example #14
0
static void mod_close(mod_Data * data) {
	Player_Stop();
	Player_Free(data->moduleHandle);
	free(data->audio_buffer);
	free(data);
}
Example #15
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;
}
Example #16
0
static void mm_destruct(struct audio_stream *a_src)
{
  Player_Stop();
  Player_Free(((struct mikmod_stream *)a_src)->module_data);
  sampled_destruct(a_src);
}
Example #17
0
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;
}
Example #18
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;
}
Example #19
0
/* Loads a module given an reader */
MODULE* Player_LoadGeneric_internal(MREADER *reader,int maxchan,BOOL curious)
{
	int t;
	MLOADER *l;
	BOOL ok;
	MODULE *mf;

	modreader = reader;
	_mm_errno = 0;
	_mm_critical = 0;
	_mm_iobase_setcur(modreader);

	/* Try to find a loader that recognizes the module */
	for(l=firstloader;l;l=l->next) {
		_mm_rewind(modreader);
		if(l->Test()) break;
	}

	if(!l) {
		_mm_errno = MMERR_NOT_A_MODULE;
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	/* init unitrk routines */
	if(!UniInit()) {
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	/* load the song using the song's loader variable */
	memset(&of,0,sizeof(MODULE));
	of.initvolume = 128;

	/* init panning array */
	for(t=0; t<64; t++) of.panning[t] = ((t+1)&2) ? 255 : 0;
	for(t=0; t<64; t++) of.chanvol[t] = 64;

	/* init module loader and load the header / patterns */
	if(l->Init()) {
		_mm_rewind(modreader);
		ok = l->Load(curious);
	} else
		ok = 0;

	/* free loader and unitrk allocations */
	l->Cleanup();
	UniCleanup();

	if(!ok) {
		ML_FreeEx(&of);
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	if(!ML_LoadSamples()) {
		ML_FreeEx(&of);
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	if(!(mf=ML_AllocUniMod())) {
		ML_FreeEx(&of);
		_mm_rewind(modreader);_mm_iobase_revert();
		if(_mm_errorhandler) _mm_errorhandler();
		return NULL;
	}

	/* Copy the static MODULE contents into the dynamic MODULE struct. */
	memcpy(mf,&of,sizeof(MODULE));
	_mm_iobase_revert();

	if(maxchan>0) {
		if(!(mf->flags&UF_NNA)&&(mf->numchn<maxchan))
			maxchan = mf->numchn;
		else
		  if((mf->numvoices)&&(mf->numvoices<maxchan))
			maxchan = mf->numvoices;

		if(maxchan<mf->numchn) mf->flags |= UF_NNA;

		if(MikMod_SetNumVoices_internal(maxchan,-1)) {
			Player_Free(mf);
			return NULL;
		}
	}
	if(SL_LoadSamples()) {
		Player_Free_internal(mf);
		return NULL;
	}
	if(Player_Init(mf)) {
		Player_Free_internal(mf);
		mf=NULL;
	}
	return mf;
}
Example #20
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;
}
Example #21
0
/* Loads a module given an reader */
MODULE* Player_LoadGeneric_internal(MREADER *reader,int maxchan,BOOL curious)
{
	int t;
	MLOADER *l;
	BOOL ok;
	MODULE *mf;

	modreader = reader;
	_mm_errno = 0;
	_mm_critical = 0;
	_mm_iobase_setcur(modreader);

	/* Try to find a loader that recognizes the module */
	for(l=firstloader;l;l=l->next) {
		_mm_rewind(modreader);
		if(l->Test()) break;
	}

	if(!l) {
		_mm_errno = MMERR_NOT_A_MODULE;
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	/* init unitrk routines */
	if(!UniInit()) {
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	/* init the module structure with vanilla settings */
	memset(&of,0,sizeof(MODULE));
	of.bpmlimit = 33;
	of.initvolume = 128;
	for (t = 0; t < UF_MAXCHAN; t++) of.chanvol[t] = 64;
	for (t = 0; t < UF_MAXCHAN; t++)
		of.panning[t] = ((t + 1) & 2) ? PAN_RIGHT : PAN_LEFT;

	/* init module loader and load the header / patterns */
	if (!l->Init || l->Init()) {
		_mm_rewind(modreader);
		ok = l->Load(curious);
		/* propagate inflags=flags for in-module samples */
		for (t = 0; t < of.numsmp; t++)
			if (of.samples[t].inflags == 0)
				of.samples[t].inflags = of.samples[t].flags;
	} else
		ok = 0;

	/* free loader and unitrk allocations */
	if (l->Cleanup) l->Cleanup();
	UniCleanup();

	if(!ok) {
		ML_FreeEx(&of);
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	if(!ML_LoadSamples()) {
		ML_FreeEx(&of);
		if(_mm_errorhandler) _mm_errorhandler();
		_mm_rewind(modreader);_mm_iobase_revert();
		return NULL;
	}

	if(!(mf=ML_AllocUniMod())) {
		ML_FreeEx(&of);
		_mm_rewind(modreader);_mm_iobase_revert();
		if(_mm_errorhandler) _mm_errorhandler();
		return NULL;
	}
	
	/* If the module doesn't have any specific panning, create a
	   MOD-like panning, with the channels half-separated. */
	if (!(of.flags & UF_PANNING))
		for (t = 0; t < of.numchn; t++)
			of.panning[t] = ((t + 1) & 2) ? PAN_HALFRIGHT : PAN_HALFLEFT;

	/* Copy the static MODULE contents into the dynamic MODULE struct. */
	memcpy(mf,&of,sizeof(MODULE));

	if(maxchan>0) {
		if(!(mf->flags&UF_NNA)&&(mf->numchn<maxchan))
			maxchan = mf->numchn;
		else
		  if((mf->numvoices)&&(mf->numvoices<maxchan))
			maxchan = mf->numvoices;

		if(maxchan<mf->numchn) mf->flags |= UF_NNA;

		if(MikMod_SetNumVoices_internal(maxchan,-1)) {
			_mm_iobase_revert();
			Player_Free(mf);
			return NULL;
		}
	}
	if(SL_LoadSamples()) {
		_mm_iobase_revert();
		Player_Free_internal(mf);
		return NULL;
	}
	if(Player_Init(mf)) {
		_mm_iobase_revert();
		Player_Free_internal(mf);
		mf=NULL;
	}
	_mm_iobase_revert();
	return mf;
}
Example #22
0
void Player_Create( ) {
    if( player ) {
        Player_Free( );
        Memory_Free( player );        
    }
    
    player = Memory_New( TPlayer );
    // create main pivot
    player->pivot = Entity_Create( );
	
	// create camera
    player->cameraPivot = Entity_Create();
    Entity_MakeCamera( player->cameraPivot );
    Entity_Attach( player->cameraPivot, player->pivot );
    player->cameraPivot->localPosition = Vec3_Set( 0, 0.4, 0 );

    // add physical body
    Shape_CreateSphere( &player->shape, 1.0f );
    Body_Create( &player->body, &player->shape );
    Dynamics_AddBody( &player->body );

    player->body.position.y = 10;
    player->body.elasticity = 0.05f;

    player->cameraOffset = Vec3_Set( 0, 0.4, 0 );
    player->cameraShakeOffset = Vec3_Zero();    
    player->velocity = Vec3_Zero();
    player->destVelocity = Vec3_Zero(); 
    
    // set parameters
    player->speed = 4.5f;
    player->speedMultiplier = 1.8f;
    player->jumpStrength = 0.1f;
    player->mouseSensivity = 0.2f;
    player->yaw = 0.0f;
    player->pitch = 0.0f;
    player->maxPitch = M_PI / 2.0;
    player->pathLength = 0.0f;
    player->crouchRadius = 0.5f;
    player->standRadius = 1.0f;
    player->crouch = false;
    player->move = false;
    player->run = false;
    player->onGround = false;
	player->cameraShakeCoeff = 0.0f;
    
    
    // ==================
    // step sounds
    Player_SetSoundGroup( "data/sounds/dirt", STEP_SOIL, "data/materials/soil.mtl" );
    Player_SetSoundGroup( "data/sounds/stonestep", STEP_ROCK, "data/materials/stone.mtl" );
    Player_SetSoundGroup( "data/sounds/wood", STEP_WOOD, "data/materials/wood.mtl" );
    Player_SetSoundGroup( "data/sounds/metal", STEP_METAL, "data/materials/metal.mtl" );
    // set default step sounds
    player->stepSoundGroup = &player->stepSounds[STEP_SOIL];

	player->weapon = Weapon_Create( WEAPON_BLASTER );
	Entity_Attach( player->weapon->model, player->cameraPivot );
    
    player->interface.font = Font_LoadFromFile( "data/fonts/font3.ttf", 16 );
    player->interface.ammo = GUI_CreateText( Renderer_GetScreenResolutionWidth() - 200, Renderer_GetScreenResolutionHeight() - 200, 190, 190, "Ammo:\n", player->interface.font );
}