Пример #1
0
 private static void QuitSDL2()
 {
     SDL_ttf.TTF_Quit();
     SDL_image.IMG_Quit();
     SDL_mixer.Mix_Quit();
     SDL.SDL_Quit();
 }
Пример #2
0
    /// <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);
    }
Пример #3
0
        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);
        }
Пример #4
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();
        }
Пример #5
0
 public void resume()
 {
     if (SDL_mixer.Mix_PausedMusic() == 1)
     {
         SDL_mixer.Mix_ResumeMusic();
     }
 }
Пример #6
0
        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()}");
            }
        }
Пример #7
0
 public void Play(int loopsCount)
 {
     if (SDL_mixer.Mix_PlayMusic(sdlMusic, loopsCount) < 0)
     {
         throw new InvalidOperationException($"Cant play music: {SDL.SDL_GetError()}");
     }
 }
Пример #8
0
 public void pause()
 {
     if (SDL_mixer.Mix_PausedMusic() != 1)
     {
         SDL_mixer.Mix_PauseMusic();
     }
 }
Пример #9
0
        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();
        }
Пример #10
0
 public void Play(int loopsCount)
 {
     if (SDL_mixer.Mix_PlayChannel(-1, chunk, loopsCount) < 0)
     {
         throw new NotImplementedException($"Cant play chunk: {SDL.SDL_GetError()}");
     }
 }
Пример #11
0
 internal Song(string fileName)
 {
     FilePath = fileName;
     initializeMixer();
     INTERNAL_mixMusic = SDL_mixer.Mix_LoadMUS(fileName);
     IsDisposed        = false;
 }
Пример #12
0
 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);
     }
 }
Пример #13
0
    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();
    }
Пример #14
0
 protected override void Dispose(bool disposing)
 {
     if (!chunk.Equals(IntPtr.Zero))
     {
         SDL_mixer.Mix_FreeMusic(chunk);
     }
     chunk = IntPtr.Zero;
 }
Пример #15
0
        private static void InitializeSdlSystems()
        {
            Console.WriteLine("---");
            Console.WriteLine("Initializing SDL2 core...");

            SDL2.SDL_Init(BootConfig.SdlModules.SdlInitFlags);
            SDL_mixer.Mix_Init(BootConfig.MixerModules.SdlMixerFlags);
        }
Пример #16
0
 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);
     }
 }
Пример #17
0
 public override void StopMusic()
 {
     if (music != null)
     {
         SDL_mixer.Mix_HaltMusic();
         music = null;
     }
 }
Пример #18
0
 private void DisposeMusic()
 {
     if (MusicPointer.HasValue)
     {
         SDL_mixer.Mix_FreeMusic(MusicPointer.Value);
         MusicPointer = null;
     }
 }
Пример #19
0
 public void StopSong()
 {
     if (music == IntPtr.Zero)
     {
         return;
     }
     SDL_mixer.Mix_FreeChunk(music);
 }
Пример #20
0
 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;
     }
 }
Пример #21
0
 public MixerSound(string wavFile)
 {
     mixerChunkPtr = SDL_mixer.Mix_LoadWAV(wavFile);
     if (mixerChunkPtr == IntPtr.Zero)
     {
         throw new MixerException();
     }
 }
Пример #22
0
 internal Song(string fileName)
 {
     FilePath = fileName;
     Name     = Path.GetFileNameWithoutExtension(FilePath);
     initializeMixer();
     INTERNAL_mixMusic = SDL_mixer.Mix_LoadMUS(fileName);
     IsDisposed        = false;
 }
Пример #23
0
 internal static void closeMixer()
 {
     if (initialized)
     {
         SDL_mixer.Mix_CloseAudio();
         initialized = false;
     }
 }
Пример #24
0
    /// <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));
        }
    }
Пример #25
0
        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);
        }
Пример #26
0
 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;
     }
 }
Пример #27
0
 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}");
     }
 }
Пример #28
0
        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);
            }
        }
Пример #29
0
        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);
            }
        }
Пример #30
0
 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();
 }