예제 #1
0
파일: main.c 프로젝트: Frozenhorns/project
int		main(int ac, char **av, char *envp[])
{
  t_vm	*vm;
  func	*instruct;

  if (ac == 1)
    return (my_printf("Usage: ./corewar[option] [option]champ.cor ...\n"));
  srand(time(NULL));
  if ((vm = create_struct_vm(ac, av)) != NULL)
    {
      instruct = get_ptr_func();
      if (envp[0] != NULL)
	{
	  if ((vm->image = init_image()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization pictures failed.\n"));
	  if ((vm->sound = init_sound()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization sounds failed.\n"));
	}
      vm->no_graph = rendering(vm);
      battle_ground(vm, instruct);
      if (vm->winner != NULL)
	return (my_printf("Le joueur %s(%d) a gagné.\n", vm->winner->prog_name,
			  vm->winner->data[ID]));
    }
  return (EXIT_SUCCESS);
}
예제 #2
0
void retro_init(void)
{
   init_gamepak_buffer();
   init_sound();
#ifdef HW_RENDER_TEST
   init_video_ge();
#endif
}
예제 #3
0
ROM_END


/*******************************************************************************************/

static DRIVER_INIT( marvins )
{
	init_sound( 0x40 );
	snk_gamegroup = 0;
}
예제 #4
0
ROM_END

/*******************************************************************************************/



static void init_marvins(void)
{
	init_sound( 0x40 );
}
예제 #5
0
void AgiEngine::initialize() {
	memset(&opt, 0, sizeof(struct agi_options));
	opt.gamerun = GAMERUN_RUNGAME;
	opt.hires = true;

	// TODO: Some sound emulation modes do not fit our current music
	//       drivers, and I'm not sure what they are. For now, they might
	//       as well be called "PC Speaker" and "Not PC Speaker".

	switch (MidiDriver::detectMusicDriver(MDT_PCSPK)) {
	case MD_PCSPK:
		opt.soundemu = SOUND_EMU_PC;
		break;
	default:
		opt.soundemu = SOUND_EMU_NONE;
		break;
	}

	if (ConfMan.hasKey("render_mode"))
		opt.renderMode = Common::parseRenderMode(ConfMan.get("render_mode").c_str());

	_console = new Console(this);

	init_machine();

	game.color_fg = 15;
	game.color_bg = 0;

	*game.name = 0;

	game.sbuf = (uint8 *) calloc(_WIDTH, _HEIGHT);
	game.hires = (uint8 *) calloc(_WIDTH * 2, _HEIGHT);

	_sprites = new SpritesMan;
	_text = new TextMan;
	init_video();

	tick_timer = 0;
	_timer->installTimerProc(agi_timer_function_low, 10 * 1000, NULL);

	game.ver = -1;		/* Don't display the conf file warning */

	debugC(2, kDebugLevelMain, "Detect game");
	if (agi_detect_game() == err_OK) {
		game.state = STATE_LOADED;
		debugC(2, kDebugLevelMain, "game loaded");
	} else {
		report("Could not open AGI game");
	}

	debugC(2, kDebugLevelMain, "Init sound");
	init_sound();
	g_agi_music = new AGIMusic(_mixer);
}
예제 #6
0
void init_kb()
{
	set_vector(IE0_ADDRESS, (void*)kb_isr);
	write_max(ENA, 0x60); // enable keyboard interrupt as INT0
    EX0 = 1; // enable INT0
	write_max(KB, 0);
	TMOD |= 0x01;
	TCON |= 0x11;

    init_sound();
}
예제 #7
0
static void madcrash_init( void ){
/*
	The following lines patch out the ROM test (which fails - probably
	because of bit rot, so the rest of the test mode (what little there
	is) can be explored.

	unsigned char *mem = Machine->memory_region[0];
	mem[0x3a5d] = 0; mem[0x3a5e] = 0; mem[0x3a5f] = 0;
*/
	init_sound( 0x20 );
	madcrash_vreg = 0x00;
}
예제 #8
0
static DRIVER_INIT( madcrash )
{
/*
    The following lines patch out the ROM test (which fails - probably
    because of bit rot, so the rest of the test mode (what little there
    is) can be explored.

    UINT8 *mem = memory_region(REGION_CPU1);
    mem[0x3a5d] = 0; mem[0x3a5e] = 0; mem[0x3a5f] = 0;
*/
	init_sound( 0x20 );
	snk_gamegroup = 1;
	snk_irq_delay = 1700;
}
예제 #9
0
파일: main.c 프로젝트: evktalo/lacewing
void init_at_startup(void)
{

   allegro_init();

   install_keyboard();
   install_timer();

   three_finger_flag = 0;
   key_led_flag = 0;

//   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
//   LOCK_VARIABLE (tick_counter);
//   LOCK_VARIABLE (frames_per_second);
//   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);
//   LOCK_VARIABLE (inputs_per_second);
//   LOCK_VARIABLE (inputcounter);

//   install_int (framecount, 1000);
   install_int (tickover, 30);

   set_color_depth(8);
   init_config();

   if (set_gfx_mode((options.windowed == 1) ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 640x480 mode\n%s\n", allegro_error);
      exit(1);
   }

   init_palette();

   init_display();
   init_menus_once_only();

   init_sound(); // must come after init_menus_once_only, as that's where
    // options.sound_enabled is set.

}
예제 #10
0
/*
========================================================================
main:	This is the main entry point for the VirtualT application.
========================================================================
*/
int main(int argc, char **argv)
{
	if (process_args(argc, argv))	/* Parse command line args */
		return 1;

	setup_working_path(argv);	/* Create a working dir path */
	setup_unix_signals();		/* Setup Unix signal handling */

	// Added by JV for prefs
	init_pref();				/* load user Menu preferences */
	check_installation();		/* Test if install needs to be performed */
	load_setup_preferences();	/* Load user Peripheral setup preferences */
	load_memory_preferences();	/* Load user Memory setup preferences */
	load_remote_preferences();  /* Load user Remote Socket preferences */
	
	/* Perform initialization */
	init_mem();					/* Initialize Memory */
	init_io();					/* Initialize I/O structures */
	init_sound();				/* Initialize Sound system */
	init_display();				/* Initialize the Display */
	init_cpu();					/* Initialize the CPU */
	init_throttle_timer();		/* Initialize the throttle timer */
	init_remote();				/* Initialize the remote control */
	init_lpt();					/* Initialize the printer subsystem */
	init_other_windows();		/* Initialize other windows that were opened (memedit, regs, etc. */
	get_model_time();			/* Load the emulated time for current model */

	/* Perform Emulation */
	emulate();					/* Main emulation loop */

	/* Save RAM contents after emulation */
	save_ram();
	save_model_time();			/* Save the emulated time */

	/* Cleanup */
	deinit_io();				/* Deinitialize I/O */
	deinit_sound();				/* Deinitialize sound */
	deinit_lpt();				/* Deinitialize the printer */
	deinit_throttle_timer();	/* Deinitialize the throttle timer */
	deinit_display();			/* Deinitialze and free the main window */
	free_mem();					/* Free memory used by ReMem and/or Rampac */

	return 0;
}
예제 #11
0
int main(int argc, wchar* argv[])
{
	//if (argc==2) 
		//ndcid=atoi(argv[1]);

#if defined(USES_HOMEDIR)
	string home = (string)getenv("HOME");
	if(home.c_str())
	{
		home += "/.reicast";
		mkdir(home.c_str(), 0755); // create the directory if missing
		SetHomeDir(home);
	}
	else
		SetHomeDir(".");
#else
	SetHomeDir(".");
#endif

	printf("Home dir is: %s\n",GetPath("/").c_str());

	common_linux_setup();

	printf("common linux setup done\n");
	
	settings.profile.run_counts=0;
		
	dc_init(argc,argv);

	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)==-1)
	die("error initializing SDL");
	
	SetupInput();
	
	#ifdef USE_OSS	
		init_sound();
	#endif
	
	dc_run();
	
	clean_exit(0);

	return 0;
}
예제 #12
0
파일: vgs2a.c 프로젝트: kentaurus/vgs2
/*
 *----------------------------------------------------------------------------
 * initialize system
 *----------------------------------------------------------------------------
 */
JNIEXPORT jint JNICALL Java_com_{Company} _{Project} _{Project} _init(JNIEnv* env,jclass jc,jint sx,jint sy)
{
    /* change current directory */
    putlog(__FILE__,__LINE__,"Using data directory...");
    if(-1==chdir("/data/data/com.{Company}.{Project}")) {
        putlog(__FILE__,__LINE__,"Could not change to the save-directory. (errno=%d)",errno);
        return -1;
    } else {
        putlog(__FILE__,__LINE__,"Change directory: /data/data/com.{Company}.{Project}");
    }

    /* initialize AP */
    jint rc=(jint)vgs2_init();
    if(0==rc) {
        make_pallet();
        init_sound();
    }
    return rc;
}
예제 #13
0
void init_neo(void) {
#ifdef ENABLE_940T
	int z80_overclk = CF_VAL(cf_get_item_by_name("z80clock"));
#endif

	//neogeo_init_save_state();

#ifdef GP2X
	gp2x_ram_ptr_reset();
#endif

	cpu_68k_init();
//	neogeo_reset();
	pd4990a_init();
//	setup_misc_patch(rom_name);

	init_sound();

	neogeo_reset();
}
예제 #14
0
int uade_main (int argc, char **argv)
{
    quit_program = 0;

    default_prefs (&currprefs);

    uade_option (argc, argv);

    machdep_init ();

    if (! setup_sound ()) {
    __android_log_print(ANDROID_LOG_VERBOSE, "UADE", "Sound driver unavailable: Sound output disabled\n");
    currprefs.produce_sound = 0;
    exit(1);
    }

    init_sound();

    fix_options ();
    changed_prefs = currprefs;
    check_prefs_changed_cpu();

    memory_init ();

    custom_init (); /* Must come after memory_init */

    reset_frame_rate_hack ();
    init_m68k(); /* must come after reset_frame_rate_hack (); */

    /* compiler_init (); */

    if (currprefs.start_debugger)
      activate_debugger ();

    m68k_go();

    close_sound ();
    dump_counts ();

    return 0;
}
예제 #15
0
파일: main.c 프로젝트: BPaden/garglk
int glkunix_startup_code(glkunix_startup_t *data)
{
    myargc = data->argc;
    myargv = data->argv;

    os_init_setup ();
    os_process_arguments (myargc, myargv);

    init_buffer ();
    init_err ();
    init_memory ();
    init_proc ();
    init_sound ();
    init_text ();

    os_init_screen ();

    init_undo ();
    z_restart ();
    return TRUE;
}
void app::setup()
{
	//Init random number generator
	srand((unsigned int)time((time_t *)NULL));

	//GUI setup
	//First init
	gui.init_gui_thread();
	//Then start
	gui.start_form();

	//Init OSC
	init_osc_recv();

	//Get the most recent GUI info
	current_GUI_settings = gui.getInfo();
	//Apply the most recent settings
	applySettings(current_GUI_settings);

	//Init sound
	init_sound();
}
예제 #17
0
void init_data(gamedata &g){

  init_gameconstants(g);

  init_gamedata(g);

  // save the config
  saveConfig(ap_home, "apricots.cfg", g);

  // Set Random seed
  srand(time(0));

  /* Initialize defaults, Video and Audio */
  if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK)==-1)){
    fprintf(stderr, "Could not initialize SDL: %s.\n", SDL_GetError());
    exit(-1);
  }

  SDL_JoystickEventState(SDL_ENABLE);

  setup_display(g);

  // Set Window title
  SDL_WM_SetCaption("Apricots", NULL);

  // Hide cursor
  SDL_ShowCursor(0);
  
  load_shapes(g, g.images);

  load_font(g.virtualscreen, g.whitefont, g.greenfont);
  
  init_sound(g.sound);

  loadPlaneInfo(g);

}
예제 #18
0
int test_music(char *musicname)
{
	int fd_dev_sound;
	if(init_sound(SOUND_DEVICE_NAME, &fd_dev_sound) != 0){
		fprintf(stderr, "Error initial sound device!\n");
		return 1;
	}
	int fd_mp3;
	if((fd_mp3 = open(musicname, O_RDONLY)) < 0){
		fprintf(stderr, "Open %s:%s\n", musicname, strerror(errno));
		return 1;
	}

	struct stat mp3fd_stat;
	void *fdm;
	//int fstat(int fd, struct stat *buf);
	if((fstat(fd_mp3, &mp3fd_stat) == -1) || (mp3fd_stat.st_size == 0)){
		fprintf(stderr, "Error fstat file %s size %d\n", musicname,(int)mp3fd_stat.st_size);
		return 1;
	}
	//void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
	fdm = mmap(0, mp3fd_stat.st_size, PROT_READ, MAP_SHARED, fd_mp3, 0);

	if(fdm == NULL){
		fprintf(stderr, "mmap file %s:%s\n", musicname, strerror(errno));
		exit(1);
	}

	//mp3fd_static int decode(unsigned char const *, unsigned long, int);
	decode(fdm, mp3fd_stat.st_size, fd_dev_sound); 

	//int munmap(void *addr, size_t length);
	munmap(fdm, mp3fd_stat.st_size);  
	exit_sound(fd_dev_sound);

	return 0;
}
예제 #19
0
파일: sound.c 프로젝트: agwatic/PUAE
int setup_sound(void)
{
    ppb_audio_interface = (PPB_Audio *) NaCl_GetInterface(PPB_AUDIO_INTERFACE);
    ppb_audio_config_interface = (PPB_AudioConfig *)
        NaCl_GetInterface(PPB_AUDIO_CONFIG_INTERFACE);
    pp_instance = NaCl_GetInstance();

    if (!ppb_audio_interface) {
        write_log("Could not acquire PPB_Audio interface.\n");
        return 0;
    }
    if (!ppb_audio_config_interface) {
        write_log("Could not acquire PPB_AudioConfig interface.\n");
        return 0;
    }
    if (!pp_instance) {
        write_log("Could not find current Pepper instance.\n");
        return 0;
    }

    if (!init_sound()) return 0;
    close_sound();

    write_log("Pepper audio successfully set up.\n");
    write_log("Frequency: %d\n", currprefs.sound_freq);
    write_log("Stereo   : %d\n", currprefs.sound_stereo);
    write_log("Latency  : %d\n", currprefs.sound_latency);

    init_sound_table16();
    sample_handler = sample16s_handler;
    obtainedfreq = currprefs.sound_freq;
    have_sound = 1;
    sound_available = 1;
    update_sound (fake_vblank_hz, 1, currprefs.ntscmode);

    return sound_available;
}
예제 #20
0
파일: main.c 프로젝트: 4nykey/rockbox
int cdecl frotz_main (void)
{

    os_init_setup ();

    init_buffer ();

    init_err ();

    init_memory ();

    init_process ();

    init_sound ();

    os_init_screen ();

    init_undo ();

    z_restart ();

    interpret ();

    script_close ();

    record_close ();

    replay_close ();

    reset_memory ();

    os_reset_screen ();

    return 0;

}/* main */
예제 #21
0
void init()
{
	sigset_t sigmask;
	sigemptyset(&sigmask);
	sigaddset(&sigmask, SIGALRM);
	sigaddset(&sigmask, SIGUSR1);
	
	sigprocmask(SIG_BLOCK, &sigmask, NULL);

	console_print("Emergence Client " VERSION "\n");
	
	SDL_Init(SDL_INIT_AUDIO);
	
	init_user();
	init_network();
	init_timer();
	init_openssl();
	init_key();
	init_download();
	init_servers();

	create_cvars();
	init_console_cvars();
	init_render_cvars();
	init_map_cvars();
	create_control_cvars();
//	create_input_cvars();
	init_tick_cvars();

	init_console();
	create_colour_cvars();
	
	struct string_t *string = new_string_string(emergence_home_dir);
	string_cat_text(string, "/client.config");
	
	if(!exec_config_file(string->text))
	{
		exec_config_file(find_resource("default-controls.config"));
	}
	else
	{
		char *ver = get_cvar_string("version");
		
		if(*ver == '\0')
		{
			struct string_t *command = new_string_text("rm ");
			string_cat_string(command, emergence_home_dir);
			string_cat_text(command, "/skins/default.skin*");
			
			console_print("%s\n", command->text);
			system(command->text);
			
			vid_mode = -1;	// find a nice mode

			exec_config_file(find_resource("default-controls.config"));
		}
		
		free(ver);
	}
	
	free_string(string);
	
	
	set_cvar_string("version", VERSION);
	
	init_skin();
	init_input();
	init_control();
	

	init_render();
	init_rcon();
	init_ping();

	create_cvar_command("quit", client_shutdown_char);
	

	init_sound();
	init_game();
	
	init_alarm();
	
	render_frame();
	
	string = new_string_text("%s%s", emergence_home_dir->text, "/client.autoexec");
	if(!exec_config_file(string->text))
		exec_config_file(find_resource("default-client.autoexec"));
	free_string(string);
	
	start_server_discovery();
}
예제 #22
0
static int initVideoFile(struct ALL_DATA *all_data)
{
	struct GWIDGET *gwidget = all_data->gwidget;
	struct paRecordData *pdata = all_data->pdata;
	struct GLOBAL *global = all_data->global;
	struct vdIn *videoIn = all_data->videoIn;
	struct VideoFormatData *videoF = all_data->videoF;
	
	const char *compression= get_vid4cc(global->VidCodec);
	videoF->vcodec = get_vcodec_id(global->VidCodec);
	videoF->acodec = CODEC_ID_NONE;
	videoF->keyframe = 0;
	int ret = 0;
	
	__LOCK_MUTEX(__VMUTEX);
		gboolean capVid = videoIn->capVid;
	__UNLOCK_MUTEX(__VMUTEX);
	
	/*alloc video ring buffer*/
	alloc_videoBuff(all_data);
	
	switch (global->VidFormat)
	{
		case AVI_FORMAT:
			if(videoF->AviOut != NULL)
			{
				g_free(videoF->AviOut);
				videoF->AviOut = NULL;
			}
			videoF->AviOut = g_new0(struct avi_t, 1);
			
			if(AVI_open_output_file(videoF->AviOut, videoIn->VidFName)<0) 
			{
				g_printerr("Error: Couldn't create Video.\n");
				capVid = FALSE; /*don't start video capture*/
				__LOCK_MUTEX(__VMUTEX);
					videoIn->capVid = capVid;
				__UNLOCK_MUTEX(__VMUTEX);
				pdata->capVid = capVid;
				return(-1);
			} 
			else 
			{
				AVI_set_video(videoF->AviOut, global->width, global->height, 
					global->fps, compression);
		  
				/* start video capture*/
				capVid = TRUE;
				__LOCK_MUTEX(__VMUTEX);
					videoIn->capVid = capVid;
				__UNLOCK_MUTEX(__VMUTEX);
				pdata->capVid = capVid;
				
				/* start sound capture*/
				if(global->Sound_enable > 0) 
				{
					/*get channels and sample rate*/
					set_sound(global, pdata);
					/*set audio header for avi*/
					AVI_set_audio(videoF->AviOut, global->Sound_NumChan, 
						global->Sound_SampRate,
						get_aud_bit_rate(get_ind_by4cc(global->Sound_Format)), /*bit rate*/
						get_aud_bits(get_ind_by4cc(global->Sound_Format)),     /*sample size - only used for PCM*/
						global->Sound_Format);
					/* Initialize sound (open stream)*/
					if(init_sound (pdata)) 
					{
						g_printerr("Audio initialization error\n");
						global->Sound_enable=0;
						if(!(global->no_display))
                        {
						    gdk_threads_enter();
						    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0);
						    gdk_flush();
						    gdk_threads_leave();
						}
						else
                            capture_vid(NULL, all_data);
					} 
				}
			}
			break;
			
		case MKV_FORMAT:
			if(global->Sound_enable > 0) 
			{
				/*set channels, sample rate and allocate buffers*/
				set_sound(global, pdata);
			}
			if(init_FormatContext((void *) all_data)<0)
			{
				capVid = FALSE;
				__LOCK_MUTEX(__VMUTEX);
					videoIn->capVid = capVid;
				__UNLOCK_MUTEX(__VMUTEX);
				pdata->capVid = capVid;
				return (-1);
			}
			
			videoF->old_apts = 0;
			videoF->apts = 0;
			videoF->vpts = 0;
			
			/* start video capture*/
			capVid = TRUE;
			__LOCK_MUTEX(__VMUTEX);
				videoIn->capVid = capVid;
			__UNLOCK_MUTEX(__VMUTEX);
			pdata->capVid = capVid;
			
			
			/* start sound capture*/
			if(global->Sound_enable > 0) 
			{
				/* Initialize sound (open stream)*/
				if(init_sound (pdata)) 
				{
					g_printerr("Audio initialization error\n");
					global->Sound_enable=0;
					if(!(global->no_display))
                    {
					    /*will this work with the checkbox disabled?*/
					    gdk_threads_enter();
					    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0);
					    gdk_flush();
					    gdk_threads_leave();
					}
					else
					    capture_vid(NULL, all_data);
				}
			}
			break;
