示例#1
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);
	}
}
示例#2
0
文件: audio.c 项目: LibreGames/edgar
int initAudio()
{
	/* Set the audio rate to 44100, default mix, 2 channels and a 1024 byte buffer */

	game.audioDisabled = FALSE;

	if (Mix_OpenAudio(game.audioQuality, MIX_DEFAULT_FORMAT, 2, 1024) != 0)
	{
		printf("Could not open audio: %s\n", Mix_GetError());

		game.audioDisabled = TRUE;

		game.audio = FALSE;
	}

	else
	{
		game.audio = TRUE;

		Mix_AllocateChannels(MAX_CHANNELS);

		Mix_ReserveChannels(2);

		Mix_Volume(-1, MIX_MAX_VOLUME);
	}

	return game.audio;
}
示例#3
0
static mrb_value
mrb_sdl2_mixer_reverse_channel(mrb_state *mrb, mrb_value self)
{
  mrb_int num;
  mrb_get_args(mrb, "i", &num);
  return mrb_fixnum_value(Mix_ReserveChannels(num));
}
示例#4
0
int main(int argc, char **argv) {
  SDL_Init(SDL_INIT_AUDIO);
  Mix_Init(MIX_INIT_OGG);
  
  // This reserves channel 0 for other purposes.
  // We are just going to verify that we are not
  // allocated channel 0 when we call Mix_PlayChannel(-1, ...)
  Mix_ReserveChannels(1);
  
  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
  assert(ret == 0);

  sound = Mix_LoadWAV("sound.ogg");
  assert(sound);
  noiseLoop = Mix_LoadWAV("noise.ogg");
  assert(noiseLoop);

  music = Mix_LoadMUS("music.ogg");
  assert(music);
  emscripten_set_main_loop(one_iter, 30, 0);

  // force a quit
  while(Mix_Init(0))
    Mix_Quit();
  Mix_CloseAudio();

  return 0;
}
示例#5
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;
}
示例#6
0
	static int lua_Mix_ReserveChannels(State & state){
		Stack * stack = state.stack;
		int channels = 0;
		if (stack->is<LUA_TNUMBER>(1)){
			channels = stack->to<int>(1);
		}
		stack->push<int>(Mix_ReserveChannels(channels));
		return 1;
	}
示例#7
0
void PGE_Sounds::clearSoundBuffer()
{
    Mix_HaltChannel(-1);
    for (QHash<QString, Mix_Chunk* >::iterator it=chunksBuffer.begin(); it!=chunksBuffer.end(); ++it)
	{
        Mix_FreeChunk((*it));
	}
	chunksBuffer.clear();
    Mix_ReserveChannels(0);
}
示例#8
0
int Resume_playback(int nc,int nrc)
{
//    char SoundcardName[256];
	int audio_rate = 44100;
	int audio_channels = 2;
	int audio_bufsize = AUDIO_BUFFER;
	Uint16 audio_format = AUDIO_S16;
	SDL_version compile_version;
	n_channels=8;

	sound_enabled=true;
#ifdef __DEBUG_MESSAGES
	output_debug_message("Initializing SDL_mixer.\n");
#endif
	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_bufsize))  {
	  sound_enabled=false;
#ifdef __DEBUG_MESSAGES
  	  output_debug_message("Unable to open audio: %s\n", Mix_GetError());
  	  output_debug_message("Running the game without audio.\n");
#endif
	  return -1;	
	} // if 

#ifndef __EMSCRIPTEN__
	Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
#ifdef __DEBUG_MESSAGES
	output_debug_message("    opened %d Hz %d bit %s, %d bytes audio buffer\n",
						 audio_rate, audio_format & 0xFF,
						 audio_channels > 1 ? "stereo" : "mono", audio_bufsize);
#endif
#endif

	MIX_VERSION (&compile_version);
#ifdef __DEBUG_MESSAGES
	output_debug_message("    compiled with SDL_mixer version: %d.%d.%d\n",
						 compile_version.major,
						 compile_version.minor,
						 compile_version.patch);
	output_debug_message("    running with SDL_mixer version: %d.%d.%d\n",
						 Mix_Linked_Version()->major,
						 Mix_Linked_Version()->minor,
						 Mix_Linked_Version()->patch);
