Пример #1
1
void CSoundPlayer::PlayPosSample(enum TIngameSoundEffect aEffect,float aVolume, CCoord<int> aPos)
{
	ASSERTPTR( iDynData );
	if (aEffect==ESoundEffectNoSound) return;

	if (iObserver)
		iObserver->SoundHeard(aEffect,aVolume,aPos);

	if (!iInitialized)
		return;

	if (iDynData->LocalPlayers().size()!=1)
	{
		PlaySample(iDynData->LevelRuntime()->IngameData()->SoundFX(aEffect),aVolume,PAN_MIDDLE);
		return;
	}
	
	int chan=Mix_PlayChannel(-1,iDynData->LevelRuntime()->IngameData()->SoundFX(aEffect),0);
	Mix_Volume(chan,(int)(aVolume*iFXVolume*127.0));

	int left, right;

	StereoShaper( iDynData->LocalPlayers()[0]->Location(),aPos, left, right );

	Mix_SetPanning(chan, left, right );
}
Пример #2
0
void MAS::SpinBox::HandleEvent(Widget& obj, int msg, intptr_t arg1, intptr_t arg2) {
   if (msg == MSG_ACTIVATE) {
      if (obj == bUp) {
         double oldpos = pos;
         SetPosition(editBox.GetDouble());
         Increment();
         if (oldpos != pos) {
            PlaySample(Skin::SAMPLE_SCROLL);
            GetParent()->HandleEvent(*this, MSG_SCROLL, (intptr_t)GetIncrement());
         }
      }
      else if (obj == bDown) {
         double oldpos = pos;
         SetPosition(editBox.GetDouble());
         Decrement();
         if (oldpos != pos) {
            PlaySample(Skin::SAMPLE_SCROLL);
            GetParent()->HandleEvent(*this, MSG_SCROLL, -(intptr_t)GetIncrement());
         }
      }
      else {
         GetParent()->HandleEvent(*this, callbackID >= 0 ? callbackID : MSG_ACTIVATE);
      }
   }
   else if (msg == MSG_UCHAR && obj == editBox) {
      if (integerMode) {
         SetPosition(editBox.GetInt());
      }
      else {
         ScrollObject::SetPosition(editBox.GetDouble());
      }
   }
}
Пример #3
0
void MAS::Window::HandleEvent(MAS::Widget &obj, int msg, intptr_t arg1, intptr_t arg2) {
   Dialog::HandleEvent(obj, msg, arg1, arg2);

   if (msg == MSG_ACTIVATE) {
      if (obj == iconMin) {
         Minimize();
      }
      else if (obj == iconMax) {
         Maximize();
      }
   }
   else if (msg == MSG_DCLICK) {
      if (obj == bGrip || obj == textBack || obj == title) {
         if (TestFlag(D_RESIZABLE)) {
            if (extraFlags & W_MAXIMIZED) {
               PlaySample(Skin::SAMPLE_CLOSE);
            }
            else {
               PlaySample(Skin::SAMPLE_OPEN);
            }
            Maximize();
         }
      }
   }
   else if (msg == MSG_CLOSE && obj == *clientArea) {
      Close();
   }
}
Пример #4
0
void COpenALSound::PlaySample(int id, float volume)
{
	if (!camera) {
		return;
	}
	PlaySample(id, float3(0, 0, 0), volume, true);
}
Пример #5
0
void generator::GenerateBasicPowerUp(void)
{
	ResetParams();
	if(rnd(1)) {
		wave_type=1;
	} else {
		p_duty=frnd(0.6f);
	}
	if(rnd(1)) {
		p_base_freq=0.2f+frnd(0.3f);
		p_freq_ramp=0.1f+frnd(0.4f);
		p_repeat_speed=0.4f+frnd(0.4f);
	} else {
		p_base_freq=0.2f+frnd(0.3f);
		p_freq_ramp=0.05f+frnd(0.2f);
		if(rnd(1)) {
			p_vib_strength=frnd(0.7f);
			p_vib_speed=frnd(0.6f);
		}
	}
	p_env_attack=0.0f;
	p_env_sustain=frnd(0.4f);
	p_env_decay=0.1f+frnd(0.4f);
	PlaySample();
}
Пример #6
0
int JukeBox::Play(const std::string& category, const std::string& sample,
                  const int loop)
{
  if (!Config::GetInstance()->GetSoundEffects() || !m_init) return -1;

  uint nb_sounds= m_soundsamples.count(category+ "/" +sample);
  if (nb_sounds) {
    std::pair<sample_iterator, sample_iterator> p =
      m_soundsamples.equal_range(category+ "/" +sample);
    sample_iterator it = p.first;

    // Choose a random sound sample
    if (nb_sounds > 1) {
      uint selection = RandomLocal().GetUint(0, nb_sounds);
      if (selection == nb_sounds) --selection ;

      it = p.first ;

      for (uint i=0; i<selection && it!=p.second; ++i) it++ ;
    }

    // Play the sound
    Mix_Chunk * sampleChunk = m_cache.LoadSound(it->second.filename.c_str());
    MSG_DEBUG("jukebox.play", "Playing sample %s/%s",
              category.c_str(), sample.c_str());

    return PlaySample(sampleChunk, it->second.level, loop);
  } else if (category != "default") {
    return Play("default", sample, loop) ; // try with default profile
  }

  std::cerr << "Sound error: No sound found for sample" << category.c_str()
            << "/" << sample.c_str() << std::endl;
  return -1;
}
Пример #7
0
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param voice  Type of sound wanted (Ready,Die,Yes,...)
*/
void PlayUnitSound(const CUnit &unit, UnitVoiceGroup voice)
{
	CSound *sound = ChooseUnitVoiceSound(unit, voice);
	if (!sound) {
		return;
	}

	bool selection = (voice == VoiceSelected || voice == VoiceBuilding);
	Origin source = {&unit, unsigned(UnitNumber(unit))};

	//Wyrmgus start
//	if (UnitSoundIsPlaying(&source)) {
	if (UnitSoundIsPlaying(&source) && voice != VoiceHit && voice != VoiceMiss && voice != VoiceStep) {
	//Wyrmgus end
		return;
	}

	int channel = PlaySample(ChooseSample(sound, selection, source), &source);
	if (channel == -1) {
		return;
	}
	//Wyrmgus start
//	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range) * sound->VolumePercent / 100);
	//Wyrmgus end
	SetChannelStereo(channel, CalculateStereo(unit));
	//Wyrmgus start
	SetChannelVoiceGroup(channel, voice);
	//Wyrmgus end
}
Пример #8
0
/**
**  Ask the sound server to play a sound for a missile.
**
**  @param missile  Sound initiator, missile exploding
**  @param sound    Sound to be generated
*/
void PlayMissileSound(const Missile &missile, CSound *sound)
{
	if (!sound) {
		return;
	}
	int stereo = ((missile.position.x + (missile.Type->G ? missile.Type->G->Width / 2 : 0) +
				   UI.SelectedViewport->MapPos.x * PixelTileSize.x) * 256 /
				  ((UI.SelectedViewport->MapWidth - 1) * PixelTileSize.x)) - 128;
	clamp(&stereo, -128, 127);

	Origin source = {NULL, 0};
	//Wyrmgus start
//	unsigned char volume = CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range);
	unsigned char volume = CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range) * sound->VolumePercent / 100;
	//Wyrmgus end
	if (volume == 0) {
		return;
	}

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, volume);
	SetChannelStereo(channel, stereo);
}
Пример #9
0
void sfxr::PowerupButtonPressed()
{
    ResetParams();
    if(rnd(1))
        wave_type=1;
    else
        p_duty=frnd(0.6f);
    if(rnd(1))
    {
        p_base_freq=0.2f+frnd(0.3f);
        p_freq_ramp=0.1f+frnd(0.4f);
        p_repeat_speed=0.4f+frnd(0.4f);
    }
    else
    {
        p_base_freq=0.2f+frnd(0.3f);
        p_freq_ramp=0.05f+frnd(0.2f);
        if(rnd(1))
        {
            p_vib_strength=frnd(0.7f);
            p_vib_speed=frnd(0.6f);
        }
    }
    p_env_attack=0.0f;
    p_env_sustain=frnd(0.4f);
    p_env_decay=0.1f+frnd(0.4f);
    PlaySample();
}
Пример #10
0
void sfxr::MutateButtonPressed()
{
    if(rnd(1)) p_base_freq+=frnd(0.1f)-0.05f;
    //if(rnd(1)) p_freq_limit+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_freq_ramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_freq_dramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_duty+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_duty_ramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_vib_strength+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_vib_speed+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_vib_delay+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_env_attack+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_env_sustain+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_env_decay+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_env_punch+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_lpf_resonance+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_lpf_freq+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_lpf_ramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_hpf_freq+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_hpf_ramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_pha_offset+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_pha_ramp+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_repeat_speed+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_arp_speed+=frnd(0.1f)-0.05f;
    if(rnd(1)) p_arp_mod+=frnd(0.1f)-0.05f;
    PlaySample();
}
Пример #11
0
void TThor::GoOverground(int over)
{
    int i;

    if (over == IsOverground) return;

    if (TimeUnits < 30) {
        if (ID < BADLIFE) Message(MSG_OUT_OF_TIME);
        return;
    }
    TimeUnits -= 30;
    IsOverground = over;
    HideHelpers();
    if (GetField(X, Y)->Visib == 2) {
        if (over) PlaySample(GetUnitSound(6), 6, EffectsVolume, GetFieldPanning(X, Y));
        else PlaySample(GetUnitSound(7), 6, EffectsVolume, GetFieldPanning(X, Y));
    }
    if (over) {
        for (i = 9; i < 16; i++) {
            ActualSprite = i;
            PaintUnit();
            SDL_Delay(iniAnimDelay2);
        }
        Orient = 3; ActualSprite = 3;
        Weapons[0]->Ammo = 8;
        TotalRockets -= 8;
        if (TotalRockets < 0) {
            Weapons[0]->Ammo += TotalRockets;
            TotalRockets = 0;
        }
        Defense[0] = -utTH_DND0,    Defense[1] -= utTH_DND1,    Defense[2] -= utTH_DND2;
    }
    else {
        Rotate(3);
        for (i = 15; i > 8; i--) {
            ActualSprite = i;
            PaintUnit();
            SDL_Delay(iniAnimDelay2);
        }
        ActualSprite = 8;
        TotalRockets += Weapons[0]->Ammo;
        Weapons[0]->Ammo = 0;
        Defense[0] += utTH_DND0,    Defense[1] += utTH_DND1,    Defense[2] += utTH_DND2;
    }
    ShowHelpers();
    PaintUnit();
}
Пример #12
0
/**
**  Play a sound file
**
**  @param name  Filename of a sound to play
**
**  @return      Channel number the sound is playing on, -1 for error
*/
int PlaySoundFile(const std::string &name)
{
	CSample *sample = LoadSample(name);
	if (sample) {
		return PlaySample(sample);
	}
	return -1;
}
Пример #13
0
Файл: main.cpp Проект: nyov/sfxr
bool ExportWAV(char* filename)
{
	FILE* foutput=fopen(filename, "wb");
	if(!foutput)
		return false;
	// write wav header
	char string[32];
	unsigned int dword=0;
	unsigned short word=0;
	fwrite("RIFF", 4, 1, foutput); // "RIFF"
	dword=0;
	fwrite(&dword, 1, 4, foutput); // remaining file size
	fwrite("WAVE", 4, 1, foutput); // "WAVE"

	fwrite("fmt ", 4, 1, foutput); // "fmt "
	dword=16;
	fwrite(&dword, 1, 4, foutput); // chunk size
	word=1;
	fwrite(&word, 1, 2, foutput); // compression code
	word=1;
	fwrite(&word, 1, 2, foutput); // channels
	dword=wav_freq;
	fwrite(&dword, 1, 4, foutput); // sample rate
	dword=wav_freq*wav_bits/8;
	fwrite(&dword, 1, 4, foutput); // bytes/sec
	word=wav_bits/8;
	fwrite(&word, 1, 2, foutput); // block align
	word=wav_bits;
	fwrite(&word, 1, 2, foutput); // bits per sample

	fwrite("data", 4, 1, foutput); // "data"
	dword=0;
	int foutstream_datasize=ftell(foutput);
	fwrite(&dword, 1, 4, foutput); // chunk size

	// write sample data
	mute_stream=true;
	file_sampleswritten=0;
	filesample=0.0f;
	fileacc=0;
	PlaySample();
	while(playing_sample)
		SynthSample(256, NULL, foutput);
	mute_stream=false;

	// seek back to header and write size info
	fseek(foutput, 4, SEEK_SET);
	dword=0;
	dword=foutstream_datasize-4+file_sampleswritten*wav_bits/8;
	fwrite(&dword, 1, 4, foutput); // remaining file size
	fseek(foutput, foutstream_datasize, SEEK_SET);
	dword=file_sampleswritten*wav_bits/8;
	fwrite(&dword, 1, 4, foutput); // chunk size (data)
	fclose(foutput);

	return true;
}
Пример #14
0
void Pickup::OnCollision(Entity *e)
{
	if(e == game.player)
	{
		OnPickup();
		alive = false;
		PlaySample((SAMPLE *) game.GetData("snd_pickup"));
	}
}
Пример #15
0
/**
**  Play a game sound
**
**  @param sound   Sound to play
**  @param volume  Volume level to play the sound
*/
void PlayGameSound(CSound *sound, unsigned char volume)
{
	Origin source = {NULL, 0};

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range));
}
Пример #16
0
// play a sample from the menu event cache (navigation through the menus)
void SokobanSoundManager::PlaySample(MenuEvent EventType)
{
	// look for it in the list
	vector<SoundEvent>::iterator ii;
	for(ii=m_MenuEventSounds.begin(); ii!=m_MenuEventSounds.end(); ii++)
	{
		// look for a matching level
		if ( ii->EventType == EventType )
		{
			// play the sample
			PlaySample(ii->OpenALSampleID);

			return;
		}
	}

	// if its not found play default sample
	PlaySample(m_DefaultSoundID);
}
Пример #17
0
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param sound  Sound to be generated
*/
void PlayUnitSound(const CUnit *unit, CSound *sound)
{
	Origin source = {unit, unit->Slot};
	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelStereo(channel, CalculateStereo(unit));
}
Пример #18
0
void AudioChannel::PlayRandomSample(const GuiSoundSet& soundSet, const float3& pos)
{
	if (soundSet.sounds.empty())
		return;

	const int soundIdx = guRNG.NextInt(soundSet.sounds.size());
	const int soundID = soundSet.getID(soundIdx);
	const float soundVol = soundSet.getVolume(soundIdx);

	PlaySample(soundID, pos, soundVol);
}
Пример #19
0
void AudioChannel::PlayRandomSample(const GuiSoundSet& soundSet, const float3& pos)
{
	const int soundIdx = soundSet.getRandomIdx();

	if (soundIdx < 0)
		return;

	const int soundID = soundSet.getID(soundIdx);
	const float soundVol = soundSet.getVolume(soundIdx);

	PlaySample(soundID, pos, soundVol);
}
Пример #20
0
void ClientGame::OnButtonPressed(ButtonId buttonId)
{
    switch (buttonId)
    {
    case ButtonId_Infiltrate:
        PlaySample(m_soundAction);
        break;
    case ButtonId_Capture:
        PlaySample(m_soundAction);
        break;
    case ButtonId_Stakeout:
        PlaySample(m_soundAction);
        break;
    case ButtonId_Hack:
        PlaySample(m_soundHack);
        break;
    case ButtonId_Intel:
        PlaySample(m_soundPickup);
        break;
    }
}
Пример #21
0
void sfxr::BlitSelectButtonPressed()
{
    ResetParams();
    wave_type=rnd(1);
    if(wave_type==0)
        p_duty=frnd(0.6f);
    p_base_freq=0.2f+frnd(0.4f);
    p_env_attack=0.0f;
    p_env_sustain=0.1f+frnd(0.1f);
    p_env_decay=frnd(0.2f);
    p_hpf_freq=0.1f;
    PlaySample();
}
Пример #22
0
void generator::GenerateBasicBlipSelect(void)
{
	ResetParams();
	wave_type=rnd(1);
	if(wave_type==0) {
		p_duty=frnd(0.6f);
	}
	p_base_freq=0.2f+frnd(0.4f);
	p_env_attack=0.0f;
	p_env_sustain=0.1f+frnd(0.1f);
	p_env_decay=frnd(0.2f);
	p_hpf_freq=0.1f;
	PlaySample();
}
Пример #23
0
// pickup/coin
void generator::GenerateBasicPickUpCoin(void)
{
	ResetParams();
	p_base_freq=0.4f+frnd(0.5f);
	p_env_attack=0.0f;
	p_env_sustain=frnd(0.1f);
	p_env_decay=0.1f+frnd(0.4f);
	p_env_punch=0.3f+frnd(0.3f);
	if(rnd(1)) {
		p_arp_speed=0.5f+frnd(0.2f);
		p_arp_mod=0.2f+frnd(0.4f);
	}
	PlaySample();
}
Пример #24
0
/**
**  Play a sound file
**
**  @param name      Filename of a sound to play
**  @param listener  Optional lua callback
**
**  @return          Channel number the sound is playing on, -1 for error
*/
int PlayFile(const std::string &name, LuaActionListener *listener)
{
	int channel = -1;
	CSample *sample = LoadSample(name);

	if (sample) {
		channel = PlaySample(sample);
		if (channel != -1) {
			SetChannelVolume(channel, MaxVolume);
			SetChannelFinishedCallback(channel, PlaySoundFileCallback);
			ChannelMap[channel] = listener;
		}
	}
	return channel;
}
Пример #25
0
void sfxr::PickupCoinButtonPressed()
{
    ResetParams();
    p_base_freq=0.4f+frnd(0.5f);
    p_env_attack=0.0f;
    p_env_sustain=frnd(0.1f);
    p_env_decay=0.1f+frnd(0.4f);
    p_env_punch=0.3f+frnd(0.3f);
    if(rnd(1))
    {
        p_arp_speed=0.5f+frnd(0.2f);
        p_arp_mod=0.2f+frnd(0.4f);
    }
    PlaySample();
}
Пример #26
0
/**
**  Play a game sound
**
**  @param sound   Sound to play
**  @param volume  Volume level to play the sound
*/
void PlayGameSound(CSound *sound, unsigned char volume, bool always)
{
	Origin source = {NULL, 0};

	CSample *sample = ChooseSample(sound, false, source);

	if (!always && SampleIsPlaying(sample)) {
		return;
	}

	int channel = PlaySample(sample);
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range));
}
Пример #27
0
/**
**  Ask the sound server to play a sound for a missile.
**
**  @param missile  Sound initiator, missile exploding
**  @param sound    Sound to be generated
*/
void PlayMissileSound(const Missile &missile, CSound *sound)
{
	int stereo = ((missile.position.x + missile.Type->G->Width / 2 -
				   UI.SelectedViewport->MapPos.x * PixelTileSize.x) * 256 /
				  ((UI.SelectedViewport->MapWidth - 1) * PixelTileSize.x)) - 128;
	clamp(&stereo, -128, 127);

	Origin source = {NULL, 0};

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range));
	SetChannelStereo(channel, stereo);
}
Пример #28
0
void sfxr::JumpButtonPressed()
{
    ResetParams();
    wave_type=0;
    p_duty=frnd(0.6f);
    p_base_freq=0.3f+frnd(0.3f);
    p_freq_ramp=0.1f+frnd(0.2f);
    p_env_attack=0.0f;
    p_env_sustain=0.1f+frnd(0.3f);
    p_env_decay=0.1f+frnd(0.2f);
    if(rnd(1))
        p_hpf_freq=frnd(0.3f);
    if(rnd(1))
        p_lpf_freq=1.0f-frnd(0.6f);
    PlaySample();
}
Пример #29
0
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param voice  Type of sound wanted (Ready,Die,Yes,...)
*/
void PlayUnitSound(const CUnit *unit, UnitVoiceGroup voice)
{
	CSound *sound = ChooseUnitVoiceSound(unit, voice);
	if (!sound) {
		return;
	}

	bool selection = (voice == VoiceSelected || voice == VoiceBuilding);
	Origin source = {unit, unit->Slot};

	int channel = PlaySample(ChooseSample(sound, selection, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelStereo(channel, CalculateStereo(unit));
}
Пример #30
0
void sfxr::HitHurtButtonPressed()
{
    ResetParams();
    wave_type=rnd(2);
    if(wave_type==2)
        wave_type=3;
    if(wave_type==0)
        p_duty=frnd(0.6f);
    p_base_freq=0.2f+frnd(0.6f);
    p_freq_ramp=-0.3f-frnd(0.4f);
    p_env_attack=0.0f;
    p_env_sustain=frnd(0.1f);
    p_env_decay=0.1f+frnd(0.2f);
    if(rnd(1))
        p_hpf_freq=frnd(0.3f);
    PlaySample();
}