Exemplo n.º 1
0
/**
 * Attempt to initialize an audio device.  Returns false if initialization fails.
 */
bool init_sound()
{
    int audio_rate = 44100;
    Uint16 audio_format = AUDIO_S16;
    int audio_channels = 2;
    int audio_buffers = 2048;

    // We should only need to init once
    if( !sound_init_success ) {
        // Mix_OpenAudio returns non-zero if something went wrong trying to open the device
        if( !Mix_OpenAudio( audio_rate, audio_format, audio_channels, audio_buffers ) ) {
            Mix_AllocateChannels( 128 );
            Mix_ReserveChannels( 24 );

            // For the sound effects system.
            Mix_GroupChannels( 2, 9, 1 );
            Mix_GroupChannels( 0, 1, 2 );
            Mix_GroupChannels( 11, 14, 3 );
            Mix_GroupChannels( 15, 17, 4 );

            sound_init_success = true;
        } else {
            dbg( D_ERROR ) << "Failed to open audio mixer, sound won't work: " << Mix_GetError();
        }
    }

    return sound_init_success;
}
Exemplo n.º 2
0
/**
 * Initializes the audio subsystem.
 */
void Game::initAudio()
{
	Uint16 format = MIX_DEFAULT_FORMAT;
	if (Options::audioBitDepth == 8)
		format = AUDIO_S8;

	if (Options::audioSampleRate % 11025 != 0)
	{
		Log(LOG_WARNING) << "Custom sample rate " << Options::audioSampleRate << "Hz, audio that doesn't match will be distorted!";
		Log(LOG_WARNING) << "SDL_mixer only supports multiples of 11025Hz.";
	}
	int minChunk = Options::audioSampleRate / 11025 * 512;
	Options::audioChunkSize = std::max(minChunk, Options::audioChunkSize);

	if (Mix_OpenAudio(Options::audioSampleRate, format, MIX_DEFAULT_CHANNELS, Options::audioChunkSize) != 0)
	{
		Log(LOG_ERROR) << Mix_GetError();
		Log(LOG_WARNING) << "No sound device detected, audio disabled.";
		Options::mute = true;
	}
	else
	{
		Mix_AllocateChannels(16);
		// Set up UI channels
		Mix_ReserveChannels(4);
		Mix_GroupChannels(1, 2, 0);
		Log(LOG_INFO) << "SDL_mixer initialized successfully.";
		setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
	}
}
Exemplo n.º 3
0
void gli_initialize_sound(void)
{
    if (gli_conf_sound == 1)
    {
        if (SDL_Init(SDL_INIT_AUDIO) == -1)
        {
            gli_strict_warning("SDL init failed\n");
            gli_strict_warning(SDL_GetError());
            gli_conf_sound = 0;
            return;
        }
        if (Sound_Init() == -1)
        {
            gli_strict_warning("SDL Sound init failed\n");
            gli_strict_warning(Sound_GetError());
            gli_conf_sound = 0;
            return;
        }
        Sound_AudioInfo *audio;
        audio = malloc(sizeof(Sound_AudioInfo));
        audio->format = MIX_DEFAULT_FORMAT;
        audio->channels = 2;
        audio->rate = 44100;
        output = audio;
        if (Mix_OpenAudio(output->rate, output->format, output->channels, 4096) == -1)
        {
            gli_strict_warning("SDL Mixer init failed\n");
            gli_strict_warning(Mix_GetError());
            gli_conf_sound = 0;
            return;
        }
        int channels = Mix_AllocateChannels(SDL_CHANNELS);
        Mix_GroupChannels(0, channels - 1 , FREE);
    }
}
Exemplo n.º 4
0
static mrb_value
mrb_sdl2_mixer_group_channels(mrb_state *mrb, mrb_value self)
{
  mrb_int from, to, tag;
  mrb_get_args(mrb, "iii", &from, &to, &tag);
  return mrb_fixnum_value(Mix_GroupChannels(from, to, tag));
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
void Init_Audio()
{
  if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,AUDIO_S16SYS,2,4096) == -1)
  {
    fprintf(stderr, "Unable to init SDL Mixer: %s\n", Mix_GetError());
    exit(1);
  }
  atexit(Mix_CloseAudio);
  if(Mix_AllocateChannels(32) != 32)
  {
    fprintf(stderr, "Unable to allocate enough channels: %s\n", Mix_GetError());
    exit(1);
  }
  Mix_VolumeMusic(MIX_MAX_VOLUME>>4);
  Mix_ReserveChannels(24);
  Mix_GroupChannels(0,3,FX_Bullets); /*bullet spawns*/
  Mix_GroupChannels(4,15,FX_Impacts); /*bullet impacts*/
  Mix_GroupChannels(16,19,FX_Monsters);/*monsters*/
  Mix_GroupChannels(20,23,FX_Player); /*player*/
}
Exemplo n.º 8
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();
}
Exemplo n.º 9
0
bool SDLAudio::GroupCHANS(int from, int to, 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_GroupChannels(from, to, GroupListITR.Item()->groupNum);
            return true;
        }

    SGZLogger.warn("AudioMAN: Group \"%s\" doesn't exist!\n", name.c_str());
    return false;
}
Exemplo n.º 10
0
	static int lua_Mix_GroupChannels(State & state){
		Stack * stack = state.stack;
		int from = 0;
		int to = 0;
		int tag = -1;
		if (stack->is<LUA_TNUMBER>(1) && stack->is<LUA_TNUMBER>(2)){
			from = stack->to<int>(1);
			to = stack->to<int>(2);
			if (from <= to){
				if (stack->is<LUA_TNUMBER>(3)){
					tag = stack->to<int>(3);
				}
				int result = Mix_GroupChannels(from, to, tag);
				stack->push<int>(result);
				return 1;
			}
		}
		return 0;
	}
