예제 #1
0
파일: sound.cpp 프로젝트: BSVino/Digitanks
void CSoundLibrary::StopSound(CBaseEntity* pEntity, const tstring& pszFilename)
{
	if (!pEntity)
	{
		// Un-register the channel finish callback for the time being because we clear the active sound list by ourselves.
		Mix_ChannelFinished(NULL);

		tmap<CBaseEntity*, tmap<tstring, CSoundInstance> >::iterator it = Get()->m_aiActiveSounds.begin();

		while (it != Get()->m_aiActiveSounds.end())
		{
			tmap<tstring, CSoundInstance>::iterator it2 = Get()->m_aiActiveSounds[(*it).first].begin();
			while (it2 != Get()->m_aiActiveSounds[(*it).first].end())
			{
				Mix_HaltChannel(Get()->m_aiActiveSounds[(*it).first][(*it2).first].iChannel);
				it2++;
			}

			it++;
		}

		Get()->m_aiActiveSounds.clear();

		Mix_ChannelFinished(&CSoundLibrary::ChannelFinished);
		return;
	}

	if (Get()->m_aiActiveSounds.find(pEntity) == Get()->m_aiActiveSounds.end())
		return;

	if (pszFilename != "")
	{
		// Un-register the channel finish callback for the time being because we clear the active sound list by ourselves.
		Mix_ChannelFinished(NULL);

		tmap<tstring, CSoundInstance>::iterator it2 = Get()->m_aiActiveSounds[pEntity].begin();
		while (it2 != Get()->m_aiActiveSounds[pEntity].end())
		{
			Mix_HaltChannel(Get()->m_aiActiveSounds[pEntity][(*it2).first].iChannel);
			it2++;
		}

		Get()->m_aiActiveSounds[pEntity].clear();

		Mix_ChannelFinished(&CSoundLibrary::ChannelFinished);
		return;
	}

	if (Get()->m_aiActiveSounds[pEntity].find(pszFilename) == Get()->m_aiActiveSounds[pEntity].end())
		return;

	Mix_HaltChannel(Get()->m_aiActiveSounds[pEntity][pszFilename].iChannel);
}
예제 #2
0
파일: s_main.c 프로젝트: darkshade9/aq2w
/*
 * S_Init
 */
void S_Init(void) {
	int freq, channels;
	unsigned short format;

	memset(&s_env, 0, sizeof(s_env));

	if (Cvar_GetValue("s_disable")) {
		Com_Warn("Sound disabled.\n");
		return;
	}

	Com_Print("Sound initialization...\n");

	s_rate = Cvar_Get("s_rate", "44100", CVAR_ARCHIVE | CVAR_S_DEVICE,
			"Sound sampling rate in Hz.");
	s_reverse = Cvar_Get("s_reverse", "0", CVAR_ARCHIVE,
			"Reverse left and right channels.");
	s_volume = Cvar_Get("s_volume", "1.0", CVAR_ARCHIVE,
			"Global sound volume level.");

	Cmd_AddCommand("s_restart", S_Restart_f, "Restart the sound subsystem");
	Cmd_AddCommand("s_play", S_Play_f, NULL);
	Cmd_AddCommand("s_stop", S_Stop_f, NULL);
	Cmd_AddCommand("s_list", S_List_f, NULL);

	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
		if (SDL_Init(SDL_INIT_AUDIO) < 0) {
			Com_Warn("S_Init: %s.\n", SDL_GetError());
			return;
		}
	} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
		if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
			Com_Warn("S_Init: %s.\n", SDL_GetError());
			return;
		}
	}

	if (Mix_OpenAudio(s_rate->integer, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
		Com_Warn("S_Init: %s\n", Mix_GetError());
		return;
	}

	if (Mix_QuerySpec(&freq, &format, &channels) == 0) {
		Com_Warn("S_Init: %s\n", Mix_GetError());
		return;
	}

	if (Mix_AllocateChannels(MAX_CHANNELS) != MAX_CHANNELS) {
		Com_Warn("S_Init: %s\n", Mix_GetError());
		return;
	}

	Mix_ChannelFinished(S_FreeChannel);

	Com_Print("Sound initialized %dKHz %d channels.\n", freq, channels);

	s_env.initialized = true;

	S_InitMusic();
}
예제 #3
0
파일: sound.c 프로젝트: wimh/instead
int snd_init(int hz) 
{
	int chunk;
	if (nosound_sw)
		return -1;
	if (!hz)
		hz = audio_rate;
	else
		audio_rate = hz;

	chunk = (chunksize_sw>0)?chunksize_sw:DEFAULT_CHUNKSIZE;
	audio_buffers = (audio_rate / 11025) * chunk;
	if (audio_buffers <=0) /* wrong parameter? */
		audio_buffers = DEFAULT_CHUNKSIZE;
	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
		fprintf(stderr, "Unable to init audio!\n");
		return -1;
	}

	if (Mix_OpenAudio(hz, audio_format, audio_channels, audio_buffers)) {
		fprintf(stderr, "Unable to open audio!\n");
		return -1;
	}
	sound_on = 1;
	Mix_ChannelFinished(game_channel_finished);
	return 0;
}
예제 #4
0
파일: music.c 프로젝트: jcubic/ToME
void init_music_subsystem(void)
{
	// set this to any of 512,1024,2048,4096 the higher it is, the more FPS shown and CPU needed
	s32b audio_buffers = 512;

	/* Should we do sounds ? */
	esettings_get_int("audio.music.enable", 1);
	esettings_get_int("audio.effects.enable", 1);
	if (!esettings_get_int("audio.enable", 1))
	{
		sound_not_available = TRUE;
		return;
	}

	// initialize SDL_net
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, audio_buffers) == -1)
	{
		sound_not_available = TRUE;
		return;
	}

	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
	Mix_Volume(-1, SDL_MIX_MAXVOLUME);

