float Sound_Stream_AL::get_gain() const {
   float gain = ZENI_DEFAULT_GAIN;
   if(dynamic_cast<Sound_Renderer_AL *>(&get_Sound().get_Renderer())) {
     Sound_Renderer_AL::alGetSourcef()(source, AL_GAIN, &gain);
   }
   return gain;
 }
Exemple #2
0
  Sound_Buffer::Sound_Buffer(const String &filename)
    :
#ifndef DISABLE_AL
    m_buffer(AL_NONE),
#endif
    m_duration(float())
    //, m_loader(0)
    //, m_thread(0)
  {
    Sound &sr = get_Sound();

#ifndef DISABLE_AL
    if(dynamic_cast<Sound_Renderer_AL *>(&sr.get_Renderer())) {
      //m_loader = new Loader(filename);
      //m_thread = new Thread(*m_loader);

      std::pair<ALuint, float> loaded_ogg = load_ogg_vorbis(filename);

      if(loaded_ogg.first == AL_NONE) {
        std::cerr << "OpenAL error on '" << filename << "': " << Sound_Renderer_AL::errorString() << std::endl;
        throw Sound_Buffer_Init_Failure();
      }

      m_buffer = loaded_ogg.first;
      m_duration = loaded_ogg.second;
    }
#endif
#ifdef ENABLE_SLES
    init_SLES(filename);
#endif
  }
  Sound_Buffer::Sound_Buffer(const string &filename)
    : m_buffer(AL_NONE),
      m_loader(0),
      m_thread(0)
  {
    get_Sound();

    m_loader = new Loader(filename);
    m_thread = new Thread(*m_loader);
  }
  Sound_Buffer::Sound_Buffer()
    : m_buffer(AL_NONE),
      m_loader(0),
      m_thread(0)
  {
    get_Sound();

#ifndef DISABLE_AL
    m_buffer = alutCreateBufferHelloWorld();

    if(m_buffer == AL_NONE) {
      cerr << "ALUT error on Hello World: " << alutGetErrorString(alutGetError()) << endl;
      throw Sound_Buffer_Init_Failure();
    }
#endif
  }
