Beispiel #1
0
/**
 * @brief Initializes the sound subsystem.
 *
 *    @return 0 on success.
 */
int sound_mix_init (void)
{
   SDL_InitSubSystem(SDL_INIT_AUDIO);
   if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT , 2, 1024) < 0) {
      WARN("Opening Audio: %s", Mix_GetError());
      DEBUG();
      return -1;
   }
   Mix_AllocateChannels(SOUND_CHANNEL_MAX);

   /* Reset some variables. */
   group_pos = 0;

   /* Debug magic. */
   print_MixerVersion();

   /* Finish function. */
   Mix_ChannelFinished( voice_mix_markStopped );

   return 0;
}
Beispiel #2
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() << "\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";

        play_music();
    }
    return true;
}
Sound::Sound() {
	
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
        return;
    }

	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) {
		printf("%s", Mix_GetError());
	}
	for(int i = 0; i < nbChannelSound; i++){
		activeChannel[i] = false;
	}
	menu = Mix_LoadMUSType_RW(SDL_RWFromMem(music_menu_mp3, music_menu_mp3_len), MUS_MP3, 0);
	battle = Mix_LoadMUSType_RW(SDL_RWFromMem(music_battle_mp3, music_battle_mp3_len), MUS_MP3, 0);

	bipSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_bip_wav, sound_bip_wav_len), 0);
	bombeBounceSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_bounce_wav, sound_bounce_wav_len), 0);
	playerBurnSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_burn_wav, sound_burn_wav_len), 0);
	cancelSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_cancel_wav, sound_cancel_wav_len), 0);
	endSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_end_wav, sound_end_wav_len), 0);
	fireSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_fire_wav, sound_fire_wav_len), 0);
	hole1Sound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_hole1_wav, sound_hole1_wav_len), 0);
	hole2Sound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_hole2_wav, sound_hole2_wav_len), 0);
	hole3Sound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_hole3_wav, sound_hole3_wav_len), 0);
	playerKickSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_kick_wav, sound_kick_wav_len), 0);
	louisSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_louis_wav, sound_louis_wav_len), 0);
	mineSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_mine_wav, sound_mine_wav_len), 0);
	teleporterCloseSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_teleporter_close_wav, sound_teleporter_close_wav_len), 0);
	teleporterOpenSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_teleporter_open_wav, sound_teleporter_open_wav_len), 0);
	validSound = Mix_LoadWAV_RW(SDL_RWFromMem(sound_valide_wav, sound_valide_wav_len), 0);

	Mix_PlayMusic(menu, -1);
	Mix_VolumeMusic (MIX_MAX_VOLUME);
	Mix_AllocateChannels(nbChannelSound);
	Mix_Volume(0, MIX_MAX_VOLUME / 2);
	Mix_Volume(3, MIX_MAX_VOLUME / 2);

	mineOffsetChannel = 14;
}
void audio_initialize(int soundMax, int musicMax, int pakMax)
{
	int flags=MIX_INIT_OGG;
	if(soundMax <= 0 || musicMax <= 0)
	{
		slog("cannot initialize for 0 sounds or 0 musics");
		return;
	}
	if(Mix_Init(flags) != flags)
	{
		slog("Not initialized for ogg");
		return;
	}
	if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0)
	{
		slog("failed to open audio");
		return;
	}
	atexit(audio_close_lists);

	if(Mix_AllocateChannels(5) != 5)
	{
		slog("unable to allocate enough channels");
		return;
	}

	musicList = (Music *) malloc (sizeof (Music) * musicMax);
	soundList = (Sound *) malloc (sizeof (Sound) * soundMax);
	pakList = (SoundPak *) malloc (sizeof (SoundPak) * pakMax);

	memset(musicList, 0, sizeof (Music) * musicMax);
	memset(soundList, 0, sizeof (Sound) * soundMax);
	memset(pakList, 0, sizeof (SoundPak) * pakMax);

	maxMusics = musicMax;
	maxSounds = soundMax;
	maxPaks = pakMax;

	atexit(audio_close_lists);
}
Beispiel #5
0
bool audio::init()
{
//	sran1(SDL_GetTicks());

	sfact = NULL;
	// start SDL with audio support
	if(SDL_InitSubSystem(SDL_INIT_AUDIO) ==- 1) {
		printf("SDL_Init (audio): %s\n", SDL_GetError());
		return false;
	}

	audio_rate = 22050;			//Frequency of audio playback
	audio_format = AUDIO_S16SYS; 	//Format of the audio we're playing
	audio_channels = 2;			//2 channels = stereo
	audio_buffers = 1024;		//Size of the audio buffers in memory

	//Initialize SDL_mixer with our chosen audio settings
	if(Mix_OpenAudio(audio_rate,
							audio_format,
							audio_channels,
							audio_buffers) != 0) {
		printf("Unable to initialize audio: %s\n", Mix_GetError());
		return false;
	}

	// allocate 32 mixing channels
	Mix_AllocateChannels(32);
	sfact = new soundFactory(32);

	music = NULL;
//	Mix_Volume(-1,MIX_MAX_VOLUME * .30);
//	Mix_VolumeMusic(MIX_MAX_VOLUME * .5);

	Mix_HookMusicFinished(song_done);
	songs.load("./data/config/playlist.xml");
//	songs.print();

	return true;

}
SDLMixerSoundSystem::SDLMixerSoundSystem()
 : m_queuesEmpty(true)
{
    int retval = SDL_InitSubSystem ( SDL_INIT_AUDIO );
    CrbReleaseAssert ( retval == 0 );

    int channels = g_prefsManager->GetInt ( "SoundChannels", 32 ),
        frequency = g_prefsManager->GetInt ( "SoundMixFreq", 22050 ),
        bufferSize = g_prefsManager->GetInt ( "SoundBufferSize", 1024 );

    if ( channels < 16 ) channels = 16;
    if ( frequency < 22050 ) frequency = 22050;
    if ( bufferSize < 512 ) bufferSize = 512;

    if ( !isPowerOfTwo ( bufferSize ) ) bufferSize = nearestPowerOfTwo ( bufferSize );

    retval = Mix_OpenAudio ( frequency, AUDIO_S16SYS, 2, bufferSize );
    CrbReleaseAssert ( retval == 0 );

    Mix_AllocateChannels ( channels );
    m_channelPlaying.setSize ( channels );
}
Beispiel #7
0
DKAudio::DKAudio(DKString file)
{
	if(!DKFile::FileExists(file)){
		DKDebug("Audio File Does Not Exist\n");
		return;
	}
	Mix_Init(0);
	Mix_Quit(); //???
	int error = 0;
	error = Mix_OpenAudio(8000,MIX_DEFAULT_FORMAT,2,BUFFER);
	if(error){
		DKDebug("Audio Error");
	}

	Mix_AllocateChannels(10);

	sound = Mix_LoadWAV(file.c_str());
	if(!sound){
		//DKDebug(Mix_GetError());
	}
	Mix_VolumeMusic(64);
}
Beispiel #8
0
/**
 * Initialize SDL sounds so that sdl_play_sample can be called.
 * @return 0 on success, nonzero otherwise.
 */