#ifdef USE_SDL
	if (!strcmp(ANGBAND_SYS, "sdl"))
	{
		Mix_HookMusicFinished(music_finished);
		Mix_ChannelFinished(channel_finished);
	}
#endif

	sound_not_available = FALSE;
}
예제 #5
0
sound_player::sound_player()
{
    sounds = nullptr;
    sound_count = 0;
    singleton = this;
    camera_x = 0;
    camera_y = 0;
    camera_radius = 1.0;
    master_volume = 1.0;
    sound_effect_volume = 0.5;
    positionless_volume = MIX_MAX_VOLUME;
    sound_effects_enabled = true;

#define NUM_CHANNELS 32
#if NUM_CHANNELS >= 32
    available_channels_bitmap = ~0;
    Mix_AllocateChannels(32);
#else
    channels_in_use_bitmap = (1 << NUM_CHANNELS) - 1;
    Mix_AllocateChannels(NUM_CHANNELS);
#endif
#undef NUM_CHANNELS

    Mix_ChannelFinished(on_channel_finished);
}
예제 #6
0
/** Start a sound channel */
static glui32 play_sound(schanid_t chan)
{
    SDL_LockAudio();
    chan->status = CHANNEL_SOUND;
    chan->buffered = 0;
    chan->sdl_channel = Mix_GroupAvailable(FREE);
    Mix_GroupChannel(chan->sdl_channel, BUSY);
    SDL_UnlockAudio();
    chan->sample = Mix_LoadWAV_RW(chan->sdl_rwops, FALSE);
    if (chan->sdl_channel < 0)
    {
        gli_strict_warning("No available sound channels");
    }
    if (chan->sdl_channel >= 0 && chan->sample)
    {
        SDL_LockAudio();
        sound_channels[chan->sdl_channel] = chan;
        SDL_UnlockAudio();
        Mix_Volume(chan->sdl_channel, chan->volume);
        Mix_ChannelFinished(&sound_completion_callback);
        if (Mix_PlayChannel(chan->sdl_channel, chan->sample, chan->loop-1) >= 0)
            return 1;
    }
    gli_strict_warning("play sound failed");
    gli_strict_warning(Mix_GetError());
    SDL_LockAudio();
    cleanup_channel(chan);
    SDL_UnlockAudio();
    return 0;
}
예제 #7
0
/** Start a compressed sound channel */
static glui32 play_compressed(schanid_t chan, char *ext)
{
    SDL_LockAudio();
    chan->status = CHANNEL_SOUND;
    chan->buffered = 1;
    chan->sdl_channel = Mix_GroupAvailable(FREE);
    Mix_GroupChannel(chan->sdl_channel, BUSY);
    SDL_UnlockAudio();
    chan->decode = Sound_NewSample(chan->sdl_rwops, ext, output, 65536);
    Uint32 soundbytes = Sound_Decode(chan->decode);
    Sound_Sample *sample = chan->decode;
    chan->sample = Mix_QuickLoad_RAW(sample->buffer, soundbytes);
    if (chan->sdl_channel < 0)
        gli_strict_warning("No available sound channels");
    if (chan->sdl_channel >= 0 && chan->sample)
    {
        SDL_LockAudio();
        sound_channels[chan->sdl_channel] = chan;
        SDL_UnlockAudio();
        Mix_Volume(chan->sdl_channel, chan->volume);
        Mix_ChannelFinished(&sound_completion_callback);
        if (Mix_PlayChannel(chan->sdl_channel, chan->sample, 0) >= 0)
            return 1;
    }
    gli_strict_warning("play sound failed");
    gli_strict_warning(Mix_GetError());
    SDL_LockAudio();
    cleanup_channel(chan);
    SDL_UnlockAudio();
    return 0;
}
예제 #8
0
THSoundEffects::THSoundEffects()
{
    m_ppSounds = NULL;
    m_iSoundCount = 0;
    ms_pSingleton = this;
    m_iCameraX = 0;
    m_iCameraY = 0;
    m_fCameraRadius = 1.0;
    m_fMasterVolume = 1.0;
    m_fSoundEffectsVolume = 0.5;
    m_iPostionlessVolume = MIX_MAX_VOLUME;
    m_bSoundEffectsOn = true;

#define NUM_CHANNELS 32
#if NUM_CHANNELS >= 32
    m_iChannelStatus = ~0;
    Mix_AllocateChannels(32);
#else
    m_iChannelStatus = (1 << NUM_CHANNELS) - 1;
    Mix_AllocateChannels(NUM_CHANNELS);
#endif
#undef NUM_CHANNELS

    Mix_ChannelFinished(_onChannelFinish);
}
예제 #9
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);
  }
}
예제 #10
0
int play2() {
  Mix_ChannelFinished(done);

  int channel2 = Mix_PlayChannel(-1, sound2, 1);
  assert(channel2 == 1);
  return channel2;
}
예제 #11
0
파일: sound.c 프로젝트: ramonelalto/gambas
static bool start_sound_engine()
{
  /* This is where we open up our audio device.  Mix_OpenAudio takes
     as its parameters the audio format we'd /like/ to have. */
  if(Mix_OpenAudio(info.rate, info.format, info.channels, info.buffers))
  {
    GB.Error("Unable to open audio");
    return TRUE;
  }

	if (pipe(_ch_pipe))
	{
		GB.Error("Unable to initialize channel pipe");
		return TRUE;
	}
	
  Mix_QuerySpec(&info.rate, &info.format, &info.channels);
	//fprintf(stderr, "Mix_QuerySpec: %d %d %d\n", info.rate, info.format, info.channels);

  channel_count = Mix_AllocateChannels(-1);

  Mix_ChannelFinished(channel_finished);

	return FALSE;
}
예제 #12
0
static bool Init()
{
   if (!gSDLIsInit)
   {
      ELOG("Please init Stage before creating sound.");
      return false;
   }

   if (!sChannelsInit)
   {
      sChannelsInit = true;
      for(int i=0;i<sMaxChannels;i++)
      {
         sUsedChannel[i] = false;
         sDoneChannel[i] = false;
      }
      Mix_ChannelFinished(onChannelDone);
      Mix_HookMusicFinished(onMusicDone);
      #ifndef EMSCRIPTEN
      Mix_SetPostMix(onPostMix,0);
      #endif
   }

   return sChannelsInit;
}
예제 #13
0
SDLAudio::~SDLAudio(void)
{
	// TODO
	delete ambim;
	Mix_HookMusic(NULL, NULL);
	FreeBuffers();
	SDL_DestroyMutex(OurMutex);
	Mix_ChannelFinished(NULL);
}
예제 #14
0
/**
 * Constructor.  This should never be called directly; use Load() instead.
 * @param chunk The loaded chunk (may not be @c nullptr).
 */
