Пример #1
0
static mrb_value
mrb_sdl2_mixer_set_distance(mrb_state *mrb, mrb_value self)
{
  mrb_int channel, distance;
  mrb_get_args(mrb, "ii", &channel, &distance);
  return mrb_fixnum_value(Mix_SetDistance((int)channel, (Uint8)distance));
}
Пример #2
0
void SoundManager::playSound(int chunkIdx, Ogre::Vector3 soundPosition, Ogre::Camera* mCamera) {
  if (!initialized) {
    std::cout << "SoundManager: Manager not initialized." << std::endl;
    return;
  }

  if (sounding) {
    Mix_ChannelFinished(channelDoneWrapper);
    int channel = Mix_PlayChannel(-1, chunks[chunkIdx], 0);
    int dist = calcDistance(mCamera->getPosition(), soundPosition);
    // put this sound in our list of active sounds.
    Sound s;
    s.soundPosition = soundPosition;
    s.chunk = chunks[chunkIdx];
    s.distance = dist;
    s.channel = channel;
    s.active = true;
    activeSounds.push_back(s);

    // Initialize sound position
    int rightIntensity = calcPanning(mCamera, soundPosition);
    Mix_SetPanning(s.channel, 254 - rightIntensity, rightIntensity);
    Mix_SetDistance(s.channel, dist);
  }
}
Пример #3
0
static void do_distance_update(void)
{
	static Uint8 distance = 1;
	static Uint8 distincr = 1;
	static int distanceok = 1;
	static Uint32 next_distance_update = 0;

	if ((distanceok) && (SDL_GetTicks() >= next_distance_update)) {
		distanceok = Mix_SetDistance(0, distance);
		if (!distanceok) {
			fprintf(stderr, "Mix_SetDistance(0, %d) failed!\n", (int) distance);
			fprintf(stderr, "Reason: [%s].\n", Mix_GetError());
		}

		if (distance == 0) {
			printf("Distance at nearest point.\n");
			distincr *= -1;
		}
		else if (distance == 255) {
			printf("Distance at furthest point.\n");
			distincr *= -1;
		}

		distance += distincr;
		next_distance_update = SDL_GetTicks() + 15;
	}
}
void SoundManager::SetVolume(int _channel, float _volume)
{
	if(status_ != SoundStatus::OK)
		return;
	unsigned char distance = (1.0f - _volume) * 255;
	Mix_SetDistance(_channel, distance);
}
Пример #5
0
void playBattleSound(int id, int x, int y)
{
	float distance;
	int channel;
	float vol;

	if (player->alive == ALIVE_ALIVE)
	{
		lastPlayerX = player->x;
		lastPlayerY = player->y;
	}

	distance = getDistance(lastPlayerX, lastPlayerY, x, y);

	if (distance <= MAX_BATTLE_SOUND_DISTANCE)
	{
		channel = Mix_PlayChannel(-1, sounds[id], 0);
		if (channel != -1)
		{
			vol = 255;
			vol /= MAX_BATTLE_SOUND_DISTANCE;
			vol *= distance;

			Mix_SetDistance(channel, vol);
		}
	}
}
Пример #6
0
// Volume 0-F1_0
int digi_mixer_start_sound(short soundnum, fix volume, int pan, int looping, int loop_start, int loop_end, int soundobj)
{
  int mix_vol = fix2byte(fixmul(digi_volume, volume));
  int mix_pan = fix2byte(pan);
  int mix_loop = looping * -1;
  int channel;

  if (!digi_initialised) return -1;
  Assert(GameSounds[soundnum].data != (void *)-1);

  mixdigi_convert_sound(soundnum);

  if (MIX_DIGI_DEBUG) con_printf(CON_DEBUG,"digi_start_sound %d, volume %d, pan %d (start=%d, end=%d)\n", soundnum, mix_vol, mix_pan, loop_start, loop_end);

  channel = Mix_PlayChannel(-1, &(SoundChunks[soundnum]), mix_loop);
  Mix_SetPanning(channel, 255-mix_pan, mix_pan);
  if (volume > F1_0)
    Mix_SetDistance(channel, 0);
  else
    Mix_SetDistance(channel, 255-mix_vol);

  return channel;
}
Пример #7
0
/**\brief Plays the sound.
 */
