diff --git a/Source/Utilities/Audio/SoundReader.cs b/Source/Utilities/Audio/AudioLoader.cs similarity index 83% rename from Source/Utilities/Audio/SoundReader.cs rename to Source/Utilities/Audio/AudioLoader.cs index d62e4269..09baf18b 100644 --- a/Source/Utilities/Audio/SoundReader.cs +++ b/Source/Utilities/Audio/AudioLoader.cs @@ -17,62 +17,62 @@ namespace OpenTK.Audio /// Encapsulates a sound stream and provides decoding and streaming capabilities. /// /// - public class SoundReader : IDisposable + public class AudioLoader : IDisposable { static object reader_lock = new object(); - static List readers = new List(); + static List readers = new List(); bool disposed; Stream stream; - SoundReader implementation; + AudioLoader implementation; #region --- Constructors --- - #region static SoundReader() + #region static AudioLoader() - static SoundReader() + static AudioLoader() { // TODO: Plugin architecture for sound formats. This is overkill now that we only have a WaveLoader (future proofing). - readers.Add(new WaveReader()); + readers.Add(new WaveLoader()); } #endregion - #region protected SoundReader() + #region protected AudioLoader() - protected SoundReader() { } + protected AudioLoader() { } #endregion - #region public SoundReader(string filename) + #region public AudioLoader(string filename) - /// Creates a new SoundReader that can read the specified sound file. + /// Creates a new AudioLoader that can read the specified sound file. /// The path to the sound file. - /// A new OpenTK.Audio.SoundReader, which can be used to read from the specified sound file. - public SoundReader(string filename) + /// A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound file. + public AudioLoader(string filename) : this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { } #endregion - #region public SoundReader(Stream s) + #region public AudioLoader(Stream s) - /// Creates a new SoundReader that can read the specified soundstream. + /// Creates a new AudioLoader that can read the specified soundstream. /// The System.IO.Stream to read from. - /// A new OpenTK.Audio.SoundReader, which can be used to read from the specified sound stream. - public SoundReader(Stream s) + /// A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound stream. + public AudioLoader(Stream s) { try { lock (reader_lock) { - foreach (SoundReader reader in readers) + foreach (AudioLoader reader in readers) { long pos = s.Position; if (reader.Supports(s)) { s.Position = pos; - implementation = (SoundReader) + implementation = (AudioLoader) reader.GetType().GetConstructor( System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, @@ -198,7 +198,7 @@ namespace OpenTK.Audio #region IDisposable Members - /// Closes the underlying Stream and disposes of the SoundReader resources. + /// Closes the underlying Stream and disposes of the AudioLoader resources. public virtual void Dispose() { this.Dispose(true); @@ -217,7 +217,7 @@ namespace OpenTK.Audio } } - ~SoundReader() + ~AudioLoader() { this.Dispose(false); } diff --git a/Source/Utilities/Audio/AudioLoaderException.cs b/Source/Utilities/Audio/AudioLoaderException.cs new file mode 100644 index 00000000..80b769cf --- /dev/null +++ b/Source/Utilities/Audio/AudioLoaderException.cs @@ -0,0 +1,24 @@ +#region --- License --- +/* Licensed under the MIT/X11 license. + * Copyright (c) 2006-2008 the OpenTK Team. + * This notice may not be removed from any source distribution. + * See license.txt for licensing details. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK.Audio +{ + /// Represents exceptions related to OpenTK.Audio.AudioLoader objects. + public class AudioLoaderException : AudioException + { + /// Constructs a new AudioLoaderException. + public AudioLoaderException() : base() { } + /// Constructs a new AudioLoaderException with the specified error message. + /// The error message of the AudioLoaderException. + public AudioLoaderException(string message) : base(message) { } + } +} diff --git a/Source/Utilities/Audio/SoundReaderException.cs b/Source/Utilities/Audio/SoundReaderException.cs deleted file mode 100644 index 1d2c35ac..00000000 --- a/Source/Utilities/Audio/SoundReaderException.cs +++ /dev/null @@ -1,24 +0,0 @@ -#region --- License --- -/* Licensed under the MIT/X11 license. - * Copyright (c) 2006-2008 the OpenTK Team. - * This notice may not be removed from any source distribution. - * See license.txt for licensing details. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenTK.Audio -{ - /// Represents exceptions related to OpenTK.Audio.SoundReader objects. - public class SoundReaderException : AudioException - { - /// Constructs a new SoundReaderException. - public SoundReaderException() : base() { } - /// Constructs a new SoundReaderException with the specified error message. - /// The error message of the SoundReaderException. - public SoundReaderException(string message) : base(message) { } - } -} diff --git a/Source/Utilities/Audio/WaveReader.cs b/Source/Utilities/Audio/WaveLoader.cs similarity index 94% rename from Source/Utilities/Audio/WaveReader.cs rename to Source/Utilities/Audio/WaveLoader.cs index 3ac04ce0..800a48dc 100644 --- a/Source/Utilities/Audio/WaveReader.cs +++ b/Source/Utilities/Audio/WaveLoader.cs @@ -15,7 +15,7 @@ using System.Runtime.InteropServices; namespace OpenTK.Audio { - internal sealed class WaveReader : SoundReader + internal sealed class WaveLoader : AudioLoader { SoundData decoded_data; @@ -40,9 +40,9 @@ namespace OpenTK.Audio BinaryReader reader; - internal WaveReader() { } + internal WaveLoader() { } - internal WaveReader(Stream s) + internal WaveLoader(Stream s) { if (s == null) throw new ArgumentNullException(); if (!s.CanRead) throw new ArgumentException("Cannot read from specified Stream."); @@ -191,7 +191,7 @@ namespace OpenTK.Audio //return new SoundData(decoded_data, new SoundFormat(channels, bits_per_sample, sample_rate)); return decoded_data; } - catch (SoundReaderException e) + catch (AudioLoaderException e) { reader.Close(); throw; @@ -211,7 +211,7 @@ namespace OpenTK.Audio { base.Stream = value; if (!ReadHeaders(reader)) - throw new SoundReaderException("Invalid WAVE/RIFF file: invalid or corrupt signature."); + throw new AudioLoaderException("Invalid WAVE/RIFF file: invalid or corrupt signature."); Debug.Write(String.Format("Opened WAVE/RIFF file: ({0}, {1}, {2}, {3}) ", sample_rate.ToString(), bits_per_sample.ToString(), channels.ToString(), audio_format.ToString()));