コード例 #1
0
ファイル: Sound.cpp プロジェクト: Agreon/Fallen
    void Sound::setVolume(int vol)
    {
		Mix_VolumeMusic(vol);
		Mix_Volume( -1, vol );
    }
コード例 #2
0
ファイル: Sound.cpp プロジェクト: Agreon/Fallen
    void Sound::muteSounds()
    {
		if(Mix_Volume(-1,-1) == 0) Mix_Volume(-1,128);
		else Mix_Volume(-1,0);
    }
コード例 #3
0
ファイル: SDLSound.cpp プロジェクト: clemos/nme
   SDLSoundChannel(const ByteArray &inBytes, const SoundTransform &inTransform)
   {
      Mix_QuerySpec(&mFrequency, &mFormat, &mChannels);
      if (mFrequency!=44100)
         ELOG("Warning - Frequency mismatch %d",mFrequency);
      if (mFormat!=32784)
         ELOG("Warning - Format mismatch    %d",mFormat);
      if (mChannels!=2)
         ELOG("Warning - channe mismatch    %d",mChannels);

      if (sMusicFrequency==0)
      {
         sMusicFrequency = mFrequency;
      }

      mChunk = 0;
      mDynamicBuffer = new short[BUF_SIZE * STEREO_SAMPLES];
      memset(mDynamicBuffer,0,BUF_SIZE*sizeof(short));
      mSound = 0;
      mChannel = -1;
      mDynamicChunk.allocated = 0;
      mDynamicChunk.abuf = (Uint8 *)mDynamicBuffer;
      mDynamicChunk.alen = BUF_SIZE * sizeof(short) * STEREO_SAMPLES; // bytes
      mDynamicChunk.volume = MIX_MAX_VOLUME;
      mDynamicFillPos = 0;
      mSoundPos0 = 0;
      mDynamicDataDue = 0;

      mBufferAheadSamples = 0;//mFrequency / 20; // 50ms buffer

      // Allocate myself a channel
      for(int i=0;i<sMaxChannels;i++)
         if (!sUsedChannel[i])
         {
            IncRef();
            sDoneChannel[i] = false;
            sUsedChannel[i] = true;
            mChannel = i;
            break;
         }

      if (mChannel>=0)
      {
         FillBuffer(inBytes,true);
         // Just once ...
         if (mDynamicFillPos<1024)
         {
            mDynamicRequestPending = true;
            mDynamicChunk.alen = mDynamicFillPos * sizeof(short) * STEREO_SAMPLES;
            if (Mix_PlayChannel( mChannel , &mDynamicChunk,  0 ))
              onChannelDone(mChannel);
         }
         else
         {
            mDynamicRequestPending = false;
            // TODO: Lock?
            if (Mix_PlayChannel( mChannel , &mDynamicChunk,  -1 )<0)
              onChannelDone(mChannel);
         }
         if (!sDoneChannel[mChannel])
         {
            mSoundPos0 = getMixerTime(0);

            Mix_Volume( mChannel, inTransform.volume*MIX_MAX_VOLUME );
         }
      }
   }
コード例 #4
0
ファイル: SDLSound.cpp プロジェクト: clemos/nme
 void setTransform(const SoundTransform &inTransform) 
 {
    if (mChannel>=0)
       Mix_Volume( mChannel, inTransform.volume*MIX_MAX_VOLUME );
 }