Exemplo n.º 11
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(Mix_OpenAudio(44100, AUDIO_S16, 2, 2048))
      return; /* Unable to open audio */

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

   /* Initialize music */

   samplesPerMusicTick = 44100 / 700; /*played at 700Hzs */

   if(YM3812Init(1, 3579545, 44100))
      printf("Unable to create virtual OPL!!\n");

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

   YM3812Write(0,1,0x20); /* Set WSE=1 */

   Mix_HookMusic(SD_IMFMusicPlayer, 0);
   Mix_ChannelFinished(SD_ChannelFinished);
   AdLibPresent = true;
   SoundBlasterPresent = true;

   alTimeCount = 0;

   SD_SetSoundMode(SDM_OFF);
   SD_SetMusicMode(SMM_OFF);

   SD_SetupDigi();

   SD_Started = true;
}
Exemplo n.º 12
0
/**
 * Initializes the audio subsystem.
 */
void Game::initAudio()
{
	Uint16 format;
	if (Options::audioBitDepth == 8)
		format = AUDIO_S8;
	else
		format = AUDIO_S16SYS;
	if (Mix_OpenAudio(Options::audioSampleRate, format, 2, 1024) != 0)
	{
		Log(LOG_ERROR) << Mix_GetError();
		Log(LOG_WARNING) << "No sound device detected, audio disabled.";
		Options::mute = true;
	}
	else
	{
		Mix_AllocateChannels(16);
		// Set up UI channels
		Mix_ReserveChannels(4);
		Mix_GroupChannels(1, 2, 0);
		Log(LOG_INFO) << "SDL_mixer initialized successfully.";
		setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
	}
}
Exemplo n.º 13
0
/**
 * @brief Creates a sound group.
 *
 *    @param tag Identifier of the group to create.
 *    @param start Where to start creating the group.
 *    @param size Size of the group.
 *    @param ID of the group on success, otherwise 0.
 */
int sound_mix_createGroup( int size )
{
   int ret;
   mixGroup_t *g;

   /* Create new group. */
   ngroups++;
   groups = realloc( groups, sizeof(mixGroup_t) * ngroups );
   g = &groups[ngroups-1];

   /* Reserve channels. */
   ret = Mix_ReserveChannels( group_pos + size );
   if (ret != group_pos + size) {
      WARN("Unable to reserve sound channels: %s", Mix_GetError());
      return -1;
   }

   /* Get a new ID. */
   g->id    = ++group_idgen;

   /* Set group struct. */
   g->start = group_pos;
   g->end   = group_pos+size-1;

   /* Create group. */
   ret = Mix_GroupChannels( g->start, g->end, g->id );
   if (ret != size) {
      WARN("Unable to create sound group: %s", Mix_GetError());
      ngroups--;
      return -1;
   }

   /* Add to stack. */
   group_pos += size;

   return g->id;
}