本文整理汇总了C++中Mix_VolumeChunk函数的典型用法代码示例。如果您正苦于以下问题:C++ Mix_VolumeChunk函数的具体用法?C++ Mix_VolumeChunk怎么用?C++ Mix_VolumeChunk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Mix_VolumeChunk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
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: set_sound_volume
/*!
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;
}
示例3: PlaySound
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: Mix_FreeChunk
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: play_sound
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: Mix_FreeChunk
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: sdlplayer_fx
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: noegnud_sound_play
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: Mix_LoadWAV
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: Mix_VolumeChunk
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: sound_playfx
//------------------------------
// Sound functions
//------------------------------
void sound_playfx(Mix_Chunk* snd)
{
if(sound_enabled == true)
{
Mix_VolumeChunk(snd, sound_volfx*10);
Mix_PlayChannel( -1, snd, 0 );
}
}
示例12: Mix_VolumeChunk
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: Mix_VolumeChunk
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: set_strings_volume
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: Mix_VolumeChunk
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);
}
}