void audio_init(void) { vs_rst(1); delay_m(100); vs_spi_open(); delay_m(200); audio_reset(); delay_m(50); AUDIO_FIFO_INIT(); //audio_sin_test(); vs_vol=DEFAULT_VOLUME; vs_sbamp=DEFAULT_BASSAMP; vs_sbfreq=DEFAULT_BASSFREQ; vs_stamp=DEFAULT_TREBLEAMP; vs_stfreq=DEFAULT_TREBLEFREQ; audio_set_volume(vs_vol); vs_setbassfreq(vs_sbfreq); vs_setbassamp(vs_sbamp); vs_settreblefreq(vs_stfreq); vs_settrebleamp(vs_stamp); }
int audio_play_start(void) { audio_soft_reset(); audio_set_volume(vs_vol); vs_spi_clk_data(); return 0; }
/** * Handles the 'value-changed' signal on the GtkRange 'vol_scale', * changing the voume accordingly. * * There are many ways for the user to change the slider value. * Think about testing them all if you touch this function. * Here's a list of actions you can do to trigger this callback: * - click somewhere on the slider * - click on the slider's knob and drag it * - mouse scroll on the slider * - keyboard (when the slider has focus), here's a list of keys: * Up, Down, Left, Right, Page Up, Page Down, Home, End * * @param range the GtkRange that received the signal. * @param window user data set when the signal handler was connected. */ void on_vol_scale_value_changed(GtkRange *range, PopupWindow *window) { gdouble value; value = gtk_range_get_value(range); audio_set_volume(window->audio, AUDIO_USER_POPUP, value, 0); }
void audio_volume(int cmd) { if((cmd & 0x1) == 1) { vs_vol += STEP; audio_set_volume(vs_vol); return; } if((cmd & 0x1) == 0) { vs_vol -= STEP; audio_set_volume(vs_vol); return; } }
void audio_init () { #ifdef USE_AUDIO int audio_rate; Uint16 audio_format; int audio_channels; int i; sound_supported = (Mix_OpenAudio (MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == 0); if (!sound_supported) return; sound_pop = CustomMix_LoadWAV (dataFolder, "pop.wav", 30); sound_bam1 = CustomMix_LoadWAV (dataFolder, "bam1.wav", 12); sound_fff = CustomMix_LoadWAV (dataFolder, "fff.wav", 48); sound_slide = CustomMix_LoadWAV (dataFolder, "slide.wav", 128); sound_yahoohoo1[0] = NULL; sound_yahoohoo1[1] = CustomMix_LoadWAV (dataFolder, "yahoohoo.wav", 50); sound_yahoohoo1[2] = CustomMix_LoadWAV (dataFolder, "woho.wav", 32); sound_yahoohoo1[3] = CustomMix_LoadWAV (dataFolder, "pastaga.wav", 70); sound_yahoohoo2[0] = sound_yahoohoo1[2]; sound_yahoohoo2[1] = CustomMix_LoadWAV (dataFolder, "woo.wav", 45); sound_yahoohoo3[0] = CustomMix_LoadWAV (dataFolder, "applose.wav", 96); sound_splash[0] = CustomMix_LoadWAV (dataFolder, "splash1.wav",72); sound_splash[1] = CustomMix_LoadWAV (dataFolder, "splash2.wav",72); sound_splash[2] = CustomMix_LoadWAV (dataFolder, "splash3.wav",72); sound_splash[3] = CustomMix_LoadWAV (dataFolder, "splash4.wav",72); sound_splash[4] = CustomMix_LoadWAV (dataFolder, "splash5.wav",72); sound_splash[5] = CustomMix_LoadWAV (dataFolder, "splash6.wav",72); sound_splash[6] = CustomMix_LoadWAV (dataFolder, "splash7.wav",72); sound_splash[7] = CustomMix_LoadWAV (dataFolder, "splash8.wav",72); sound_bim[0] = CustomMix_LoadWAV (dataFolder, "bim1.wav",72); sound_bim[1] = CustomMix_LoadWAV (dataFolder, "bim2.wav",72); music[0] = CustomMix_LoadMUS (dataFolder, "flobopuyo_menu.ogg"); music[1] = CustomMix_LoadMUS (dataFolder, "flobopuyo_game1.ogg"); music[2] = CustomMix_LoadMUS (dataFolder, "flobopuyo_game2.ogg"); music[3] = CustomMix_LoadMUS (dataFolder, "flobopuyo_gameover.ogg"); Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels); sound_on = 1; music_on = 1; audio_music_set_volume (100); audio_set_volume (50); #endif }
/****************************************************************************** ** Description : set volume playing audio; ** Input : None; ** Output : None; ** Return : None; ******************************************************************************/ static INT32_T ipanel_adec_set_volume(UINT32_T volume) { #define VOLUME_MAX_PERC (100) #define VOLUME_START_PERC (68)/* minimal volume displayed in UI */ int volume_percentage=0; if( IPANEL_ENABLE == g_mute_mode) { hw_set_aud_mute(FALSE); } g_mute_mode = 0 ; if(volume < 6 ) { volume = 0; } if(volume > 100) { volume = 100; } volume_percentage = VOLUME_START_PERC + (VOLUME_MAX_PERC-VOLUME_START_PERC)*volume/100; if ( VOLUME_START_PERC == volume_percentage) { audio_set_volume(0); } else { audio_set_volume(volume_percentage); } return IPANEL_OK; }
void audio_sin_test(void) { char sin_start[8] = {0x53, 0xef, 0x6e, 0x44, 0x00, 0x00, 0x00, 0x00}; char sin_end[8] = {0x45, 0x78, 0x69, 0x74, 0x00, 0x00, 0x00, 0x00}; vs_write_reg(VS_MODE, 0x0820); audio_set_volume(50); vs_spi_clk_data(); vs_write_data(sin_start, 8); delay_m(20000); vs_write_data(sin_end, 8); delay_m(500); /* 500 ms delay_m */ }
int open_os2(audio_output_t *ao) { ULONG rc,i; char *temp; ULONG openflags; PPIB ppib; USHORT bits; if(maop.usDeviceID) return (maop.usDeviceID); if(!ai) return -1; if(!ao->device) ao->device = "0"; if(ao->rate < 0) ao->rate = 44100; if(ao->channels < 0) ao->channels = 2; if(ao->format < 0) ao->format = MPG123_ENC_SIGNED_16; if(ao->format == MPG123_ENC_SIGNED_16) bits = 16; else if(ao->format == MPG123_ENC_UNSIGNED_8) bits = 8; else return -1; /* open the mixer device */ memset (&maop, 0, sizeof(maop)); maop.usDeviceID = 0; maop.pszDeviceType = (PSZ) MAKEULONG(MCI_DEVTYPE_AUDIO_AMPMIX, atoi(ao->device)); openflags = MCI_WAIT | MCI_OPEN_TYPE_ID; if(!lockdevice) openflags |= MCI_OPEN_SHAREABLE; rc = mciSendCommand(0, MCI_OPEN, openflags, &maop, 0); if (ULONG_LOWD(rc) != MCIERR_SUCCESS) { MciError(rc); maop.usDeviceID = 0; return(-1); } /* volume in ao->gain ?? */ /* Set the MCI_MIXSETUP_PARMS data structure to match the audio stream. */ memset(&mmp, 0, sizeof(mmp)); mmp.ulBitsPerSample = bits; mmp.ulFormatTag = MCI_WAVE_FORMAT_PCM; mmp.ulSamplesPerSec = ao->rate; mmp.ulChannels = ao->channels; /* Setup the mixer for playback of wave data */ mmp.ulFormatMode = MCI_PLAY; mmp.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; mmp.pmixEvent = DARTEvent; rc = mciSendCommand( maop.usDeviceID, MCI_MIXSETUP, MCI_WAIT | MCI_MIXSETUP_INIT, &mmp, 0 ); if ( ULONG_LOWD(rc) != MCIERR_SUCCESS ) { MciError(rc); maop.usDeviceID = 0; return(-1); } volume = audio_set_volume(ai,volume); /* Set up the BufferParms data structure and allocate * device buffers from the Amp-Mixer */ memset(&mbp, 0, sizeof(mbp)); free(MixBuffers); free(bufferinfo); if(numbuffers < 5) numbuffers = 5; if(numbuffers > 200) numbuffers = 200; MixBuffers = calloc(numbuffers, sizeof(*MixBuffers)); bufferinfo = calloc(numbuffers, sizeof(*bufferinfo)); ulMCIBuffers = numbuffers; mbp.ulNumBuffers = ulMCIBuffers; /* mbp.ulBufferSize = mmp.ulBufferSize; */ /* I don't like this... they must be smaller than 64KB or else the engine needs major rewrite */ mbp.ulBufferSize = audiobufsize; mbp.pBufList = MixBuffers; rc = mciSendCommand( maop.usDeviceID, MCI_BUFFER, MCI_WAIT | MCI_ALLOCATE_MEMORY, (PVOID) &mbp, 0 ); if ( ULONG_LOWD(rc) != MCIERR_SUCCESS ) { MciError(rc); maop.usDeviceID = 0; return(-1); } pBufferplayed = playedbuffer.pBuffer = calloc(1,audiobufsize); ulMCIBuffers = mbp.ulNumBuffers; /* never know! */ /* Fill all device buffers with zeros and set linked list */ for(i = 0; i < ulMCIBuffers; i++) { MixBuffers[i].ulFlags = 0; MixBuffers[i].ulBufferLength = mbp.ulBufferSize; memset(MixBuffers[i].pBuffer, 0, MixBuffers[i].ulBufferLength); MixBuffers[i].ulUserParm = (ULONG) &bufferinfo[i]; bufferinfo[i].NextBuffer = &MixBuffers[i+1]; } bufferinfo[i-1].NextBuffer = &MixBuffers[0]; /* Create a semaphore to know when data has been played by the DART thread */ DosCreateEventSem(NULL,&dataplayed,0,FALSE); playingbuffer = &MixBuffers[0]; tobefilled = &MixBuffers[1]; playingframe = 0; nomoredata = TRUE; nobuffermode = FALSE; justflushed = FALSE; if(boostprio) { temp = alloca(strlen(boostprio)+1); strcpy(temp,boostprio); boostdelta = atoi(temp+1); *(temp+1) = 0; boostclass = atoi(temp); } if(boostclass > 4) boostdelta = 3; if(boostdelta > 31) boostdelta = 31; if(boostdelta < -31) boostdelta = -31; if(normalprio) { temp = alloca(strlen(normalprio)+1); strcpy(temp,normalprio); normaldelta = atoi(temp+1); *(temp+1) = 0; normalclass = atoi(temp); } if(normalclass > 4) normaldelta = 3; if(normaldelta > 31) normaldelta = 31; if(normaldelta < -31) normaldelta = -31; DosGetInfoBlocks(&mainthread,&ppib); /* ppib not needed, but makes some DOSCALLS.DLL crash */ DosSetPriority(PRTYS_THREAD,boostclass,boostdelta,mainthread->tib_ptib2->tib2_ultid); /* Write buffers to kick off the amp mixer. see DARTEvent() */ rc = mmp.pmixWrite( mmp.ulMixHandle, MixBuffers, ulMCIBuffers ); return maop.usDeviceID; }
PuyoCommander::PuyoCommander(bool fs, bool snd, bool audio) { int init_flags = SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK; SDL_Delay(500); corona = NULL; fullscreen = GetBoolPreference(kFullScreen,fs); #ifdef HAVE_OPENGL useGL = GetBoolPreference(kOpenGL,false); #endif sound = GetBoolPreference(kMusic,snd); fx = GetBoolPreference(kAudioFX,audio); music_volume = GetIntPreference(kMusicVolume, 100); int audio_volume = GetIntPreference(kAudioVolume, 80); initGameControls(); #ifdef USE_DGA /* This Hack Allows Hardware Surface on Linux */ if (fullscreen) setenv("SDL_VIDEODRIVER","dga",0); if (SDL_Init(init_flags) < 0) { setenv("SDL_VIDEODRIVER","x11",1); if (SDL_Init(init_flags) < 0) { fprintf(stderr, "SDL initialisation error: %s\n", SDL_GetError()); exit(1); } } else { if (fullscreen) SDL_WM_GrabInput(SDL_GRAB_ON); } #else #ifdef WIN32 _putenv("SDL_VIDEODRIVER=windib"); #endif if ( SDL_Init(init_flags) < 0 ) { fprintf(stderr, "SDL initialisation error: %s\n", SDL_GetError()); exit(1); } #endif initControllers(); initHiScores(AI_NAMES); #ifdef USE_AUDIO audio_init(); audio_music_start(0); if (sound==false) Mix_PauseMusic(); audio_set_music_on_off(sound); audio_set_sound_on_off(fx); audio_set_volume(audio_volume); audio_music_set_volume(music_volume); #endif display = SDL_SetVideoMode( 320, 240, 0, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); if ( display == NULL ) { fprintf(stderr, "SDL_SetVideoMode error: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); SDL_ShowCursor(SDL_DISABLE); smallFont = SoFont_new(); SoFont_load (smallFont, IIM_Load_DisplayFormatAlpha ("font4b.png")); menuFont = SoFont_new(); SoFont_load (menuFont, IIM_Load_DisplayFormatAlpha ("font3b.png")); darkFont = SoFont_new(); SoFont_load (darkFont, IIM_Load_DisplayFormatAlpha ("fontdark.png")); IIM_Surface * menuselector = IIM_Load_DisplayFormatAlpha("menusel.png"); mainMenu = menu_new(main_menu_load(menuFont),menuselector); gameOver1PMenu = menu_new(gameover_1p_menu_load(menuFont, smallFont),menuselector); gameOver2PMenu = menu_new(gameover_2p_menu_load(menuFont, smallFont),menuselector); nextLevelMenu = menu_new(nextlevel_1p_menu_load(menuFont, smallFont),menuselector); looserMenu = menu_new(looser_1p_menu_load(menuFont, smallFont),menuselector); finishedMenu = menu_new(finished_1p_menu_load(menuFont, smallFont),menuselector); gameOverMenu = gameOver2PMenu; optionMenu = menu_new(options_menu_load(menuFont, smallFont),menuselector); controlsMenu = menu_new(controls_menu_load(menuFont, smallFont),menuselector); rulesMenu = menu_new(rules_menu_load(menuFont),menuselector); highScoresMenu = menu_new(high_scores_menu_load(menuFont),menuselector); aboutMenu = menu_new(about_menu_load(menuFont),menuselector); singleGameMenu = menu_new(single_game_menu_load(menuFont,smallFont),menuselector); twoPlayerGameMenu = menu_new(two_player_game_menu_load(menuFont,smallFont),menuselector); mustRestartMenu = menu_new(must_restart_menu_load(menuFont),menuselector); if (menu_pause == NULL) menu_pause = menu_new(pause_menu_load(menuFont),menuselector); menu_set_sounds (optionMenu, sound_pop, sound_slide); menu_set_sounds (controlsMenu, sound_pop, sound_slide); menu_set_sounds (mainMenu, sound_pop, sound_slide); menu_set_sounds (rulesMenu, sound_pop, sound_slide); menu_set_sounds (highScoresMenu, sound_pop, sound_slide); menu_set_sounds (aboutMenu, sound_pop, sound_slide); menu_set_sounds (singleGameMenu, sound_pop, sound_slide); menu_set_sounds (twoPlayerGameMenu, sound_pop, sound_slide); menu_set_sounds (menu_pause , sound_pop, sound_slide); melt = doom_melt_new(); scrollingText = scrolling_text_new( "Welcome to the wonderful world of FloboPuyo !!! Enjoy its nice graphics, " "happy music and entertaining gameplay... " "Will you be able to defeat all of the mighty players ? " "Will you beat the Puyo Gods ??? Have a try ! " "We wish you good luck. " " Hello from PuyoLand !", smallFont); theCommander = this; }
int main(int argc, char *argv[]) { int r; char *data_file = NULL; char *save_file = NULL; int screen_width = DEFAULT_SCREEN_WIDTH; int screen_height = DEFAULT_SCREEN_HEIGHT; int fullscreen = 0; int game_map = 1; int map_generator = 0; int preserve_map_bugs = 0; int log_level = DEFAULT_LOG_LEVEL; int opt; while (1) { opt = getopt(argc, argv, "d:fg:hl:m:pr:t:"); if (opt < 0) break; switch (opt) { case 'd': { int d = atoi(optarg); if (d >= 0 && d < LOG_LEVEL_MAX) { log_level = d; } } break; case 'f': fullscreen = 1; break; case 'g': data_file = malloc(strlen(optarg)+1); if (data_file == NULL) exit(EXIT_FAILURE); strcpy(data_file, optarg); break; case 'h': fprintf(stdout, HELP, argv[0]); exit(EXIT_SUCCESS); break; case 'l': save_file = malloc(strlen(optarg)+1); if (save_file == NULL) exit(EXIT_FAILURE); strcpy(save_file, optarg); break; case 'm': game_map = atoi(optarg); break; case 'p': preserve_map_bugs = 1; break; case 'r': { char *hstr = strchr(optarg, 'x'); if (hstr == NULL) { fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); } screen_width = atoi(optarg); screen_height = atoi(hstr+1); } break; case 't': map_generator = atoi(optarg); break; default: fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); break; } } /* Set up logging */ log_set_file(stdout); log_set_level(log_level); LOGI("main", "freeserf %s", FREESERF_VERSION); r = load_data_file(data_file); if (r < 0) { LOGE("main", "Could not load game data."); exit(EXIT_FAILURE); } free(data_file); gfx_data_fixup(); LOGI("main", "SDL init..."); r = sdl_init(); if (r < 0) exit(EXIT_FAILURE); /* TODO move to right place */ midi_play_track(MIDI_TRACK_0); audio_set_volume(75); /*gfx_set_palette(DATA_PALETTE_INTRO);*/ gfx_set_palette(DATA_PALETTE_GAME); LOGI("main", "SDL resolution %ix%i...", screen_width, screen_height); r = sdl_set_resolution(screen_width, screen_height, fullscreen); if (r < 0) exit(EXIT_FAILURE); game.mission_level = game_map - 1; /* set game map */ game.map_generator = map_generator; game.map_preserve_bugs = preserve_map_bugs; /* Init globals */ allocate_global_memory(); player_interface_init(); /* Initialize global lookup tables */ init_spiral_pattern(); game_init(); /* Either load a save game if specified or start a new game. */ if (save_file != NULL) { int r = game_load_save_game(save_file); if (r < 0) exit(EXIT_FAILURE); free(save_file); } else { game_load_random_map(); } /* Move viewport to initial position */ viewport_move_to_map_pos(&interface.viewport, interface.map_cursor_pos); /* Start game loop */ game_loop(); LOGI("main", "Cleaning up..."); /* Clean up */ audio_cleanup(); sdl_deinit(); gfx_unload(); return EXIT_SUCCESS; }
bool menu_run(Settings *settings) { assert(settings != NULL); SDL_EnableKeyRepeat(10000 / WINDOW_FRAMERATE, 10000 / WINDOW_FRAMERATE); glClearColor(0, 0, 0, 1); int level_set_index = 0, theme_index = 0; menu_preload(); // default settings if(settings->first_run) { settings->play_with_computer = true; settings->volume = 100; strncpy(settings->level_set, s_sets_names[level_set_index], LIM_STR_LEN); settings->level = 1; strncpy(settings->theme, s_themes_names[theme_index], LIM_STR_LEN); settings->ball_speed = BALL_DEFAULT_SPEED; } Timer timer = timer_new(WINDOW_FRAMERATE); const bool* events = NULL; bool leave = false; bool vol_updated = false; while(!leave) { events = event_poll(); if(events[EVENT_QUIT] || events[EVENT_KEY_ESCAPE]) { return false; } if(events[EVENT_KEY_UP]) { if(s_focus == 0) { s_focus = __MENU_LABEL_LAST - 1; } else { s_focus--; } audio_play(SOUND_TOCK); } if(events[EVENT_KEY_DOWN]) { s_focus++; audio_play(SOUND_TOCK); if(s_focus == __MENU_LABEL_LAST) { s_focus = 0; } } if(events[EVENT_KEY_LEFT]) { bool action = true; switch(s_focus) { case LABEL_SECOND_PLAYER: settings->play_with_computer = !settings->play_with_computer; break; case LABEL_SOUND_VOLUME: settings->volume -= 10; if(settings->volume < 0) { settings->volume = 0; action = false; } else { vol_updated = true; } break; case LABEL_LEVEL_SET: s_level_set_index--; if(s_level_set_index < 0) { s_level_set_index = s_sets_names_length - 1; } settings->level = 1; break; case LABEL_LEVEL: (settings->level)--; if(settings->level <= 0) { settings->level = s_sets_levels[s_level_set_index]; } break; case LABEL_THEME: s_theme_index--; if(s_theme_index < 0) { s_theme_index = s_themes_names_length - 1; } break; case LABEL_BALL_SPEED: (settings->ball_speed)--; if(settings->ball_speed < BALL_MIN_SPEED) { settings->ball_speed = BALL_MAX_SPEED; } break; default: action = false; break; } if(action) { audio_play(SOUND_TICK); } } if(events[EVENT_KEY_RIGHT]) { bool action = true; switch(s_focus) { case LABEL_SECOND_PLAYER: settings->play_with_computer = !settings->play_with_computer; break; case LABEL_SOUND_VOLUME: settings->volume += 10; if(settings->volume > 100) { settings->volume = 100; action = false; } else { vol_updated = true; } break; case LABEL_LEVEL_SET: s_level_set_index++; if(s_level_set_index >= s_sets_names_length) { s_level_set_index = 0; } settings->level = 1; break; case LABEL_LEVEL: (settings->level)++; if(settings->level > s_sets_levels[s_level_set_index]) { settings->level = 1; } break; case LABEL_THEME: s_theme_index++; if(s_theme_index >= s_themes_names_length) { s_theme_index = 0; } break; case LABEL_BALL_SPEED: (settings->ball_speed)++; if(settings->ball_speed > BALL_MAX_SPEED) { settings->ball_speed = BALL_MIN_SPEED; } break; default: action = false; break; } if(action) { audio_play(SOUND_TICK); } } if(events[EVENT_KEY_ENTER]) { if(s_focus == LABEL_QUIT) { return false; } else { leave = true; } } if(vol_updated) { audio_set_volume(settings->volume); vol_updated = false; } glClear(GL_COLOR_BUFFER_BIT); menu_display(settings); SDL_GL_SwapBuffers(); timer_sleep(&timer); } strncpy(settings->level_set, s_sets_names[s_level_set_index], LIM_STR_LEN); strncpy(settings->theme, s_themes_names[s_theme_index], LIM_STR_LEN); settings->first_run = false; return true; }
void SACM_Volume(int volume) { audio_set_volume(&__gaudio, volume); }
int main(int argc, char **argv) { wav_t *w; audio_meta_t meta; state_t s; audio_config_t audio_cfg; audio_device_t audio_dev; audio_t *audio; talking_skull_t *talking_skull; bool has_servo_track; pi_usb_init(); s.gain = 1; if ((s.m = maestro_new()) == NULL) { fprintf(stderr, "couldn't find a recognized device.\n"); exit(1); } while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-') { if (strcmp(argv[1], "--") == 0) { argc -= 1; argv += 1; break; } if (argc > 2 && strcmp(argv[1], "--gain") == 0) { s.gain = atof(argv[2]); argc -= 2; argv += 2; } if (argc > 1 && strcmp(argv[1], "--servo") == 0) { has_servo_track = true; argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--baxter") == 0) { maestro_set_servo_range(s.m, SERVO_ID, BAXTER_MOUTH); argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--deer") == 0) { maestro_set_servo_is_inverted(s.m, SERVO_ID, 0); maestro_set_servo_range(s.m, SERVO_ID, TALKING_DEER); argc -= 1; argv += 1; } if (argc > 1 && strcmp(argv[1], "--skull2") == 0) { maestro_set_servo_is_inverted(s.m, SERVO_ID, 0); maestro_set_servo_range(s.m, SERVO_ID, TALKING_SKULL2); argc -= 1; argv += 1; } } w = wav_new(argv[1]); if (! w) { perror(argv[1]); exit(1); } meta = wav_get_meta(w); talking_skull = talking_skull_new(&meta, has_servo_track, update_servo, &s); if (has_servo_track) { wav_extract_servo_track(w); } audio_device_init_playback(&audio_dev); audio_config_init_default(&audio_cfg); wav_configure_audio(w, &audio_cfg); printf("Config from wav file: "); audio_config_print(&audio_cfg, stdout); printf("\n"); audio = audio_new(&audio_cfg, &audio_dev); if (! audio) { perror("audio_new"); exit(1); } audio_set_volume(audio, 100); wav_play_with_talking_skull(w, audio, talking_skull); if (s.m) { maestro_set_servo_pos(s.m, SERVO_ID, 50); maestro_destroy(s.m); } wav_destroy(w); audio_destroy(audio); return 0; }
int main(int argc, char **argv) { unsigned char *buffer; audio_t *in; audio_config_t cfg; audio_meta_t meta; audio_device_t in_dev, out_dev; server_args_t server_args; pthread_t server_thread; pthread_t play_thread; unsigned char *auto_play_buffer = NULL; size_t auto_play_bytes_left = 0; wav_t *auto_wav; pi_usb_init(); if ((maestro = maestro_new()) == NULL) { fprintf(stderr, "couldn't find a recognized device, disabling skull.\n"); } else { maestro_set_servo_is_inverted(maestro, SERVO_ID, true); maestro_set_servo_range(maestro, SERVO_ID, TALKING_SKULL2); } piface = piface_new(); if ((auto_wav = wav_new("chant1.wav")) == NULL) { perror("chant1.wav"); exit(1); } pthread_mutex_init(&speak_lock, NULL); server_args.port = 5555; server_args.command = remote_event; server_args.state = NULL; pc = producer_consumer_new(1); pthread_create(&server_thread, NULL, server_thread_main, &server_args); pthread_create(&play_thread, NULL, play_thread_main, NULL); audio_config_init_default(&cfg); cfg.channels = 2; cfg.rate = 48000; audio_device_init_playback(&out_dev); audio_device_init_capture(&in_dev); out = audio_new(&cfg, &out_dev); in = audio_new(&cfg, &in_dev); if (! out) { perror("out"); fprintf(stderr, "Failed to initialize playback\n"); exit(1); } if (! in) { perror("in"); fprintf(stderr, "Failed to initialize capture\n"); exit(1); } audio_set_volume(in, 100); audio_set_volume(out, 100); size = audio_get_buffer_size(in); assert(audio_get_buffer_size(out) == size); buffer = fatal_malloc(size); audio_meta_init_from_config(&meta, &cfg); skull = talking_skull_new(&meta, false, servo_update, NULL); fprintf(stderr, "Copying from capture to play using %u byte buffers\n", size); last_audio = time(NULL); while (audio_capture_buffer(in, buffer)) { pthread_mutex_lock(&speak_lock); if (auto_play_bytes_left == 0 && time(NULL) - last_audio >= IDLE_AUDIO_SECS) { auto_play_buffer = wav_get_raw_data(auto_wav, &auto_play_bytes_left); gain = 3; } if (auto_play_bytes_left > 0) { size_t n = auto_play_bytes_left > size ? size : auto_play_bytes_left; memcpy(buffer, auto_play_buffer, n); auto_play_buffer += n; auto_play_bytes_left -= n; } producer_consumer_produce(pc, buffer); pthread_mutex_unlock(&speak_lock); buffer = fatal_malloc(size); } fprintf(stderr, "Failed to capture buffer!\n"); audio_destroy(in); audio_destroy(out); free(buffer); return 0; }
int main(int argc, char *argv[]) { int r; char *data_file = NULL; char *save_file = NULL; int map_generator = 0; log_set_file(stdout); init_config_data(); //- read config data int screen_width = get_config_int(CONFIG_SCREEN_WIDTH, DEFAULT_SCREEN_WIDTH); int screen_height = get_config_int(CONFIG_SCREEN_HEIGHT, DEFAULT_SCREEN_HEIGHT); int fullscreen = get_config_bool(CONFIG_FULLSCREEN, 0); int log_level = get_config_int(CONFIG_LOGGLEVEL, DEFAULT_LOG_LEVEL); enum_lng_t language = str_to_lagEnum((char *)get_config_string(CONFIG_LANGUAGE, "EN")); int play_midi = get_config_bool(CONFIG_MUSIC, 1); int play_SFX = get_config_bool(CONFIG_SFX, 1); int volume = get_config_int(CONFIG_VOLUME, 75); //- read command line parameters int opt; while (1) { opt = getopt(argc, argv, "d:fg:hl:r:t:s:"); if (opt < 0) break; switch (opt) { case 'd': { int d = atoi(optarg); if (d >= 0 && d < LOG_LEVEL_MAX) { log_level = d; } } break; case 'f': fullscreen = 1; break; case 'g': data_file = (char *)malloc(strlen(optarg)+1); if (data_file == NULL) exit(EXIT_FAILURE); strcpy(data_file, optarg); break; case 'h': fprintf(stdout, HELP, argv[0]); exit(EXIT_SUCCESS); break; case 'l': save_file = (char *)malloc(strlen(optarg)+1); if (save_file == NULL) exit(EXIT_FAILURE); strcpy(save_file, optarg); break; case 'r': { char *hstr = strchr(optarg, 'x'); if (hstr == NULL) { fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); } screen_width = atoi(optarg); screen_height = atoi(hstr+1); } break; case 't': map_generator = atoi(optarg); break; case 's': { char * tmp_language_str = (char *) malloc(strlen(optarg) + 1); if (tmp_language_str != NULL) { strcpy(tmp_language_str, optarg); language = str_to_lagEnum(tmp_language_str); } } break; default: fprintf(stderr, USAGE, argv[0]); exit(EXIT_FAILURE); break; } } /* Set up logging */ log_set_level((log_level_t)log_level); LOGI("main", "freeserf %s", FREESERF_VERSION); /* load language */ init_language_data(language); r = load_data_file(data_file); if (r < 0) { LOGE("main", "Could not load game data."); exit(EXIT_FAILURE); } free(data_file); gfx_data_fixup(); LOGI("main", "SDL init..."); r = sdl_init(); if (r < 0) exit(EXIT_FAILURE); /* TODO move to right place */ midi_play_track(MIDI_TRACK_0); audio_set_volume(volume); midi_enable(play_midi); sfx_enable(play_SFX); /*gfx_set_palette(DATA_PALETTE_INTRO);*/ gfx_set_palette(DATA_PALETTE_GAME); LOGI("main", "SDL resolution %ix%i...", screen_width, screen_height); r = sdl_set_resolution(screen_width, screen_height, fullscreen); if (r < 0) exit(EXIT_FAILURE); game.map_generator = map_generator; /* Initialize global lookup tables */ init_spiral_pattern(); game_init(); /* Initialize Missions*/ init_mission("missions.xml"); /* Initialize interface */ interface_init(&interface); gui_object_set_size((gui_object_t *)&interface, screen_width, screen_height); gui_object_set_displayed((gui_object_t *)&interface, 1); /* Either load a save game if specified or start a new game. */ if (save_file != NULL) { int r = game_load_save_game(save_file); if (r < 0) exit(EXIT_FAILURE); free(save_file); interface_set_player(&interface, 0); } else { int r = game_load_random_map(3, &interface.random); if (r < 0) exit(EXIT_FAILURE); /* Add default player */ r = game_add_player(12, 64, 40, 40, 40); if (r < 0) exit(EXIT_FAILURE); interface_set_player(&interface, r); } viewport_map_reinit(); if (save_file != NULL) { interface_close_game_init(&interface); } /* Start game loop */ game_loop(); LOGI("main", "Cleaning up..."); /* Clean up */ map_deinit(); viewport_map_deinit(); audio_cleanup(); sdl_deinit(); gfx_unload(); language_cleanup(); mission_cleanup(); config_cleanup(); return EXIT_SUCCESS; }
static javacall_result video_set_volume(javacall_handle handle, long* level){ return audio_set_volume(handle, level); }