int sdl_init_sounds(void) {
#ifdef HAVE_SDL_MIXER
    int ret;

    ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
    if (ret != 0)
        return 1;

    /*
     * use a 4096 byte buffer:
     * 44100*2*2 bytes/sec / 4096 bytes = about 1/43 seconds
     */
    ret = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);
    if (ret < 0)
        return 1;
    Mix_AllocateChannels(16);   /* max. 16 simultaneous samples */
    return 0;
#else
    printf("This version of triplane has been compiled without sound support.\n");
    return 1;
#endif
}
Beispiel #9
0
Sound::Sound(uint8_t vol)
	:chunks(34), priorities(MIXER_CHANNELS)
{
	if (Mix_OpenAudio(OUTPUT_RATE, OUTPUT_FORMAT, 
			  OUTPUT_CHANNELS, OUTPUT_CHUNK_SIZE) == -1) {
		throw Sound_Error(Mix_GetError());
	}
	Mix_AllocateChannels(MIXER_CHANNELS);

	std::string filename;
	Mix_Chunk *chunk;
	for ( auto i=0; i < 34; ++i ) {
		filename = DATADIR "/sounds/" + filenames[i] + ".ogg";
		chunk = Mix_LoadWAV(filename.c_str());
		if (chunk == NULL)
			throw Sound_Error(Mix_GetError());

		chunks[i] = chunk;
	}
	//delete[] filename;
	Mix_Volume(-1, vol*16);
}
Beispiel #10
0
    /* Initialize the sound module */
    void Init()
    {
        /* Skip disabled audio */
        if (!EnableAudio)
        {
            verbose << "Audio disabled -- skipping initialization" << endl;
            return;
        }

        verbose << "Initializing audio...";

        if (Mix_OpenAudio(22050, AUDIO_S16, 2, 1024))
        {
            error << "Mix_OpenAudio Failure" << endl;
            exit(1);
        }
        Mix_AllocateChannels(32);

        verbose << "Audio initialized." << endl;

        if (! (EnableAudio && EnableSFX)) return;

        for (int i=0; i<SFX_MAX; i++)
        {
            string filename = SoundPath;
            filename += SoundFileNames[i];
            mix_sound[i] = Mix_LoadWAV(filename.c_str());

            verbose << "Loading " << filename << "...";

            if (!mix_sound)
                error << endl << "Could not load " << filename << endl;

            else
                verbose << "done." << endl;
        }

        verbose << "...done" << endl;
    }