//WebM = MKV + WebVTT
//add META data capture
		case WEBM_FORMAT:
                     
			if(global->Sound_enable > 0) 
			{
				/*set channels, sample rate and allocate buffers*/
				set_sound(global, pdata);
			}
			if(init_FormatContext((void *) all_data)<0)
			{
				capVid = FALSE;
				__LOCK_MUTEX(__VMUTEX);
					videoIn->capVid = capVid;
				__UNLOCK_MUTEX(__VMUTEX);
				pdata->capVid = capVid;
				return (-1);
			}
			
			videoF->old_apts = 0;
			videoF->apts = 0;
			videoF->vpts = 0;
			
			/* start video capture*/
			capVid = TRUE;
			__LOCK_MUTEX(__VMUTEX);
				videoIn->capVid = capVid;
			__UNLOCK_MUTEX(__VMUTEX);
			pdata->capVid = capVid;
			
			
			/* start sound capture*/
			if(global->Sound_enable > 0) 
			{
				/* Initialize sound (open stream)*/
				if(init_sound (pdata)) 
				{
					g_printerr("Audio initialization error\n");
					global->Sound_enable=0;
					if(!(global->no_display))
                    {
					    /*will this work with the checkbox disabled?*/
					    gdk_threads_enter();
					    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0);
					    gdk_flush();
					    gdk_threads_leave();
					}
					else
					    capture_vid(NULL, all_data);
				}
			}
			break;            
		default:
			
			break;
	}
	
	return (ret);
}
예제 #23
0
파일: main.c 프로젝트: evktalo/angry_moth
/*
Self-explanatory.
*/
void init_at_startup(void)
{

   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
   LOCK_VARIABLE (frames_per_second);
   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);

   install_int (framecount, 1000);
   install_int (tickover, 20);

   set_color_depth(8);

   int randseed = get_config_int("Misc", "Seed", 0);
   srand(randseed);

   options.windowed = get_config_int("Misc", "Windowed", 0);


 int windowed;
 switch(options.windowed)
 {
    default:
     case 1: windowed = GFX_AUTODETECT_WINDOWED; break;
     case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break;
 }

