Exemple #1
0
int appInit(int argc, char **argv) {
    const char *opt;

    _flubAppCtx.launchedFromConsole = _appLaunchedFromConsole();

    if((opt = strrchr(argv[0], PLATFORM_PATH_SEP)) != NULL) {
        _flubAppCtx.progName = opt;
    } else {
        _flubAppCtx.progName = argv[0];
    }

    if((!logInit()) ||
            (!cmdlineInit(argc, argv)) ||
            (!flubSDLInit()) ||
            (!flubPhysfsInit(argv[0])) ||
            (!flubCfgInit()) ||
            (!videoInit()) ||
            (!texmgrInit()) ||
            (!flubFontInit()) ||
            (!gfxInit()) ||
            (!audioInit()) ||
            (!inputInit()) ||
            (!consoleInit()) ||
            (!flubGuiThemeInit())
      ) {
        return 0;
    }

    return 1;
}
Exemple #2
0
//**********************************************************************
//** SOUND
//**********************************************************************
//returns the number of samples the buffer can contain 
int PS3_initSound (void) {

	audioPortParam params;
	audioPortConfig config;

	audioInit();

	params.numChannels = AUDIO_CHANNEL_COUNT;
	params.numBlocks = AUDIO_BLOCK_COUNT;
	params.attrib = 0;
	params.level = 1;

	audioPortOpen(&params, &audio_port);


	audioGetPortConfig(audio_port, &config);
	audio_buffer = (float *)config.audioDataStart;
	audio_buffer_end = (float *)(config.audioDataStart + config.portSize);
	audio_read_index_addr = config.readIndex;

	audioPortStart(audio_port);
	portSize = config.portSize;
	audio_block_index = 0;
	//audio_last_read_block = -1;
	return config.portSize;

}
Exemple #3
0
int main() {
	
	//initialize all necessary sensors and utilities
	lcd_init();
	timer1_init();
	timer3_init();
	move_servo(90);
 	ADC_init();
	USART_Init(MYUBRR);
	init_push_buttons();
	
	oi_t *sensor_data = oi_alloc();
	oi_init(sensor_data);
	
	audioInit(sensor_data);
	//oi_play_song(1);
	
	while(1) {
		//empty currentObjects before proceeding by setting all stored objects to "invalid" - ignored by later checks
		for (int i = 0; i < 20; i++) {
			currentObjects[i].isValid = 0;
		}
		char received = serial_getc(); //take keyboard input from putty
		takeDirectionInput(received, currentObjects); //translate keyboard input into functionality
	}
	
	return 0;
}
Exemple #4
0
void EXPORT_THIS *d_init_partial(const char *data_dir) {
	if ((d = malloc(sizeof(DARNIT))) == NULL) {
		fprintf(stderr, "libDarnit: Error: Unable to malloc(%i)\n", (int) sizeof(DARNIT));
		return d;
	}

	tpw_init();

	d->platform.platform = 0;
	darnitSetPlatform(1);
	glColor4f(255, 255, 255, 255);
	d->video.tint_r = d->video.tint_g = d->video.tint_b = d->video.tint_a = 255;
	utilInit();

	if (inputInit() < 0);
	else if (audioInit() < 0);
	else if (socketInit() < 0);
	else {
		if (fsInit(data_dir) < 0)
			return NULL;
		return d;
	}

	free(d);
	return NULL;
}
Exemple #5
0
void initAudio(void) {
	
	audioInit();
	runScript(PATH_SCRIPTS, "audio.lua");
  /* probe for artpacks & songs */
  Sound_initTracks();
  Sound_setup();
}
Exemple #6
0
int main(int argc, char *argv[])
{
	displayInit(argc, argv);
	audioInit();
	fftwInit();
	textureInit();

	atexit(audioDeinit);
	atexit(fftwDeinit);
	atexit(textureDeinit);

	glutMainLoop();
	return 0;  /* Not reached. */
}
Exemple #7
0
static UINT32
sysInit(
	void
)
{
	/* board dependent modules */
	rtcInit();
	wdtInit();

	inputInit();

	audioInit();
	fmInit();
	lineBufferInit();
	graphicInit();
	scalarInit();
	if (strcmp(SYSCONFIG_PRODUCT, "gplus.microwindowsUI__gplus.evm32900b") != 0) {
		aesInit();
	}
	sdmaInit();
#ifdef SYSCONFIG_ARCH_SPMP8050
	rotatorInit();
#endif
#ifdef SYSCONFIG_ARCH_SPMP8050
	cevaInit();
#endif
	if( gp_ver.major == MACH_GPL32900 )
	{
		cevaInit();
	}
	
	storageInit();

	if (strcmp(SYSCONFIG_MAINSTORAGE, "gp_usb_disk")) {
		usbInit();
	}

	usbWifiInit();
    touchpanelInit();
#ifdef SYSCONFIG_SDIO
	system("modprobe cfg80211");
	system("modprobe mac80211");
	system("modprobe sunrpc");
#endif
	sensorInit();
	ppuInit();
	//tvInit();

	powerInit();
	batteryInit();
	gsensorInit();
	asensorInit();
#ifdef SYSCONFIG_GP_FAST_BOOT
	gpFastBootInit();
#endif /* SYSCONFIG_GP_FAST_BOOT */
	if( gp_ver.major == MACH_GPL32900B )
	{
		On2Init();
		LBPInit();
	}

	return SP_OK;
}
Exemple #8
0
int main(int argc, char *argv[]) {
	SDL_TimerID tim;
	hesloindex = 0;
	heslo[0] = 0;
	aktualnaScena = 0;
	done = 1;
	loadScena(aktualnaScena);
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { printf("init error: %s\n", SDL_GetError()); exit(1); }
	//screen = SDL_SetVideoMode(640, 384, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	screen = SDL_SetVideoMode(640, 384, 24, SDL_HWSURFACE);
	loko = IMG_Load(RESPATH"img/loko.png");
	lokobum = IMG_Load(RESPATH"img/loko-bum.png");
	stena = IMG_Load(RESPATH"img/stena.png");
	vrata = IMG_Load(RESPATH"img/vrata.png");
	vecivagony = IMG_Load(RESPATH"img/veci-vagony.png");
	printf("loko: %d %d\n", (int)loko->w, (int)loko->h);
	audioInit();
	LoadSound(0, RESPATH"sounds/loko.wav");
	LoadSound(1, RESPATH"sounds/bell.wav");
	LoadSound(2, RESPATH"sounds/horn.wav");
	LoadSound(3, RESPATH"sounds/crash.wav");
	LoadSound(4, RESPATH"sounds/vagon.wav");
	SDL_ShowCursor(SDL_DISABLE);
	tim = SDL_AddTimer(150, timCallBack, NULL);
	int keyantirepeat = 1;
	while(done){
		SDL_PollEvent(&event);
		if (event.type == SDL_KEYDOWN) {
			switch (event.key.keysym.sym) {
				case SDLK_ESCAPE :
					done = 0;
					break;
				case SDLK_RIGHT :
					direction = RIGHT;
					break;
				case SDLK_UP :
					direction = UP;
					break;
				case SDLK_LEFT :
					direction = LEFT;
					break;
				case SDLK_DOWN :
					direction = DOWN;
					break;
				case SDLK_RETURN :
				case SDLK_SPACE :
					if (hesloindex) {
						int i;
						for (i = 0; i < 50; i++) {
							if(strncmp(heslo, hesla[i], 5) == 0) {
								aktualnaScena = i + 1;
								loadScena(aktualnaScena);
							}
						}
						hesloindex = 0;
						heslo[hesloindex] = 0;
					} else if (kolook && (aktualnaScena < 50)) {
						loadScena(++aktualnaScena);
					} else {
						loadScena(aktualnaScena);
					}
					
					break;
				case SDLK_BACKSPACE :
					heslo[--hesloindex] = 0;
					break;
				default :
					if ((event.key.keysym.sym >= 'a') && (event.key.keysym.sym <= 'z') && keyantirepeat) {
						keyantirepeat = 0;
						if (hesloindex >= 5) {
							//over heslo
							hesloindex = 0;
							heslo[hesloindex] = 0;
						}
						heslo[hesloindex++] = (unsigned char)event.key.keysym.sym - 'a' + 'A';
						heslo[hesloindex] = 0;
					}
					break;
			}
		} else if (event.type == SDL_KEYUP) {
			keyantirepeat = 1;
		} else if (event.type == SDL_QUIT) {
			done = 0;
		}
		if (onTime) {
			onTime = 0;
			if (++anim >= 3) anim = 0;
			if (vrataanim && vrataanim < 5) vrataanim++;
			if (lokobumanim < 100) {
				lokobumanim++;
				if (lokobumanim == 10) lokobumanim = 7;
			} else {
				if (!anim) if (!kolook) control();
			}
			draw(screen);
		} else {
			SDL_Delay(50);
		}
	}
	SDL_RemoveTimer(tim);
	SDL_CloseAudio();
	SDL_Quit();
	return 0;
}
Exemple #9
0
////////////////////////////////////////////////////////////////////////////////
// SIGNAL
////////////////////////////////////////////////////////////////////////////////
void signalInit() {
	audioInit();
	goertzelInit();
}
static int
PSL1GHT_AUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
    deprintf( "PSL1GHT_AUD_OpenDevice(%08X.%08X, %s, %d)\n", SHW64(this), devname, iscapture);
    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
    int valid_datatype = 0;

    this->hidden = SDL_malloc(sizeof(*(this->hidden)));
    if (!this->hidden) {
        SDL_OutOfMemory();
        return 0;
    }
    SDL_memset(this->hidden, 0, (sizeof *this->hidden));


    // PS3 Libaudio only handles floats
    while ((!valid_datatype) && (test_format)) {
        this->spec.format = test_format;
        switch (test_format) {
        case AUDIO_F32MSB:
            valid_datatype = 1;
            break;
        default:
            test_format = SDL_NextAudioFormat();
            break;
        }
    }

    int ret=audioInit();

    //set some parameters we want
    //either 2 or 8 channel
    _params.numChannels = AUDIO_PORT_2CH;
    //8 16 or 32 block buffer
    _params.numBlocks = AUDIO_BLOCK_8;
    //extended attributes
    _params.attrib = 0;
    //sound level (1 is default)
    _params.level = 1;

    ret=audioPortOpen(&_params, &_portNum);
    deprintf("audioPortOpen: %d\n",ret);
    deprintf("  portNum: %d\n",_portNum);

    ret=audioGetPortConfig(_portNum, &_config);
    deprintf("audioGetPortConfig: %d\n",ret);
    deprintf("  readIndex: 0x%8X\n",_config.readIndex);
    deprintf("  status: %d\n",_config.status);
    deprintf("  channelCount: %ld\n",_config.channelCount);
    deprintf("  numBlocks: %ld\n",_config.numBlocks);
    deprintf("  portSize: %d\n",_config.portSize);
    deprintf("  audioDataStart: 0x%8X\n",_config.audioDataStart);

    // create an event queue that will tell when a block is read
    ret=audioCreateNotifyEventQueue( &_snd_queue, &_snd_queue_key);
    printf("audioCreateNotifyEventQueue: %d\n",ret);

    // Set it to the sprx
    ret = audioSetNotifyEventQueue(_snd_queue_key);
    printf("audioSetNotifyEventQueue: %d\n",ret);

    // clears the event queue
    ret = sysEventQueueDrain(_snd_queue);
    printf("sysEentQueueDrain: %d\n",ret);

    ret=audioPortStart(_portNum);
    deprintf("audioPortStart: %d\n",ret);

    _last_filled_buf = _config.numBlocks - 1;

    this->spec.format = test_format;
    this->spec.size = sizeof(float) * AUDIO_BLOCK_SAMPLES * _config.channelCount;
    this->spec.freq = 48000;
    this->spec.samples = AUDIO_BLOCK_SAMPLES;
    this->spec.channels = _config.channelCount;

    return ret == 0;
}
Exemple #11
0
void JSoundSystem::InitSoundSystem()
{

	audioInit();
	
}
void Parse_options(int *argcp, char **argvp, char *realName, char *host,
		   int *port, int *my_team, int *list, int *join, int *motd,
		   char *nickName, char *dispName, char *shut_msg)
{
    int			i,
			j,
			firstKeyDef,
			num;
    keys_t		key;
    KeySym		ks;
    char		*ptr,
			*str,
			*myName = "xpilot",
			*myClass = "XPilot",
			resValue[MAX_CHARS];
    XrmDatabase		argDB, rDB;

    XrmInitialize();

    argDB = 0;
    XrmParseCommand(&argDB, opts, NELEM(opts), myName, argcp, argvp);

    /*
     * Check for bad arguments.
     */
    for (i = 1; i < *argcp; i++) {
	if (argvp[i][0] == '-') {
	    errno = 0;
	    error("Unknown option '%s'", argvp[i]);
	    error("Type: %s -help to see a list of options", argvp[0]);
	    exit(1);
	}
    }

    if (Get_resource(argDB, myName, myClass, "help", NULL, resValue,
		     sizeof resValue) != 0) {
	Usage();
    }

    if (Get_resource(argDB, myName, myClass, "version", NULL, resValue,
		     sizeof resValue) != 0) {
	puts(TITLE);
	exit(0);
    }

    Get_resource(argDB, myName, myClass, "shutdown", "", shut_msg,
		 MAX_CHARS);

    if (Get_string_resource(argDB, myName, myClass, "display", NULL, dispName,
			    MAX_DISP_LEN) == 0
	|| dispName[0] == '\0') {
#ifdef VMS
	if ((ptr = getenv("DECW$DISPLAY")) != NULL) {
#else
	if ((ptr = getenv("DISPLAY")) != NULL) {
#endif
	    strncpy(dispName, ptr, MAX_DISP_LEN);
	    dispName[MAX_DISP_LEN - 1] = '\0';
	} else {
#ifdef VMS
	    strcpy(dispName, "::0.0");
	    sprintf(dispName, "%s::0.0", host);
#else
	    strcpy(dispName, ":0.0");
#endif
	}
    }
    if ((dpy = XOpenDisplay(dispName)) == NULL) {
	error("Can't open display '%s'", dispName);
	exit(1);
    }
    Get_resource(argDB, myName, myClass, "visual", "",
		 visualName, sizeof visualName);
    if (strncasecmp(visualName, "list", 4) == 0) {
	List_visuals();
	exit(0);
    }

    Get_file_defaults(&rDB, myName, myClass);

    XrmMergeDatabases(argDB, &rDB);

    Get_string_resource(rDB, myName, myClass, "geometry", "", resValue,
			sizeof resValue);
    geometry = strdup(resValue);

    Get_resource(rDB, myName, myClass, "name", realName, nickName,
		 MAX_NAME_LEN);
    CAP_LETTER(nickName[0]);
    if (nickName[0] < 'A' || nickName[0] > 'Z') {
	errno = 0;
	error("Your player name \"%s\" should start with an uppercase letter",
	    nickName);
	exit(1);
    }
    strncpy(realname, realName, sizeof(realname) - 1);
    strncpy(name, nickName, sizeof(name) - 1);

    Get_int_resource(rDB, myName, myClass, "team", TEAM_NOT_SET, my_team);
    if (*my_team < 0 || *my_team > 9) {
	*my_team = TEAM_NOT_SET;
    }
    team = *my_team;
    Get_int_resource(rDB, myName, myClass, "port", SERVER_PORT, port);
    Get_bool_resource(rDB, myName, myClass, "list", "False", list);
    Get_bool_resource(rDB, myName, myClass, "join", "False", join);
    Get_bool_resource(rDB, myName, myClass, "motd", "True", motd);

    Get_float_resource(rDB, myName, myClass, "power", 45.0, &power);
    Get_float_resource(rDB, myName, myClass, "turnSpeed", 35.0, &turnspeed);
    Get_float_resource(rDB, myName, myClass, "turnResistance", 0.12,
		       &turnresistance);
    Get_float_resource(rDB, myName, myClass, "altPower", 35.0, &power_s);
    Get_float_resource(rDB, myName, myClass, "altTurnSpeed", 25.0,
		       &turnspeed_s);
    Get_float_resource(rDB, myName, myClass, "altTurnResistance", 0.12,
		       &turnresistance_s);
    Get_float_resource(rDB, myName, myClass, "sparkProb", 0.50,
		       &spark_prob);
    spark_rand = (int)(spark_prob * MAX_SPARK_RAND + 0.5f);
    Get_int_resource(rDB, myName, myClass, "charsPerSecond", 50,
		     &charsPerSecond);
    Get_bool_resource(rDB, myName, myClass, "markingLights", "True", &i);
    markingLights = (i == false) ? false : true;

    Get_int_resource(rDB, myName, myClass, "backgroundPointDist", 8,
		     &map_point_distance);
    Get_int_resource(rDB, myName, myClass, "backgroundPointSize",
		     DEF_MAP_POINT_SIZE, &map_point_size);
    LIMIT(map_point_size, MIN_MAP_POINT_SIZE, MAX_MAP_POINT_SIZE);
    Get_int_resource(rDB, myName, myClass, "sparkSize",
		     DEF_SPARK_SIZE, &spark_size);
    LIMIT(spark_size, MIN_SPARK_SIZE, MAX_SPARK_SIZE);

    Get_resource(rDB, myName, myClass, "visual", "",
		 visualName, sizeof visualName);
    Get_bool_resource(rDB, myName, myClass, "mono", "False", &i);
    mono = (i != 0) ? true : false;
    Get_bool_resource(rDB, myName, myClass, "colorSwitch", "True", &i);
    colorSwitch = (i != 0) ? true : false;
    Get_int_resource(rDB, myName, myClass, "maxColors", 4,
		     &maxColors);
    Get_string_resource(rDB, myName, myClass, "black", "",
			color_names[BLACK], sizeof(color_names[BLACK]));
    Get_string_resource(rDB, myName, myClass, "white", "",
			color_names[WHITE], sizeof(color_names[WHITE]));
    Get_string_resource(rDB, myName, myClass, "blue", "",
			color_names[BLUE], sizeof(color_names[BLUE]));
    Get_string_resource(rDB, myName, myClass, "red", "",
			color_names[RED], sizeof(color_names[RED]));
    for (i = 0; i < MAX_COLORS; i++) {
	char buf[8], def[MAX_COLOR_LEN];
	sprintf(buf, "color%d", i);
	strcpy(def, (i < NUM_COLORS) ? color_names[i] : "");
	Get_string_resource(rDB, myName, myClass, buf, def,
			    color_names[i], sizeof(color_names[i]));
    }

    instruments = 0;
    Get_bool_resource(rDB, myName, myClass, "showShipName", "True", &i);
    if (i) {
	SET_BIT(instruments, SHOW_SHIP_NAME);
    }
    Get_bool_resource(rDB, myName, myClass, "showHUD", "True", &i);
    if (i) {
	SET_BIT(instruments, SHOW_HUD_INSTRUMENTS);
    }
    Get_bool_resource(rDB, myName, myClass, "verticalHUDLine", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_HUD_VERTICAL);
    }
    Get_bool_resource(rDB, myName, myClass, "horizontalHUDLine", "True", &i);
    if (i) {
	SET_BIT(instruments, SHOW_HUD_HORIZONTAL);
    }
    Get_bool_resource(rDB, myName, myClass, "fuelMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_FUEL_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "fuelGauge", "True", &i);
    if (i) {
	SET_BIT(instruments, SHOW_FUEL_GAUGE);
    }
    Get_bool_resource(rDB, myName, myClass, "turnSpeedMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_TURNSPEED_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "powerMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_POWER_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "packetSizeMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_PACKET_SIZE_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "packetLossMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_PACKET_LOSS_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "packetDropMeter", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_PACKET_DROP_METER);
    }
    Get_bool_resource(rDB, myName, myClass, "slidingRadar", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_SLIDING_RADAR);
    }
    Get_bool_resource(rDB, myName, myClass, "outlineWorld", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_OUTLINE_WORLD);
    }
    Get_bool_resource(rDB, myName, myClass, "clock", "False", &i);
    if (i) {
	SET_BIT(instruments, SHOW_CLOCK);
    }

    Get_float_resource(rDB, myName, myClass, "speedFactHUD", 0.0,
		       &hud_move_fact);
    Get_float_resource(rDB, myName, myClass, "speedFactPTR", 0.0,
		       &ptr_move_fact);
    Get_int_resource(rDB, myName, myClass, "fuelNotify", 500, &fuelLevel3);
    Get_int_resource(rDB, myName, myClass, "fuelWarning", 200, &fuelLevel2);
    Get_int_resource(rDB, myName, myClass, "fuelCritical", 100, &fuelLevel1);

    Get_resource(rDB, myName, myClass, "gameFont", GAME_FONT,
		 gameFontName, sizeof gameFontName);
    Get_resource(rDB, myName, myClass, "messageFont", MESSAGE_FONT,
		 messageFontName, sizeof messageFontName);
    Get_resource(rDB, myName, myClass, "scoreListFont", SCORE_LIST_FONT,
		 scoreListFontName, sizeof scoreListFontName);
    Get_resource(rDB, myName, myClass, "buttonFont", BUTTON_FONT,
		 buttonFontName, sizeof buttonFontName);
    Get_resource(rDB, myName, myClass, "textFont", TEXT_FONT,
		 textFontName, sizeof textFontName);
    Get_resource(rDB, myName, myClass, "talkFont", TALK_FONT,
		 talkFontName, sizeof talkFontName);

    Get_int_resource(rDB, myName, myClass, "receiveWindowSize",
		     DEF_RECEIVE_WINDOW_SIZE, &receive_window_size);
    LIMIT(receive_window_size, MIN_RECEIVE_WINDOW_SIZE,
	  MAX_RECEIVE_WINDOW_SIZE);

