示例#1
0
void SoundMix::PlaySoundWithVolume( int sound, int volume )
{

	if (Config::GetSound()!=1)
	{
		return;
	}

	wave = Load( sound );

	if ( !wave )
	{
		return;
	}

	if ( wave )
	{
		Mix_VolumeChunk( wave, volume );
		if ( Mix_PlayChannel( -1, wave, 0 ) == -1 )
		{
			printf( "Mix_PlayChannel: %s\n", Mix_GetError() );
			// may be critical error, or maybe just no channels were free.
			// you could allocated another channel in that case...
			Mix_FreeChunk( wave );
			wave = NULL;
		}
	}
}
示例#2
0
/*! 
  Change volume for a sound associated with the specified sound context
  \pre     sound_context != NULL
  \arg \c  sound_context the sound context
       \i  volume is a value 0-128 
  \return  true if volume was set; false otherwise
  \author  ehall
  \date    Created:  2000-09-13
  \date    Modified: 2000-09-13
*/
bool_t set_sound_volume( char *sound_context, int volume )
{
    int i;
    sound_context_data_t *data;

    if ( ! get_hash_entry( sound_contexts_, sound_context, 
			   (hash_entry_t*) &data ) ) {
	return False;
    }
    data->volume = volume;

    i = (int) (((double)data->num_sounds)*rand()/(RAND_MAX+1.0));
    for ( i=0; i<data->num_sounds; i++ ) {
	if ( data->chunks[i] == NULL ) {
	    bool_t found;
	    found = get_sound_data( data->sound_names[i], &(data->chunks[i]) );
	    check_assertion( found, "sound name not found" );
	    check_assertion( data->chunks[i]!=NULL, "sound chunk not set" );
	}

	Mix_VolumeChunk( data->chunks[i], data->volume );

    }
    return True;
}
extern void PlaySound(char * file, unsigned char volume, int channel, int times)
{
	Mix_Chunk* soundeff = SoundEffects.find(file)->second;
	Mix_PlayChannel(channel, soundeff, times - 1);

	Mix_VolumeChunk(soundeff, volume);
}
示例#4
0
void THSoundEffects::setSoundArchive(THSoundArchive *pArchive)
{
    for(size_t i = 0; i < m_iSoundCount; ++i)
    {
        Mix_FreeChunk(m_ppSounds[i]);
    }
    delete[] m_ppSounds;
    m_ppSounds = NULL;
    m_iSoundCount = 0;

    if(pArchive == NULL)
        return;

    m_ppSounds = new Mix_Chunk*[pArchive->getSoundCount()];
    for(; m_iSoundCount < pArchive->getSoundCount(); ++m_iSoundCount)
    {
        m_ppSounds[m_iSoundCount] = NULL;
        SDL_RWops *pRwop = pArchive->loadSound(m_iSoundCount);
        if(pRwop)
        {
            m_ppSounds[m_iSoundCount] = Mix_LoadWAV_RW(pRwop, 1);
            if(m_ppSounds[m_iSoundCount])
                Mix_VolumeChunk(m_ppSounds[m_iSoundCount], MIX_MAX_VOLUME);
        }
    }
}
示例#5
0
static void *
play_sound(const char *filename, int loop, double volume)
{
    struct player_sound *sound;
    unsigned long hash;
    int sdl_volume = (int)(volume * MIX_MAX_VOLUME);

    hash = crc32(0, (void *)filename, strlen(filename));
    hash %= sizeof(sounds) / sizeof(sounds[0]);
    for (sound = sounds[hash]; sound != NULL; sound = sound->next) {
        if (strcmp(filename, sound->filename) == 0)
            break;
    }

    if (sound == NULL) {
        fprintf(stderr, "play_sound: %s not loaded?\n", filename);
        return NULL;
    }

    if (sound->chunk != NULL) {
        Mix_VolumeChunk(sound->chunk, sdl_volume);
        sound->chunk_channel = Mix_PlayChannel(-1, sound->chunk, loop ? -1 : 0);
    } else if (sound->music != NULL) {
        Mix_HaltMusic();
        active_music = sound->music;
        Mix_VolumeMusic(sdl_volume);
        Mix_PlayMusic(sound->music, loop ? -1 : 1);
    }
    return sound;
}
示例#6
0
void sound_player::populate_from(sound_archive *pArchive)
{
    for(size_t i = 0; i < sound_count; ++i)
    {
        Mix_FreeChunk(sounds[i]);
    }
    delete[] sounds;
    sounds = nullptr;
    sound_count = 0;

    if(pArchive == nullptr)
        return;

    sounds = new Mix_Chunk*[pArchive->get_number_of_sounds()];
    for(; sound_count < pArchive->get_number_of_sounds(); ++sound_count)
    {
        sounds[sound_count] = nullptr;
        SDL_RWops *pRwop = pArchive->load_sound(sound_count);
        if(pRwop)
        {
            sounds[sound_count] = Mix_LoadWAV_RW(pRwop, 1);
            if(sounds[sound_count])
                Mix_VolumeChunk(sounds[sound_count], MIX_MAX_VOLUME);
        }
    }
}
示例#7
0
int sdlplayer_fx(char *filename, int volume)
{
  Mix_Chunk *sample;

  g_warning("sdlplayer %s\n", filename);

  sample=Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1);
  if(!sample) {
    return(cleanExit("Mix_LoadWAV_RW"));
    // handle error
  }

  Mix_VolumeChunk(sample, MIX_MAX_VOLUME);

  if((_channel_fx = Mix_PlayChannel(-1, sample, 0))==-1) {
    return(cleanExit("Mix_LoadChannel(0x%p,1)", _channel_fx));
  }

  while( Mix_Playing( _channel_fx ) )
    {
      SDL_Delay(50);
    }

  // free the sample
  // Mix_Chunk *sample;
  Mix_FreeChunk(sample);
  _channel_fx = -1;

  g_warning("sdlplayer complete playing of %s\n", filename);

  return(0);
}
示例#8
0
void noegnud_sound_play(const char *filename,float volume) {
    noegnud_tcollection *soundcollection;
    noegnud_sound_tsound *sound;
    int internal_volume;

    if (!noegnud_sound_initialised) return;

    soundcollection=noegnud_sound_load(filename);
    if (soundcollection) {
	if (volume<0) volume=0;
	if (volume>1) volume=1;

	sound=(noegnud_sound_tsound *)soundcollection->data;
	internal_volume=volume*MIX_MAX_VOLUME;
	if (sound->chunk) {
#ifdef NOEGNUDDEBUG
	    printf("[SOUND] noegnud_sound_play: playing chunk \"%s\" (%2.3f)\n",filename,volume);
#endif
	    Mix_VolumeChunk(sound->chunk,internal_volume);
	    Mix_PlayChannel(-1,sound->chunk,0);
	} else if (sound->music) {
#ifdef NOEGNUDDEBUG
	    printf("[SOUND] noegnud_sound_play: playing music \"%s\" (%2.3f)\n",filename,volume);
#endif
	    Mix_VolumeMusic(internal_volume);
	    Mix_PlayMusic(sound->music,0);
	} else {
	    printf("[SOUND] WARNING: noegnud_sound_play: unknown file format/could not load \"%s\"\n",filename);
	}
    } else {
	printf("[SOUND] noegnud_sound_play: could not load/play \"%s\"\n",filename);
    }
}
示例#9
0
void PGE_Sounds::SND_PlaySnd(QString sndFile)
{
    if(current!=sndFile)
    {
        #ifdef USE_QMEDIAPLAYER
        if(mp3Play) { mp3Play->stop(); delete mp3Play; mp3Play=NULL; }
        #elif USE_SDL_MIXER
        if(sound) { Mix_FreeChunk(sound); sound=NULL; }
        sound = Mix_LoadWAV(sndFile.toUtf8().data() );
        if(!sound)
            qDebug() << QString("Mix_LoadWAV: %1").arg(SDL_GetError());
        else
            Mix_VolumeChunk(sound, MIX_MAX_VOLUME);
        #endif
        current = sndFile;
    }

    #ifdef USE_QMEDIAPLAYER
    qDebug() << QString("Play Sound (QMediaPlayer)");
    if(!mp3Play)
    {
        qDebug() << QString("QMediaPlayer is null");
    }
    else
        mp3Play->play();
    #elif USE_SDL_MIXER

    LogDebug(QString("Play Sound (SDL2_mixer)"));
    if(Mix_PlayChannel( -1, sound, 0 )==-1)
    {
        qDebug() << QString("Mix_PlayChannel: %1").arg(SDL_GetError());
    }

#endif
}
示例#10
0
void TempFigure::setFigure(int x, int y, Surface& image, SDL_Surface* screen,
      int levelWidth, int levelHeight) {
   Figure::setFigure(x, y, image, screen, GRAVITY_DISABLED, levelWidth,
         levelHeight, false, 5, 1, 1, 1);
   scratch.setChunk("sounds/scratch.wav");
   Mix_VolumeChunk(scratch.getMix_Chunk(), 128);
   marker = ACTIVE;
}
示例#11
0
文件: main.c 项目: dorkster/espada
//------------------------------
// Sound functions
//------------------------------
void sound_playfx(Mix_Chunk* snd)
{
    if(sound_enabled == true)
    {
        Mix_VolumeChunk(snd, sound_volfx*10);
        Mix_PlayChannel( -1, snd, 0 );
    }
}
示例#12
0
	void SoundSystem::SetAllSoundEffectVolumes(int volume)
	{
		if (volume > 128) { volume = 128; } else if (volume < 0) { volume = 0; }

		for (auto& it : m_SoundEffect) {
			Mix_VolumeChunk(it.second.get(), volume);
		}
	}