//   windowed  = GFX_AUTODETECT_WINDOWED;
//   windowed = GFX_AUTODETECT_FULLSCREEN;

//   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
//   if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0)
   if (set_gfx_mode(windowed, 800, 600, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 800x600 256 colour display mode. Sorry!\n%s\n", allegro_error);
      exit(1);
   }

 init_trig();

 prepare_display();
 init_sound();
/*
 PP.ckey [CKEY_UP] = KEY_UP;
 PP.ckey [CKEY_DOWN] = KEY_DOWN;
 PP.ckey [CKEY_LEFT] = KEY_LEFT;
 PP.ckey [CKEY_RIGHT] = KEY_RIGHT;
 PP.ckey [CKEY_FIRE1] = KEY_Z;
 PP.ckey [CKEY_FIRE2] = KEY_X;
 PP.ckey [CKEY_FIRE3] = KEY_C;
*/
 int p = 0;

 init_joystick();

 player[0].control = get_config_int("misc", "player1_control", CONTROL_KEY_A);
 player[1].control = get_config_int("misc", "player2_control", CONTROL_KEY_B);

// if a particular joystick isn't available, default to keyboard controls.
//  note that this doesn't set the config values
 for (p = 0; p < 2; p ++)
 {
  if (options.joystick_available [0] == 0
   && PP.control == CONTROL_JOY_A)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
  if (options.joystick_available [1] == 0
   && PP.control == CONTROL_JOY_B)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
 }

 options.ckey [0] [CKEY_UP] = get_config_int("Misc", "key1_up", KEY_8_PAD);
 options.ckey [0] [CKEY_DOWN] = get_config_int("Misc", "key1_down", KEY_2_PAD);
 options.ckey [0] [CKEY_LEFT] = get_config_int("Misc", "key1_left", KEY_4_PAD);
 options.ckey [0] [CKEY_RIGHT] = get_config_int("Misc", "key1_right", KEY_6_PAD);
 options.ckey [0] [CKEY_LEFT2] = get_config_int("Misc", "key1_left2", KEY_1_PAD);
 options.ckey [0] [CKEY_RIGHT2] = get_config_int("Misc", "key1_right2", KEY_3_PAD);
 options.ckey [0] [CKEY_FIRE1] = get_config_int("Misc", "key1_fire1", KEY_Z);
 options.ckey [0] [CKEY_FIRE2] = get_config_int("Misc", "key1_fire2", KEY_X);
 options.ckey [0] [CKEY_FIRE3] = get_config_int("Misc", "key1_fire3", KEY_C);
 options.ckey [0] [CKEY_FIRE4] = get_config_int("Misc", "key1_fire4", KEY_V);
 options.ckey [0] [CKEY_COMMAND] = get_config_int("Misc", "key1_command", KEY_A);

 options.ckey [1] [CKEY_UP] = get_config_int("Misc", "key2_up", KEY_UP);
 options.ckey [1] [CKEY_DOWN] = get_config_int("Misc", "key2_down", KEY_DOWN);
 options.ckey [1] [CKEY_LEFT] = get_config_int("Misc", "key2_left", KEY_LEFT);
 options.ckey [1] [CKEY_RIGHT] = get_config_int("Misc", "key2_right", KEY_RIGHT);
 options.ckey [1] [CKEY_LEFT2] = get_config_int("Misc", "key2_left2", KEY_J);
 options.ckey [1] [CKEY_RIGHT2] = get_config_int("Misc", "key2_right2", KEY_K);
 options.ckey [1] [CKEY_FIRE1] = get_config_int("Misc", "key2_fire1", KEY_T);
 options.ckey [1] [CKEY_FIRE2] = get_config_int("Misc", "key2_fire2", KEY_Y);
 options.ckey [1] [CKEY_FIRE3] = get_config_int("Misc", "key2_fire3", KEY_U);
 options.ckey [1] [CKEY_FIRE4] = get_config_int("Misc", "key2_fire4", KEY_I);
 options.ckey [1] [CKEY_COMMAND] = get_config_int("Misc", "key2_command", KEY_O);


/*
 PP.ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP);
 PP.ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN);
 PP.ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT);
 PP.ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT);
 PP.ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z);
 PP.ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X);
 PP.ckey [CKEY_FIRE3] = get_config_int("Misc", "key_fire3", KEY_C);
 PP.ckey [CKEY_FIRE4] = get_config_int("Misc", "key_fire4", KEY_V);
*/
/*
 player[1].ckey [CKEY_UP] = get_config_int("MiscP2", "key_up", KEY_UP);
 player[1].ckey [CKEY_DOWN] = get_config_int("MiscP2", "key_down", KEY_DOWN);
 player[1].ckey [CKEY_LEFT] = get_config_int("MiscP2", "key_left", KEY_LEFT);
 player[1].ckey [CKEY_RIGHT] = get_config_int("MiscP2", "key_right", KEY_RIGHT);
 player[1].ckey [CKEY_LEFT2] = get_config_int("MiscP2", "key_left2", KEY_K);
 player[1].ckey [CKEY_RIGHT2] = get_config_int("MiscP2", "key_right2", KEY_L);
 player[1].ckey [CKEY_FIRE1] = get_config_int("MiscP2", "key_fire1", KEY_0_PAD);
 player[1].ckey [CKEY_FIRE2] = get_config_int("MiscP2", "key_fire2", KEY_P);
 player[1].ckey [CKEY_FIRE3] = get_config_int("MiscP2", "key_fire3", KEY_O);
 player[1].ckey [CKEY_FIRE4] = get_config_int("MiscP2", "key_fire4", KEY_I);

 options.joy_stick = get_config_int("Misc", "joy_stick", 0);

 options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70);
 options.init_joystick = get_config_int("Misc", "joy_init", 1);*/

// options.joystick = 0;
// options.key_or_joy = 0; // don't put in initfile!

 options.sfx_volume = get_config_int("Misc", "sfx_volume", 70);
 options.ambience_volume = get_config_int("Misc", "ambience_volume", 100);
 options.run_vsync = get_config_int("Misc", "run_vsync", 0);
 options.fix_camera_angle = get_config_int("Misc", "fix_camera_angle", 0);
 options.joystick_dual = get_config_int("Misc", "joystick_dual", 1);

// set_config_int("Misc", "Tourist", 3);
// set_config_int("Misc", "joy_stick", 0);

// if (options.init_joystick)
// if (options.joystick == 1) // set in init_joystick
 {
  options.joy_button [0] [0] = get_config_int("Misc", "joy1_button_1", 0);
  if (options.joy_button [0] [0] > joy[0].num_buttons)
   options.joy_button [0] [0] = joy[0].num_buttons - 1;
  options.joy_button [0] [1] = get_config_int("Misc", "joy1_button_2", 1);
  if (options.joy_button [0] [1] > joy[0].num_buttons)
   options.joy_button [0] [1] = joy[0].num_buttons - 1;
  options.joy_button [0] [2] = get_config_int("Misc", "joy1_button_3", 2);
  if (options.joy_button [0] [2] > joy[0].num_buttons)
   options.joy_button [0] [2] = joy[0].num_buttons - 1;
  options.joy_button [0] [3] = get_config_int("Misc", "joy1_button_4", 4);
  if (options.joy_button [0] [3] > joy[0].num_buttons)
   options.joy_button [0] [3] = joy[0].num_buttons - 1;
  options.joy_button [0] [4] = get_config_int("Misc", "joy1_button_5", 5);
  if (options.joy_button [0] [4] > joy[0].num_buttons)
   options.joy_button [0] [4] = joy[0].num_buttons - 1;
  options.joy_button [0] [5] = get_config_int("Misc", "joy1_button_6", 6);
  if (options.joy_button [0] [5] > joy[0].num_buttons)
   options.joy_button [0] [5] = joy[0].num_buttons - 1;

  options.joy_button [1] [0] = get_config_int("Misc", "joy2_button_1", 0);
  if (options.joy_button [1] [0] > joy[0].num_buttons)
   options.joy_button [1] [0] = joy[0].num_buttons - 1;
  options.joy_button [1] [1] = get_config_int("Misc", "joy2_button_2", 1);
  if (options.joy_button [1] [1] > joy[0].num_buttons)
   options.joy_button [1] [1] = joy[0].num_buttons - 1;
  options.joy_button [1] [2] = get_config_int("Misc", "joy2_button_3", 2);
  if (options.joy_button [1] [2] > joy[0].num_buttons)
   options.joy_button [1] [2] = joy[0].num_buttons - 1;
  options.joy_button [1] [3] = get_config_int("Misc", "joy2_button_4", 4);
  if (options.joy_button [1] [3] > joy[0].num_buttons)
   options.joy_button [1] [3] = joy[0].num_buttons - 1;
  options.joy_button [1] [4] = get_config_int("Misc", "joy2_button_5", 5);
  if (options.joy_button [1] [4] > joy[0].num_buttons)
   options.joy_button [1] [4] = joy[0].num_buttons - 1;
  options.joy_button [1] [5] = get_config_int("Misc", "joy2_button_6", 6);
  if (options.joy_button [1] [5] > joy[0].num_buttons)
   options.joy_button [1] [5] = joy[0].num_buttons - 1;
 }

 ticked = 0;

 arena.players = 1;
// NOTE: it's assumed in a few places that if there's just one player, it's player[0].


}
예제 #24
0
파일: main.c 프로젝트: dradtke/battlechess
/* the main program body */
int main(int argc, char *argv[])
{
   ALLEGRO_PATH *font_path;
   int w = 0, h = 0;
   int www = FALSE;
   int i, n;
   int display_flags = ALLEGRO_GENERATE_EXPOSE_EVENTS;

   srand(time(NULL));
   
   al_set_org_name("liballeg.org");
   al_set_app_name("SPEED");

   if (!al_init()) {
      fprintf(stderr, "Could not initialise Allegro.\n");
      return 1;
   }
   al_init_primitives_addon();

   /* parse the commandline */
   for (i=1; i<argc; i++) {
      if (strcmp(argv[i], "-cheat") == 0) {
         cheat = TRUE;
      }
      else if (strcmp(argv[i], "-simple") == 0) {
         low_detail = TRUE;
      }
      else if (strcmp(argv[i], "-nogrid") == 0) {
         no_grid = TRUE;
      }
      else if (strcmp(argv[i], "-nomusic") == 0) {
         no_music = TRUE;
      }
      else if (strcmp(argv[i], "-www") == 0) {
         www = TRUE;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         /* if no width is specified, assume fullscreen_window */
         display_flags |= w ? ALLEGRO_FULLSCREEN : ALLEGRO_FULLSCREEN_WINDOW;
      }
      else {
         n = atoi(argv[i]);

         if (!n) {
            usage();
            return 1;
         }

         if (!w) {
            w = n;
            if (display_flags & ALLEGRO_FULLSCREEN_WINDOW) {
               /* toggle from fullscreen_window to fullscreen */
               display_flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
               display_flags |= ALLEGRO_FULLSCREEN;
            }
         }
         else if (!h) {
            h = n;
         }
         else {
            usage();
            return 1;
         }
      }
   }

   /* it's a real shame that I had to take this out! */
   if (www) {
      printf(
	 "\n"
	 "Unfortunately the built-in web browser feature had to be removed.\n"
	 "\n"
	 "I did get it more or less working as of Saturday evening (forms and\n"
	 "Java were unsupported, but tables and images were mostly rendering ok),\n"
	 "but the US Department of Justice felt that this was an unacceptable\n"
	 "monopolistic attempt to tie in web browsing functionality to an\n"
	 "unrelated product, so they threatened me with being sniped at from\n"
	 "the top of tall buildings by guys with high powered rifles unless I\n"
	 "agreed to disable this code.\n"
	 "\n"
	 "We apologise for any inconvenience that this may cause you.\n"
      );

      return 1;
   }
   
   if (!w || !h) {
      if (argc == 1 || (display_flags & ALLEGRO_FULLSCREEN_WINDOW)) {
         w = 640;
         h = 480;
      }
      else {
         usage();
         return 1;
      }
   }

   /* set the screen mode */
   al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
   al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);

   al_set_new_display_flags(display_flags);
   screen = al_create_display(w, h);
   if (!screen) {
      fprintf(stderr, "Error setting %dx%d display mode\n", w, h);
      return 1;
   }

   al_init_image_addon();

   /* The Allegro 5 port introduced an external data dependency, sorry.
    * To avoid performance problems on graphics drivers that don't support
    * drawing to textures, we build up transition screens on memory bitmaps.
    * We need a font loaded into a memory bitmap for those, then a font
    * loaded into a video bitmap for the game view. Blech!
    */
   font_path = get_resources_path();
   al_set_path_filename(font_path, "a4_font.tga");

   al_init_font_addon();
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   font = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }

   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
   font_video = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font_video) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }
   
   al_destroy_path(font_path);

   /* set up everything else */
   al_install_keyboard();
   al_install_joystick();
   if (al_install_audio()) {
      if (!al_reserve_samples(8))
         al_uninstall_audio();
   }

   init_input();
   init_sound();
   init_hiscore();

   /* the main program body */
   while (title_screen()) {
      if (play_game()) {
	 show_results();
	 score_table();
      }
   }

   /* time to go away now */
   shutdown_hiscore();
   shutdown_sound();

   goodbye();

   shutdown_input();

   al_destroy_font(font);
   al_destroy_font(font_video);

   return 0;
}
예제 #25
0
blargg_err_t Nsf_Emu::load_( Data_Reader& in )
{
	assert( offsetof (header_t,unused [4]) == header_size );
	RETURN_ERR( rom.load( in, header_size, &header_, 0 ) );
	
	set_track_count( header_.track_count );
	RETURN_ERR( check_nsf_header( &header_ ) );
	
	if ( header_.vers != 1 )
		set_warning( "Unknown file version" );
	
	// sound and memory
	blargg_err_t err = init_sound();
	if ( err )
		return err;
	
	// set up data
	nes_addr_t load_addr = get_le16( header_.load_addr );
	init_addr = get_le16( header_.init_addr );
	play_addr = get_le16( header_.play_addr );
	if ( !load_addr ) load_addr = rom_begin;
	if ( !init_addr ) init_addr = rom_begin;
	if ( !play_addr ) play_addr = rom_begin;
	if ( load_addr < rom_begin || init_addr < rom_begin )
	{
		const char* w = warning();
		if ( !w )
			w = "Corrupt file (invalid load/init/play address)";
		return w;
	}
	
	rom.set_addr( load_addr % bank_size );
	int total_banks = rom.size() / bank_size;
	
	// bank switching
	int first_bank = (load_addr - rom_begin) / bank_size;
	for ( int i = 0; i < bank_count; i++ )
	{
		unsigned bank = i - first_bank;
		if ( bank >= (unsigned) total_banks )
			bank = 0;
		initial_banks [i] = bank;
		
		if ( header_.banks [i] )
		{
			// bank-switched
			memcpy( initial_banks, header_.banks, sizeof initial_banks );
			break;
		}
	}
	
	pal_only = (header_.speed_flags & 3) == 1;
	
	#if !NSF_EMU_EXTRA_FLAGS
		header_.speed_flags = 0;
	#endif
	
	set_tempo( tempo() );
	
	return setup_buffer( (long) (clock_rate_ + 0.5) );
}
예제 #26
0
static void marvins_init(void){
	init_sound( 0x40 );
}
예제 #27
0
static void vangrd2_init( void ){
	init_sound( 0x20 );
	madcrash_vreg = 0xf1;
}
예제 #28
0
파일: tracker.c 프로젝트: bion/ats
/* ATS_SOUND *tracker (ANARGS *anargs, char *soundfile)
 * partial tracking function 
 * anargs: pointer to analysis parameters
 * soundfile: path to input file 
 * returns an ATS_SOUND with data issued from analysis
 */