#ifdef SOUND
    Get_string_resource(rDB, myName, myClass, "sounds", SOUNDFILE, sounds,
			sizeof sounds);

    Get_int_resource(rDB, myName, myClass, "maxVolume", 100, &maxVolume);

    Get_resource(rDB, myName, myClass, "audioServer", NULL, audioServer,
		 sizeof audioServer);
#endif

    Get_bool_resource(rDB, myName, myClass, "toggleShield", "False",
		      &toggle_shield);

    /*
     * Key bindings
     */
    maxKeyDefs = 2 * NUM_KEYS;
    if ((keyDefs = (keydefs_t *)
	malloc(maxKeyDefs * sizeof(keydefs_t))) == NULL) {
	error("No memory for key bindings");
	exit(1);
    }
    num = 0;
    for (i = 0; i < NELEM(keyResources); i++) {
	key = keyResources[i].key;
	Get_resource(rDB, myName, myClass,
		     keyResources[i].resource, keyResources[i].fallback,
		     resValue, sizeof resValue);

	firstKeyDef = num;
	for (str = strtok(resValue, " \t\r\n");
	    str != NULL;
	    str = strtok(NULL, " \t\r\n")) {

	    if ((ks = XStringToKeysym(str)) == NoSymbol) {
		printf("\"%s\" is not a valid keysym.\n", str);
		continue;
	    }

	    for (j = firstKeyDef; j < num; j++) {
		if (keyDefs[j].keysym == ks
		    && keyDefs[j].key == key) {
		    break;
		}
	    }
	    if (j < num) {
		continue;
	    }
	    if (num >= maxKeyDefs) {
		maxKeyDefs += NUM_KEYS;
		if ((keyDefs = (keydefs_t *)
		    realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t)))
		    == NULL) {
		    error("No memory for key bindings");
		    exit(1);
		}
	    }

	    keyDefs[num].keysym = ks;
	    keyDefs[num].key = key;
	    num++;
	}
    }
    if (num < maxKeyDefs) {
	maxKeyDefs = num;
	if ((keyDefs = (keydefs_t *)
	    realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t))) == NULL) {
	    error("No memory for key bindings");
	    exit(1);
	}
    }

    XrmDestroyDatabase(rDB);

