private static void QuitSDL2() { SDL_ttf.TTF_Quit(); SDL_image.IMG_Quit(); SDL_mixer.Mix_Quit(); SDL.SDL_Quit(); }
/// <summary> /// Plays a sound. Returns an instance handle that can be passed to StopSound() to stop playback of the sound. /// </summary> /// <param name="sound">The sound to play.</param> /// <param name="repeat">Whether or not the sound should repeat until stopped.</param> /// <param name="fadeTime">The amount of time (in seconds) to fade in the sound's volume.</param> public static SoundInstance PlaySound(Sound sound, bool repeat = false, float fadeTime = 0) { // Start playing the new sound: int channel = SDL_mixer.Mix_FadeInChannel(-1, sound.Handle, repeat ? -1 : 0, GetFadeTimeMs(fadeTime)); // Silently fail when we run out of channels: if (channel == -1) { return(new SoundInstance()); } // Invalidate old sound instances using this channel: foreach (var instanceAndChannel in SoundInstances) { if (instanceAndChannel.Value == channel) { SoundInstances.Remove(instanceAndChannel.Key); break; } } // Return a new sound instance for this channel: SoundInstance instance = new SoundInstance(); SoundInstances[instance] = channel; return(instance); }
internal static int initialiser_son() { if (SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, SDL_mixer.MIX_DEFAULT_CHANNELS, 1024) < 0) { Program.MessageErr("Mix_OpenAudio: ERREUR ({0})\n", SDL.SDL_GetError()); SDL.SDL_Quit(); return(1); } if (prechargerSons() > 0) { Program.MessageErr("prechargerSons: ERREUR ({0})\n", SDL.SDL_GetError()); SDL_mixer.Mix_CloseAudio(); SDL.SDL_Quit(); return(2); } if (prechargerMusiques() > 0) { Program.MessageErr("prechargerMusiques: ERREUR ({0})\n", SDL.SDL_GetError()); SDL_mixer.Mix_CloseAudio(); SDL.SDL_Quit(); return(3); } SDL_mixer.Mix_AllocateChannels(sons.Count); ArreterJouerSons(); ReglerVolumeSons(50); ReglerVolumeMusique(50); return(0); }
public void GEALOSinit() { if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0) { Console.WriteLine($"There was an issue initilizing SDL. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG | SDL_image.IMG_InitFlags.IMG_INIT_PNG | SDL_image.IMG_InitFlags.IMG_INIT_TIF | SDL_image.IMG_InitFlags.IMG_INIT_WEBP) < 0) { Console.WriteLine($"There was an issue initilizing SDL_image. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_ttf.TTF_Init() < 0) { Console.WriteLine($"There was an issue initilizing SDL_ttf. {SDL.SDL_GetError()}"); Environment.Exit(-1); } if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 4096) < 0 || SDL_mixer.Mix_Init(SDL_mixer.MIX_InitFlags.MIX_INIT_FLAC | SDL_mixer.MIX_InitFlags.MIX_INIT_MID | SDL_mixer.MIX_InitFlags.MIX_INIT_MOD | SDL_mixer.MIX_InitFlags.MIX_INIT_MP3 | SDL_mixer.MIX_InitFlags.MIX_INIT_OGG | SDL_mixer.MIX_InitFlags.MIX_INIT_OPUS) < 0) { Console.WriteLine($"There was an issue initilizing SDL_mixer. {SDL.SDL_GetError()}"); Environment.Exit(-1); } running = true; GEALOSprog(); }
public void resume() { if (SDL_mixer.Mix_PausedMusic() == 1) { SDL_mixer.Mix_ResumeMusic(); } }
private byte[] musicBytes; // Cannot be local or GC will destory it with great anger public SDL2SoundProvider() { if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024) < 0) { log.Error($"SDL_mixer could not initialize! SDL_mixer Error: {SDL.SDL_GetError()}"); } }
public void Play(int loopsCount) { if (SDL_mixer.Mix_PlayMusic(sdlMusic, loopsCount) < 0) { throw new InvalidOperationException($"Cant play music: {SDL.SDL_GetError()}"); } }
public void pause() { if (SDL_mixer.Mix_PausedMusic() != 1) { SDL_mixer.Mix_PauseMusic(); } }
private static void Close() { //Free loaded images _PromptTexture.Free(); //Free the sound effects SDL_mixer.Mix_FreeChunk(_Scratch); SDL_mixer.Mix_FreeChunk(_High); SDL_mixer.Mix_FreeChunk(_Medium); SDL_mixer.Mix_FreeChunk(_Low); _Scratch = IntPtr.Zero; _High = IntPtr.Zero; _Medium = IntPtr.Zero; _Low = IntPtr.Zero; //Free the music SDL_mixer.Mix_FreeMusic(_Music); _Music = IntPtr.Zero; //Destroy window SDL.SDL_DestroyRenderer(Renderer); SDL.SDL_DestroyWindow(_Window); _Window = IntPtr.Zero; Renderer = IntPtr.Zero; //Quit SDL subsystems SDL_mixer.Mix_Quit(); SDL_image.IMG_Quit(); SDL.SDL_Quit(); }
public void Play(int loopsCount) { if (SDL_mixer.Mix_PlayChannel(-1, chunk, loopsCount) < 0) { throw new NotImplementedException($"Cant play chunk: {SDL.SDL_GetError()}"); } }
internal Song(string fileName) { FilePath = fileName; initializeMixer(); INTERNAL_mixMusic = SDL_mixer.Mix_LoadMUS(fileName); IsDisposed = false; }
static int prechargerSons() { try { sons = new Dictionary <String, IntPtr>() { // fin de manche { "temps_ecoule", SDL_mixer.Mix_LoadWAV(@"res\sons\temps_ecoule.wav") }, // bonus { "bonus_vitesse_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\vitesse+.wav") }, { "bonus_vitesse_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\vitesse-.wav") }, { "bonus_portee_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\portee+.wav") }, { "bonus_portee_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\portee-.wav") }, { "bonus_bombe_plus", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\bombe+.wav") }, { "bonus_bombe_moins", SDL_mixer.Mix_LoadWAV(@"res\sons\bonus\bombe-.wav") }, // explosion { "explosion", SDL_mixer.Mix_LoadWAV(@"res\sons\bombes\explosion.wav") }, // boutons { "clic_bouton", SDL_mixer.Mix_LoadWAV(@"res\sons\clic_bouton.wav") } }; return(0); } catch { return(1); } }
private static void Start() { // ====================================================================================== // Initialize SDL // ====================================================================================== if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) != 0) { throw new Exception("Failed to initialize SDL."); } if (SDL_ttf.TTF_Init() != 0) { throw new Exception("Failed to initialize SDL_ttf."); } SDL_mixer.MIX_InitFlags mixInitFlags = SDL_mixer.MIX_InitFlags.MIX_INIT_MP3 | SDL_mixer.MIX_InitFlags.MIX_INIT_OGG | SDL_mixer.MIX_InitFlags.MIX_INIT_FLAC; if (((SDL_mixer.MIX_InitFlags)SDL_mixer.Mix_Init(mixInitFlags) & mixInitFlags) != mixInitFlags) { throw new Exception("Failed to initialize SDL_mixer."); } if (SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024) != 0) { throw new Exception("Failed to initialize SDL_mixer."); } SDL_mixer.Mix_AllocateChannels(AudioChannelCount); Window = SDL.SDL_CreateWindow( Game.Title, SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), (int)Game.Resolution.X, (int)Game.Resolution.Y, 0); if (Window == IntPtr.Zero) { throw new Exception("Failed to create window."); } Renderer = SDL.SDL_CreateRenderer(Window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RendererFlags.SDL_RENDERER_TARGETTEXTURE); if (Renderer == IntPtr.Zero) { throw new Exception("Failed to create renderer."); } IntPtr renderTargetHandle = SDL.SDL_CreateTexture(Renderer, SDL.SDL_PIXELFORMAT_RGBA8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, (int)Game.Resolution.X, (int)Game.Resolution.Y); RenderTarget = new Texture(renderTargetHandle, (int)Game.Resolution.X, (int)Game.Resolution.Y); // ====================================================================================== // Instantiate the game object // ====================================================================================== Game = new Game(); }
protected override void Dispose(bool disposing) { if (!chunk.Equals(IntPtr.Zero)) { SDL_mixer.Mix_FreeMusic(chunk); } chunk = IntPtr.Zero; }
private static void InitializeSdlSystems() { Console.WriteLine("---"); Console.WriteLine("Initializing SDL2 core..."); SDL2.SDL_Init(BootConfig.SdlModules.SdlInitFlags); SDL_mixer.Mix_Init(BootConfig.MixerModules.SdlMixerFlags); }
public override void play() { if (SDL_mixer.Mix_PlayChannel(-1, sound, 0) == -1) { Console.WriteLine($"There was an issue playing the sound. {SDL.SDL_GetError()}"); Environment.Exit(-1); } }
public override void StopMusic() { if (music != null) { SDL_mixer.Mix_HaltMusic(); music = null; } }
private void DisposeMusic() { if (MusicPointer.HasValue) { SDL_mixer.Mix_FreeMusic(MusicPointer.Value); MusicPointer = null; } }
public void StopSong() { if (music == IntPtr.Zero) { return; } SDL_mixer.Mix_FreeChunk(music); }
public SDL2MusicPlayer() { if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 2048) < 0) { log.Error($"SDL_mixer could not initialize! SDL_mixer Error: {SDL.SDL_GetError()}"); return; } }
public MixerSound(string wavFile) { mixerChunkPtr = SDL_mixer.Mix_LoadWAV(wavFile); if (mixerChunkPtr == IntPtr.Zero) { throw new MixerException(); } }
internal Song(string fileName) { FilePath = fileName; Name = Path.GetFileNameWithoutExtension(FilePath); initializeMixer(); INTERNAL_mixMusic = SDL_mixer.Mix_LoadMUS(fileName); IsDisposed = false; }
internal static void closeMixer() { if (initialized) { SDL_mixer.Mix_CloseAudio(); initialized = false; } }
/// <summary> /// Stops a playing sound. /// </summary> /// <param name="instance">An instance handle from a prior call to PlaySound().</param> /// <param name="fadeTime">The amount of time (in seconds) to fade out the sound's volume.</param> public static void StopSound(SoundInstance instance, float fadeTime = 0) { int channel; if (SoundInstances.TryGetValue(instance, out channel)) { SDL_mixer.Mix_FadeOutChannel(channel, GetFadeTimeMs(fadeTime)); } }
public CORE() { SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_AUDIO); win = SDL.SDL_CreateWindow("SDL2 Sharp", 50, 50, 1280, 720, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN); ren = SDL.SDL_CreateRenderer(win, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC); SDL_mixer.Mix_OpenAudio( SDL_mixer.MIX_DEFAULT_FREQUENCY, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 128); }
private static void initializeMixer() { if (!initialized) { SDL.SDL_InitSubSystem(SDL.SDL_INIT_AUDIO); SDL_mixer.Mix_OpenAudio(44100, SDL.AUDIO_S16SYS, 2, 1024); initialized = true; } }
protected void PlayChunk(int volume, int loops = 0) { SetVolume(volume); // TODO only if volume has changed ? Channel = SDL_mixer.Mix_PlayChannel(-1, AudioChunk, loops); if (Channel < 0) { Console.WriteLine($"ERROR Mix_PlayChannel: {AudioFilename}"); } }
public override void load(string path) { sound = SDL_mixer.Mix_LoadWAV(path); if (sound == IntPtr.Zero) { Console.WriteLine($"There was an issue loading the sound. {SDL.SDL_GetError()}"); Environment.Exit(-1); } }
public override void load(string path) { music = SDL_mixer.Mix_LoadMUS(path); if (music == IntPtr.Zero) { Console.WriteLine($"There was an issue loading the music. {SDL.SDL_GetError()}"); Environment.Exit(-1); } }
public void Dispose() { sceneRenderer.Dispose(); Screen.Dispose(); SDL_mixer.Mix_CloseAudio(); SDL_mixer.Mix_Quit(); SDL_ttf.TTF_Quit(); SDL_image.IMG_Quit(); SDL_Quit(); }