ATS_SOUND *tracker (ANARGS *anargs, char *soundfile, char *resfile)
{
  int fd, M_2, first_point, filptr, n_partials = 0;
  int frame_n, k, sflen, *win_samps, peaks_size, tracks_size = 0;
  int i, frame, i_tmp;
  float *window, norm, sfdur, f_tmp;
  /* declare structures and buffers */
  ATS_SOUND *sound = NULL;
  ATS_PEAK *peaks, *tracks = NULL, cpy_peak;
  ATS_FRAME *ana_frames = NULL, *unmatched_peaks = NULL;
  mus_sample_t **bufs;
  ATS_FFT fft;
#ifdef FFTW
  fftw_plan plan;
  FILE *fftw_wisdom_file;
#endif

  /* open input file
     we get srate and total_samps in file in anargs */
  if ((fd = mus_sound_open_input(soundfile))== -1) {
    fprintf(stderr, "%s: %s\n", soundfile, strerror(errno));
    return(NULL);
  }
  /* warn about multi-channel sound files */
  if (mus_sound_chans(soundfile) > 1) {
    fprintf(stderr, "Error: file has %d channels, must be mono!\n",
	    mus_sound_chans(soundfile));
    return(NULL);
  }

  fprintf(stderr, "tracking...\n");

  /* get sample rate and # of frames from file header */
  anargs->srate = mus_sound_srate(soundfile);
  sflen = mus_sound_frames(soundfile);
  sfdur = (float)sflen/anargs->srate;
  /* check analysis parameters */
  /* check start time */
  if( !(anargs->start >= 0.0 && anargs->start < sfdur) ){
    fprintf(stderr, "Warning: start %f out of bounds, corrected to 0.0\n", anargs->start);
    anargs->start = (float)0.0;
  }
  /* check duration */
  if(anargs->duration == ATSA_DUR) {
    anargs->duration = sfdur - anargs->start;
  }
  f_tmp = anargs->duration + anargs->start;
  if( !(anargs->duration > 0.0 && f_tmp <= sfdur) ){
    fprintf(stderr, "Warning: duration %f out of bounds, limited to file duration\n", anargs->duration);
    anargs->duration = sfdur - anargs->start;
  }
  /* print time bounds */
  fprintf(stderr, "start: %f duration: %f file dur: %f\n", anargs->start, anargs->duration , sfdur);
  /* check lowest frequency */
  if( !(anargs->lowest_freq > 0.0 && anargs->lowest_freq < anargs->highest_freq)){
    fprintf(stderr, "Warning: lowest freq. %f out of bounds, forced to default: %f\n", anargs->lowest_freq, ATSA_LFREQ);
    anargs->lowest_freq = ATSA_LFREQ;
  }
  /* check highest frequency */
  if( !(anargs->highest_freq > anargs->lowest_freq && anargs->highest_freq <= anargs->srate * 0.5 )){
    fprintf(stderr, "Warning: highest freq. %f out of bounds, forced to default: %f\n", anargs->highest_freq, ATSA_HFREQ);
    anargs->highest_freq = ATSA_HFREQ;
  }
  /* frequency deviation */
  if( !(anargs->freq_dev > 0.0 && anargs->freq_dev < 1.0) ){
    fprintf(stderr, "Warning: freq. dev. %f out of bounds, should be > 0.0 and <= 1.0,  forced to default: %f\n", anargs->freq_dev, ATSA_FREQDEV);
    anargs->freq_dev = ATSA_FREQDEV;
  }
  /* window cycles */
  if( !(anargs->win_cycles >= 1 && anargs->win_cycles <= 8) ){
    fprintf(stderr, "Warning: windows cycles %d out of bounds, should be between 1 and 8, forced to default: %d\n", anargs->win_cycles, ATSA_WCYCLES);
    anargs->win_cycles = ATSA_WCYCLES;
  }
  /* window type */
  if( !(anargs->win_type >= 0 && anargs->win_type <= 3) ){
    fprintf(stderr, "Warning: window type %d out of bounds, should be between 0 and 3, forced to default: %d\n", anargs->win_type, ATSA_WTYPE);
    anargs->win_type = ATSA_WTYPE;
  }
  /* hop size */
  if( !(anargs->hop_size > 0.0 && anargs->hop_size <= 1.0) ){
    fprintf(stderr, "Warning: hop size %f out of bounds, should be > 0.0 and <= 1.0, forced to default: %f\n", anargs->hop_size, ATSA_HSIZE);
    anargs->hop_size = ATSA_HSIZE;
  }
  /* lowest mag */
  if( !(anargs->lowest_mag <= 0.0) ){
    fprintf(stderr, "Warning: lowest magnitude %f out of bounds, should be >= 0.0 and <= 1.0, forced to default: %f\n", anargs->lowest_mag, ATSA_LMAG);
    anargs->lowest_mag = ATSA_LMAG;
  }
  /* set some values before checking next set of parameters */
  anargs->first_smp = (int)floor(anargs->start * (float)anargs->srate);
  anargs->total_samps = (int)floor(anargs->duration * (float)anargs->srate);
  /* fundamental cycles */
  anargs->cycle_smp = (int)floor((double)anargs->win_cycles * (double)anargs->srate / (double)anargs->lowest_freq);
  /* window size */
  anargs->win_size = (anargs->cycle_smp % 2 == 0) ? anargs->cycle_smp+1 : anargs->cycle_smp;
  /* calculate hop samples */
  anargs->hop_smp = floor( (float)anargs->win_size * anargs->hop_size );
  /* compute total number of frames */
  anargs->frames = compute_frames(anargs);
  /* check that we have enough frames for the analysis */
  if( !(anargs->frames >= ATSA_MFRAMES) ){
    fprintf(stderr, "Error: %d frames are not enough for analysis, nead at least %d\n", anargs->frames , ATSA_MFRAMES);
    return(NULL);
  }
  /* check other user parameters */
  /* track length */
  if( !(anargs->track_len >= 1 && anargs->track_len < anargs->frames) ){
    i_tmp = (ATSA_TRKLEN < anargs->frames) ? ATSA_TRKLEN : anargs->frames-1;
    fprintf(stderr, "Warning: track length %d out of bounds, forced to: %d\n", anargs->track_len , i_tmp);
    anargs->track_len = i_tmp;
  }    
  /* min. segment length */
  if( !(anargs->min_seg_len >= 1 && anargs->min_seg_len < anargs->frames) ){
    i_tmp = (ATSA_MSEGLEN < anargs->frames) ? ATSA_MSEGLEN : anargs->frames-1;
    fprintf(stderr, "Warning: min. segment length %d out of bounds, forced to: %d\n", anargs->min_seg_len, i_tmp);
    anargs->min_seg_len = i_tmp;
  }
  /* min. gap length */
  if( !(anargs->min_gap_len >= 0 && anargs->min_gap_len < anargs->frames) ){
    i_tmp = (ATSA_MGAPLEN < anargs->frames) ? ATSA_MGAPLEN : anargs->frames-1;
    fprintf(stderr, "Warning: min. gap length %d out of bounds, forced to: %d\n", anargs->min_gap_len, i_tmp);
    anargs->min_gap_len = i_tmp;
  }
  /* SMR threshold */
  if( !(anargs->SMR_thres >= 0.0 && anargs->SMR_thres < ATSA_MAX_DB_SPL) ){
    fprintf(stderr, "Warning: SMR threshold %f out of bounds, shoul be >= 0.0 and < %f dB SPL, forced to default: %f\n", anargs->SMR_thres, ATSA_MAX_DB_SPL, ATSA_SMRTHRES);
    anargs->SMR_thres = ATSA_SMRTHRES;
  }
  /* min. seg. SMR */
  if( !(anargs->min_seg_SMR >= anargs->SMR_thres && anargs->min_seg_SMR < ATSA_MAX_DB_SPL) ){
    fprintf(stderr, "Warning: min. seg. SMR  %f out of bounds, shoul be >= %f and < %f dB SPL, forced to default: %f\n", anargs->min_seg_SMR, anargs->SMR_thres, ATSA_MAX_DB_SPL, ATSA_MSEGSMR);
    anargs->min_seg_SMR = ATSA_MSEGSMR;
  }
  /* last peak contibution */
  if( !(anargs->last_peak_cont >= 0.0 && anargs->last_peak_cont <= 1.0) ){
    fprintf(stderr, "Warning: last peak contibution %f out of bounds, should be >= 0.0 and <= 1.0, forced to default: %f\n", anargs->last_peak_cont, ATSA_LPKCONT);
    anargs->last_peak_cont = ATSA_LPKCONT;
  }
  /* SMR cont. */
  if( !(anargs->SMR_cont >= 0.0 && anargs->SMR_cont <= 1.0) ){
    fprintf(stderr, "Warning: SMR contibution %f out of bounds, should be >= 0.0 and <= 1.0, forced to default: %f\n", anargs->SMR_cont, ATSA_SMRCONT);
    anargs->SMR_cont = ATSA_SMRCONT;
  }
  /* continue computing parameters */
  /* fft size */
  anargs->fft_size = ppp2(2*anargs->win_size);

  /* allocate memory for sound, we read the whole sound in memory */
  bufs = (mus_sample_t **)malloc(sizeof(mus_sample_t*));
  bufs[0] = (mus_sample_t *)malloc(sflen * sizeof(mus_sample_t));
  /*  bufs = malloc(sizeof(mus_sample_t*));
      bufs[0] = malloc(sflen * sizeof(mus_sample_t)); */
  /* make our window */
  window = make_window(anargs->win_type, anargs->win_size);
  /* get window norm */
  norm = window_norm(window, anargs->win_size);
  /* fft mag for computing frequencies */
  anargs->fft_mag = (double)anargs->srate / (double)anargs->fft_size;
  /* lowest fft bin for analysis */
  anargs->lowest_bin = floor( anargs->lowest_freq / anargs->fft_mag );
  /* highest fft bin for analisis */
  anargs->highest_bin = floor( anargs->highest_freq / anargs->fft_mag );
  /* allocate an array analysis frames in memory */
  ana_frames = (ATS_FRAME *)malloc(anargs->frames * sizeof(ATS_FRAME));
  /* alocate memory to store mid-point window sample numbers */
  win_samps = (int *)malloc(anargs->frames * sizeof(int));
  /* center point of window */
  M_2 = floor((anargs->win_size - 1) / 2); 
  /* first point in fft buffer to write */
  first_point = anargs->fft_size - M_2;  
  /* half a window from first sample */
  filptr = anargs->first_smp - M_2;   
  /* read sound into memory */
  mus_sound_read(fd, 0, sflen-1, 1, bufs);     

  /* make our fft-struct */
  fft.size = anargs->fft_size;
  fft.rate = anargs->srate;
#ifdef FFTW
  fft.data = fftw_malloc(sizeof(fftw_complex) * fft.size);
  if(fftw_import_system_wisdom()) fprintf(stderr, "system wisdom loaded!\n");
  else fprintf(stderr, "cannot locate system wisdom!\n");
  if((fftw_wisdom_file = fopen("ats-wisdom", "r")) != NULL) {
    fftw_import_wisdom_from_file(fftw_wisdom_file);
    fprintf(stderr, "ats-wisdom loaded!\n");
    fclose(fftw_wisdom_file);
  } else fprintf(stderr, "cannot locate ats-wisdom!\n");
  plan = fftw_plan_dft_1d(fft.size, fft.data, fft.data, FFTW_FORWARD, FFTW_PATIENT);
#else
  fft.fdr = (double *)malloc(anargs->fft_size * sizeof(double));
  fft.fdi = (double *)malloc(anargs->fft_size * sizeof(double));
#endif

  /* main loop */
  for (frame_n=0; frame_n<anargs->frames; frame_n++) {
    /* clear fft arrays */
#ifdef FFTW
    for(k=0; k<fft.size; k++) fft.data[k][0] = fft.data[k][1] = 0.0f;
#else
    for(k=0; k<fft.size; k++) fft.fdr[k] = fft.fdi[k] = 0.0f;
#endif
    /* multiply by window */
    for (k=0; k<anargs->win_size; k++) {
      if ((filptr >= 0) && (filptr < sflen)) 
#ifdef FFTW
        fft.data[(k+first_point)%fft.size][0] = window[k] * MUS_SAMPLE_TO_FLOAT(bufs[0][filptr]);
#else
        fft.fdr[(k+first_point)%anargs->fft_size] = window[k] * MUS_SAMPLE_TO_FLOAT(bufs[0][filptr]);
#endif
      filptr++;
    }
    /* we keep sample numbers of window midpoints in win_samps array */
    win_samps[frame_n] = filptr - M_2 - 1;
    /* move file pointer back */
    filptr = filptr - anargs->win_size + anargs->hop_smp;
    /* take the fft */
#ifdef FFTW
    fftw_execute(plan);
#else
    fft_slow(fft.fdr, fft.fdi, fft.size, 1);
#endif
    /* peak detection */
    peaks_size = 0;
    peaks = peak_detection(&fft, anargs->lowest_bin, anargs->highest_bin, anargs->lowest_mag, norm, &peaks_size); 
    /* peak tracking */
    if (peaks != NULL) {
      /* evaluate peaks SMR (masking curves) */
      evaluate_smr(peaks, peaks_size);
      if (frame_n) {
	/* initialize or update tracks */
	if ((tracks = update_tracks(tracks, &tracks_size, anargs->track_len, frame_n, ana_frames, anargs->last_peak_cont)) != NULL) {
	  /* do peak matching */
          unmatched_peaks = peak_tracking(tracks, &tracks_size, peaks, &peaks_size,  anargs->freq_dev, 2.0 * anargs->SMR_cont, &n_partials);
	  /* kill unmatched peaks from previous frame */
          if(unmatched_peaks[0].peaks != NULL) {
	    for(k=0; k<unmatched_peaks[0].n_peaks; k++) {
	      cpy_peak = unmatched_peaks[0].peaks[k];
	      cpy_peak.amp = cpy_peak.smr = 0.0;
	      peaks = push_peak(&cpy_peak, peaks, &peaks_size);
             }
             free(unmatched_peaks[0].peaks);
           }
           /* give birth to peaks from new frame */
           if(unmatched_peaks[1].peaks != NULL) {
             for(k=0; k<unmatched_peaks[1].n_peaks; k++) {
               tracks = push_peak(&unmatched_peaks[1].peaks[k], tracks, &tracks_size);
               unmatched_peaks[1].peaks[k].amp = unmatched_peaks[1].peaks[k].smr = 0.0;
               ana_frames[frame_n-1].peaks = push_peak(&unmatched_peaks[1].peaks[k], ana_frames[frame_n-1].peaks, &ana_frames[frame_n-1].n_peaks);
             }
             free(unmatched_peaks[1].peaks);
           }
         } else {
           /* give number to all peaks */
           qsort(peaks, peaks_size, sizeof(ATS_PEAK), peak_frq_inc);
           for(k=0; k<peaks_size; k++) peaks[k].track = n_partials++;
         }
      } else {
        /* give number to all peaks */
        qsort(peaks, peaks_size, sizeof(ATS_PEAK), peak_frq_inc);
        for(k=0; k<peaks_size; k++) peaks[k].track = n_partials++;
      }
      /* attach peaks to ana_frames */
      ana_frames[frame_n].peaks = peaks;
      ana_frames[frame_n].n_peaks = n_partials;
      ana_frames[frame_n].time = (double)(win_samps[frame_n] - anargs->first_smp) / (double)anargs->srate;
      /* free memory */
      free(unmatched_peaks);
    } else {
      /* if no peaks found, initialize empty frame */
      ana_frames[frame_n].peaks = NULL;
      ana_frames[frame_n].n_peaks = 0;
      ana_frames[frame_n].time = (double)(win_samps[frame_n] - anargs->first_smp) / (double)anargs->srate;
    }
  }
  /* free up some memory */
  free(window);
  free(tracks);
#ifdef FFTW
  fftw_destroy_plan(plan);
  fftw_free(fft.data);
#else
  free(fft.fdr);
  free(fft.fdi);
#endif
  /* init sound */
  fprintf(stderr, "Initializing ATS data...");
  sound = (ATS_SOUND *)malloc(sizeof(ATS_SOUND));
  init_sound(sound, anargs->srate, (int)(anargs->hop_size * anargs->win_size), 
             anargs->win_size, anargs->frames, anargs->duration, n_partials,
             ((anargs->type == 3 || anargs->type == 4) ? 1 : 0));
  /* store values from frames into the arrays */
  for(k=0; k<n_partials; k++) {
    for(frame=0; frame<sound->frames; frame++) {
      sound->time[k][frame] = ana_frames[frame].time;
      for(i=0; i<ana_frames[frame].n_peaks; i++) 
        if(ana_frames[frame].peaks[i].track == k) {
	  sound->amp[k][frame] = ana_frames[frame].peaks[i].amp;
          sound->frq[k][frame] = ana_frames[frame].peaks[i].frq;
          sound->pha[k][frame] = ana_frames[frame].peaks[i].pha;
          sound->smr[k][frame] = ana_frames[frame].peaks[i].smr;
        }
    }
  }
  fprintf(stderr, "done!\n");
  /* free up ana_frames memory */
  /* first, free all peaks in each slot of ana_frames... */
  for (k=0; k<anargs->frames; k++) free(ana_frames[k].peaks);  
  /* ...then free ana_frames */
  free(ana_frames);                                            
  /* optimize sound */
  optimize_sound(anargs, sound);
  /* compute  residual */
  if( anargs->type == 3 || anargs->type == 4 ) {
    fprintf(stderr, "Computing residual...");
    compute_residual(bufs, sflen, resfile, sound, win_samps, anargs->srate);
    fprintf(stderr, "done!\n");
  }
  /* free the rest of the memory */
  free(win_samps);
  free(bufs[0]);
  free(bufs);
  /* analyze residual */
  if( anargs->type == 3 || anargs->type == 4 ) {
    fprintf(stderr, "Analyzing residual...");
    residual_analysis(ATSA_RES_FILE, sound);
    fprintf(stderr, "done!\n");
  }
#ifdef FFTW
  fftw_wisdom_file = fopen("ats-wisdom", "w");
  fftw_export_wisdom_to_file(fftw_wisdom_file);
  fclose(fftw_wisdom_file);
#endif
  fprintf(stderr, "tracking completed.\n");
  return(sound);
}
예제 #29
0
파일: main.c 프로젝트: metredigm/hunter
int main(int argc, char** argv) {
	init_core();
	debug_message("[hunter] initialized core");

	init_graphic();
	debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW)));

	init_sound();
	debug_message("[hunter] initialized sound");

	init_systems();
	debug_message("[hunter] initialized systems");

	window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW);
	input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT);
	syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER);
	text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT);
	hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER);
	shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE);
	camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA);
	debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW);

	float delta_ref_point = time_get_elapsed(window_handle);
	float delta_accumulator = 0.0f;
	float delta_frame_time = 0.0f;

	float fps_accumulator = 0.0f;
	float fps_value = 0.0f;
	float fps_value_last = fps_value;
	unsigned int fps_counter = 0;

	unsigned int game_kill_flag = 0;

	debug_message("[hunter] posting init event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_INIT);

	while (!game_kill_flag) {
		delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point;
		delta_ref_point = time_get_elapsed(window_handle);

		window_update(window_handle);

		input_state current_input_state;
		input_get_input_state(input_handle, &current_input_state);

		game_kill_flag |= window_get_should_close(window_handle);
		game_kill_flag |= current_input_state.key_dev;

		window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f);
		debug_draw_clear(debug_draw_handle);
		window_clear(window_handle);

		delta_accumulator += delta_frame_time;

		if (delta_accumulator < 0.0f) {
			delta_accumulator = 0.0f;
		}

		while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) {
			syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC);

			delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS;
		}

		syscontainer_post_event(syscontainer_handle, EVENT_DRAW);

		window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA);

		debug_draw_render_all(debug_draw_handle);

		hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle);
		hl_render_clear(hl_render_handle);

		fps_counter++;
		fps_accumulator += delta_frame_time;

		if (fps_accumulator >= 1.0f) {
			fps_value_last = fps_value;
			fps_value = (float) fps_counter / fps_accumulator;
			fps_counter = 0;
			fps_accumulator = 0.0f;
		}

		text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12};
		sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last);

		text_submit_batch(text_handle, &fps_batch);

		text_render_all(text_handle);
		text_flush_batch(text_handle);

		window_swap_buffers(window_handle);
	}

	debug_message("[hunter] posting destroy event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_DESTROY);

	free_systems();
	free_sound();
	free_graphic();
	free_core();

	h_free_all();

	debug_message("[hunter] terminated cleanly");
	return 0;
}
예제 #30
0
파일: project.c 프로젝트: kdvjap/Snake8515
/*
 * main -- Main program.
 */
