예제 #1
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;
}
예제 #2
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;
}
예제 #3
0
static mrb_value
mrb_sdl2_mixer_group_channel(mrb_state *mrb, mrb_value self)
{
  mrb_int from, tag;
  mrb_get_args(mrb, "ii", &from, &tag);
  return mrb_fixnum_value(Mix_GroupChannel(from, tag));
}
예제 #4
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;
}
예제 #5
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;
}
예제 #6
0
파일: mixer.c 프로젝트: iaco79/IrrGameDemo
/* Assign several consecutive channels to a group */
int Mix_GroupChannels(int from, int to, int tag)
{
	int status = 0;
	for( ; from <= to; ++ from ) {
		status += Mix_GroupChannel(from, tag);
	}
	return(status);
}
예제 #7
0
	static int lua_Mix_GroupChannel(State & state){
		Stack * stack = state.stack;
		int channel = 0;
		int tag = -1;
		if (stack->is<LUA_TNUMBER>(1)){
			channel = stack->to<int>(1);
			if (stack->is<LUA_TNUMBER>(2)){
				tag = stack->to<int>(2);
			}
			int result = Mix_GroupChannel(channel, tag);
			stack->push<int>(result == 1);
			return 1;
		}
		return 0;
	}
예제 #8
0
bool SDLAudio::GroupCHAN(int chan, std::string name)
{
    /** Check to see if we've created it */
    SListIterator<SGZChanGroup*> GroupListITR = GroupList.GetIterator();

    for( GroupListITR.Start(); GroupListITR.Valid(); GroupListITR.Forth() )
        if((GroupListITR.Item()->Name.compare(name))==0)
        {
            Mix_GroupChannel(chan, GroupListITR.Item()->groupNum);
            return true;
        }

    SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str());
    return false;
}
예제 #9
0
static void cleanup_channel(schanid_t chan)
{
    if (chan->sdl_rwops)
    {
        if (!chan->decode)
            SDL_FreeRW(chan->sdl_rwops);
        else
            Sound_FreeSample(chan->decode);
        chan->sdl_rwops = 0;
        chan->decode = 0;
        chan->buffered = 0;
    }
    if (chan->sdl_memory)
    {
        free(chan->sdl_memory);
        chan->sdl_memory = 0;
    }
    switch (chan->status)
    {
        case CHANNEL_SOUND:
            if (chan->sample)
                Mix_FreeChunk(chan->sample);
            if (chan->sdl_channel >= 0)
            {
                Mix_GroupChannel(chan->sdl_channel, FREE);
                sound_channels[chan->sdl_channel] = 0;
            }
            break;
        case CHANNEL_MUSIC:
            if (chan->music)
            {
                Mix_FreeMusic(chan->music);
                music_channel = 0;
            }
            break;
    }
    chan->status = CHANNEL_IDLE;
    chan->sdl_channel = -1;
    chan->music = 0;
}
예제 #10
0
void SDLAudio::group_to(int channel, int tag) {
  Mix_GroupChannel(channel, tag);
}