Renamed SoundReader to AudioLoader and WaveReader to WaveLoader.

This commit is contained in:
the_fiddler 2008-04-06 14:31:11 +00:00
parent 8722f71cb6
commit c587cc5189
4 changed files with 49 additions and 49 deletions

View file

@ -17,62 +17,62 @@ namespace OpenTK.Audio
/// Encapsulates a sound stream and provides decoding and streaming capabilities.
/// </summary>
/// <typeparam name="SampleType"></typeparam>
public class SoundReader : IDisposable
public class AudioLoader : IDisposable
{
static object reader_lock = new object();
static List<SoundReader> readers = new List<SoundReader>();
static List<AudioLoader> readers = new List<AudioLoader>();
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)
/// <summary>Creates a new SoundReader that can read the specified sound file.</summary>
/// <summary>Creates a new AudioLoader that can read the specified sound file.</summary>
/// <param name="filename">The path to the sound file.</param>
/// <returns>A new OpenTK.Audio.SoundReader, which can be used to read from the specified sound file.</returns>
public SoundReader(string filename)
/// <returns>A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound file.</returns>
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)
/// <summary>Creates a new SoundReader that can read the specified soundstream.</summary>
/// <summary>Creates a new AudioLoader that can read the specified soundstream.</summary>
/// <param name="s">The System.IO.Stream to read from.</param>
/// <returns>A new OpenTK.Audio.SoundReader, which can be used to read from the specified sound stream.</returns>
public SoundReader(Stream s)
/// <returns>A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound stream.</returns>
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
/// <summary>Closes the underlying Stream and disposes of the SoundReader resources.</summary>
/// <summary>Closes the underlying Stream and disposes of the AudioLoader resources.</summary>
public virtual void Dispose()
{
this.Dispose(true);
@ -217,7 +217,7 @@ namespace OpenTK.Audio
}
}
~SoundReader()
~AudioLoader()
{
this.Dispose(false);
}

View file

@ -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
{
/// <summary>Represents exceptions related to OpenTK.Audio.AudioLoader objects.</summary>
public class AudioLoaderException : AudioException
{
/// <summary>Constructs a new AudioLoaderException.</summary>
public AudioLoaderException() : base() { }
/// <summary>Constructs a new AudioLoaderException with the specified error message.</summary>
/// <param name="message">The error message of the AudioLoaderException.</param>
public AudioLoaderException(string message) : base(message) { }
}
}

View file

@ -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
{
/// <summary>Represents exceptions related to OpenTK.Audio.SoundReader objects.</summary>
public class SoundReaderException : AudioException
{
/// <summary>Constructs a new SoundReaderException.</summary>
public SoundReaderException() : base() { }
/// <summary>Constructs a new SoundReaderException with the specified error message.</summary>
/// <param name="message">The error message of the SoundReaderException.</param>
public SoundReaderException(string message) : base(message) { }
}
}

View file

@ -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()));