#ifdef SOUND
    audioInit(dispName);
#endif /* SOUND */
}
Exemple #13
0
int main(int argc, char **argv) {
    gfxInitDefault();

    PrintConsole botScreen;
    PrintConsole topScreen;

    consoleInit(GFX_TOP, &topScreen);
    consoleInit(GFX_BOTTOM, &botScreen);
    consoleSelect(&topScreen);

    constexpr size_t NUM_SAMPLES = 160*200;
    u32 *audio_buffer = (u32*)linearAlloc(NUM_SAMPLES * sizeof(u32));
    fillBuffer(audio_buffer, NUM_SAMPLES);

    AudioState state;
    {
        auto dspfirm = loadDspFirmFromFile();
        if (!dspfirm) {
            printf("Couldn't load firmware\n");
            goto end;
        }
        auto ret = audioInit(*dspfirm);
        if (!ret) {
            printf("Couldn't init audio\n");
            goto end;
        }
        state = *ret;
    }

    state.waitForSync();
    initSharedMem(state);
    state.write().dsp_configuration->mixer1_enabled_dirty = true;
    state.write().dsp_configuration->mixer1_enabled = true;
    //state.write().dsp_configuration->limiter_enabled = 1;
    state.notifyDsp();
    printf("init\n");

    state.waitForSync();
    state.notifyDsp();
    state.waitForSync();
    for (auto& gain : state.write().source_configurations->config[0].gain) {
        for (auto& g : gain) {
            g = 0.0;
        }
    }
    state.write().source_configurations->config[0].gain[0][0] = 1.0;
    state.write().source_configurations->config[0].gain[1][0] = 1.0;
    state.write().source_configurations->config[0].gain[1][1] = 0.5;
    state.write().source_configurations->config[0].gain_1_dirty = true;
    state.notifyDsp();
    state.waitForSync();
    state.notifyDsp();
    state.waitForSync();
    state.notifyDsp();

    {
        while (true) {
            state.waitForSync();
            printf("sync = %i, play = %i, cbi = %i\n", state.read().source_statuses->status[0].sync, state.read().source_statuses->status[0].is_enabled, state.read().source_statuses->status[0].current_buffer_id);
            if (state.read().source_statuses->status[0].sync == 1) break;
            state.notifyDsp();
        }
        printf("fi: %i\n", state.frame_id);

        u16 buffer_id = 0;
        //unsigned next_queue_position = 0;

        state.write().source_configurations->config[0].play_position = 0;
        state.write().source_configurations->config[0].physical_address = osConvertVirtToPhys(audio_buffer);
        state.write().source_configurations->config[0].length = NUM_SAMPLES;
        state.write().source_configurations->config[0].mono_or_stereo = DSP::HLE::SourceConfiguration::Configuration::MonoOrStereo::Stereo;
        state.write().source_configurations->config[0].format = DSP::HLE::SourceConfiguration::Configuration::Format::PCM16;
        state.write().source_configurations->config[0].fade_in = false;
        state.write().source_configurations->config[0].adpcm_dirty = false;
        state.write().source_configurations->config[0].is_looping = false;
        state.write().source_configurations->config[0].buffer_id = ++buffer_id;
        state.write().source_configurations->config[0].partial_reset_flag = true;
        state.write().source_configurations->config[0].play_position_dirty = true;
        state.write().source_configurations->config[0].embedded_buffer_dirty = true;

        state.write().source_configurations->config[0].enable = true;
        state.write().source_configurations->config[0].enable_dirty = true;

        state.notifyDsp();

        bool continue_reading = true;
        for (size_t frame_count = 0; continue_reading; frame_count++) {
            state.waitForSync();

            if (state.read().source_statuses->status[0].current_buffer_id) {
                printf("%i cbi = %i\n", frame_count, state.read().source_statuses->status[0].current_buffer_id);
            }

            for (size_t i = 0; i < 160; i++) {
                if (state.write().intermediate_mix_samples->mix1.pcm32[0][i]) {
                    printf("[intermediate] frame=%i, sample=%i\n", frame_count, i);
                    for (size_t j = 0; j < 20; j++) {
                        printf("%08lx ", (u32)state.write().intermediate_mix_samples->mix1.pcm32[0][j]);
                    }
                    printf("\n");
                    break;
                }
            }

            for (size_t i = 0; i < 160 * 2; i++) {
                if (state.read().final_samples->pcm16[i]) {
                    printf("[final] frame=%i, sample=%i\n", frame_count, i);
                    for (size_t j = 0; j < 20; j++) {
                        printf("%04x ", (u16)state.read().final_samples->pcm16[j]);
                    }
                    printf("\n");
                    continue_reading = false;
                    break;
                }
            }

            state.notifyDsp();
        }

        state.waitForSync();
        state.write().source_configurations->config[0].sync = 2;
        state.write().source_configurations->config[0].sync_dirty = true;
        state.notifyDsp();

        while (true) {
            state.waitForSync();
            printf("sync = %i, play = %i\n", state.read().source_statuses->status[0].sync, state.read().source_statuses->status[0].is_enabled);
            if (state.read().source_statuses->status[0].sync == 2) break;
            state.notifyDsp();
        }
        state.notifyDsp();

        printf("Done!\n");
    }

end:
    audioExit(state);
    waitForKey();
    gfxExit();
    return 0;
}
Exemple #14
0
int main(int argc,char *argv[])
{
	u32 portNum,i;
	audioPortParam params;
	audioPortConfig config;

	s32 ret = audioInit();

	printf("audioInit: %08x\n",ret);

	params.numChannels = AUDIO_PORT_2CH;
	params.numBlocks = AUDIO_BLOCK_8;
	params.attrib = 0x1000;
	params.level = 1.0f;
	ret = audioPortOpen(&params,&portNum);
	printf("audioPortOpen: %08x\n",ret);
	printf("      portNum: %d\n",portNum);

	ret = audioGetPortConfig(portNum,&config);
	printf("audioGetPortConfig: %08x\n",ret);
	printf("config.readIndex: %08x\n",config.readIndex);
	printf("config.status: %d\n",config.status);
	printf("config.channelCount: %ld\n",config.channelCount);
	printf("config.numBlocks: %ld\n",config.numBlocks);
	printf("config.portSize: %d\n",config.portSize);
	printf("config.audioDataStart: %08x\n",config.audioDataStart);

	ret = audioCreateNotifyEventQueue(&snd_queue,&snd_key);
	printf("audioCreateNotifyEventQueue: %08x\n",ret);
	printf("snd_queue: %16lx\n",(long unsigned int)snd_queue);
	printf("snd_key: %16lx\n",snd_key);

	ret = audioSetNotifyEventQueue(snd_key);
	printf("audioSetNotifyEventQueue: %08x\n",ret);

	ret = sysEventQueueDrain(snd_queue);
	printf("sysEventQueueDrain: %08x\n",ret);

	ret = audioPortStart(portNum);
	printf("audioPortStart: %08x\n",ret);

	i = 0;
	while(i<1000) {
		playOneBlock(&config);
		i++;
	}

	ret = audioPortStop(portNum);
	printf("audioPortStop: %08x\n",ret);

	ret = audioRemoveNotifyEventQueue(snd_key);
	printf("audioRemoveNotifyEventQueue: %08x\n",ret);

	ret = audioPortClose(portNum);
	printf("audioPortClose: %08x\n",ret);

	ret = sysEventQueueDestroy(snd_queue,0);
	printf("sysEventQueueDestroy: %08x\n",ret);

	ret = audioQuit();
	printf("audioQuit: %08x\n",ret);

	return 0;
}
Exemple #15
0
static int
ps3_audio_start(audio_mode_t *am, audio_fifo_t *af)
{
  prop_sub_t *s_vol;
  audio_buf_t *ab;

  u32 port_num;

  AudioPortConfig config;

  int ret;
  int cur_channels = 0;
  int running = 0;

  sys_event_queue_t snd_queue;
  u64 snd_queue_key;
  int achannels = 0;

  if(audioInit())
    return -1;

  s_vol = prop_subscribe(PROP_SUB_DIRECT_UPDATE,
			 PROP_TAG_CALLBACK_FLOAT, set_mastervol, NULL,
			 PROP_TAG_ROOT, prop_mastervol,
			 NULL);

  TRACE(TRACE_DEBUG, "AUDIO", "PS3 audio system initialized");

  while(1) {
    ab = af_deq2(af, !running, am);
    if(ab == AF_EXIT) {
      ab = NULL;
      break;
    }

    if(ab != NULL) {

      if(ab->ab_channels != cur_channels) {
      
	if(running) {
	  audioPortStop(port_num);
	  audioRemoveNotifyEventQueue(snd_queue_key);
	  audioPortClose(port_num);
	  sys_event_queue_destroy(snd_queue, 0);
	  running = 0;
	}

	cur_channels = ab->ab_channels;

	AudioOutConfiguration conf;
	memset(&conf, 0, sizeof(conf));

	switch(cur_channels) {
	case 2:
	  achannels = 2;
	  conf.channel = 2;
	  conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM;
	  break;

	case 6:
	  achannels = 8;
	  if(max_pcm >= 6) {
	    conf.channel = 6;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM;
	  } else if(max_dts == 6) {
	    conf.channel = 6;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_DTS;
	  } else if(max_ac3 == 6) {
	    conf.channel = 6;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_AC3;
	  } else {
	    conf.channel = 2;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM;
	    conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_A;
	  }
	  break;

	case 7:
	case 8:
	  achannels = 8;
	  if(max_pcm == 8) {
	    conf.channel = 8;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM;
	  } else if(max_dts == 6) {
	    conf.channel = 6;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_DTS;
	    conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_B;
	  } else if(max_ac3 == 6) {
	    conf.channel = 6;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_AC3;
	    conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_B;
	  } else {
	    conf.channel = 2;
	    conf.encoder = AUDIO_OUT_CODING_TYPE_LPCM;
	    conf.down_mixer = AUDIO_OUT_DOWNMIXER_TYPE_A;
	  }
	  break;
	}



	int r;
	r = audioOutConfigure(AUDIO_OUT_PRIMARY, &conf, NULL, 1);
	if(r == 0) {
	  int i;
	  for(i = 0; i < 100;i++) {
	    AudioOutState state;
	    r = audioOutGetState(AUDIO_OUT_PRIMARY, 0, &state );
	    if(r != 0)
	      break;
	    TRACE(TRACE_DEBUG, "AUDIO", "The state is %d", state.state);
	    if(state.state == 2)
	      continue;
	    usleep(100);
	    break;
	  }
	}

	AudioPortParam params;

	params.numChannels = achannels;
	params.numBlocks = AUDIO_BLOCK_8;
	params.attr = 0;
	params.level = 1;
	
	ret = audioPortOpen(&params, &port_num);

	TRACE(TRACE_DEBUG, "AUDIO", "PS3 audio port %d opened", port_num);
	
	audioGetPortConfig(port_num, &config);
	audioCreateNotifyEventQueue(&snd_queue, &snd_queue_key);
	audioSetNotifyEventQueue(snd_queue_key);
	sys_event_queue_drain(snd_queue);
	audioPortStart(port_num);
	
	running = 1;
      }
    }
    
    playOneBlock((u64*)(u64)config.readIndex,
		 (float*)(u64)config.audioDataStart,
		 am, ab, snd_queue, achannels);

    
    if(ab != NULL)
      ab_free(ab);
  }
  TRACE(TRACE_DEBUG, "AUDIO", "leaving the loop");

  if(running) {
    audioPortStop(port_num);
    audioRemoveNotifyEventQueue(snd_queue_key);
    audioPortClose(port_num);
    sys_event_queue_destroy(snd_queue, 0);
  }

  audioQuit();
  prop_unsubscribe(s_vol);
  return 0;
}
    void Application::init(const string &name) {
        if(glfwInit() == GL_FALSE) {
            throw runtime_error("Could not initialize GLFW");
        }
        
        vector<int> hint {
            GLFW_CONTEXT_VERSION_MAJOR, 3,
            GLFW_CONTEXT_VERSION_MINOR, 2,
            GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE,
            GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE,
            GLFW_DEPTH_BITS, 16,
            GLFW_SAMPLES, 4, 
            GLFW_REFRESH_RATE, 60,
        };
        
        for (size_t h = 0; h < hint.size(); h += 2)
            glfwWindowHint(hint[h], hint[h+1]);
        
        ivec2 size(640, 480);
        
        m_window = glfwCreateWindow(size.x, size.y, name.c_str(), nullptr, nullptr);
        
        if (!m_window) {
            throw runtime_error("OpenGL initialization failed, invalid window hints");
        }
        
        glfwMakeContextCurrent(m_window);
        
#ifndef EMSCRIPTEN
        if(gl3wInit()) {
            throw runtime_error("failed to initialize gl3w");
        }
        
        FMOD_RESULT result = FMOD::System_Create(&m_audio);
        checkError(result);
        result = m_audio->init(100, FMOD_INIT_NORMAL, nullptr);
        checkError(result);
        
        printf("ApplicationPath: %s\n", getApplicationPath()->c_str());
        printf("ResourcePath: %s\n", getResourcePath()->c_str());
#else
        audioInit();
#endif

        // shader test
        auto handleVertex = glCreateShader(GL_VERTEX_SHADER);
        auto handleFragment = glCreateShader(GL_FRAGMENT_SHADER);
        
        string sourceVertexStr = "#version 150\n in vec3 a_pos; void main() { }";
        string sourceFragmentStr = "#version 150\n in vec3 a_pos; out vec4 o_fragColor; void main() { o_fragColor = vec4(1, 0, 1, 1); }";
        
        const GLchar *sv = sourceVertexStr.c_str();
        const GLchar *sf = sourceVertexStr.c_str();

        auto check = [](GLuint handle) {
            GLint status;
            glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
            if (status == GL_FALSE) {
                GLint logLength;
                glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &logLength);
                
                GLchar *logStr = new GLchar[logLength + 1];
                glGetShaderInfoLog(handle, logLength, nullptr, logStr);
                
                fprintf(stderr, "Shader compiler error:\n%s\n", logStr);
                delete[] logStr;
            }
        };
        
        glShaderSource(handleVertex, 1, &sv, nullptr);
        glShaderSource(handleFragment, 1, &sf, nullptr);
        
        glCompileShader(handleVertex);
        check(handleVertex);
        glCompileShader(handleFragment);
        check(handleFragment);
        
        GLint status;
        
        auto handleProgram = glCreateProgram();
        
        glAttachShader(handleProgram, handleVertex);
        glAttachShader(handleProgram, handleFragment);
        
        glLinkProgram(handleProgram);
    
        glGetProgramiv(handleProgram, GL_LINK_STATUS, &status);
        
        if (status == GL_FALSE) {
            GLint logLength;
            glGetProgramiv(handleProgram, GL_INFO_LOG_LENGTH, &logLength);
            
            GLchar *logStr = new GLchar[logLength + 1];
            glGetProgramInfoLog(handleProgram, logLength, nullptr, logStr);
            
            fprintf(stderr, "Linker error:\n%s\n", logStr);
            delete[] logStr;
            return;
        }
        
        glDetachShader(handleProgram, handleVertex);
        glDetachShader(handleProgram, handleFragment);
    }
