bool
MusicManager::exists_music(const std::string& file)
{
  if(!audio_device)
    return true;
  
  // song already loaded?
  std::map<std::string, MusicResource>::iterator i = musics.find(file);
  if(i != musics.end()) {
    return true;                                      
  }
  
#ifndef GP2X
  Mix_Music* song = Mix_LoadMUS(file.c_str());
#else
  char mfile[100];
  snprintf(mfile,sizeof(mfile),"%s",file.c_str());
  MODULE *song=Player_Load(mfile, 64, 0);
#endif
        
  if(song == 0)
    return false;

  // insert into music list
  std::pair<std::map<std::string, MusicResource>::iterator, bool> result = 
    musics.insert(
        std::make_pair<std::string, MusicResource> (file, MusicResource()));
  MusicResource& resource = result.first->second;
  resource.manager = this;
  resource.music = song;

  return true;
}
示例#2
0
文件: strm_mod.c 项目: bavoha/soundy
/*-------------------------------------------------------------------------------------
// -
//-------------------------------------------------------------------------------------*/
void* SDYSTRMAPI MOD_Open(const char *szFile, SDY_WFX *pWfx, SDY_IO *pIO, sdyDword dwReserved)
{
	void* pMod;
	
	if(!g_MikMod)
		if(MOD_Init() != 0)
			return sdyNull;
	
	pMod = Player_Load((char*)szFile, 32, 0);
	if(!pMod)
		return sdyNull;
	
	Player_Start(pMod);
	
	if(pWfx)
	{
		pWfx->wFormatTag		= 1;
		pWfx->nChannels 		= (md_mode & DMODE_STEREO) ? 2 : 1;
		pWfx->nSamplesPerSec	= md_mixfreq;
		pWfx->nAvgBytesPerSec	= md_mixfreq * ( (md_mode & DMODE_STEREO) ? 2 : 1 ) * ( (md_mode & DMODE_16BITS) ? 2 : 1 );
		pWfx->nBlockAlign		= ( (md_mode & DMODE_16BITS) ? 2 : 1 ) * ( (md_mode & DMODE_STEREO) ? 2 : 1 );
		pWfx->wBitsPerSample	= (md_mode & DMODE_16BITS) ? 16 : 8;
		pWfx->cbSize			= 0;
	}
	
	g_nRefs++;
	
	return pMod;
}
示例#3
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;

}
示例#4
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;
  }
}
示例#5
0
static mod_Data * mod_open(char * path) {
	MODULE * moduleHandle;
	mod_Data * data;

	if(!(moduleHandle = Player_Load(path, 128, 0))) return NULL;

	data = malloc(sizeof(mod_Data));

	data->audio_buffer = malloc(MIKMOD_FRAME_SIZE);
	data->moduleHandle = moduleHandle;

	Player_Start(data->moduleHandle);

	return data;
}
示例#6
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;
}
示例#7
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;
}
示例#8
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;
}
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 );

    }
}
示例#10
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;
}
示例#11
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;
}
示例#12
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;
}