#endif

	if (nc>0) n_channels=Mix_AllocateChannels(nc);
	if (nrc>0) Mix_ReserveChannels(nrc);

	Sound_unpause_music();

	return n_channels;
} /* Resume_playback */ 
示例#9
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();
}
示例#10
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;
}
示例#11
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;
}
示例#12
0
void ConfigManager::clearSoundIndex()
{
    Mix_ReserveChannels(0);

    if(main_sfx_index.isEmpty()) return;

    int size = main_sfx_index.size();
    obj_sound_index *d = main_sfx_index.data();

    for(int i = 0; i < size; i++)
    {
        if(d[i].chunk)
            Mix_FreeChunk(d[i].chunk);
    }

    main_sfx_index.clear();
}
示例#13
0
int open_audio (int frequency, Uint16 format, int channels, int chunksize)
{
  if (Mix_OpenAudio( frequency, format, channels, chunksize ) < 0)
    return -1;

  // allocate 16 channels for mixing
  if (Mix_AllocateChannels(8)  != 8)
    return -2;

  /* reserve some channels and register panning effects */
  if (Mix_ReserveChannels(SOUND_RESERVED_CHANNELS) != SOUND_RESERVED_CHANNELS)
    return -3;

  /* prepare the spanning effects */
  Mix_SetPanning( SOUND_LEFT_SPEAKER, 230, 24 );
  Mix_SetPanning( SOUND_RIGHT_SPEAKER, 24, 230 );
  return 0;
}
示例#14
0
文件: audio.cpp 项目: Hrishi29x/abyss
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*/
}
示例#15
0
void MusicManager::rebuildSoundCache()
{
    // Reinit reserved channels list
    int numberOfReservedChannels = 0;
    
    // For sounds which are failing to load
    std::string failedSounds;
    int countOfFailedSounds = 0;
    constexpr static int MaxFailedSoundToDisplay = 15;

    for(int i=0; i<91; i++)
    {
        if(sounds[i].channel != -1)
        {
            sounds[i].channel = numberOfReservedChannels++;
        }
        if(sounds[i].needReload)
        {
            if(!sounds[i].doLoad())
            {
                countOfFailedSounds++;
                if(countOfFailedSounds > MaxFailedSoundToDisplay)
                    continue;
                failedSounds += " " + sounds[i].fullPath + "\n";
            }
        }
    }
    Mix_AllocateChannels(numberOfReservedChannels + 32);
    Mix_ReserveChannels(numberOfReservedChannels);

    if (countOfFailedSounds > MaxFailedSoundToDisplay)
    {
        failedSounds += "And " + std::to_string(countOfFailedSounds - MaxFailedSoundToDisplay) + " more sounds...\n";
    }

    if(!failedSounds.empty())
    {
        std::string errorMsg = "Some audio files failed to load:\n" + failedSounds;
        MessageBoxA(0, errorMsg.c_str(), "Errors while loading sound files", MB_OK | MB_ICONWARNING);
    }
}
示例#16
0
Mix_Chunk *PGE_Sounds::SND_OpenSnd(QString sndFile)
{
    QString filePath = sndFile;
    Mix_Chunk* tmpChunk = NULL;
    if(!chunksBuffer.contains(filePath))
    {
        tmpChunk = Mix_LoadWAV( sndFile.toUtf8() );
        if(!tmpChunk) {
            PGE_MsgBox::warn(QString("OpenSFX: Mix_LoadWAV: %1\n%2").arg(sndFile).arg(Mix_GetError()));
        }
        chunksBuffer[filePath] = tmpChunk;
    }
    else
    {
        tmpChunk = chunksBuffer[filePath];
    }

    Mix_ReserveChannels(chunksBuffer.size()>4 ? 4: chunksBuffer.size());

    return tmpChunk;
}
示例#17
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;
}
示例#18
0
bool SDLAudio::Init(void)
{
	// TODO: we assume SDLVideo already got loaded
	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
		return false;
	}
	OurMutex = SDL_CreateMutex();
	if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 8192) < 0) {
		return false;
	}
	Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);

	channel_data.resize(Mix_AllocateChannels(-1));
	for (unsigned int i = 0; i < channel_data.size(); i++) {
		channel_data[i] = NULL;
	}

	g_sdlaudio = this;
	Mix_ReserveChannels(1); // for speech
	Mix_ChannelFinished(channel_done_callback);
	return true;
}
示例#19
0
void I_InitSound()
{ 
  int i;
  
  fprintf( stderr, "I_InitSound: ");
  SDL_Init(SDL_INIT_AUDIO);
  I_InitMusic();
  Mix_AllocateChannels(NUM_CHANNELS);
  Mix_ReserveChannels(3);

  // Initialize external data (all sounds) at start, keep static.
 
  for (i=1 ; i<NUMSFX ; i++)
  { 
    // Alias? Example is the chaingun sound linked to pistol.
    if (!S_sfx[i].link)
    {
      // Load data from WAD file.
      S_sfx[i].data = getsfx( S_sfx[i].name, &lengths[i] );

      // Samples now 16bit LE stereo, upsampled to double length and padded
      S_sfx[i].chunk = Mix_QuickLoad_RAW( S_sfx[i].data, lengths[i] );
    }	
    else
    {
      // Previously loaded already?
      S_sfx[i].data = S_sfx[i].link->data;
      lengths[i] = lengths[(S_sfx[i].link - S_sfx)/sizeof(sfxinfo_t)];
      S_sfx[i].chunk = Mix_QuickLoad_RAW( S_sfx[i].data, lengths[i] );
    }
  }

  fprintf( stderr, " pre-cached all sound data\n");
  
  // Finished initialization.
  fprintf(stderr, "I_InitSound: sound module ready\n");
  SDL_PauseAudio(0);
}
示例#20
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);
	}
}
示例#21
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;
}
示例#22
0
Audio::Audio(ScenarioRunner* sr)
{
    Mix_ReserveChannels(1);
    this->sr = sr;
}
示例#23
0
bool SDLAudio::ReserveCHANS(int num)
{
    Mix_ReserveChannels(num);
    return true;
}
示例#24
0
void ConfigManager::buildSoundIndex()
{
    int need_to_reserve = 0;
    int total_channels = 32;
    bool newBuild = main_sfx_index.empty();
#ifdef DEBUG_BUILD
    ElapsedTimer loadingTime;
    loadingTime.start();
#endif

    if(newBuild)
    {
        //build array table
        main_sfx_index.resize(static_cast<size_t>(main_sound.size()) - 1);

        for(unsigned long i = 1; i < main_sound.size(); i++)
        {
            obj_sound_index sound;

            if(main_sound.contains(i))
            {
                obj_sound &snd = main_sound[i];
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                FileMapper fileMap;

                if(fileMap.open_file(snd.absPath.c_str()))
                {
                    sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                 static_cast<int>(fileMap.size())), 1);
                    fileMap.close_file();
                }

#else
                sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                sound.path = snd.absPath;

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }

            main_sfx_index[static_cast<size_t>(i) - 1] = sound;
        }
    }
    else
    {
        for(unsigned long i = 1; (i < main_sound.size()) && (i <= static_cast<unsigned long>(main_sfx_index.size())); i++)
        {
            if(main_sound.contains(i))
            {
                obj_sound_index &sound = main_sfx_index[static_cast<size_t>(i) - 1];
                obj_sound &snd = main_sound[i];
                sound.setPath(snd.absPath);

                if(sound.need_reload)
                {
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                    FileMapper fileMap;

                    if(fileMap.open_file(snd.absPath.c_str()))
                    {
                        sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                     static_cast<int>(fileMap.size())),
                                                     static_cast<int>(fileMap.size()));
                        fileMap.close_file();
                    }

#else
                    sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                }

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }
        }
    }

    if(need_to_reserve > 0)
    {
        total_channels = (total_channels + need_to_reserve + 32);
        total_channels = Mix_AllocateChannels(total_channels);
    }

    //Final channel definition (use reserved channels at end of channels set)
    //int set_channel = (total_channels-1);
    //for(int i=0; i < main_sfx_index.size(); i++)
    //{
    //    obj_sound_index &sound = main_sfx_index[i];
    //    if(sound.channel>=0)
    //    {
    //        sound.channel = set_channel--;
    //    }
    //}

    if(need_to_reserve == total_channels)
        need_to_reserve = 0;

    //else
    //    need_to_reserve=set_channel;
#ifndef DEBUG_BUILD
    Mix_ReserveChannels(need_to_reserve)
#endif
#define RESERVE_CHANS_COMMAND Mix_ReserveChannels(need_to_reserve)
    D_pLogDebug("Loading of sounds passed in %d milliseconds", static_cast<int>(loadingTime.elapsed()));
    D_pLogDebug("Reserved audio channels: %d", RESERVE_CHANS_COMMAND);
    D_pLogDebug("SFX Index entries: %d", main_sfx_index.size());
#undef RESERVE_CHANS_COMMAND
    SDL_ClearError();
}