Exemple #17
0
void boardInit()
{
  RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE);
  RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph, ENABLE);
  RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph, ENABLE);

#if !defined(REV9E)
  // some REV9E boards need that the pwrInit() is moved a little bit later
  pwrInit();
#endif

  keysInit();
  adcInit();
  delaysInit();
  lcdInit();    // delaysInit() must be called before
  audioInit();
  init2MhzTimer();
  init5msTimer();
  __enable_irq();
  i2cInit();
  usbInit();
  
#if defined(HAPTIC)  
  hapticInit();
#endif

#if defined(REV9E)
  bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif

#if defined(DEBUG)
  DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif

#if defined(REV9E)
  if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
    lcd_clear();
    lcd_bmp(76, 2, bmp_lock, 0, 60);
    lcdRefresh();
    lcdRefreshWait();

    tmr10ms_t start = get_tmr10ms();
    tmr10ms_t duration = 0;
    uint8_t pwr_on = 0;
    while (pwrPressed()) {
      duration = get_tmr10ms() - start;
      if (duration < PWR_PRESS_DURATION_MIN) {
        unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4);
        lcd_clear();
        lcd_bmp(76, 2, bmp_startup, index*60, 60);
      }
      else if (duration >= PWR_PRESS_DURATION_MAX) {
        displaySleepBitmap();
        turnBacklightOff();
      }
      else {
        if (pwr_on != 1) {
          pwr_on = 1;
          pwrInit();
          backlightInit();
          haptic.play(15, 3, PLAY_NOW);
        }
      }
      lcdRefresh();
      lcdRefreshWait();
    }
    if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
      boardOff();
    }
  }
  else {
    pwrInit();
    backlightInit();
  }
  topLcdInit();
#else
  backlightInit();
#endif
}