Sound::Sound(Mix_Chunk *chunk) :
    std::enable_shared_from_this<Sound>(),
    chunk(chunk)
{
    if (!mixerInitialized) {
        Mix_ChannelFinished(OnMixChannelFinished);
        mixerInitialized = true;
    }
}
예제 #15
0
void CSoundHandler::init()
{
	CAudioBase::init();

	if (initialized)
	{
		// Load sounds
		Mix_ChannelFinished(soundFinishedCallbackC);
	}
}
예제 #16
0
int play2() {
  Mix_ChannelFinished(done);

  int channel2 = Mix_PlayChannel(-1, sound2, 0);
  assert(channel2 == 1);
  int channel3 = Mix_PlayChannel(-1, sound3, 0);
  assert(channel3 == 2);
  assert(Mix_PlayMusic(music, 1) == 0);
  return channel2;
}
예제 #17
0
SoundSys::SoundSys()
{
	Mix_Init(MIX_INIT_FLAC);
	Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 8192);
	Mix_ChannelFinished(&Finished);
	m_bgmvol = m_sevol = m_vcevol = FULLVOL;
	//Init the array of sound
	for (int i = 0; i < SNDS; ++i)
		m_snds[i] = { i, -1, -1, FULLVOL, "blank", nullptr, nullptr};
}
void SDLSoundManager::play(SoundManager::SoundID sid, std::string channel, FPoint pos, bool loop) {

	SoundMapIterator it;
	VirtualChannelMapIterator vcit = channels.end();

	if (!sid || !AUDIO || !SOUND_VOLUME)
		return;

	it = sounds.find(sid);
	if (it == sounds.end())
		return;

	/* create playback object and start playback of sound chunk */
	Playback p;
	p.sid = sid;
	p.location = pos;
	p.virtual_channel = channel;
	p.loop = loop;
	p.finished = false;

	if (p.virtual_channel != GLOBAL_VIRTUAL_CHANNEL) {

		/* if playback exists, stop it befor playin next sound */
		vcit = channels.find(p.virtual_channel);
		if (vcit != channels.end())
			Mix_HaltChannel(vcit->second);

		vcit = channels.insert(std::pair<std::string, int>(p.virtual_channel, -1)).first;
	}

	// Let playback own a reference to prevent unloading playbacked sound.
	if (!loop)
		it->second->refCnt++;

	Mix_ChannelFinished(&channel_finished);
	int c = Mix_PlayChannel(-1, it->second->chunk, (loop ? -1 : 0));

	if (c == -1)
		logError("SoundManager: Failed to play sound, no more channels available.");

	// precalculate mixing volume if sound has a location
	Uint8 d = 0;
	if (p.location.x != 0 || p.location.y != 0) {
		float v = 255.0f * (calcDist(lastPos, p.location) / (SOUND_FALLOFF));
		clamp(v, 0.f, 255.f);
		d = Uint8(v);
	}

	Mix_SetPosition(c, 0, d);

	if (vcit != channels.end())
		vcit->second = c;

	playback.insert(std::pair<int, Playback>(c, p));
}
예제 #19
0
/* Notify the sound channel completion */
static void sound_completion_callback(int chan)
{
    channel_t *sound_channel = sound_channels[chan];
    if (!sound_channel || Mix_Playing(chan))
    {
        gli_strict_warning("sound callback failed");
        return;
    }
    if (!sound_channel->buffered || !sound_channel->decode)
    {
        if (sound_channel->notify)
        {
            gli_event_store(evtype_SoundNotify, 0,
                            sound_channel->resid, sound_channel->notify);
        }
        cleanup_channel(sound_channel);
        sound_channels[chan] = 0;
        return;
    }
    Uint32 soundbytes = Sound_Decode(sound_channel->decode);
    if (!soundbytes)
    {
        sound_channel->loop--;
        if (!sound_channel->loop)
        {
            if (sound_channel->notify)
            {
                gli_event_store(evtype_SoundNotify, 0,
                                sound_channel->resid, sound_channel->notify);
            }
            cleanup_channel(sound_channel);
            sound_channels[chan] = 0;
            return;
        }
        else
        {
            Sound_Rewind(sound_channel->decode);
            soundbytes = Sound_Decode(sound_channel->decode);
        }
    }
    Sound_Sample *sample = sound_channel->decode;
    sound_channel->sample = Mix_QuickLoad_RAW(sample->buffer, soundbytes);
    Mix_ChannelFinished(&sound_completion_callback);
    if (Mix_PlayChannel(sound_channel->sdl_channel,
                        sound_channel->sample,
                        FALSE) >= 0)
    {
        return;
    }
    gli_strict_warning("buffer sound failed");
    gli_strict_warning(Mix_GetError());
    cleanup_channel(sound_channel);
    return;
}
예제 #20
0
	void Sound::init(const int iMaxChannels, std::string sStart, std::string sEnd)	{
		Mix_AllocateChannels(iMaxChannels);
		s_iMaxChannels = iMaxChannels;
		s_sPathStart   = sStart;
		s_sPathEnd     = sEnd;
		s_abChannelPlaying = new bool[s_iMaxChannels];
		for (int i = 0; i < s_iMaxChannels; i++) {
			s_abChannelPlaying[i] = false;
		}
		
		Mix_ChannelFinished(channelFinished); // register callback method
	}
