Exemple #1
0
        public void FreeChunk()
        {
            InitAudio();
            IntPtr wavPtr = Sdl.SDL_RWFromFile("test.wav", "rb");

            SdlMixer.Mix_FreeChunk(wavPtr);
            QuitAudio();
        }
Exemple #2
0
 private void Dispose(bool disposing)
 {
     SdlMixer.Mix_FreeChunk(sound);
     //if (string.IsNullOrEmpty(tempfile) == false)
     //{
     //    File.Delete(tempfile);
     //    tempfile = "";
     //}
 }
Exemple #3
0
 /// <summary>
 /// Triggers when a channel is finished.
 /// </summary>
 /// <param name="channel"></param>
 private void OnChannelEnded(int channel)
 {
     try
     {
         SdlMixer.Mix_FreeChunk(soundChunks[channel]);
     }
     catch
     {
         Console.WriteLine("Cannot free sound chunk");
     }
 }
Exemple #4
0
        /// <summary>
        /// Triggers a sound to be played.
        /// </summary>
        /// <param name="key"></param>
        private void PlaySound(string key)
        {
            // See if we have the category
            if (!categories.Contains(key))
            {
                // No music, no effect
                Debug("No sounds for {0}", key);
                return;
            }

            // If the category is empty, remove it
            if (categories[key].Count == 0)
            {
                // Remove the category and return
                categories.Remove(key);
                return;
            }

            // Get the random song key
            FileInfo file  = categories[key].GetRandomSound();
            string   sound = file.FullName;

            Debug("Playing sound: {0}", sound);
            IntPtr soundChunk = SdlMixer.Mix_LoadWAV(sound);

            // Start playing the music
            int result = -1;

            try
            {
                result = SdlMixer.Mix_PlayChannel(soundIndex, soundChunk, 0);
            }
            catch (Exception e)
            {
                Error("Can't play sound: {0}", e.Message);
            }

            if (result == -1)
            {
                // Remove the chunk
                SdlMixer.Mix_FreeChunk(soundChunk);
                categories[key].Remove(file);

                // Find a new one
                PlaySound(key);
            }

            // Save the chunk
            soundChunks[soundIndex] = soundChunk;
            soundIndex = (soundIndex + 1) % MaximumSoundsChunks;
        }
Exemple #5
0
 /// <summary>
 /// Closes sound handle
 /// </summary>
 protected override void CloseHandle()
 {
     try
     {
         if (this.Handle != IntPtr.Zero)
         {
             SdlMixer.Mix_FreeChunk(this.Handle);
             this.Handle = IntPtr.Zero;
         }
     }
     catch (NullReferenceException)
     {
     }
     catch (AccessViolationException)
     {
     }
     finally
     {
         this.Handle = IntPtr.Zero;
     }
 }
Exemple #6
0
 /// <summary>
 /// Unload the sound and free the resources used.
 /// </summary>
 public void Unload()
 {
     SdlMixer.Mix_FreeChunk(chunk);
 }
Exemple #7
0
 ///< Frees the memory used by SdlMixer.
 public void unload() //not being called yet
 {
     SdlMixer.Mix_FreeChunk(handle);
 }