Example #1
0
/**
 * @brief Prints the current and compiled SDL_Mixer versions.
 */
static void print_MixerVersion (void)
{
   int frequency;
   Uint16 format;
   int channels;
   SDL_version compiled;
   const SDL_version *linked;
   char device[PATH_MAX];

   /* Query stuff. */
   Mix_QuerySpec(&frequency, &format, &channels);
   MIX_VERSION(&compiled);
   linked = Mix_Linked_Version();
   SDL_AudioDriverName(device, PATH_MAX);

   /* Version itself. */
   DEBUG("SDL_Mixer Started: %d Hz %s", frequency,
         (channels == 2) ? "Stereo" : "Mono" );
   /* Check if major/minor version differ. */
   if ((linked->major*100 + linked->minor) > compiled.major*100 + compiled.minor)
      WARN("SDL_Mixer is newer than compiled version");
   if ((linked->major*100 + linked->minor) < compiled.major*100 + compiled.minor)
      WARN("SDL_Mixer is older than compiled version.");
   /* Print other debug info. */
   DEBUG("Renderer: %s",device);
   DEBUG("Version: %d.%d.%d [compiled: %d.%d.%d]", 
         compiled.major, compiled.minor, compiled.patch,
         linked->major, linked->minor, linked->patch);
   DEBUG();
}
Example #2
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 */ 
bool C4MusicSystem::InitializeMOD()
{
#if AUDIO_TK == AUDIO_TK_SDL_MIXER
	SDL_version compile_version;
	const SDL_version * link_version;
	MIX_VERSION(&compile_version);
	link_version=Mix_Linked_Version();
	LogF("SDL_mixer runtime version is %d.%d.%d (compiled with %d.%d.%d)",
	     link_version->major, link_version->minor, link_version->patch,
	     compile_version.major, compile_version.minor, compile_version.patch);
	if (!SDL_WasInit(SDL_INIT_AUDIO) && SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE))
	{
		LogF("SDL: %s", SDL_GetError());
		return false;
	}
	//frequency, format, stereo, chunksize
	if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 1024))
	{
		LogF("SDL_mixer: %s", SDL_GetError());
		return false;
	}
	MODInitialized = true;
	return true;
#elif AUDIO_TK == AUDIO_TK_OPENAL
	alcDevice = alcOpenDevice(NULL);
	if (!alcDevice)
	{
		LogF("Sound system: OpenAL create context error");
		return false;
	}
	alcContext = alcCreateContext(alcDevice, NULL);
	if (!alcContext)
	{
		LogF("Sound system: OpenAL create context error");
		return false;
	}
#ifndef __APPLE__
	if (!alutInitWithoutContext(NULL, NULL))
	{
		LogF("Sound system: ALUT init error");
		return false;
	}
#endif
	MODInitialized = true;
	return true;
#endif
	return false;
}
Example #4
0
bool Sound_initialization(void)
{
    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;

	sound_enabled=true;
	fprintf (stderr, "Initializing SDL_mixer.\n");

	int flags = MIX_INIT_OGG | MIX_INIT_MOD;
	int initted = Mix_Init(flags);
	if (initted & flags != flags) {
		printf("Mix_Init: Failed to init required ogg and mod support!\n");
		printf("Mix_Init: %s\n", Mix_GetError());
		sound_enabled = false;
		return false;
	}

	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_bufsize))  {
	  fprintf (stderr, "Unable to open audio: %s\n", Mix_GetError());
	  sound_enabled=false;
	  fprintf (stderr, "Running the game without audio.\n");
	  return false;	
	} /* if */ 

	SDL_AudioDriverName (SoundcardName, sizeof (SoundcardName));
	Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
	fprintf (stderr, "    opened %s at %d Hz %d bit %s, %d bytes audio buffer\n",
			 SoundcardName, audio_rate, audio_format & 0xFF,
			 audio_channels > 1 ? "stereo" : "mono", audio_bufsize);
	MIX_VERSION (&compile_version);
	fprintf (stderr, "    compiled with SDL_mixer version: %d.%d.%d\n",
			 compile_version.major,
			 compile_version.minor,
			 compile_version.patch);
	fprintf (stderr, "    running with SDL_mixer version: %d.%d.%d\n",
			 Mix_Linked_Version()->major,
			 Mix_Linked_Version()->minor,
			 Mix_Linked_Version()->patch);

	Sound_Init();
	Mix_HookMusic(myMusicPlayer, 0);

	return true;
} /* Sound_init */ 
Example #5
0
void Sound::info()
{
    SDL_version compiledVersion;
    const SDL_version *linkedVersion;
    char driver[40] = "Unknown";
    const char *format = "Unknown";
    int rate = 0;
    uint16_t audioFormat = 0;
    int channels = 0;

    MIX_VERSION(&compiledVersion);
    linkedVersion = Mix_Linked_Version();

    SDL_AudioDriverName(driver, 40);

    Mix_QuerySpec(&rate, &audioFormat, &channels);
    switch (audioFormat)
    {
        case AUDIO_U8: format = "U8"; break;
        case AUDIO_S8: format = "S8"; break;
        case AUDIO_U16LSB: format = "U16LSB"; break;
        case AUDIO_S16LSB: format = "S16LSB"; break;
        case AUDIO_U16MSB: format = "U16MSB"; break;
        case AUDIO_S16MSB: format = "S16MSB"; break;
        default: break;
    }

    logger->log("Sound::info() SDL_mixer: %i.%i.%i (compiled)",
            compiledVersion.major,
            compiledVersion.minor,
            compiledVersion.patch);
    if (linkedVersion)
    {
        logger->log("Sound::info() SDL_mixer: %i.%i.%i (linked)",
            linkedVersion->major,
            linkedVersion->minor,
            linkedVersion->patch);
    }
    else
    {
        logger->log1("Sound::info() SDL_mixer: unknown");
    }
    logger->log("Sound::info() Driver: %s", driver);
    logger->log("Sound::info() Format: %s", format);
    logger->log("Sound::info() Rate: %i", rate);
    logger->log("Sound::info() Channels: %i", channels);
}
Example #6
0
/**
 * @sa S_Shutdown
 * @sa S_Restart_f
 */