示例#13
0
 void platform_support::play_sound(unsigned idx, unsigned vol)
 {
    if (idx >= max_images || !m_specific->m_sounds[idx])
    {
       return;
    }
    Mix_VolumeChunk(m_specific->m_sounds[idx], vol);
    Mix_PlayChannel( -1, m_specific->m_sounds[idx], 0 );
 }
示例#14
0
文件: sound.c 项目: VWarlock/my_demos
void set_strings_volume(void)
{
	int i;
	for(i=0;i<128;i++)
	{
		Mix_VolumeChunk(strings_note_chunk[i],(int)(MIX_MAX_VOLUME*strings_volume));
	}
	
}
示例#15
0
void CSoundEffect::SetVolume(const u32 a_Volume)
{
    if (a_Volume >= 0 && a_Volume <= MIX_MAX_VOLUME)
    {
        m_Volume = a_Volume;
        if (m_Chunk != nullptr)
            Mix_VolumeChunk(m_Chunk, m_Volume);
    }
}
示例#16
0
static mrb_value
mrb_sdl2_mixer_chunk_volume(mrb_state *mrb, mrb_value self)
{
  Mix_Chunk *c;
  mrb_int volume;
  mrb_get_args(mrb, "i", &volume);
  c = mrb_sdl2_chunk_get_ptr(mrb, self);
  return mrb_fixnum_value(Mix_VolumeChunk(c, volume));
}
示例#17
0
文件: audio.c 项目: LibreGames/edgar
void playSound(char *name)
{
	int i;
	Mix_Chunk *chunk = NULL;

	if (game.audio == FALSE || game.sfxDefaultVolume == 0)
	{
		return;
	}

	for (i=0;i<soundIndex;i++)
	{
		if (strcmpignorecase(sound[i].name, name) == 0)
		{
			chunk = sound[i].effect;

			if (chunk == NULL)
			{
				return;
			}

			break;
		}
	}

	if (chunk == NULL)
	{
		if (soundIndex == MAX_SOUNDS)
		{
			showErrorAndExit("Ran out of space for sounds");
		}

		chunk = loadSound(name);

		sound[soundIndex].effect = chunk;

		STRNCPY(sound[soundIndex].name, name, sizeof(sound[soundIndex].name));

		soundIndex++;

		if (chunk == NULL)
		{
			return;
		}
	}

	Mix_VolumeChunk(chunk, game.sfxDefaultVolume * VOLUME_STEPS);

	#if DEV == 1
	if (game.gameType == REPLAYING)
	{
		printf("%f %s\n", (float)game.frames / 60, name);
	}
	#endif

	playSoundChunk(chunk, -1, 0);
}
示例#18
0
文件: sound.c 项目: VWarlock/my_demos
void set_piano_volume(void)
{
	int i;
	for(i=0;i<128;i++)
	{
		Mix_VolumeChunk(piano_note_chunk[i],(int)(MIX_MAX_VOLUME*piano_volume));
	}
	
}
示例#19
0
void	Sounds::Mute_Sounds()
{
	unsigned int	i;

	i = 0;
	while (i != this->sounds.size())
	{
		Mix_VolumeChunk(this->sounds[i], 0);
	}
}
示例#20
0
void	Sounds::Volume_Sounds_Down()
{
	unsigned int	i;

	i = 0;
	while (i != this->sounds.size())
	{
		Mix_VolumeChunk(this->sounds[i], this->volume_sound - 8);
	}
}
示例#21
0
void TMASound::play(bool loop,int volume,int pan)
{
    if (psound!=NULL)
    {
        if (volume>128) volume=128;
        Mix_VolumeChunk(psound,volume);
        ii_voice = Mix_PlayChannel(-1,psound,(loop)?(-1):0);
        //if (pan!=127) voice_set_pan(ii_voice,pan);
    }        
}
示例#22
0
void Sound::PlaySound(const char *referenceName, int volume, int loops)
{
    char DEBUGMSG3[1024];
    Mix_VolumeChunk(Sound::Chunks[referenceName],volume);
    if(Mix_PlayChannel(-1, Sound::Chunks[referenceName], loops) == -1) {
    	//sprintf(DEBUGMSG3,"Unable to play WAV file: %s\n", Mix_GetError());
        //MessageBox (0, DEBUGMSG3, "Error", MB_ICONHAND); 
        exit (1);
    }
}
示例#23
0
void SDLSound::setSoundVolume(unsigned int volume)
{
    if ( volume > 100 ) volume = 100;
    unsigned int sdlvol = (volume*100)/MIX_MAX_VOLUME;
    chunks_t::iterator i = m_chunks.begin();
    while ( i != m_chunks.end() ) {
        Mix_VolumeChunk(i->second->getData(), sdlvol);
        ++i;
    }
}
示例#24
0
void glSound::setVolume(int new_volume)
{
	if (sound == nullptr) return;
	if (new_volume < 0)						new_volume = 0;
	else if (new_volume > MIX_MAX_VOLUME)	new_volume = MIX_MAX_VOLUME;

	volume = new_volume;

	Mix_VolumeChunk(sound,new_volume);
}
示例#25
0
void Sound::PlaySound(const char *referenceName, int volume, int loops)
{
    char DEBUGMSG3[1024];
    Mix_VolumeChunk(Sound::Chunks[referenceName],volume);
    if(Mix_PlayChannel(-1, Sound::Chunks[referenceName], loops) == -1) {
    	sprintf(DEBUGMSG3,"Unable to play WAV file: %s\n", Mix_GetError());
        DebugMsg(DEBUGMSG3); 
        exit (1);
    }
}
示例#26
0
void SoundEffect::setVolume(float volume) noexcept
{
	sfz_assert_debug(0.0f <= volume);
	sfz_assert_debug(volume <= 1.0f);

	if (!this->isLoaded()) return;

	int volumeInt = int(std::round(volume * MIX_MAX_VOLUME));
	Mix_VolumeChunk(this->mChunkPtr, volumeInt);
}
示例#27
0
/*
 * @brief
 */