예제 #21
0
파일: sound.cpp 프로젝트: BSVino/Digitanks
CSoundLibrary::CSoundLibrary()
{
	s_pSoundLibrary = this;
	m_iSoundsLoaded = 0;

	SDL_Init(SDL_INIT_AUDIO);

	if(Mix_OpenAudio(22050, AUDIO_S16, 2, 4096))
		SDL_Quit();

	Mix_ChannelFinished(&CSoundLibrary::ChannelFinished);
}
예제 #22
0
Sound::Sound() {
  if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) > 0) {
    std::cout << Mix_GetError() << std::endl;
    return;
  }

  channels = 0;
  Mix_AllocateChannels(0);
  Mix_ChannelFinished([](int channel) {
    Veil::SDL::Sound::instance()->removeChannel();
  });
}
예제 #23
0
bool CHANNEL_init(void)
{
	if (pipe(_pipe))
	{
		GB.Error("Unable to initialize channel pipe");
		return TRUE;
	}

	_count = Mix_AllocateChannels(-1);

	Mix_ChannelFinished(channel_finished_cb);
	return FALSE;
}
예제 #24
0
///////////////////////////////////////////////////////////////////////////
//
//      SD_Startup() - starts up the Sound Mgr
//              Detects all additional sound hardware and installs my ISR
//
///////////////////////////////////////////////////////////////////////////
void
SD_Startup(void)
{
    int     i;

    if (SD_Started)
        return;

    if((audioMutex = SDL_CreateMutex()) == NULL)
    {
        printf("Unable to create audio mutex\n");
        return;
    }

    if(Mix_OpenAudio(param_samplerate, AUDIO_S16, 2, param_audiobuffer))
    {
        printf("Unable to open audio: %s\n", Mix_GetError());
        return;
    }

    Mix_ReserveChannels(2);  // reserve player and boss weapon channels
    Mix_GroupChannels(2, MIX_CHANNELS-1, 1); // group remaining channels

    // Init music
    if(YM3812Init(1,3579545,param_samplerate))
    {
        printf("Unable to create virtual OPL!!\n");
    }

    for(i=1; i<0xf6; i++)
        YM3812Write(oplChip,i,0,MAX_VOLUME);

    YM3812Write(oplChip,1,0x20,MAX_VOLUME); // Set WSE=1
//    YM3812Write(0,8,0); // Set CSM=0 & SEL=0		 // already set in for statement

    samplesPerMusicTick = param_samplerate / MUSIC_RATE;    // SDL_t0FastAsmService played at 700Hz
    Mix_HookMusic(SDL_IMFMusicPlayer, 0);
    Mix_ChannelFinished(SD_ChannelFinished);
    AdLibPresent = true;
    SoundBlasterPresent = true;

    alTimeCount = 0;

    SD_SetSoundMode(sdm_Off);
    SD_SetMusicMode(smm_Off);

    SD_Started = true;

    SoundInfo.Init();
    SoundSeq.Init();
}
예제 #25
0
void SoundProcessor::initSoundEngine()
{
	// TODO start a 'watchdog' thread (FMOD waits indefinitely if the sound is currently used!)
	toInfoLog(TextStorage::instance().get(IDS::START_INIT_SOUND_TEXT_ID)->getText());

#ifdef _FMOD_SOUND
	unsigned int version;

	if(!ERRCHECK(FMOD::System_Create(&soundEngine))) { 
		throw SDLException(TextStorage::instance().get(IDS::START_INIT_FMOD_SYSTEM_CREATE_ERROR_TEXT_ID)->getText());
	}

	BOOST_ASSERT(soundEngine);
	if(!ERRCHECK(soundEngine->getVersion(&version))) {
		throw SDLException(TextStorage::instance().get(IDS::START_INIT_FMOD_GET_VERSION_ERROR_TEXT_ID)->getText());
	}

	if (version < FMOD_VERSION)
	{
		std::ostringstream os;
		os << TextStorage::instance().get(IDS::START_INIT_FMOD_VERSION_ERROR_TEXT_ID)->getText() << "[" << version << " < " << FMOD_VERSION << "]";
		throw SDLException(os.str());
	}

	printSoundInformation();

	if(!ERRCHECK(soundEngine->init(32, FMOD_INIT_NORMAL, 0))) {
		throw SDLException(TextStorage::instance().get(IDS::START_INIT_FMOD_SYSTEM_INIT_ERROR_TEXT_ID)->getText());
	}
#elif _SDL_MIXER_SOUND
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)==-1) 
	{
		std::ostringstream os;
		os << "ERROR (SoundProcessor::initSoundEngine()): " << Mix_GetError();
		throw SDLException(os.str());
	}		
	Mix_ChannelFinished(::soundChannelDone);
	
	/*
	int flags = MIX_INIT_MP3; // TODO MOD!
	int initted = Mix_Init(flags);
	if(initted&flags != flags) {
		std::ostringstream os;
		os << "ERROR (SoundProcessor::initSoundEngine()): " << Mix_GetError();
		throw SDLException(os.str());
	}*/