Beispiel #11
0
SdlAudio::SdlAudio() :
	bgm_volume(0),
	bgs_channel(0),
	bgs_playing(false),
	me_channel(0),
	me_stopped_bgm(false)
{
	if (!(SDL_WasInit(SDL_INIT_AUDIO) & SDL_INIT_AUDIO)) {
		if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
			Output::Error("Couldn't initialize audio.\n%s\n", SDL_GetError());
		}
	}
#ifdef GEKKO
	int const frequency = 32000;
#else
	int const frequency = 44100;
#endif
	if (Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) < 0) {
		Output::Error("Couldn't initialize audio.\n%s\n", Mix_GetError());
	}
	Mix_AllocateChannels(32); // Default is MIX_CHANNELS = 8
}
Beispiel #12
0
int InitSDL_mixer(){
	//On initialise SDL_Mixer 2, qui gérera la musique et les effets sonores
	int flags = MIX_INIT_MP3;
	int initted = Mix_Init(flags);
	if ((initted & flags) != flags)
	{
		printf("Mix_Init: Failed to init SDL_Mixer\n");
		printf("Mix_Init: %s\n", Mix_GetError());
		return 0;
	}
	printf("SDL_Mixer Initialisation complete. \n");
	/* Open 44.1KHz, signed 16bit, system byte order,
	stereo audio, using 1024 byte chunks (voir la doc pour plus d'infos) */
	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
		printf("Mix_OpenAudio: %s\n", Mix_GetError());
		return 0;
	}
	printf("Mix_OpenAudio Initialisation complete. \n");
	// Définit le nombre de pistes audio (channels) à mixer
	Mix_AllocateChannels(32);
	return 1;
}
Beispiel #13
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;
}
Beispiel #14
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);
}
Beispiel #15
0
static boolean I_SDL_InitSound(void)
{
    int i;

    // No sounds yet

    for (i = 0; i < NUMSFX; ++i)
        sound_chunks[i].abuf = NULL;

    for (i = 0; i < NUM_CHANNELS; ++i)
        channels_playing[i] = sfx_None;

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
    {
        fprintf(stderr, "Unable to set up sound.\n");
        return false;
    }

    if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
    {
        fprintf(stderr, "Error initializing SDL_mixer: %s\n", Mix_GetError());
        return false;
    }

    Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels);

    // precache sounds to avoid slowdown inside game
    for (i = 0; i < NUMSFX; i++)
        CacheSFX_SDL(i);

    Mix_AllocateChannels(NUM_CHANNELS);

    SDL_PauseAudio(0);

    sound_initialized = true;

    return true;
}
Beispiel #16
0
SDL_Surface* init_window ()
{
	if (SDL_Init (SDL_INIT_VIDEO))
	{
		fprintf (stderr, "SDL_Init failed : %s\n", SDL_GetError());
		exit (1);
	}
	if (TTF_Init ())
	{
		fprintf (stderr, "TTF_Init failed : %s\n", SDL_GetError());
		exit (2);
	}

	SDL_WM_SetIcon (SDL_LoadBMP("ressources/ico.bmp"), NULL);
	SDL_WM_SetCaption ("HEX (...a saute !)", "");

	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1)
		fprintf(stderr, "Mix init failed : %s\n", Mix_GetError());
	Mix_AllocateChannels(3); //MIX_CHANNELS

	const SDL_VideoInfo* info = SDL_GetVideoInfo();
	int bpp;
	if (info == NULL)
	{
		fprintf (stderr, "Unable to get video information\n Trying to force BPP to 8.\n");
		bpp = 8;
	}
	else
		bpp = info->vfmt->BitsPerPixel;

	SDL_Surface* window = SDL_SetVideoMode (DWIDTH, DHEIGHT, bpp, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
	if (window == NULL)
	{
		fprintf (stderr, "Unable to set video mode : %s\n", SDL_GetError());
		exit (3);
	}
	return window;
}
int main(int argc, char **argv) {
  SDL_Init(SDL_INIT_AUDIO);
  Mix_Init(MIX_INIT_OGG);

  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
  assert(ret == 0);

  Mix_AllocateChannels(kNumChannels);

  sound = Mix_LoadWAV("sound.ogg");

  // allocate all the channels
  for ( int i = 0; i < kNumChannels; i++ )
  {
    assert(loadAndPlay() != -1);
  }

    // This point, we should have exhausted our channels




  int lastChannel = loadAndPlay();

#if EMSCRIPTEN
  int result = (lastChannel == -1);
  REPORT_RESULT();
#endif

  assert(lastChannel == -1);

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

  return 0;
}
Beispiel #18
0
dboolean I_SDL_InitSound(void)
{
    int i;

    // No sounds yet
    for (i = 0; i < NUM_CHANNELS; ++i)
        channels_playing[i] = NULL;

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
        return false;

    {
        const SDL_version       *linked = Mix_Linked_Version();

        if (linked->major != MIX_MAJOR_VERSION || linked->minor != MIX_MINOR_VERSION)
            I_Error("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);

        if (linked->patch != MIX_PATCHLEVEL)
            C_Warning("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);
    }

    if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
        return false;

    Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels);

    Mix_AllocateChannels(NUM_CHANNELS);

    SDL_PauseAudio(0);

    sound_initialized = true;

    return true;
}
Beispiel #19
0
void SoundReconfigure(SoundDevice *s)
{
	s->isInitialised = false;

	if (Mix_AllocateChannels(s->channels) != s->channels)
	{
		printf("Couldn't allocate channels!\n");
		return;
	}

	Mix_Volume(-1, ConfigGetInt(&gConfig, "Sound.SoundVolume"));
	Mix_VolumeMusic(ConfigGetInt(&gConfig, "Sound.MusicVolume"));
	if (ConfigGetInt(&gConfig, "Sound.MusicVolume") > 0)
	{
		MusicResume(s);
	}
	else
	{
		MusicPause(s);
	}

	s->isInitialised = true;
}
Beispiel #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);
	}
}
Beispiel #21
0
SoundPlayer::SoundPlayer()
{
	int sdlret = SDL_Init(SDL_INIT_AUDIO);
        if(sdlret == -1){
                std::cout << "SDL value: " << sdlret << std::endl;
                std::cout << SDL_GetError();
        }
	Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);

	/*bgMusic = Mix_LoadMUS("sounds/bgMusic.wav");
	if(bgMusic == NULL) {
		std::cout << Mix_GetError() << std::endl;
	}*/
	//Mix_PlayMusic(bgMusic, -1);

	Mix_AllocateChannels(24);

	paddleSwing = Mix_LoadWAV("sounds/paddleSwing.wav");
	score = Mix_LoadWAV("sounds/score.wav");
	shipHit = Mix_LoadWAV("sounds/shipHit.wav");

	mute = false;
}
SoundManager::SoundManager(FileUtility* fileUtility, Configuration* config) {
	std::ostringstream oss;
	
	std::cout << "SoundManager..." << std::endl;

	m_fileUtility = fileUtility;
	m_config = config;

	std::cout << "Mix_OpenAudio (freq " << MIX_DEFAULT_FREQUENCY << ")..." << std::endl;
	if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048) != 0) {
		m_enabled = false;
		std::cerr << "\tsound is disabled" << std::endl;
		std::cerr << '\t' << Mix_GetError() << std::endl;
	} else {
		m_enabled = true;
		Mix_AllocateChannels(16);
		std::cout << "\tsound is enabled" << std::endl;
		Mix_VolumeMusic(m_config->MusicVolume * 12);
		for (unsigned int a = 1; a <= 8; ++a) {
			Mix_Volume(a, m_config->SoundVolume * 12);
		}
	}
}
Beispiel #23
0
void Sound::init()
{
    // Don't initialize sound engine twice
    if (mInstalled)
        return;

    logger->log("Sound::init() Initializing sound...");

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
    {
        logger->log("Sound::init() Failed to initialize audio subsystem");
        return;
    }

    const size_t audioBuffer = 4096;

    const int res = Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
                                  MIX_DEFAULT_CHANNELS, audioBuffer);
    if (res < 0)
    {
        logger->log("Sound::init Could not initialize audio: %s",
                    Mix_GetError());
        return;
    }

    Mix_AllocateChannels(16);
    Mix_VolumeMusic(mMusicVolume);
    Mix_Volume(-1, mSfxVolume);

    info();

    mInstalled = true;

    if (!mCurrentMusicFile.empty())
        playMusic(mCurrentMusicFile);
}
Beispiel #24
0
/*
 * S_Shutdown
 */