Exemple #5
0
  void Sound_Buffer::init_SLES(const String &filename) {
    if(dynamic_cast<Sound_Renderer_SLES *>(&get_Sound().get_Renderer())) {
      // use asset manager to open asset by filename
      AAsset* asset = AAssetManager_open(File_Ops::get_AAssetManager(), (filename + ".wav").c_str(), AASSET_MODE_UNKNOWN);
      if(!asset)
        throw Sound_Buffer_Init_Failure();

      // open asset as file descriptor
      off_t start, length;
      int fd = AAsset_openFileDescriptor(asset, &start, &length);
      assert(0 <= fd);
      AAsset_close(asset);

      // configure audio source
      loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
      format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
      audioSrc = {&loc_fd, &format_mime};
    }
  }
  Sound_Buffer::Sound_Buffer()
    : m_buffer(AL_NONE)
    //, m_loader(0)
    //, m_thread(0)
  {
#ifndef DISABLE_AL
    Sound &sr = get_Sound();

    if(dynamic_cast<Sound_Renderer_AL *>(&sr.get_Renderer())) {
      Sound_Renderer_AL::alGenBuffers()(1, &m_buffer);

      if(m_buffer == AL_NONE) {
        std::cerr << "OpenAL error on alGenBuffers: " << Sound_Renderer_AL::errorString() << std::endl;
        throw Sound_Buffer_Init_Failure();
      }

      char buffer[64];
      memset(buffer, 0, sizeof(buffer));
      Sound_Renderer_AL::alBufferData()(m_buffer, AL_FORMAT_MONO16, buffer, sizeof(buffer), 22050);
    }
#endif
  }
  Sound_Stream_AL::Sound_Stream_AL(const String &path, const bool &looping_, const float &time_)
    : buffers_used(0),
    looping(looping_)
  {
    if(!dynamic_cast<Sound_Renderer_AL *>(&get_Sound().get_Renderer()))
      throw Sound_Stream_Init_Failure();

    const int result = ov_fopen((path + ".ogg").c_str(), &oggStream);
    if(result < 0)
      throw Sound_Stream_Ogg_Read_Failure();

    vorbisInfo = ov_info(&oggStream, -1);
    vorbisComment = ov_comment(&oggStream, -1);
 
    if(vorbisInfo->channels == 1)
        format = AL_FORMAT_MONO16;
    else
        format = AL_FORMAT_STEREO16;

    ov_time_seek(&oggStream, time_);

    Sound_Renderer_AL::alGenBuffers()(NUM_BUFFERS, buffers);
    Sound_Renderer_AL::alGenSources()(1, &source);

    ALfloat pos[3] = {0.0f, 0.0f, 0.0f};
    Sound_Renderer_AL::alSourcefv()(source, AL_POSITION,        pos    );
    Sound_Renderer_AL::alSourcefv()(source, AL_VELOCITY,        pos    );
    Sound_Renderer_AL::alSourcefv()(source, AL_DIRECTION,       pos    );
    Sound_Renderer_AL::alSourcef() (source, AL_ROLLOFF_FACTOR,  0.0    );
    Sound_Renderer_AL::alSourcei() (source, AL_SOURCE_RELATIVE, AL_TRUE);

    const ALenum error = Sound_Renderer_AL::alGetError()();
    if(error != AL_NO_ERROR) {
      destroy();
      std::cerr << "OpenAL error: " << Sound_Renderer_AL::errorString(error) << std::endl;
      throw Sound_Stream_Init_Failure();
    }
  }
 void Sound_Stream_AL::set_time(const float &time) {
   if(dynamic_cast<Sound_Renderer_AL *>(&get_Sound().get_Renderer()))
     ov_time_seek(&oggStream, time);
 }
 void Sound_Stream_AL::set_gain(const float &gain) {
   if(dynamic_cast<Sound_Renderer_AL *>(&get_Sound().get_Renderer()))
     Sound_Renderer_AL::alSourcef()(source, AL_GAIN, gain);
 }
void Team_Select_State::perform_logic(){

		if(start_game > 5.0f){

			vector<Player_info *> *player_list = new vector<Player_info*>;

			for(int player_idx = 0; player_idx < 4; player_idx ++){

				if(player_state[player_idx] != 2) continue;

				Player_info * newPlayer = new Player_info();

				newPlayer->genders_ = player_gender[player_idx];
				newPlayer->controls_ = player_control_state[player_idx];
				newPlayer->sensitivities_ = player_sensitivity_state[player_idx];


				if(player_team[player_idx] == "Green"){
					newPlayer->colors_ = 0;
				}
				else if(player_team[player_idx] == "Red"){
					newPlayer->colors_ = 1;
				}
				else if(player_team[player_idx] == "Blue"){
					newPlayer->colors_ = 2;
				}
				else if(player_team[player_idx] == "Orange"){
					newPlayer->colors_ = 3;
				}

				newPlayer->self_addr = RakNet::UNASSIGNED_SYSTEM_ADDRESS;

				player_list->push_back(newPlayer);
			}

			get_Sound().stop_BGM();
			get_Game().pop_state();
			get_Game().push_state(new Play_State_Base(player_list, level));
		}


		for(int player_idx = 0; player_idx < 4; player_idx ++){
			if(player_gender_state[player_idx] == 0)
				player_gender[player_idx] = "Boy";
			else
				player_gender[player_idx] = "Girl";

			if(player_control_state[player_idx] == 0)
				player_control[player_idx] = "Normal";
			else
				player_control[player_idx] = "Invert";

			if(player_team_state[player_idx] == 0)
				player_team[player_idx] = "Green";
			else if(player_team_state[player_idx] == 1)
				player_team[player_idx] = "Red";
			else if(player_team_state[player_idx] == 2)
				player_team[player_idx] = "Blue";
			else
				player_team[player_idx] = "Orange";

		}
	}