コード例 #5
0
ファイル: SoundManager.cpp プロジェクト: nolnoch/game-tech
int SoundManager::getVolume() {
  return Mix_Volume(-1, -1);
}
コード例 #6
0
ファイル: audio.cpp プロジェクト: zurn/Zakes
void audio::set_sfx_vol(int vol)
{
	Mix_Volume(-1, vol);
}
コード例 #7
0
ファイル: Audio.cpp プロジェクト: spycrab/HadakaVM
void Audio::setVoiceVolume(uint32_t volume)
{
    Mix_Volume(0,((MIX_MAX_VOLUME/100)*volume)%101);
}
コード例 #8
0
ファイル: soundmanager.cpp プロジェクト: Rawng/ManaPlus
void SoundManager::init()
{
    // Don't initialize sound engine twice
    if (mInstalled)
        return;

    logger->log1("SoundManager::init() Initializing sound...");

    mPlayBattle = config.getBoolValue("playBattleSound");
    mPlayGui = config.getBoolValue("playGuiSound");
    mPlayMusic = config.getBoolValue("playMusic");
    mFadeoutMusic = config.getBoolValue("fadeoutmusic");
    mMusicVolume = config.getIntValue("musicVolume");
    mSfxVolume = config.getIntValue("sfxVolume");
    mCacheSounds = config.getIntValue("uselonglivesounds");

    config.addListener("playBattleSound", this);
    config.addListener("playGuiSound", this);
    config.addListener("playMusic", this);
    config.addListener("sfxVolume", this);
    config.addListener("musicVolume", this);
    config.addListener("fadeoutmusic", this);
    config.addListener("uselonglivesounds", this);

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
    {
        logger->log1("SoundManager::init() Failed to "
            "initialize audio subsystem");
        return;
    }

    const size_t audioBuffer = 4096;
    int channels = config.getIntValue("audioChannels");
    switch (channels)
    {
        case 3:
            channels = 4;
            break;
        case 4:
            channels = 6;
            break;
        default:
            break;
    }

    const int res = Mix_OpenAudio(config.getIntValue("audioFrequency"),
        MIX_DEFAULT_FORMAT, channels, audioBuffer);

    if (res < 0)
    {
        logger->log("SoundManager::init Could not initialize audio: %s",
                    Mix_GetError());
        if (Mix_OpenAudio(22010, MIX_DEFAULT_FORMAT, 2, audioBuffer) < 0)
            return;
        logger->log("Fallback to stereo audio");
    }

    Mix_AllocateChannels(16);
    Mix_VolumeMusic(mMusicVolume);
    Mix_Volume(-1, mSfxVolume);

    info();

    mInstalled = true;

    if (!mCurrentMusicFile.empty() && mPlayMusic)
        playMusic(mCurrentMusicFile);
}
コード例 #9
0
ファイル: Sound.cpp プロジェクト: ppiecuch/Prototype
void Sound::Volume(int channel,int vol){
	Mix_Volume(1,vol);
}
コード例 #10
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// * Sets the volume 
void CSound::SetVolume(long volume)
{
    Mix_Volume(-1,volume);
    Mix_VolumeMusic(volume);
}
コード例 #11
0
ファイル: digi_mixer.c プロジェクト: arbruijn/d1xnacl
void digi_mixer_set_digi_volume( int dvolume )
{
  digi_volume = dvolume;
  if (!digi_initialised) return;
  Mix_Volume(-1, fix2byte(dvolume));
}
コード例 #12
0
ファイル: x_Game.cpp プロジェクト: richi902/FurbyKill-3D
//
// Update
//
void Game::Update()
{
	list<Sprite *>::iterator it;
	Sprite *curSpr;
	static bool HPwarning = false;
	static int chan = NULL;

	if(showExitConfirm)
		return;
	
	UpdateMessages();
	
	if(player->GetWeapon()==0)
		RELOAD_TIME = 650;
	if(player->GetWeapon()==1)
		RELOAD_TIME = 280;

	// Update sprites
	for(it = sprites.begin(); it != sprites.end(); it++)
	{
		curSpr = *it;
		
		if(curSpr->GetId() == ET_FURBY)
		{
			Furby *fb = (Furby *)curSpr;
			fb->Update(raycaster);
		
		}
		else if(curSpr->GetId() == SHOT_INDEX)
		{
			Shot *shot = (Shot *)curSpr;	
			shot->Update(raycaster);
			
			if(shot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY()))
			{
				if(player->GetHealth() != 0)
				{
					framework->PlaySound(PlayerHurt);
				}
			AddMessage("You got hit by a shot from a furby!");
				player->DecrementHealth(10);

				it = sprites.erase(it);
				
			}
			if(shot->IsVanished())
				it = sprites.erase(it);
		}
		else if(curSpr->GetId() == DEATH_ANIMATION_INDEX)
		{
			DeathAnimation *da = (DeathAnimation *)curSpr;
			da->Update();
			
			if(da->HasEnded())
			{
				float itsX, itsY;
				itsX = da->GetPosX();
				itsY = da->GetPosY();
				
				delete da;
				it = sprites.erase(it);
				
				
				Sprite *corpse = new Sprite(spriteImgs[2], itsX, itsY, 2);
				sprites.push_back(corpse);				
			}
		}

		if(curSpr->GetId() == ET_SKULL)
		{
			Skull *sk = (Skull *)curSpr;
			sk->Update(raycaster);
		}
		else if(curSpr->GetId() == SK_SHOT_INDEX)
		{
			SkullShot *skullshot = (SkullShot *)curSpr;
			skullshot->Update(raycaster);

			if(skullshot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY()))
			{
				if(player->GetHealth() !=0)
				{
					framework->PlaySound(PlayerHurt);
				}
			
				AddMessage("You got hit by a shot from a Skull!");
				player->DecrementHealth(20);

				it = sprites.erase(it);
			}
			if(skullshot->IsVanished())
				it = sprites.erase(it);
		}
		else if(curSpr->GetId() == SKDEATH_ANIMATION_INDEX)
		{
			SKDeathAnimation *skda = (SKDeathAnimation *)curSpr;
			skda->Update();
			
			if(skda->HasEnded())
			{
				float itsX, itsY;
				itsX = skda->GetPosX();
				itsY = skda->GetPosY();
				
 				delete skda;
				it = sprites.erase(it);
				
				Sprite *skcorpse = new Sprite(spriteImgs[20], itsX, itsY, 2);
				sprites.push_back(skcorpse);				
			}
		}

		
	
	}

	if(player->GetHealth() <= 30 && HPwarning == false)
	{
		chan = framework->PlaySound(HeartBeat, -1);
		Mix_Volume(chan, MIX_MAX_VOLUME);
		HPwarning = true;
	}

	if(player->GetHealth() > 30 && HPwarning == true)
	{
			Mix_HaltChannel(chan);
			HPwarning = false;
	}

	if(player->GetHealth() == 0)
	{
		
		framework->PlaySound(PlayerDead);
		GameOver();
	}
	
	if(raycaster->MapChangeNeeded())
        NextMap();	
}
コード例 #13
0
void ONScripter::variableEditMode( SDL_KeyboardEvent *event )
{
    int  i;
    const char *var_name;
    char var_index[12];

    switch ( event->keysym.sym ) {
      case SDLK_m:
        if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
        variable_edit_mode = EDIT_MP3_VOLUME_MODE;
        variable_edit_num = music_volume;
        break;

      case SDLK_s:
        if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
        variable_edit_mode = EDIT_SE_VOLUME_MODE;
        variable_edit_num = se_volume;
        break;

      case SDLK_v:
        if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
        variable_edit_mode = EDIT_VOICE_VOLUME_MODE;
        variable_edit_num = voice_volume;
        break;

      case SDLK_n:
        if ( variable_edit_mode != EDIT_SELECT_MODE ) return;
        variable_edit_mode = EDIT_VARIABLE_INDEX_MODE;
        variable_edit_num = 0;
        break;

      case SDLK_9: case SDLK_KP9: variable_edit_num = variable_edit_num * 10 + 9; break;
      case SDLK_8: case SDLK_KP8: variable_edit_num = variable_edit_num * 10 + 8; break;
      case SDLK_7: case SDLK_KP7: variable_edit_num = variable_edit_num * 10 + 7; break;
      case SDLK_6: case SDLK_KP6: variable_edit_num = variable_edit_num * 10 + 6; break;
      case SDLK_5: case SDLK_KP5: variable_edit_num = variable_edit_num * 10 + 5; break;
      case SDLK_4: case SDLK_KP4: variable_edit_num = variable_edit_num * 10 + 4; break;
      case SDLK_3: case SDLK_KP3: variable_edit_num = variable_edit_num * 10 + 3; break;
      case SDLK_2: case SDLK_KP2: variable_edit_num = variable_edit_num * 10 + 2; break;
      case SDLK_1: case SDLK_KP1: variable_edit_num = variable_edit_num * 10 + 1; break;
      case SDLK_0: case SDLK_KP0: variable_edit_num = variable_edit_num * 10 + 0; break;

      case SDLK_MINUS: case SDLK_KP_MINUS:
        if ( variable_edit_mode == EDIT_VARIABLE_NUM_MODE && variable_edit_num == 0 ) variable_edit_sign = -1;
        break;

      case SDLK_BACKSPACE:
        if ( variable_edit_num ) variable_edit_num /= 10;
        else if ( variable_edit_sign == -1 ) variable_edit_sign = 1;
        break;

      case SDLK_RETURN: case SDLK_KP_ENTER:
        switch( variable_edit_mode ){

          case EDIT_VARIABLE_INDEX_MODE:
            variable_edit_index = variable_edit_num;
            variable_edit_num = script_h.getVariableData(variable_edit_index).num;
            if ( variable_edit_num < 0 ){
                variable_edit_num = -variable_edit_num;
                variable_edit_sign = -1;
            }
            else{
                variable_edit_sign = 1;
            }
            break;

          case EDIT_VARIABLE_NUM_MODE:
            script_h.setNumVariable( variable_edit_index, variable_edit_sign * variable_edit_num );
            break;

          case EDIT_MP3_VOLUME_MODE:
            music_volume = variable_edit_num;
            Mix_VolumeMusic( music_volume * MIX_MAX_VOLUME / 100 );
            break;

          case EDIT_SE_VOLUME_MODE:
            se_volume = variable_edit_num;
            for ( i=1 ; i<ONS_MIX_CHANNELS ; i++ )
                if ( wave_sample[i] ) Mix_Volume( i, se_volume * MIX_MAX_VOLUME / 100 );
            if ( wave_sample[MIX_LOOPBGM_CHANNEL0] ) Mix_Volume( MIX_LOOPBGM_CHANNEL0, se_volume * MIX_MAX_VOLUME / 100 );
            if ( wave_sample[MIX_LOOPBGM_CHANNEL1] ) Mix_Volume( MIX_LOOPBGM_CHANNEL1, se_volume * MIX_MAX_VOLUME / 100 );
            break;

          case EDIT_VOICE_VOLUME_MODE:
            voice_volume = variable_edit_num;
            if ( wave_sample[0] ) Mix_Volume( 0, se_volume * MIX_MAX_VOLUME / 100 );

          default:
            break;
        }
        if ( variable_edit_mode == EDIT_VARIABLE_INDEX_MODE )
            variable_edit_mode = EDIT_VARIABLE_NUM_MODE;
        else
            variable_edit_mode = EDIT_SELECT_MODE;
        break;

      case SDLK_ESCAPE:
        if ( variable_edit_mode == EDIT_SELECT_MODE ){
            variable_edit_mode = NOT_EDIT_MODE;
            SDL_WM_SetCaption( DEFAULT_WM_TITLE, DEFAULT_WM_ICON );
            SDL_Delay( 100 );
            SDL_WM_SetCaption( wm_title_string, wm_icon_string );
            return;
        }
        variable_edit_mode = EDIT_SELECT_MODE;

      default:
        break;
    }

    if ( variable_edit_mode == EDIT_SELECT_MODE ){
        sprintf( wm_edit_string, "%s%s", EDIT_MODE_PREFIX, EDIT_SELECT_STRING );
    }
    else if ( variable_edit_mode == EDIT_VARIABLE_INDEX_MODE ) {
        sprintf( wm_edit_string, "%s%s%d", EDIT_MODE_PREFIX, "Variable Index?  %", variable_edit_sign * variable_edit_num );
    }
    else if ( variable_edit_mode >= EDIT_VARIABLE_NUM_MODE ){
        int p=0;
        
        switch( variable_edit_mode ){

          case EDIT_VARIABLE_NUM_MODE:
            sprintf( var_index, "%%%d", variable_edit_index );
            var_name = var_index; p = script_h.getVariableData(variable_edit_index).num; break;

          case EDIT_MP3_VOLUME_MODE:
            var_name = "MP3 Volume"; p = music_volume; break;

          case EDIT_VOICE_VOLUME_MODE:
            var_name = "Voice Volume"; p = voice_volume; break;

          case EDIT_SE_VOLUME_MODE:
            var_name = "Sound effect Volume"; p = se_volume; break;

          default:
            var_name = "";
        }
        sprintf( wm_edit_string, "%sCurrent %s=%d  New value? %s%d",
                 EDIT_MODE_PREFIX, var_name, p, (variable_edit_sign==1)?"":"-", variable_edit_num );
    }

    SDL_WM_SetCaption( wm_edit_string, wm_icon_string );
}
コード例 #14
0
ファイル: mixer.cpp プロジェクト: vanfanel/rawgl
	void setChannelVolume(uint8_t channel, uint8_t volume) {
		Mix_Volume(channel, volume * MIX_MAX_VOLUME / 63);
	}