static void S_LoadSampleChunk(s_sample_t *sample) {
	char path[MAX_QPATH];
	void *buf;
	int32_t i, len;
	SDL_RWops *rw;

	if (sample->media.name[0] == '*') // place holder
		return;

	if (sample->media.name[0] == '#') { // global path
		g_strlcpy(path, (sample->media.name + 1), sizeof(path));
	} else { // or relative
		g_snprintf(path, sizeof(path), "sounds/%s", sample->media.name);
	}

	buf = NULL;
	rw = NULL;

	i = 0;
	while (SAMPLE_TYPES[i]) {

		StripExtension(path, path);
		g_strlcat(path, SAMPLE_TYPES[i++], sizeof(path));

		if ((len = Fs_Load(path, &buf)) == -1)
			continue;

		if (!(rw = SDL_RWFromMem(buf, len))) {
			Fs_Free(buf);
			continue;
		}

		if (!(sample->chunk = Mix_LoadWAV_RW(rw, false)))
			Com_Warn("%s\n", Mix_GetError());

		Fs_Free(buf);

		SDL_FreeRW(rw);

		if (sample->chunk) { // success
			break;
		}
	}

	if (sample->chunk) {
		Mix_VolumeChunk(sample->chunk, s_volume->value * MIX_MAX_VOLUME);
		Com_Debug("Loaded %s\n", path);
	} else {
		if (g_str_has_prefix(sample->media.name, "#players")) {
			Com_Debug("Failed to load player sample %s\n", sample->media.name);
		} else {
			Com_Warn("Failed to load %s\n", sample->media.name);
		}
	}
}
示例#28
0
void Audio::Play(unsigned clipid)
{
    if (clipid >= Audio::clips.size())
    {
        return;
    }
    Clip& clip = Audio::clips[clipid];

    Mix_VolumeChunk(clip.chunk, clip.volume);
    Mix_PlayChannel(-1, clip.chunk, 0);
}
示例#29
0
static Sound *CustomMix_LoadWAV(char *path, char *fileName, int volume)
{
    Sound *result;
    char temp[1024];
    if (!sound_supported) return NULL;
    sprintf(temp, "%s/sfx/%s", dataFolder, fileName);
    result = Mix_LoadWAV(temp);
    if (result)
      Mix_VolumeChunk (result, volume);
    return result;
}
示例#30
0
// Add the Random Generator referance to the rest of the classes.
Player::Player(boost::random::mt19937 &generator) : Entity(generator)
{
	m_Thrust = false;
	m_Fire = false;
	m_TurnRight = false;
	m_TurnLeft = false;
	m_Active = false;
	m_Hit = false;
	m_ExplosionOn = false;
	m_ShipHeight = 25;
	m_ShipWidth = 15;
	m_Radius = m_ShipHeight - 7;
	m_Scale = 2;

	m_MaxThrust = 325;
	m_ThrustMagnitude = 1.55;
	m_TurnRate = 0.06;

	m_NumberOfShots = 4;
	m_ThrustDrawTimerAmount = 0.100;
	m_ExplosiontTimerAmount = 2.500;

	pTimer = new Timer();
	pShip = new PlayerShip();
	
	//Player Ship Color
	ShipColor.Red = 100;
	ShipColor.Green = 40;
	ShipColor.Blue = 255;
	ShipColor.Alpha = 255;

	p_Shotsound = Mix_LoadWAV("PlayerShot.wav");
	Mix_VolumeChunk(p_Shotsound, MIX_MAX_VOLUME / 3);
	p_Thrustsound = Mix_LoadWAV("PlayerThrust.wav");
	Mix_VolumeChunk(p_Thrustsound, MIX_MAX_VOLUME / 3);
	p_Explosionsound = Mix_LoadWAV("PlayerExplosion.wav");
	Mix_VolumeChunk(p_Explosionsound, MIX_MAX_VOLUME / 4);

	InitializeShot(generator);
	pShip->InitializeLines(generator);
}