int WINAPI wWinMain(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPWSTR _lpCmdLine, int _nCmdShow) { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); srand((unsigned)time(0)); // Load config into config file class g_configFile = new ConfigFile(); g_configFile->load(); // Init window HWND hwnd = 0; if((hwnd = InitWindow(_hInstance, _nCmdShow, g_configFile->getScreenSize())) == 0) { return 0; } initSoundEngine(); setMusicVolume(g_configFile->getMusicVolume()); setSoundVolume(g_configFile->getSoundVolume()); ClientHandler* clientHandler = new ClientHandler(hwnd); HRESULT hr = clientHandler->run(); delete clientHandler; deleteSoundEngine(); return hr; }
Sound::Sound() : currentMusic(0) { assert( soundPtr == 0); soundPtr = this; loaderThread = 0; //Load Sound audioOpen = false; /* Open the audio device */ if (Mix_OpenAudio( MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048) < 0) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); return; } else { audioOpen = true; loaderThread = SDL_CreateThread(soundThread, this); } setMusicVolume(getConfig()->musicVolume); setSoundVolume(getConfig()->soundVolume); // for now... //playMusic("01 - pronobozo - lincity.ogg"); playMusic( getConfig()->playSongName ); }
/** * Load all *.wav from directory. * @param directory path to the directory */ void SDLSound::loadSound(const char* directory) { char **list = filesystem::enumerateFiles(directory); for (char **i = list; *i != NULL; i++) { std::string filename = directory; filename.append(*i); if (!filesystem::isDirectory(filename.c_str())) { try { SDL_RWops * ops = getFileForSDL(filename.c_str()); if ( ! ops ) continue; Mix_Chunk *chunk = Mix_LoadWAV_RW(ops, 1); if (chunk) { std::string idName = getIdName(*i); m_chunks.insert( std::pair<std::string,SoundData*>(idName, new SoundData(chunk)) ); } else { LOGGER.info("Couldn't load wav_rw '%s': %s", filename.c_str(), Mix_GetError()); } } catch (Exception &e) { LOGGER.info("Couldn't load wav '%s': %s", filename.c_str(), e.what()); } } } filesystem::freeList(list); setSoundVolume(gameconfig->sound.getEffectsVol()); }
void SDLAudio::playSound( std::string filename, int volume, int looping ) // Play a sound, at specified volume as a percent (default: uses the setting last set for the sound, or 100 if not changed since sound struct was constructed ) { // and loop specified amount of times (-1 infinite, otherwise integer is literal; default: 0) int availChannel = -1; // let's find a channel that isn't currently playing anything for ( int i = 0; i < MAX_SOUND_CHANNELS; i++ ) { if (Mix_Playing( i ) == 0 ) { availChannel = i; break; } } // if we found a free channel (availChannel should be set to something other than -1) if ( availChannel != -1 ) { try { currentSounds[availChannel] = assetCache.getSound(filename); setSoundVolume( currentSounds[availChannel], volume ); Mix_PlayChannel( availChannel, currentSounds[availChannel], 0 ); } catch( NotFoundException& ex) { // Error, file was not found std::cerr<<ex.what()<<std::endl; } } }
void SettingsPageComponent::sliderDragEnded(IconSliderComponent* slider) { if( slider == screenBrightnessSlider && brightnessSliderTimer.isTimerRunning()) { brightnessSliderTimer.stopTimer(); setScreenBrightness(); } else if( slider == volumeSlider&& volumeSliderTimer.isTimerRunning()) { volumeSliderTimer.stopTimer(); setSoundVolume(); } }
bool CAutoSoundPlayer::TurnOn(CTurnOn *msg) { if (_soundHandle == -1) { CProximity prox; prox._balance = _balance; prox._repeated = _repeated; if (_fieldE8) prox._positioningMode = POSMODE_VECTOR; prox._channelVolume = (_startSeconds == -1) ? _volume : 0; _soundHandle = playSound(_filename, prox); if (_startSeconds != -1) setSoundVolume(_soundHandle, _volume, _startSeconds); _active = true; } return true; }
void initSND() { static double analog[] = { -1, -0.8667, -0.7334, -0.6, -0.4668, -0.3335, -0.2, -0.067, 0.0664, 0.2, 0.333, 0.4668, 0.6, 0.7334, 0.8667, 1 } ; int i; for (i=0; i<16; i++) { pcmVals[i] = analog[i]*0x70; } for (i=0; i<4; i++) { soundKill(sound[i]); chanOn = 0; chanVol[i] = 0; chanFreq[i] = 0; setSoundVolume(i); } srand(time(NULL)); if (!soundDisabled) soundEnable(); }
SoundManager::SoundManager() { int audio_rate = 22050; Uint16 audio_format = MIX_DEFAULT_FORMAT; int audio_channels = 2; int audio_buffers = 4096; if(SDL_Init(SDL_INIT_AUDIO) == -1) { std::cout << "Unable to initialize audio in SoundManager" << std::endl; SDL_Quit(); } if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { std::cout << "Unable to open audio" << std::endl; SDL_Quit(); } soundVolume = 60; musicVolume = 60; setMusicVolume(musicVolume); setSoundVolume(soundVolume); }
bool CAutoSoundPlayer::SetVolumeMsg(CSetVolumeMsg *msg) { if (_soundHandle != -1 && isSoundActive(_soundHandle)) setSoundVolume(_soundHandle, msg->_volume, msg->_secondsTransition); return true; }
void Sound::playSound_normal(char* sound, int volume){//直接読み込み場所とボリュームを設定し、ノーマルで再生 int SoundData = LoadSoundMem(sound); setSoundVolume(volume); ChangeVolumeSoundMem(255 * volumeData, SoundData); PlaySoundMem(SoundData, DX_PLAYTYPE_NORMAL, TRUE); }
void SDLAudio::setSoundVolume ( std::string filename, int volAsPercent ) // Public version of setSoundVolume that takes filename as parameter and the volume as a percent { Mix_Chunk* sound = assetCache.getSound( filename ); setSoundVolume(sound, volAsPercent); // call the private version of this function using the pointer to the sound struct }
void Sound::playSound_back(int sound, int volume){//メモリにセットしてあるものを、ボリュームを変えてバックグラウンドで再生 setSoundVolume(volume); ChangeVolumeSoundMem(255 * volume, sound); PlaySoundMem(sound, DX_PLAYTYPE_BACK, TRUE); }
/** * Initialises OpenJazz. * * Establishes the paths from which to read files, loads configuration, sets up * the game window and loads required data. * * @param argc Number of arguments, as passed to main function * @param argv Array of argument strings, as passed to main function */ void startUp (int argc, char *argv[]) { File* file; unsigned char* pixels = NULL; int count; int screenW = DEFAULT_SCREEN_WIDTH; int screenH = DEFAULT_SCREEN_HEIGHT; int scaleFactor = 1; #ifdef FULLSCREEN_ONLY bool fullscreen = true; #else bool fullscreen = false; #endif // Determine paths // Use hard-coded paths, if available #ifdef DATAPATH firstPath = new Path(NULL, createString(DATAPATH)); #else firstPath = NULL; #endif #ifdef __HAIKU__ dev_t volume = dev_for_path("/boot"); char buffer[10 + B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH]; status_t result; result = find_directory(B_SYSTEM_DATA_DIRECTORY, volume, false, buffer, sizeof(buffer)); strncat(buffer, "/openjazz/", sizeof(buffer)); firstPath = new Path(firstPath, createString(buffer)); result = find_directory(B_USER_NONPACKAGED_DATA_DIRECTORY, volume, false, buffer, sizeof(buffer)); strncat(buffer, "/openjazz/", sizeof(buffer)); firstPath = new Path(firstPath, createString(buffer)); #endif #ifdef __SYMBIAN32__ #ifdef UIQ3 firstPath = new Path(firstPath, createString("c:\\shared\\openjazz\\")); #else firstPath = new Path(firstPath, createString("c:\\data\\openjazz\\")); #endif firstPath = new Path(firstPath, createString(KOpenJazzPath)); #endif // Use any provided paths, appending a directory separator as necessary for (count = 1; count < argc; count++) { // If it isn't an option, it should be a path if (argv[count][0] != '-') { #ifdef _WIN32 if (argv[count][strlen(argv[count]) - 1] != '\\') { firstPath = new Path(firstPath, createString(argv[count], "\\")); #else if (argv[count][strlen(argv[count]) - 1] != '/') { firstPath = new Path(firstPath, createString(argv[count], "/")); #endif } else { firstPath = new Path(firstPath, createString(argv[count])); } } } // Use the path of the program, but not on Wii as this does crash in // dolphin emulator. Also is not needed, because CWD is used there #ifndef WII count = strlen(argv[0]) - 1; // Search for directory separator #ifdef _WIN32 while ((argv[0][count] != '\\') && (count >= 0)) count--; #else while ((argv[0][count] != '/') && (count >= 0)) count--; #endif // If a directory was found, copy it to the path if (count > 0) { firstPath = new Path(firstPath, new char[count + 2]); memcpy(firstPath->path, argv[0], count + 1); firstPath->path[count + 1] = 0; } #endif // Use the user's home directory, if available #ifdef HOMEDIR #ifdef _WIN32 firstPath = new Path(firstPath, createString(getenv("HOME"), "\\")); #else firstPath = new Path(firstPath, createString(getenv("HOME"), "/.")); #endif #endif // Use the current working directory firstPath = new Path(firstPath, createString("")); // Default settings // Sound settings #if defined(WIZ) || defined(GP2X) volume = 40; #endif // Create the network address netAddress = createString(NET_ADDRESS); // Load settings from config file setup.load(&screenW, &screenH, &fullscreen, &scaleFactor); // Get command-line override for (count = 1; count < argc; count++) { // If there's a hyphen, it should be an option if (argv[count][0] == '-') { #ifndef FULLSCREEN_ONLY if (argv[count][1] == 'f') fullscreen = true; #endif if (argv[count][1] == 'm') { setMusicVolume(0); setSoundVolume(0); } } } // Create the game's window canvas = NULL; if (!video.init(screenW, screenH, fullscreen)) { delete firstPath; throw E_VIDEO; } #ifdef SCALE video.setScaleFactor(scaleFactor); #endif if (SDL_NumJoysticks() > 0) SDL_JoystickOpen(0); // Set up audio openAudio(); // Load fonts // Open the panel, which contains two fonts try { file = new File("PANEL.000", false); } catch (int e) { closeAudio(); delete firstPath; log("Unable to find game data files. When launching OpenJazz, pass the location"); log("of the original game data, eg:"); log(" OpenJazz ~/jazz1"); #ifdef __HAIKU__ char alertBuffer[100+B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; strcpy(alertBuffer, "Unable to find game data files!\n" "Put the data into the folder:\n"); strncat(alertBuffer, buffer, sizeof(alertBuffer)); BAlert* alert = new BAlert("OpenJazz", alertBuffer, "Exit", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->Go(); #endif throw e; } pixels = file->loadRLE(46272); delete file; panelBigFont = NULL; panelSmallFont = NULL; font2 = NULL; fontbig = NULL; fontiny = NULL; fontmn1 = NULL; try { panelBigFont = new Font(pixels + (40 * 320), true); panelSmallFont = new Font(pixels + (48 * 320), false); font2 = new Font("FONT2.0FN"); fontbig = new Font("FONTBIG.0FN"); fontiny = new Font("FONTINY.0FN"); fontmn1 = new Font("FONTMN1.0FN"); fontmn2 = new Font("FONTMN2.0FN"); } catch (int e) { if (panelBigFont) delete panelBigFont; if (panelSmallFont) delete panelSmallFont; if (font2) delete font2; if (fontbig) delete fontbig; if (fontiny) delete fontiny; if (fontmn1) delete fontmn1; delete[] pixels; closeAudio(); delete firstPath; throw e; } delete[] pixels; // Establish arbitrary timing globalTicks = SDL_GetTicks() - 20; // Fill trigonometric function look-up tables for (count = 0; count < 1024; count++) sinLut[count] = fixed(sinf(2 * PI * float(count) / 1024.0f) * 1024.0f); // Initiate networking net = new Network(); level = NULL; jj2Level = NULL; } /** * De-initialises OpenJazz. * * Frees data, writes configuration, and shuts down SDL. */ void shutDown () { delete net; delete panelBigFont; delete panelSmallFont; delete font2; delete fontbig; delete fontiny; delete fontmn1; delete fontmn2; #ifdef SCALE if (video.getScaleFactor() > 1) SDL_FreeSurface(canvas); #endif closeAudio(); // Save settings to config file setup.save(); delete firstPath; }
void CCommand::Initialize() { // Set Baud rate setRadio(0); setSquelch(255); setSoundVolume(0); setRadio(1); setSoundVolume(0); setSquelch(255); /* dbgWin->slotSendSerial("G2?"); dbgWin->slotSendSerial("G4?"); dbgWin->slotSendSerial("GE?"); dbgWin->slotSendSerial("GD?"); dbgWin->slotSendSerial("GA0?"); dbgWin->slotSendSerial("GA1?"); dbgWin->slotSendSerial("GA2?"); dbgWin->slotSendSerial("GF?"); */ sleep(1); setUpdateMode(CCommand::eUpdOn); /* NOT NEEDED */ //dbgWin->slotSendSerial("J730000"); setRadio(0); // Noise blanker is off setNoiseBlanker(false); setRadio(1); setNoiseBlanker(false); // Init radio 0 Frequency; setRadio(0); setModulation(CCommand::eWFM); setFilter(CCommand::e230k); setFrequency(106500000); setSquelch(0); setVoiceControl(CCommand::eVSCOff); setIFShift(128); // Init radio 1 Frequency setRadio(1); setModulation(CCommand::eFM); setFilter(CCommand::e15k); setFrequency(145425000); setSquelch(0); setSoundVolume(0); setVoiceControl(CCommand::eVSCOff); setIFShift(128); /* NOT NEEDED */ /* Unknown dbgWin->slotSendSerial("J4200"); dbgWin->slotSendSerial("J4700"); dbgWin->slotSendSerial("J6700"); dbgWin->slotSendSerial("JC400"); dbgWin->slotSendSerial("J7100"); dbgWin->slotSendSerial("J720000"); dbgWin->slotSendSerial("JC000"); */ // Mute radio before restoring values setRadio(0); setSoundMute(true); setSoundVolume(0); /* Unknown dbgWin->slotSendSerial("J8001"); dbgWin->slotSendSerial("J8100"); dbgWin->slotSendSerial("J8200"); dbgWin->slotSendSerial("J8300"); dbgWin->slotSendSerial("JC500"); */ setRadio(0); setSquelch(255); setVoiceControl(CCommand::eVSCOff); setRadio(1); setSquelch(255); setVoiceControl(CCommand::eVSCOff); setRadio(0); setSoundVolume(0); setRadio(1); setSoundVolume(0); setSquelch(255); setRadioMode(CCommand::eBoth); //dbgWin->slotSendSerial("JB000"); setRadio(1); setSquelch(255); setVoiceControl(CCommand::eVSCOff); setRadio(0); setSquelch(1); setVoiceControl(CCommand::eVSCOff); setRadio(1); setVoiceControl(CCommand::eVSCOff); setSquelch(1); setRadio(0); setSoundVolume(60); setSoundMute(false); }
void Sound::playSound_back(char* sound, int volume){//直接読み込み場所とボリュームを設定し、バックグラウンドで再生 int SoundData = LoadSoundMem(sound); setSoundVolume(volume); ChangeVolumeSoundMem(255 * volumeData, SoundData); PlaySoundMem(SoundData, DX_PLAYTYPE_BACK, TRUE); }
void Sound::playSound_normal(int sound, int volume){//メモリにセットしてあるものを、ボリュームを変えてノーマルで再生 setSoundVolume(volume); ChangeVolumeSoundMem(255 * volume, sound); PlaySoundMem(sound, DX_PLAYTYPE_NORMAL, TRUE); }
void Sound::playSound_loop(int sound, int volume){//メモリにセットしてあるものを、ボリュームを変えてループで再生 setSoundVolume(volume); ChangeVolumeSoundMem(255 * volume, sound); PlaySoundMem(sound, DX_PLAYTYPE_LOOP, TRUE); }
//Follow brightest light direction void lightFollow(){ //Boleans for storing previous rotation direction bool wasRotatingR, wasRotatingL; //Displays brightest direction displayStringAt(90, 120, "Light Dir = %d",BrightLight);//Display //Display sound level label displayStringAt(5, 120, "Sound Level");//Display //rotate Left if(BrightLight < 4 && BrightLight > 0){ motor[right] = 10; motor[left] = -10; //Find direction of rotation wasRotatingR = false; wasRotatingL = true; } //Rotate Right else if(BrightLight > 6){ motor[right] = -10; motor[left] = 10; //Find direction of rotation wasRotatingR = true; wasRotatingL = false; } //Drive forward while slightly turning right else if (BrightLight == 4){ //If robot was rotating than stop, so robot doesn't pass light direction if(wasRotatingR || wasRotatingL){ //stop motors motor[right] = 0; motor[left] = 0; wait1Msec(500); } //set right slightly faster than left for slow tilt motor[right] = 30; motor[left] = 28; wasRotatingR = false; wasRotatingL = false; } //Drive forward else if (BrightLight == 5){ //If robot was rotating than stop, so robot doesn't pass light direction if(wasRotatingR || wasRotatingL){ //stop motors motor[right] = 0; motor[left] = 0; wait1Msec(500); //play sound when directly following light setSoundVolume(20); //playSound playSound(soundFastUpwardTones); } motor[right] = 30; motor[left] = 30; //Set both rotation values to false: robot is driving forward wasRotatingR = false; wasRotatingL = false; } //Drive forward while slightly turning left else if (BrightLight == 6 ){ //If robot was rotating than stop, so robot doesn't pass light direction if(wasRotatingR || wasRotatingL){ motor[right] = 0; motor[left] = 0; wait1Msec(500); } motor[right] = 28; motor[left] = 30; //Set both rotation values to false: robot is driving forward wasRotatingR = false; wasRotatingL = false; } //When no brightest light direction is detected, continue rotating in last //rotation direction, or rotate left if robot wasn't previously rotating else{ if(wasRotatingR){ motor[right] = -10; motor[left] = 10; } else if(wasRotatingL){ motor[right] = 10; motor[left] = -10; } else{ motor[right] = 10; motor[left] = -10; wasRotatingL = true; } }//end else }//end light follow
void Sound::playSound_loop(char* sound, int volume){//直接読み込み場所とボリュームを設定し、ループで再生 int SoundData = LoadSoundMem(sound); setSoundVolume(volume); ChangeVolumeSoundMem(255 * volumeData, SoundData); PlaySoundMem(SoundData, DX_PLAYTYPE_LOOP, TRUE); }