コード例 #15
0
ファイル: Audio.cpp プロジェクト: spycrab/HadakaVM
void Audio::setSFXVolume(uint32_t volume)
{
    int voice_volume = Mix_Volume(0,-1);
    Mix_Volume(-1,((MIX_MAX_VOLUME/100)*volume)%101);
    Mix_Volume(0,voice_volume);
}
コード例 #16
0
void PonscripterLabel::variableEditMode(SDL_KeyboardEvent* event)
{
    switch (event->keysym.sym) {
    case SDLK_m:
        if (variable_edit_mode != EDIT_SELECT_MODE) return;

        variable_edit_mode = EDIT_MP3_VOLUME_MODE;
        variable_edit_num  = music_volume;
        break;

    case SDLK_s:
        if (variable_edit_mode != EDIT_SELECT_MODE) return;

        variable_edit_mode = EDIT_SE_VOLUME_MODE;
        variable_edit_num  = se_volume;
        break;

    case SDLK_v:
        if (variable_edit_mode != EDIT_SELECT_MODE) return;

        variable_edit_mode = EDIT_VOICE_VOLUME_MODE;
        variable_edit_num  = voice_volume;
        break;

    case SDLK_n:
        if (variable_edit_mode != EDIT_SELECT_MODE) return;

        variable_edit_mode = EDIT_VARIABLE_INDEX_MODE;
        variable_edit_num  = 0;
        break;

    case SDLK_9: case SDLK_KP_9:
	variable_edit_num = variable_edit_num * 10 + 9; break;
    case SDLK_8: case SDLK_KP_8:
	variable_edit_num = variable_edit_num * 10 + 8; break;
    case SDLK_7: case SDLK_KP_7:
	variable_edit_num = variable_edit_num * 10 + 7; break;
    case SDLK_6: case SDLK_KP_6:
	variable_edit_num = variable_edit_num * 10 + 6; break;
    case SDLK_5: case SDLK_KP_5:
	variable_edit_num = variable_edit_num * 10 + 5; break;
    case SDLK_4: case SDLK_KP_4:
	variable_edit_num = variable_edit_num * 10 + 4; break;
    case SDLK_3: case SDLK_KP_3:
	variable_edit_num = variable_edit_num * 10 + 3; break;
    case SDLK_2: case SDLK_KP_2:
	variable_edit_num = variable_edit_num * 10 + 2; break;
    case SDLK_1: case SDLK_KP_1:
	variable_edit_num = variable_edit_num * 10 + 1; break;
    case SDLK_0: case SDLK_KP_0:
	variable_edit_num = variable_edit_num * 10 + 0; break;

    case SDLK_MINUS: case SDLK_KP_MINUS:
        if (variable_edit_mode == EDIT_VARIABLE_NUM_MODE &&
	    variable_edit_num == 0)
	{
	    variable_edit_sign = -1;
	}
        break;

    case SDLK_BACKSPACE:
        if (variable_edit_num) variable_edit_num /= 10;
        else if (variable_edit_sign == -1) variable_edit_sign = 1;

        break;

    case SDLK_RETURN: case SDLK_KP_ENTER:
        switch (variable_edit_mode) {
        case EDIT_VARIABLE_INDEX_MODE:
            variable_edit_index = variable_edit_num;
            variable_edit_num =
                script_h.getVariableData(variable_edit_index).get_num();
            if (variable_edit_num < 0) {
                variable_edit_num  = -variable_edit_num;
                variable_edit_sign = -1;
            }
            else {
                variable_edit_sign = 1;
            }

            break;

        case EDIT_VARIABLE_NUM_MODE:
            script_h.setNumVariable(variable_edit_index, variable_edit_sign * variable_edit_num);
            break;

        case EDIT_MP3_VOLUME_MODE:
            music_volume = variable_edit_num;
            if (mp3_sample)
                SMPEG_setvolume(mp3_sample, !volume_on_flag? 0 : music_volume);
            break;

        case EDIT_SE_VOLUME_MODE:
            se_volume = variable_edit_num;
            for (int i = 1; i < ONS_MIX_CHANNELS; i++)
                if (wave_sample[i])
                    Mix_Volume(i, !volume_on_flag? 0 : se_volume * 128 / 100);

            if (wave_sample[MIX_LOOPBGM_CHANNEL0])
                Mix_Volume(MIX_LOOPBGM_CHANNEL0, !volume_on_flag? 0 : se_volume * 128 / 100);

            if (wave_sample[MIX_LOOPBGM_CHANNEL1])
                Mix_Volume(MIX_LOOPBGM_CHANNEL1, !volume_on_flag? 0 : se_volume * 128 / 100);

            break;

        case EDIT_VOICE_VOLUME_MODE:
            voice_volume = variable_edit_num;
            if (wave_sample[0])
                Mix_Volume(0, !volume_on_flag? 0 : se_volume * 128 / 100);

        default:
            break;
        }

        if (variable_edit_mode == EDIT_VARIABLE_INDEX_MODE)
            variable_edit_mode = EDIT_VARIABLE_NUM_MODE;
        else
            variable_edit_mode = EDIT_SELECT_MODE;

        break;

    case SDLK_ESCAPE:
        if (variable_edit_mode == EDIT_SELECT_MODE) {
            variable_edit_mode = NOT_EDIT_MODE;
            SDL_SetWindowTitle(screen, DEFAULT_WM_TITLE);
            SDL_Delay(100);
            SDL_SetWindowTitle(screen, wm_title_string);
            return;
        }

        variable_edit_mode = EDIT_SELECT_MODE;

    default:
        break;
    }

    if (variable_edit_mode == EDIT_SELECT_MODE) {
        wm_edit_string = EDIT_MODE_PREFIX EDIT_SELECT_STRING;
    }
    else if (variable_edit_mode == EDIT_VARIABLE_INDEX_MODE) {
        wm_edit_string.format(EDIT_MODE_PREFIX "Variable Index?  %%%d",
			      variable_edit_sign * variable_edit_num);
    }
    else if (variable_edit_mode >= EDIT_VARIABLE_NUM_MODE) {
        int p = 0;
	pstring var_name;

        switch (variable_edit_mode) {
        case EDIT_VARIABLE_NUM_MODE:
	    var_name.format("%%%d", variable_edit_index);
	    p = script_h.getVariableData(variable_edit_index).get_num();
            break;

        case EDIT_MP3_VOLUME_MODE:
            var_name = "MP3 Volume"; p = music_volume; break;

        case EDIT_VOICE_VOLUME_MODE:
            var_name = "Voice Volume"; p = voice_volume; break;

        case EDIT_SE_VOLUME_MODE:
            var_name = "Sound effect Volume"; p = se_volume; break;

        default:
            var_name = "";
        }

	wm_edit_string.format(EDIT_MODE_PREFIX "Current %s=%d  New value? %d",
			      (const char*) var_name, p,
			      variable_edit_num * variable_edit_sign);
    }

    SDL_SetWindowTitle(screen, wm_title_string);
    //TODO
    //SDL_SetWindowIcon(screen, wm_icon_string);
}
コード例 #17
0
ファイル: audio.cpp プロジェクト: Arikado/Wii-Homebrew
int cAudio :: PlaySound( string filename, int channel /* = -1 */, int Volume /* = -1  */ )
{
	if( !bSounds || !bInitialised )
	{
		return 0;
	}

	if( channel > 128 ) // new
	{
		printf( "PlaySound channel is out of range : %d\n", channel );
		return 0;
	}

	if( !valid_file( filename ) )
	{
		printf( "Couldn't find sound file : %s\n", filename.c_str() );
		return 0;
	}

	SCounter++;
	
	if( SCounter == AUDIO_MAX_SOUNDS )
	{
		SCounter = 0;
	}
	
	if( Sound[SCounter] )
	{
		Mix_FreeChunk( Sound[SCounter] );
		Sound[SCounter] = NULL;
	}

	Sound[SCounter] = Mix_LoadWAV( filename.c_str() );

	int channel_used = Mix_PlayChannel( channel, Sound[SCounter], 0 );

	if( channel_used == -1 )
	{
		if( bDebug ) 
		{
			printf( "Couldn't play sound file : %s\n", filename.c_str() );
		}

		return 0;
	}
	else
	{
		Sounds_Played++;

		if( Volume != -1 ) // new
		{
			if( Volume > 128 || Volume < 0 )
			{
				printf( "PlaySound Volume out is of range : %d\n", Volume );
				Volume =  Sound_Volume;
			}

			Mix_Volume( channel_used, Volume );
		}
		else
		{
			Mix_Volume( channel_used, Sound_Volume );
		}
	}

	return 1;
}
コード例 #18
0
void SoundManager::effect_change_volume(const float vol)
{
    Mix_Volume(-1, MIX_MAX_VOLUME * vol);
    _effect_volume = vol;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: Paul-Wortmann/Star.P.G.
//----------------------------------- Main -------------------------------------
int main(int argc, char *argv[])
{
    std::string cheat_string = "cheat";
    //std::locale::global( std::locale( "" ) );
    events_init();
    game.log.File_Set("Star.P.G..log");
    game.log.File_Clear();
    if (argc > 1)
    {
        for (int count = 0; count < (argc+1); count++)
        {
            //game.log.File_Write(argv[count]);
            if (cheat_string.compare(argv[count]) == 0) game_o.cheats_enabled = true;
        }
    }
    //game_o.cheats_enabled = true; /// test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    game.log.File_Write("------------------");
    game.log.File_Write("| Star.P.G V1.01 |");
    game.log.File_Write("------------------\n");
    game.log.File_Write("Starting up!");
    game.log.File_Write("");
    game.log.File_Write("------------------\n");
    //if (game_o.cheats_enabled) game.log.File_Write("Cheating enabled!\n");
    game.config.File_Set("Star.P.G..cfg");
    game.config.Set_Defaults();
    game.log.File_Write("Loading config...");
    game.config.File_Set("Star.P.G..cfg");
    game.config.File_Read();
    game.log.File_Write("Loading language file -> data/configuration/languages/"+game.config.language+".txt");
    game_o.language.load("data/configuration/languages/"+game.config.language+".txt");
 //----------------------------------- Start the PhysicsFS ----------------------
    //game.log.File_Write("Starting PhysicsFS...");
    //PHYSFS_init(argv[0]);
    //PHYSFS_addToSearchPath("Star.P.G..spg", 1);
//----------------------------------- SDL Video --------------------------------
    game.log.File_Write("Starting SDL...");
    char SDL_VID_WIN_POS[] = "SDL_VIDEO_WINDOW_POS";
    char SDL_VID_CENTERD[] = "SDL_VIDEO_CENTERED=1";
    putenv(SDL_VID_WIN_POS);
    putenv(SDL_VID_CENTERD);
    getenv("SDL_VIDEO_WINDOW_POS");
    getenv("SDL_VIDEO_CENTERED");
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD);
    game.log.File_Write("Starting OpenGL...");
    if (game.config.Display_Fullscreen) SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL | SDL_FULLSCREEN);
    else SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL/* | SDL_NOFRAME */);
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    App_Icon_Surface = SDL_LoadBMP(App_Icon);
    colorkey = SDL_MapRGB(App_Icon_Surface->format, 255, 0, 255);
    SDL_SetColorKey(App_Icon_Surface, SDL_SRCCOLORKEY, colorkey);
    SDL_WM_SetIcon(App_Icon_Surface,NULL);
    SDL_WM_SetCaption(App_Name, 0);
    //SDL_ShowCursor(SDL_DISABLE);