void S_Init (void)
{
    SDL_version version;
    char drivername[MAX_VAR];

    Com_Printf("\n------- sound initialization -------\n");

    OBJZERO(s_env);

    snd_init = Cvar_Get("snd_init", "1", CVAR_ARCHIVE, "Should the sound renderer get initialized");
    snd_init->modified = false; /* don't restart right away */
    Cmd_AddCommand("snd_restart", S_Restart_f, "Restart the sound renderer");

    if (!snd_init->integer) {
        Com_Printf("not initializing.\n");
        Cmd_AddCommand("music_change", Cmd_Dummy_f, "Dummy command if sound is disabled");
        Cvar_Get("snd_music", "PsymongN3", 0, "Background music track");
        return;
    }

    cl_soundSysPool = Mem_CreatePool("Client: Sound system");

    snd_distance_scale = Cvar_Get("snd_distance_scale", "0.1", 0, "Sound distance scale");
    snd_volume = Cvar_Get("snd_volume", "0.7", CVAR_ARCHIVE, "Sound volume - default is 0.7");
    snd_rate = Cvar_Get("snd_rate", "44100", CVAR_ARCHIVE, "Hz value for sound renderer - default is 44100");
    snd_chunkbufsize = Cvar_Get("snd_chunkbufsize", "1024", CVAR_ARCHIVE, "The sound buffer chunk size");
    /* set volumes to be changed so they are applied again for next sound/music playing */
    /** @todo implement the volume change for already loaded sample chunks */
    snd_volume->modified = true;

    Cmd_AddCommand("snd_play", S_Play_f, "Plays a sound fx file. Pass path relative to base/sound without file extension");
    Cmd_AddParamCompleteFunction("snd_play", S_CompleteSounds);

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

    MIX_VERSION(&version)
    Com_Printf("SDL_mixer version: %d.%d.%d\n", version.major, version.minor, version.patch);
    Com_Printf("... requested audio rate: %i\n", snd_rate->integer);

    if (Mix_OpenAudio(snd_rate->integer, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, snd_chunkbufsize->integer) == -1) {
        Com_Printf("S_Init: %s\n", Mix_GetError());
        return;
    }

    if (Mix_QuerySpec(&s_env.rate, &s_env.format, &s_env.numChannels) == 0) {
        Com_Printf("S_Init: %s\n", Mix_GetError());
        return;
    }

    if (SDL_AudioDriverName(drivername, sizeof(drivername)) == NULL)
        Q_strncpyz(drivername, "(UNKNOWN)", sizeof(drivername));
    Com_Printf("... driver: '%s'\n", drivername);

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

    Mix_ChannelFinished(S_FreeChannel);

    Com_Printf("... audio rate: %i\n", s_env.rate);
    Com_Printf("... audio channels: %i\n", s_env.numChannels);

#if COMPARE_VERSION(1, 2, 10)
    if (!(Mix_Init(MIX_INIT_OGG) & MIX_INIT_OGG))
        Com_Printf("... could not load ogg vorbis support\n");
    else
        Com_Printf("... loaded ogg vorbis support\n");
#endif

    s_env.initialized = true;

    M_Init();
    S_MumbleInit();
}