/** * Toggles the sound on or off. */ void FCEUD_SoundToggle(void) { if (s_mute) { int soundvolume; g_config->getOption("SDL.SoundVolume", &soundvolume); s_mute = 0; FCEUI_SetSoundVolume(soundvolume); FCEU_DispMessage("Sound mute off.", 0); } else { s_mute = 1; FCEUI_SetSoundVolume(0); FCEU_DispMessage("Sound mute on.", 0); } }
void FCEUD_SoundToggle(void) { if(mute) { mute=0; FCEUI_SetSoundVolume(soundvolume); FCEU_DispMessage("Sound mute off."); } else { mute=1; FCEUI_SetSoundVolume(0); FCEU_DispMessage("Sound mute on."); } }
/** * Adjust the volume either down (-1), up (1), or to the default (0). * Unmutes if mute was active before. */ void FCEUD_SoundVolumeAdjust(int n) { int soundvolume; g_config->getOption("SDL.SoundVolume", &soundvolume); switch (n) { case -1: soundvolume -= 10; if (soundvolume < 0) { soundvolume = 0; } break; case 0: soundvolume = 100; break; case 1: soundvolume += 10; if (soundvolume > 150) { soundvolume = 150; } break; } s_mute = 0; FCEUI_SetSoundVolume(soundvolume); g_config->setOption("SDL.SoundVolume", soundvolume); FCEU_DispMessage("Sound volume %d.", soundvolume); }
void FCEUD_SoundVolumeAdjust(int adjust) { switch(adjust) { case -1: soundvolume-=50; if(soundvolume<0) soundvolume=0; break; //lower volume case 0: soundvolume=1024; break; case 1: soundvolume+=50; if(soundvolume>1024) soundvolume=1024; break; //raise volume } FCEUI_SetSoundVolume(soundvolume); FCEU_DispMessage("Sound volume %d.", soundvolume); }
int main(int argc,char *argv[]) { char *t; if(timeBeginPeriod(1)!=TIMERR_NOERROR) { AddLogText("Error setting timer granularity to 1ms.",1); } if(!FCEUI_Initialize()) goto doexito; srand(GetTickCount()); // rand() is used for some GUI sillyness. fceu_hInstance=GetModuleHandle(0); GetBaseDirectory(); sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory); LoadConfig(TempArray); t=ParseArgies(argc,argv); /* Bleh, need to find a better place for this. */ { palyo&=1; FCEUI_SetVidSystem(palyo); genie&=1; FCEUI_SetGameGenie(genie); fullscreen&=1; soundo&=1; FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundquality); } ParseGIInput(NULL); /* Since a game doesn't have to be loaded before the GUI can be used, make sure the temporary input type variables are set. */ CreateDirs(); SetDirs(); DoVideoConfigFix(); DoTimingConfigFix(); if(eoptions&EO_CPALETTE) FCEUI_SetPaletteArray(cpalette); if(!t) fullscreen=0; CreateMainWindow(); if(!InitDInput()) goto doexito; if(!DriverInitialize()) goto doexito; InitSpeedThrottle(); UpdateMenu(); if(t) ALoad(t); else if(eoptions&EO_FOAFTERSTART) LoadNewGamey(hAppWnd, 0); doloopy: UpdateFCEUWindow(); if(GI) { while(GI) { uint8 *gfx; int32 *sound; int32 ssize; FCEUI_Emulate(&gfx, &sound, &ssize, 0); xbsave = gfx; FCEUD_Update(gfx, sound, ssize); } xbsave = NULL; RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE); StopSound(); } Sleep(50); if(!exiting) goto doloopy; doexito: DriverKill(); timeEndPeriod(1); FCEUI_Kill(); return(0); }
int GCMemROM(int method, int size) { ResetGameLoaded(); /*** Allocate and clear GameInfo ***/ FCEUGameInfo = malloc(sizeof(FCEUGI)); memset(FCEUGameInfo, 0, sizeof(FCEUGI)); /*** Set some default values ***/ FCEUGameInfo->soundchan = 1; FCEUGameInfo->soundrate = SAMPLERATE; FCEUGameInfo->name=0; FCEUGameInfo->type=GIT_CART; FCEUGameInfo->vidsys=GIV_USER; FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1; FCEUGameInfo->inputfc=-1; FCEUGameInfo->cspecial=0; /*** Set internal sound information ***/ FCEUI_Sound(SAMPLERATE); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetSoundQuality(0); // 0 - low, 1 - high FCEUI_SetLowPass(0); InitialisePads(); MakeFCEUFile((char *)nesrom, size); nesGameType = 0; if(iNESLoad(NULL, fceufp)) nesGameType = 1; else if(UNIFLoad(NULL,fceufp)) nesGameType = 2; else if(NSFLoad(fceufp)) nesGameType = 3; else { // read FDS BIOS into FDSBIOS - should be 8192 bytes if(FDSBIOS[1] == 0) { int biosSize = 0; char * tmpbuffer = (char *)malloc(64 * 1024); char filepath[1024]; switch (method) { case METHOD_SD: case METHOD_USB: sprintf(filepath, "%s/%s/disksys.rom", ROOTFATDIR, GCSettings.LoadFolder); biosSize = LoadBufferFromFAT(tmpbuffer, filepath, NOTSILENT); break; case METHOD_SMB: sprintf(filepath, "%s/disksys.rom", GCSettings.LoadFolder); biosSize = LoadBufferFromSMB(tmpbuffer, filepath, NOTSILENT); break; } if(biosSize == 8192) { memcpy(FDSBIOS, tmpbuffer, 8192); } else { if(biosSize > 0) WaitPrompt("FDS BIOS file is invalid!"); return 0; // BIOS not loaded, do not load game } free(tmpbuffer); } // load game if(FDSLoad(NULL,fceufp)) nesGameType = 4; } if (nesGameType > 0) { FCEU_ResetVidSys(); PowerNES(); FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. SetSoundVariables(); romLoaded = true; return 1; } else { WaitPrompt("Invalid game file!"); romLoaded = false; return 0; } }
/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq, lowpass, samples; FCEUI_printf("Initializing audio...\n"); g_config->getOption("SDL.Sound", &sound); if (!sound) return 0; memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return(0); } char driverName[8]; SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); g_config->getOption("SDL.Sound.LowPass", &lowpass); spec.freq = soundrate; spec.format = AUDIO_S16; spec.channels = 2; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; while(spec.samples < (soundrate / 60) * 1) spec.samples <<= 1; s_BufferSize = spec.samples * 4; s_Buffer = (int16 *) malloc(sizeof(int16) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; printf("SDL Size: %d, Internal size: %d\n", spec.samples, s_BufferSize); if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return(0); } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); FCEUI_SetLowPass(lowpass); return (1); }
int main() { xenon_make_it_faster(XENON_SPEED_FULL); xenos_init(VIDEO_MODE_AUTO); console_init(); xenon_sound_init(); pAudioStart = pAudioBuffer = (uint16_t*) malloc(48000 * sizeof (uint16_t)); memset(pAudioBuffer, 0, 48000 * sizeof (uint16_t)); usb_init(); usb_do_poll(); SYSVideoInit(); // Allocates and initializes memory. Should only be called once, before // any calls to other FCEU functions. FCEUI_Initialize(); //------------------------------------------------------------------------------------- // Set some setting //------------------------------------------------------------------------------------- // Specifies the base FCE Ultra directory. This should be called // immediately after FCEUI_Initialize() and any time afterwards. std::string base = "uda:/"; //FCEUI_SetBaseDirectory(base); // doesn't work ? newlib bug ? FCEUI_SetVidSystem(0); //Apply settings FCEUI_Sound(48000); FCEUI_SetSoundVolume(50); FCEUI_SetLowPass(0); if (FCEUI_LoadGame("uda:/Super Mario Bros. (Europe) (Rev 0A).zip", 0) != NULL) { FCEUI_SetInput(0, SI_GAMEPAD, (void*) &powerpadbuf, 0); FCEUI_SetInput(1, SI_GAMEPAD, (void*) &powerpadbuf, 0); //set to ntsc extern FCEUGI * GameInfo; GameInfo->vidsys = GIV_NTSC; } int32 * snd = NULL; int32 sndsize; // Copy contents of XBuf over to video memory(or whatever needs to be // done to make the contents of XBuf visible on screen). // Each line is 256 pixels(and bytes) in width, and there can be 240 // lines. The pitch for each line is 272 bytes. // XBuf will be 0 if the symbol FRAMESKIP is defined and this frame // was skipped. uint8 * bitmap; while (1) { FCEUI_Emulate(&bitmap, &snd, &sndsize, 0); for (int i = 0; i < (256 * 240); i++) { //Make an ARGB bitmap nesBitmap[i] = ((pcpalette[bitmap[i]].r) << 16) | ((pcpalette[bitmap[i]].g) << 8) | (pcpalette[bitmap[i]].b) | (0xFF << 24); } SYSVideoUpdate(); // Add Sound update_sound(snd,sndsize); // Add Input update_input(); } return 0; }
int GCMemROM(int size) { bool biosError = false; ResetGameLoaded(); CloseGame(); GameInfo = new FCEUGI(); memset(GameInfo, 0, sizeof(FCEUGI)); GameInfo->filename = strdup(romFilename); GameInfo->archiveCount = 0; /*** Set some default values ***/ GameInfo->name=0; GameInfo->type=GIT_CART; GameInfo->vidsys=(EGIV)GCSettings.timing; GameInfo->input[0]=GameInfo->input[1]=SI_UNSET; GameInfo->inputfc=SIFC_UNSET; GameInfo->cspecial=SIS_NONE; /*** Set internal sound information ***/ SetSampleRate(); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetLowPass(0); FCEUFILE * fceufp = new FCEUFILE(); fceufp->size = size; fceufp->filename = romFilename; fceufp->mode = FCEUFILE::READ; // read only EMUFILE_MEMFILE *fceumem = new EMUFILE_MEMFILE(nesrom, size); fceufp->stream = fceumem; romLoaded = iNESLoad(romFilename, fceufp, 1); if(!romLoaded) { romLoaded = UNIFLoad(romFilename, fceufp); } if(!romLoaded) { romLoaded = NSFLoad(romFilename, fceufp); } if(!romLoaded) { // read FDS BIOS into FDSBIOS - should be 8192 bytes if (FDSBIOS[1] == 0) { size_t biosSize = 0; char * tmpbuffer = (char *) memalign(32, 64 * 1024); char filepath[1024]; sprintf (filepath, "%s%s/disksys.rom", pathPrefix[GCSettings.LoadMethod], APPFOLDER); biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT); if(biosSize == 0 && strlen(appPath) > 0) { sprintf (filepath, "%s/disksys.rom", appPath); biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT); } if (biosSize == 8192) { memcpy(FDSBIOS, tmpbuffer, 8192); } else { biosError = true; if (biosSize > 0) ErrorPrompt("FDS BIOS file is invalid!"); else ErrorPrompt("FDS BIOS file not found!"); } free(tmpbuffer); } if (FDSBIOS[1] != 0) { romLoaded = FDSLoad(romFilename, fceufp); } } delete fceufp; if (romLoaded) { FCEU_ResetVidSys(); if(GameInfo->type!=GIT_NSF) if(FSettings.GameGenie) OpenGameGenie(); PowerNES(); //if(GameInfo->type!=GIT_NSF) // FCEU_LoadGamePalette(); FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. SetupCheats(); ResetAudio(); return 1; } else { delete GameInfo; GameInfo = 0; if(!biosError) ErrorPrompt("Invalid game file!"); romLoaded = false; return 0; } }
/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq; SDL_AudioSpec spec; g_config->getOption("SDL.Sound", &sound); if(!sound) { return 0; } memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return 0; } char driverName[8]; #if SDL_VERSION_ATLEAST(2, 0, 0) // TODO - SDL 2 #else SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); #endif // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); spec.freq = soundrate; spec.format = AUDIO_S16SYS; spec.channels = 1; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; s_BufferSize = soundbufsize * soundrate / 1000; // For safety, set a bare minimum: if (s_BufferSize < spec.samples * 2) s_BufferSize = spec.samples * 2; s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return 0; } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); return 1; }