bool Sound::Play( void ){
	if ( this->sound == NULL )
		return false;

	// Disable panning and distance
	int freechan = Audio::Instance().GetFreeChannel();
	Mix_SetDistance( freechan, 0 );
	Mix_SetPanning( freechan, 127, 127 );
	Mix_Volume( freechan, this->volume );
	this->channel = Audio::Instance().PlayChannel( freechan, this->sound, 0 );
	if ( channel == -1 )
		return false;
	
	return true;
}
Пример #8
0
void SoundManager::updateSounds(Ogre::Camera* mCamera) {

  // Remove any sounds from our list of active sounds that might not be active.
  for(int i = 0; i < activeSounds.size(); i++) {
    Sound *s = &(activeSounds[i]);
    if(s->active == false) {
      // Reset sound position on the given channel, and remove the sound
      Mix_SetPanning(s->channel, 255, 255);
      Mix_SetDistance(s->channel, 0);
      activeSounds.erase(activeSounds.begin() + i);
    }
  }

  // update sound position for all active sounds
  for(int i = 0; i < activeSounds.size(); i++) {
    Sound *s = &(activeSounds[i]);
    int rightIntensity = calcPanning(mCamera, s->soundPosition);
    Mix_SetPanning(s->channel, 254 - rightIntensity, rightIntensity);
    int dist = calcDistance(mCamera->getPosition(), s->soundPosition);
    s->distance = dist;
    Mix_SetDistance(s->channel, dist);
  }

}
Пример #9
0
	static int lua_Mix_SetDistance(State & state){
		Stack * stack = state.stack;
		int channel = MIX_CHANNEL_POST;
		Uint8 distance = 0;

		if (stack->is<LUA_TNUMBER>(1)){
			channel = stack->to<int>(1);
		}
		if (stack->is<LUA_TNUMBER>(2)){
			distance = static_cast<Uint8>(stack->to<int>(2));
		}
		int result = Mix_SetDistance(channel, distance);
		stack->push<bool>(result != 0);
		return 1;
	}
Пример #10
0
int SoundSetChannelDistanceInt(int channel, unsigned char distance)
{

	//FIXME: you know the drill
	if(Mix_Playing(channel))
	{
		//TODO: how to moron check? distance wraps so it wont break either way
		
		if(Mix_SetDistance(channel, distance))
			return 1;
		else
			return 0; //TODO: error checking?
	}
	else
		return 0;
}
int SoundManager::PlayEnqueuedSample(std::string _filename, unsigned char _distance)
{
	//Look the sound up, it's probably already loaded. If not then load it.
	if(status_ != SoundStatus::OK)
		return -1;

	Mix_Chunk* sample = GetChunk(_filename);
	if(sample)
	{
		//Play the sound
		int channel = Mix_PlayChannel(-1, sample, 0);
		
		if(channel >= 0) Mix_SetDistance(channel, _distance);
		return channel;
	}
	return -1;
}
Пример #12
0
int SoundSetChannelDistanceFloat(int channel, float distance)
{
	if(Mix_Playing(channel))
	{
		distance = ClampFloat(distance, 0.0, 1.0);
		
		int dist;
		dist = (int)(255 * distance);
		//printf("Set distance to %d\n", dist);

		if(Mix_SetDistance(channel, dist))
			return 1;
		else
			return 0; //TODO: error checking?
	}
	else
		return 0;
}
Пример #13
0
/**\brief Plays the sound at a specified coordinate from origin.
 */