#endif
	soundInitialized = true;
}
예제 #26
0
파일: sound.cpp 프로젝트: suxinde2009/Rose
bool init_sound() 
{
	VALIDATE(sample_rate, "must call set_play_params before init_sound!");

	LOG_AUDIO << "Initializing audio...\n";
	if (SDL_WasInit(SDL_INIT_AUDIO) == 0)
		if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
			return false;
		}

	if (!mix_ok) {
		if(Mix_OpenAudio(sample_rate, MIX_DEFAULT_FORMAT, 2, buffer_size) == -1) {
			mix_ok = false;
			ERR_AUDIO << "Could not initialize audio: " << Mix_GetError() << "\n";
			return false;
		}

		mix_ok = true;
		Mix_AllocateChannels(n_of_channels);
		Mix_ReserveChannels(n_reserved_channels);

		channel_chunks.clear();
		channel_chunks.resize(n_of_channels, NULL);
		channel_ids.resize(n_of_channels, -1);

		Mix_GroupChannel(bell_channel, SOUND_BELL);
		Mix_GroupChannel(timer_channel, SOUND_TIMER);
		Mix_GroupChannels(source_channel_start, source_channel_last, SOUND_SOURCES);
		Mix_GroupChannel(UI_sound_channel, SOUND_UI);
		Mix_GroupChannels(n_reserved_channels, n_of_channels - 1, SOUND_FX);

		set_sound_volume(preferences::sound_volume());
		set_UI_volume(preferences::UI_volume());
		set_music_volume(preferences::music_volume());
		set_bell_volume(preferences::bell_volume());

		Mix_ChannelFinished(channel_finished_hook);

		LOG_AUDIO << "Audio initialized.\n";

		{
			int ii = 0;
			// play_music();
		}
	}
	return true;
}
예제 #27
0
파일: sound.cpp 프로젝트: aquileia/wesnoth
bool init_sound() {
	LOG_AUDIO << "Initializing audio...\n";
	if(SDL_WasInit(SDL_INIT_AUDIO) == 0)
		if(SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
			return false;

	if(!mix_ok) {
		if(Mix_OpenAudio(preferences::sample_rate(), MIX_DEFAULT_FORMAT, 2, preferences::sound_buffer_size()) == -1) {
			mix_ok = false;
			ERR_AUDIO << "Could not initialize audio: " << Mix_GetError() << std::endl;
			return false;
		}

		mix_ok = true;
		Mix_AllocateChannels(n_of_channels);
		Mix_ReserveChannels(n_reserved_channels);

		channel_chunks.clear();
		channel_chunks.resize(n_of_channels, nullptr);
		channel_ids.resize(n_of_channels, -1);

		Mix_GroupChannel(bell_channel, SOUND_BELL);
		Mix_GroupChannel(timer_channel, SOUND_TIMER);
		Mix_GroupChannels(source_channel_start, source_channel_last, SOUND_SOURCES);
		Mix_GroupChannels(UI_sound_channel_start, UI_sound_channel_last, SOUND_UI);
		Mix_GroupChannels(n_reserved_channels, n_of_channels - 1, SOUND_FX);

		set_sound_volume(preferences::sound_volume());
		set_UI_volume(preferences::UI_volume());
		set_music_volume(preferences::music_volume());
		set_bell_volume(preferences::bell_volume());

		Mix_ChannelFinished(channel_finished_hook);

		LOG_AUDIO << "Audio initialized.\n";

		DBG_AUDIO << "Channel layout: " << n_of_channels << " channels (" << n_reserved_channels << " reserved)\n"
				  << "    " << bell_channel << " - bell\n"
				  << "    " << timer_channel << " - timer\n"
				  << "    " << source_channel_start << ".." << source_channel_last << " - sound sources\n"
				  << "    " << UI_sound_channel_start << ".." << UI_sound_channel_last << " - UI\n"
				  << "    " << UI_sound_channel_last + 1 << ".." << n_of_channels - 1 << " - sound effects\n";

		play_music();
	}
	return true;
}
예제 #28
0
// Prepare the local audio device
bool cSound_PC2::devicePrepare() {

	int audio_rate = 22050;
	Uint16 audio_format = AUDIO_U8;
	int audio_channels = 2;
	int audio_buffers = 1024;
 
	if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
		mSound = false;
	}
	else {
		mSound = true;
		Mix_ChannelFinished( Mixer_ChannelFinished2 );
	}

	return true;
}
예제 #29
0
파일: Sound.cpp 프로젝트: linwang/EDEn
void Sound::load(const char* path)
{
   /**
    * \todo This should only be called once. Move it into initialization code.
    */
   Mix_ChannelFinished(&Sound::channelFinished);

   DEBUG("Loading WAV %s", path);
   sound = Mix_LoadWAV(path);

   if(sound == NULL)
   {
      T_T(Mix_GetError());
   }

   DEBUG("Successfully loaded WAV %s.", path);
}
예제 #30
0
void JukeBox::Init()
{
  const Config* cfg = Config::GetConstInstance();
  ActiveMusic(cfg->GetSoundMusic());
  SetFrequency(cfg->GetSoundFrequency());

  if (!OpenDevice()) {
    End();
    return;
  }

  Mix_ChannelFinished(JukeBox::EndChunk);
  Mix_HookMusicFinished(JukeBox::EndMusic);

  LoadXML("default");
  LoadMusicXML();
}