//----------------------------------- SDL Audio --------------------------------
    game.log.File_Write("Starting sound system...");
    SDL_Init(SDL_INIT_AUDIO);
    Mix_AllocateChannels(game.config.Audio_Channels);
    Mix_OpenAudio(game.config.Audio_Rate, AUDIO_S16, 2, game.config.Audio_Buffers);
    Mix_Volume(-1,game.config.Audio_Sound_Volume);
    Mix_VolumeMusic(game.config.Audio_Music_Volume);
    game.log.File_Write("Initializing joystick / gamepad...");
    SDL_Init(SDL_INIT_JOYSTICK);
    game.log.File_Write("Initializing game system...");
    init_game(false);
    game.log.File_Write("Initializing projectiles...");
    init_player_bullets();
    game.log.File_Write("Initializing explosions...");
    init_explosions();
    game.log.File_Write("Initializing NPCs...\n");
    init_active_npcs();
    init_npc_bullets();
    init_npcs(0);
    game_o.current_level = 0;
    game.log.File_Write("Initializing OpenGL...");
    game.graphics.init_gl(game.config.Display_X_Resolution,game.config.Display_Y_Resolution);
    seed_rand();
    TTF_Init();
    game.log.File_Write("Loading resources...");
    loading_screen_display("data/textures/misc/loading_screen.png");
    load_resources();
    game.log.File_Write("Initializing menu system...");
    init_menu();
    init_in_game_message_class();
    init_projectiles(false);
    init_powerups();
    init_shields(false);
    init_game(false);
    game.log.File_Write("Starting game...");
    game.log.File_Write("---------------\n");