void S_Shutdown(void) {

	S_ShutdownMusic();

	S_Stop();

	Mix_AllocateChannels(0);

	S_FreeSamples();

	Mix_CloseAudio();

	if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_AUDIO)
		SDL_Quit();
	else
		SDL_QuitSubSystem(SDL_INIT_AUDIO);

	Cmd_RemoveCommand("s_play");
	Cmd_RemoveCommand("s_stop");
	Cmd_RemoveCommand("s_list");
	Cmd_RemoveCommand("s_restart");

	s_env.initialized = false;
}
Beispiel #25
0
static void	init_struct(t_struck *s)
{
	s->rep = 0;
	s->tmp[0] = -1;
	s->tmp[1] = 0;
	s->tmp[2] = 0;
	s->max = 0;
	s->cycle = 0;
	s->nb_chp = 0;
	s->dump = -1;
	s->check = 0;
	s->live = 0;
	s->turn = 7;
	s->turn_dump = -1;
	Mix_AllocateChannels(32);
	s->sound[0] = NULL;
	s->sound[1] = NULL;
	s->music = NULL;
	ft_bzero(s->proc_live[1], MEM_SIZE);
	if (!(s->map = ft_memalloc(sizeof(char) * MEM_SIZE + 4)))
		cor_err(4, NULL);
	if (!(s->col_chp = ft_memalloc(sizeof(char) * MEM_SIZE + 4)))
		cor_err(4, NULL);
}
Beispiel #26
0
void GP2DAudioManager::setMixChannels(int num) {
    m_mixingChannels = num;
    if(num >= 0) {
        Mix_AllocateChannels(num);
    }
}
Beispiel #27
0
int GP2DAudioManager::getMixChannels() {
    // Mix_AllocateChannels(-1) can also be used to retrieve the channels.
    // Which is perhaps a better way, because this Mix_AllocateChannels can
    // also be used outside of GP2D. Values will then be inconsequent.
    return Mix_AllocateChannels(-1);
}
Beispiel #28
0
void GW_PlatformSDL::initialize()
{
    if (!initialized_)
    {
        GWDBG_OUTPUT("SDL: Initialize");

        // initialize SDL video
        if ( SDL_Init( sdlinit(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) ) < 0 )
            throw GW_Exception(string("Unable to init SDL: "+string(SDL_GetError())));

#ifndef GW_NO_SDL_MIXER
        if ( Mix_OpenAudio(22050, AUDIO_S16SYS, 1, audiobufsize_get()) < 0)
            throw GW_Exception(string("Unable to init SDL_mixer: "+string(Mix_GetError())));
#endif

#ifndef GW_NO_SDL_TTF
        if ( TTF_Init() < 0 )
            throw GW_Exception(string("Unable to init SDL_ttf: "+string(TTF_GetError())));
#endif

#ifndef GW_NO_SDL_MIXER
        Mix_AllocateChannels(6);
        sound_volume(75);
#endif

        custom_initialize();

        // make sure SDL cleans up before exit
        atexit(SDL_Quit);

        // set application icon
        plat_init();

        // create a new window
        window_ = SDL_CreateWindow("Game & Watch simulator - by Hitnrun / ZsoltK & Madrigal",
                                   SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                   width_, height_,
                                   fullscreen_ ?  SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN);
        if ( !window_ )
            throw GW_Exception(string("Unable to allocate game window: " + string(SDL_GetError())));

        renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED);
        if ( !renderer_ )
            throw GW_Exception(string("Unable to allocate renderer: " + string(SDL_GetError())));


        // Let SDL & GPU do the scaling
        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
        SDL_RenderSetLogicalSize(renderer_, width_, height_);

        SDL_ShowCursor(SDL_DISABLE);

#ifndef GW_NO_SDL_TTF
        // load font
        //font_=TTF_OpenFont( bf::path( bf::path(platformdata_get() ) / "andalemo.ttf" ).string().c_str(), fontsize_get() );
        string pfont(platformdata_get() + "/" + "andalemo.ttf" );
        font_=TTF_OpenFont( pfont.c_str(), fontsize_get() );
        if (!font_)
            throw GW_Exception(string("Unable to load font: "+string(TTF_GetError())));
#endif

        initialized_=true;
    }
}
Beispiel #29
0
void Sound::addChannel() {
  channels++;
  Mix_AllocateChannels(channels);
}
Beispiel #30
0
void Sound::removeChannel() {
  channels--;
  Mix_AllocateChannels(channels);
}