int main(void) {
	uint8_t chars_into_escape_sequence = 0;
	int8_t moveStatus = 0;

	char c;

	/* Initialise our main clock */
	init_timer();

	/* Initialise serial I/O */
	init_serial_stdio(19200, 0);

	/* Make the display_row() function be called every 2ms.
	** (This function returns a timer number, but we ignore 
	** this since we'll never do anything with it.)
	*/
	execute_function_periodically(2, display_row);

	/* Register the time_increment() function to be called every 500ms.
	** This function just sets a variable (timePassedFlag).
	*/
	mainTimerNum = execute_function_periodically(500, time_increment);

	//4209435
	/* setup AVR to handle sounds*/
	init_sound();

	/*
	** Turn on interrupts (needed for timer and serial input/output to work)
	*/
	sei();
	
	/*
	** Display splash screen 
	*/
	splash_screen();
	show_instruction(NEWGAME);
	
	/*
	** Perform necessary initialisations for a new game.
	*/
	new_game();
		
	/*
	** Event loop - wait for a certain amount of time to pass or wait
	** for a character to arrive from standard input. The time_passed_flag
	** is set within the function time_increment() below - which is setup
	** to be called periodically.
	*/
	for(;;) {
		if(timePassedFlag) {
			moveStatus = move_snake();
			timePassedFlag = 0;
		} else if(input_available()) {
			/* Read the input from our terminal and handle it */
			c = fgetc(stdin);			
			if(chars_into_escape_sequence == 0 && c == '\x1b') {
				/*
				** Received ESCAPE character - we're one character into
				** an escape sequence
				*/
				chars_into_escape_sequence = 1;
			} else if(chars_into_escape_sequence == 1 && c == '[') {
				/* 
				** We're now two characters into an escape sequence
				*/
				chars_into_escape_sequence = 2;
			} else if (chars_into_escape_sequence == 2) {
				/* We're two characters into an escape sequence and
				** have received another - see if it is as expected.
				*/
				if (c == 'C') {
					/* Cursor right key pressed - Set next direction to
					** be moved to RIGHT */
					set_snake_dirn(RIGHT);
				}  
				if (c == 'D') {
					/* Cursor left key pressed - Set next direction to
					** be moved to LEFT */
					set_snake_dirn(LEFT);
				}  
				if (c == 'A') {
					/* Cursor up key pressed - Set next direction to
					** be moved to UP */
					set_snake_dirn(UP);
				}  
				if (c == 'B') {
					/* Cursor down key pressed - Set next direction to
					** be moved to DOWN */
					set_snake_dirn(DOWN);
				}

				/* else, unknown escape sequence */

				/* We're no longer part way through an escape sequence */
				chars_into_escape_sequence = 0; 
			} else if(chars_into_escape_sequence != 0) {
				/*
				** We started an escape sequence but didn't get a character
				** we recognised - discard it and assume that we're not
				** in an escape sequence.
				*/
				chars_into_escape_sequence = 0;
			} else if (c == ' ') {
				/* Space character received - move snake immediately */
				moveStatus = move_snake();
			} else {					
				if(c == 'N' || c == 'n'){	
					show_instruction(NEWGAME);				
					new_game();
				} else if(c == 'P' || c == 'p'){
					moveStatus = 0;
					pause_game();
				} else if(c == 'M' || c == 'm'){
					toggle_sound();
					display_sound_status();
				}
			}
		}

		switch(moveStatus){
			case ATE_FOOD:
				if(sound_status())
					play_sound();
				moveStatus = MOVE_OK;
				break;
		}

		if(moveStatus < 0) {
			/* Move failed - game over */
			handle_game_over();
			moveStatus = 0;
			update_score();
		}
	}
}