//----------------------------------- Main loop --------------------------------
    game.timer.start();
    game.LastTicks = game.timer.getticks();
    for(int quit = 0; !quit;)
    {
        game.config.process(false);
        if (game.config.mouse_autohide) SDL_ShowCursor(SDL_DISABLE);
        else SDL_ShowCursor(SDL_ENABLE);
        proc_textures();
        events_process();
        if (game.status_quit_active) quit = 1;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//****************************************** MENU *****************************************
        if (game.menu_active)
        {
            SDL_ShowCursor(SDL_ENABLE);
            if (game.music_next_track)
            {
                music.menu_00.play();
                game.music_next_track = false;
            }
            diplay_menu ();
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
        }
//****************************************** GAME *****************************************
        if (game.game_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                if (game.music_track ==  0) music.level_00.play();
                if (game.music_track ==  1) music.level_01.play();
                if (game.music_track ==  2) music.level_02.play();
                if (game.music_track ==  3) music.level_03.play();
                if (game.music_track ==  4) music.level_04.play();
                if (game.music_track ==  5) music.level_05.play();
                if (game.music_track ==  6) music.level_06.play();
                if (game.music_track ==  7) music.level_07.play();
                if (game.music_track ==  8) music.level_08.play();
                if (game.music_track ==  9) music.level_09.play();
                if (game.music_track == 10) music.level_10.play();
                if (game.music_track == 11) music.level_11.play();
                if (game.music_track == 12) music.level_12.play();
                if (game.music_track == 13) music.level_13.play();
                if (game.music_track == 14) music.level_14.play();
                if (game.music_track == 15) music.level_15.play();
                if (game.music_track == 16) music.level_16.play();
                if (game.music_track == 17) music.level_17.play();
                if (game.music_track == 18) music.level_18.play();
                if (game.music_track == 19) music.level_19.play();
                if (game.music_track == 20) music.level_20.play();
                if (game.music_track == 21) music.level_21.play();
                if (game.music_track == 22) music.level_22.play();
                if (game.music_track == 23) music.level_23.play();
                if (game.music_track == 24) music.level_24.play();
                if (game.music_track == 25) music.level_25.play();
            }
            game.game_resume = true;
            if (game.process_ready) process_game();
            display_game();
            if ((game.config.Display_Touchscreen) && (game.process_ready))
            {
                if(game.physics.point_in_quadrangle(-0.875f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.left = true;
                if(game.physics.point_in_quadrangle(-0.475f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.right = true;
                if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.350f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.up = true;
                if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.down = true;
                if(game.physics.point_in_quadrangle( 0.875f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.shoot = true;
                if(game.physics.point_in_quadrangle( 0.575f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.key_b = true;
                if(game.physics.point_in_quadrangle( 0.875f,0.2f, 0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.escape = true;
            }
            if (game_o.player.health < 0)
            {
                sound.menu_select_00.play();
                game.game_active             = false;
                game.game_resume             = false;
                game.pdie_active             = true;
                game.menu_level              = 8;
                game.config.menu_delay_count = 0;
                music.level_pd.play();
                game.background.set_data  ( 2, 1, 1, 0.0f, 0.0f, 0.0050f, 0.0050f, texture.background_019.ref_number);
                game.background.set_data  ( 1, 1, 1, 0.0f, 0.0f, 0.0020f, 0.0020f, texture.background_008.ref_number);
                game.background.set_active( 3, false);
                game.background.set_active( 4, false);
                game.background.set_movement_type(BOUNCE);
                SDL_WarpMouse(game.graphics.gl_to_res(game_over_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(game_over_menu.get_button_y_pos(1),game.config.mouse_resolution_y));
                game.log.File_Write("User terminated due to insufficient health...better luck next time buddy!");
            }
        if ((game.io.escape) && (game.process_ready))
        {
            sound.menu_select_01.play();
            game.music_next_track        = true;
            game.game_active             = false;
            game.menu_level              = 1;
            game.menu_active             = true;
            game.io.escape               = false;
            game.io.keyboard_delay_count = 0;
            game.config.menu_delay_count = 0;
            while (game.config.menu_delay_count < (game.config.menu_delay/2))
            {
                game.config.menu_delay_count++;
            }
        }

        if (game_o.bomb_delay_count < game_o.bomb_delay)//bomb delay counter
        {
            game_o.bomb_delay_count++;
            if (game_o.bomb_delay_count > game_o.bomb_delay) game_o.bomb_delay_count = game_o.bomb_delay;
        }
        if ((game.io.key_b) && (game.process_ready))//user pressed "b" for bomb
        {
            if ((game_o.number_bombs > 0) && (game_o.bomb_delay_count >= game_o.bomb_delay))
            {
                game_o.number_bombs--;
                use_bomb_powerup();
                game_o.bomb_delay_count = 0;
                if (!game_o.rumble.active) sound.explosion_001.play();
                if (!game_o.rumble.active) game_o.rumble.start(0.025f,45); // shake the screen about.
            }
        }
        if (game.io.pause)
        {
            if (!game.game_paused)
            {
                game_o.paused.spawn();
                game.game_paused = true;
                game.game_active = false;
                game.io.pause    = false;
                game.menu_level  = 11;
                SDL_WarpMouse(game.graphics.gl_to_res(pause_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(pause_menu.get_button_y_pos(1),game.config.mouse_resolution_y));
                game.config.menu_delay_count = 0;
                while (game.config.menu_delay_count < (game.config.menu_delay*16))
                {
                    game.config.menu_delay_count++;
                }
            }
            else
            {
                game.menu_active = false;
                game.game_paused = false;
                game.game_active = true;
            }
        };

        if (game_o.cheats_enabled == true)
        {
            if (game.io.key_0) game_o.victory_kills = game_o.level_kills;  //complete level
            if (game.io.key_1) spawn_powerup(1.0f,random_GLcoord(), 1);//spawn health power-up
            if (game.io.key_2) spawn_powerup(1.0f,random_GLcoord(), 2);//spawn shield level power-up
            if (game.io.key_3) spawn_powerup(1.0f,random_GLcoord(), 3);//spawn shield new power-up
            if (game.io.key_4) spawn_powerup(1.0f,random_GLcoord(), 4);//spawn thruster level power-up
            if (game.io.key_5) spawn_powerup(1.0f,random_GLcoord(), 5);//spawn thruster new power-up
            if (game.io.key_6) spawn_powerup(1.0f,random_GLcoord(), 6);//spawn weapon level power-up
            if (game.io.key_7) spawn_powerup(1.0f,random_GLcoord(), 7);//spawn weapon new power-up
            if (game.io.key_8) unlock_levels();                        //unlock all levels
            if (game.io.key_9) spawn_powerup(1.0f,random_GLcoord(), 8);//spawn bomb power-up
            if (game.io.key_a) game_o.anc_enabled   = !game_o.anc_enabled; //toggle active NPC count display
            if (game.io.key_f) game_o.fps_enabled   = !game_o.fps_enabled; //toggle active NPC count display
            if (game.io.key_q) spawn_powerup(1.0f,random_GLcoord(), 9);//spawn support ship 0 power-up
            if (game.io.key_w) spawn_powerup(1.0f,random_GLcoord(),10);//spawn support ship 1 power-up
            if (game.io.key_e) spawn_powerup(1.0f,random_GLcoord(),11);//spawn support ship 2 power-up
            if (game.io.key_r) spawn_powerup(1.0f,random_GLcoord(),12);//spawn support ship 3 power-up
            if (game.io.key_s)
            {
                if (!game_o.rumble.active) sound.explosion_001.play();
                if (!game_o.rumble.active) game_o.rumble.start(); // shake the screen about.
            }
        }

        if (game.io.shoot)
        {
           process_supportships(true);
           if(game_o.fw_rof_count >= game_o.projectile[game_o.player.front_weapon].rate_of_fire)
           {
              spawn_player_bullet(0);
              game_o.fw_rof_count = 0;
           }
           if(game_o.sw_rof_count >= game_o.projectile[game_o.player.side_weapon].rate_of_fire)
           {
              spawn_player_bullet(1);
              game_o.sw_rof_count = 0;
           }
        }
        else
        {
            process_supportships(false);
        }
        if (game.process_ready)
        {
            if (game.io.up)    process_player(1);
            if (game.io.down)  process_player(2);
            if (game.io.right) process_player(3);
            if (game.io.left)  process_player(4);
        }
        if ((game.io.key_1) && (game_o.projectile[ 0].active))
        {
            game_o.player.front_weapon = 0;
        }
        if ((game.io.key_2) && (game_o.projectile[ 1].active))
        {
            game_o.player.front_weapon = 1;
        }
        if ((game.io.key_3) && (game_o.projectile[ 2].active))
        {
            game_o.player.front_weapon = 2;
        }
        if ((game.io.key_4) && (game_o.projectile[ 3].active))
        {
            game_o.player.front_weapon = 3;
        }
        if ((game.io.key_5) && (game_o.projectile[ 4].active))
        {
            game_o.player.front_weapon = 4;
        }
        if ((game.io.key_6) && (game_o.projectile[ 5].active))
        {
            game_o.player.front_weapon = 5;
        }
    }
//*********************************** Game paused *****************************************
        if (game.game_paused)
        {
            if ((game.io.pause) && (game.process_ready))
            {
                game.menu_active = false;
                game.game_paused = false;
                game.game_active = true;
            }
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_pd.play();
            }
            game.menu_level = 11;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            display_game();
            diplay_menu ();
         }
//*********************************** PLAYER DEATH SCREEN *****************************************
        if (game.pdie_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_pd.play();
            }
            diplay_menu ();
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            if (!game.pdie_active)  init_game(true);
        }
//******************************* PLAYER NEXT LEVEL SCREEN *************************************
        if (game.nlvl_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_nl.play();
            }
            game.menu_level = 9;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            diplay_menu ();
        }
//******************************* OUTRO SCREEN *************************************************
     if (game.outr_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.outro_00.play();
            }
            game.menu_level = 10;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            diplay_menu ();
        }
//---------------------------- code for end of main loop -----------------------
        game.FPS = (game.timer.getticks() - game.LastTicks);
        if ((game.timer.getticks() - game.LastTicks) >= 2)
        {
            game.LastTicks = game.timer.getticks();
            game.process_ready = true;
        }
        else game.process_ready = false;
        SDL_GL_SwapBuffers();
    }
//----------------------------------- Exit -------------------------------------
    game.log.File_Write("Saving configuration...");
    game.config.File_Set("Star.P.G..cfg");
    game.config.File_Clear();
    game.config.File_Write();
    game.log.File_Write("\n");
    game.log.File_Write("Shutting down...");
    game.log.File_Write("---------------\n");
//    game.log.File_Write("PhysicsFS deinit...");
//    PHYSFS_deinit();
    game.log.File_Write("SDL deinit...");
    SDL_Quit();
    return(0);
}
コード例 #20
0
ファイル: mixer.c プロジェクト: 0xD34D/supermariowar-android
/* Mixing function */
static void mix_channels(void *udata, Uint8 *stream, int len)
{
	Uint8 *mix_input;
	int i, mixable, volume = SDL_MIX_MAXVOLUME;
	Uint32 sdl_ticks;

#if SDL_VERSION_ATLEAST(1, 3, 0)
	/* Need to initialize the stream in SDL 1.3+ */
	memset(stream, mixer.silence, len);
#endif

	/* Mix the music (must be done before the channels are added) */
	if ( music_active || (mix_music != music_mixer) ) {
		mix_music(music_data, stream, len);
	}

	/* Mix any playing channels... */
	sdl_ticks = SDL_GetTicks();
	for ( i=0; i<num_channels; ++i ) {
		if( ! mix_channel[i].paused ) {
			if ( mix_channel[i].expire > 0 && mix_channel[i].expire < sdl_ticks ) {
				/* Expiration delay for that channel is reached */
				mix_channel[i].playing = 0;
				mix_channel[i].fading = MIX_NO_FADING;
				mix_channel[i].expire = 0;
				_Mix_channel_done_playing(i);
			} else if ( mix_channel[i].fading != MIX_NO_FADING ) {
				Uint32 ticks = sdl_ticks - mix_channel[i].ticks_fade;
				if( ticks > mix_channel[i].fade_length ) {
				    Mix_Volume(i, mix_channel[i].fade_volume_reset); /* Restore the volume */
					if( mix_channel[i].fading == MIX_FADING_OUT ) {
						mix_channel[i].playing = 0;
						mix_channel[i].expire = 0;
						_Mix_channel_done_playing(i);
					}
					mix_channel[i].fading = MIX_NO_FADING;
				} else {
					if( mix_channel[i].fading == MIX_FADING_OUT ) {
						Mix_Volume(i, (mix_channel[i].fade_volume * (mix_channel[i].fade_length-ticks))
								   / mix_channel[i].fade_length );
					} else {
						Mix_Volume(i, (mix_channel[i].fade_volume * ticks) / mix_channel[i].fade_length );
					}
				}
			}
			if ( mix_channel[i].playing > 0 ) {
				int index = 0;
				int remaining = len;
				while (mix_channel[i].playing > 0 && index < len) {
					remaining = len - index;
					volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME;
					mixable = mix_channel[i].playing;
					if ( mixable > remaining ) {
						mixable = remaining;
					}

					mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
					SDL_MixAudio(stream+index,mix_input,mixable,volume);
					if (mix_input != mix_channel[i].samples)
						free(mix_input);

					mix_channel[i].samples += mixable;
					mix_channel[i].playing -= mixable;
					index += mixable;

					/* rcg06072001 Alert app if channel is done playing. */
					if (!mix_channel[i].playing && !mix_channel[i].looping) {
						_Mix_channel_done_playing(i);
					}
				}

				/* If looping the sample and we are at its end, make sure
				   we will still return a full buffer */
				while ( mix_channel[i].looping && index < len ) {
					int alen = mix_channel[i].chunk->alen;
					remaining = len - index;
					if (remaining > alen) {
						remaining = alen;
					}

					mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining);
					SDL_MixAudio(stream+index, mix_input, remaining, volume);
					if (mix_input != mix_channel[i].chunk->abuf)
						free(mix_input);

					--mix_channel[i].looping;
					mix_channel[i].samples = mix_channel[i].chunk->abuf + remaining;
					mix_channel[i].playing = mix_channel[i].chunk->alen - remaining;
					index += remaining;
				}
				if ( ! mix_channel[i].playing && mix_channel[i].looping ) {
					--mix_channel[i].looping;
					mix_channel[i].samples = mix_channel[i].chunk->abuf;
					mix_channel[i].playing = mix_channel[i].chunk->alen;
				}
			}
		}
	}

	/* rcg06122001 run posteffects... */
	Mix_DoEffects(MIX_CHANNEL_POST, stream, len);

	if ( mix_postmix ) {
		mix_postmix(mix_postmix_data, stream, len);
	}
}
コード例 #21
0
ファイル: options.c プロジェクト: akien-mga/tbftss
static void changeSoundVolume(char *value)
{
	app.soundVolume = atoi(value);

	Mix_Volume(-1, app.soundVolume * MIX_MAX_VOLUME / 10);
}