bool Sound::Play( Coordinate offset ){
	if ( this->sound == NULL )
		return false;

	// Distance fading
	double dist = this->fadefactor * offset.GetMagnitude();
	if ( dist > 255 )
		return false;			// Sound is out of range
	Uint8 sounddist = static_cast<Uint8>( dist );

	// Left-Right panning
	float panx = this->panfactor * static_cast<float>(offset.GetX())+127.f;
	Uint8 soundpan = 127;
	if ( panx < 0 )
		soundpan = 0;
	else if ( panx > 254 )
		soundpan = 254;
	else
		soundpan = static_cast<Uint8>( panx );

	int freechan = Audio::Instance().GetFreeChannel();
	if( Mix_SetDistance( freechan, sounddist ) == 0 )
		LogMsg(ERR,"Set distance %d failed on channel %d.", sounddist, freechan );
	//else
	//	LogMsg(INFO,"Distance set to %d on channel %d.", sounddist, freechan );

	/**\bug SDL_mixer bug possibly: Need to check whether SDL_mixer is getting
	 * Left/Right speaker switched around.
	 */
	if( Mix_SetPanning( freechan, 254 - soundpan, soundpan ) == 0 )
		LogMsg(ERR,"Set panning %d failed on channel %d.", soundpan - 127, freechan );
	//else
	//	LogMsg(INFO,"Panning set to %d on channel %d.", soundpan - 127, freechan );

	Mix_Volume( freechan, this->volume );
	this->channel = Audio::Instance().PlayChannel( freechan, this->sound, 0 );

	if ( channel == -1 )
		return false;
	
	return true;
}
Пример #14
0
void reposition_sound(int id, unsigned int distance)
{
	audio_lock lock;
	for (unsigned ch = 0; ch < channel_ids.size(); ++ch)
	{
		if (channel_ids[ch] != id) continue;
		if (distance >= DISTANCE_SILENT) {
			// Don't call Mix_FadeOutChannel if the channel's volume is set to
			// zero. It doesn't do anything in that case and the channel will
			// resume playing as soon as its volume is reset to a non-zero
			// value, which results in issues like sound sources deleted while
			// their volume is zero coming back to life and escaping Wesnoth's
			// sound source management code.
			if (Mix_Volume(ch, -1) == 0) {
				Mix_HaltChannel(ch);
			} else {
				Mix_FadeOutChannel(ch, 100);
			}
		} else {
			Mix_SetDistance(ch, distance);
		}
	}
}
Пример #15
0
void play_sound_internal(const std::string& files, channel_group group, unsigned int repeats,
			unsigned int distance, int id, int loop_ticks, int fadein_ticks)
{
	if(files.empty() || distance >= DISTANCE_SILENT || !mix_ok) {
		return;
	}

	audio_lock lock;

	// find a free channel in the desired group
	int channel = Mix_GroupAvailable(group);
	if(channel == -1) {
		LOG_AUDIO << "All channels dedicated to sound group(" << group << ") are busy, skipping.\n";
		return;
	}

	Mix_Chunk *chunk;
	std::string file = pick_one(files);

	try {
		chunk = load_chunk(file, group);
		assert(chunk);
	} catch(const chunk_load_exception&) {
		return;
	}

	/*
	 * This check prevents SDL_Mixer from blowing up on Windows when UI sound is played
	 * in response to toggling the checkbox which disables sound.
	 */
	if(group != SOUND_UI) {
		Mix_SetDistance(channel, distance);
	}

	int res;
	if(loop_ticks > 0) {
		if(fadein_ticks > 0) {
			res = Mix_FadeInChannelTimed(channel, chunk, -1, fadein_ticks, loop_ticks);
		} else {
			res = Mix_PlayChannel(channel, chunk, -1);
		}

		if(res >= 0) {
			Mix_ExpireChannel(channel, loop_ticks);
		}
	} else {
		if(fadein_ticks > 0) {
			res = Mix_FadeInChannel(channel, chunk, repeats, fadein_ticks);
		} else {
			res = Mix_PlayChannel(channel, chunk, repeats);
		}
	}

	if(res < 0) {
		ERR_AUDIO << "error playing sound effect: " << Mix_GetError() << std::endl;
		//still keep it in the sound cache, in case we want to try again later
		return;
	}

	channel_ids[channel] = id;

	//reserve the channel's chunk from being freed, since it is playing
	channel_chunks[res] = chunk;
}
Пример #16
0
void CSoundEffect::SetDistanceEffect(int dist)
{
	Mix_SetDistance(Channel, dist);
}
Пример #17
0
bool SDLAudio::SetDistance(int channel, int distance)
{
    Mix_SetDistance(channel, distance);
    return true;
}
Пример #18
0
void digi_mixer_set_channel_volume(int channel, int volume) {
  int mix_vol = fix2byte(volume);
  if (!digi_initialised) return;
  Mix_SetDistance(channel, 255-mix_vol);
}