mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-29 21:07:01 +00:00
Renamed SoundReader to AudioLoader and WaveReader to WaveLoader.
This commit is contained in:
parent
8722f71cb6
commit
c587cc5189
|
@ -17,62 +17,62 @@ namespace OpenTK.Audio
|
||||||
/// Encapsulates a sound stream and provides decoding and streaming capabilities.
|
/// Encapsulates a sound stream and provides decoding and streaming capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="SampleType"></typeparam>
|
/// <typeparam name="SampleType"></typeparam>
|
||||||
public class SoundReader : IDisposable
|
public class AudioLoader : IDisposable
|
||||||
{
|
{
|
||||||
static object reader_lock = new object();
|
static object reader_lock = new object();
|
||||||
static List<SoundReader> readers = new List<SoundReader>();
|
static List<AudioLoader> readers = new List<AudioLoader>();
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
Stream stream;
|
Stream stream;
|
||||||
SoundReader implementation;
|
AudioLoader implementation;
|
||||||
|
|
||||||
#region --- Constructors ---
|
#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).
|
// 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
|
#endregion
|
||||||
|
|
||||||
#region protected SoundReader()
|
#region protected AudioLoader()
|
||||||
|
|
||||||
protected SoundReader() { }
|
protected AudioLoader() { }
|
||||||
|
|
||||||
#endregion
|
#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>
|
/// <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>
|
/// <returns>A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound file.</returns>
|
||||||
public SoundReader(string filename)
|
public AudioLoader(string filename)
|
||||||
: this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
: this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
#endregion
|
#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>
|
/// <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>
|
/// <returns>A new OpenTK.Audio.AudioLoader, which can be used to read from the specified sound stream.</returns>
|
||||||
public SoundReader(Stream s)
|
public AudioLoader(Stream s)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lock (reader_lock)
|
lock (reader_lock)
|
||||||
{
|
{
|
||||||
foreach (SoundReader reader in readers)
|
foreach (AudioLoader reader in readers)
|
||||||
{
|
{
|
||||||
long pos = s.Position;
|
long pos = s.Position;
|
||||||
if (reader.Supports(s))
|
if (reader.Supports(s))
|
||||||
{
|
{
|
||||||
s.Position = pos;
|
s.Position = pos;
|
||||||
implementation = (SoundReader)
|
implementation = (AudioLoader)
|
||||||
reader.GetType().GetConstructor(
|
reader.GetType().GetConstructor(
|
||||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public |
|
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public |
|
||||||
System.Reflection.BindingFlags.Instance,
|
System.Reflection.BindingFlags.Instance,
|
||||||
|
@ -198,7 +198,7 @@ namespace OpenTK.Audio
|
||||||
|
|
||||||
#region IDisposable Members
|
#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()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
this.Dispose(true);
|
this.Dispose(true);
|
||||||
|
@ -217,7 +217,7 @@ namespace OpenTK.Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SoundReader()
|
~AudioLoader()
|
||||||
{
|
{
|
||||||
this.Dispose(false);
|
this.Dispose(false);
|
||||||
}
|
}
|
24
Source/Utilities/Audio/AudioLoaderException.cs
Normal file
24
Source/Utilities/Audio/AudioLoaderException.cs
Normal 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) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -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) { }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenTK.Audio
|
namespace OpenTK.Audio
|
||||||
{
|
{
|
||||||
internal sealed class WaveReader : SoundReader
|
internal sealed class WaveLoader : AudioLoader
|
||||||
{
|
{
|
||||||
SoundData decoded_data;
|
SoundData decoded_data;
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ namespace OpenTK.Audio
|
||||||
|
|
||||||
BinaryReader reader;
|
BinaryReader reader;
|
||||||
|
|
||||||
internal WaveReader() { }
|
internal WaveLoader() { }
|
||||||
|
|
||||||
internal WaveReader(Stream s)
|
internal WaveLoader(Stream s)
|
||||||
{
|
{
|
||||||
if (s == null) throw new ArgumentNullException();
|
if (s == null) throw new ArgumentNullException();
|
||||||
if (!s.CanRead) throw new ArgumentException("Cannot read from specified Stream.");
|
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 new SoundData(decoded_data, new SoundFormat(channels, bits_per_sample, sample_rate));
|
||||||
return decoded_data;
|
return decoded_data;
|
||||||
}
|
}
|
||||||
catch (SoundReaderException e)
|
catch (AudioLoaderException e)
|
||||||
{
|
{
|
||||||
reader.Close();
|
reader.Close();
|
||||||
throw;
|
throw;
|
||||||
|
@ -211,7 +211,7 @@ namespace OpenTK.Audio
|
||||||
{
|
{
|
||||||
base.Stream = value;
|
base.Stream = value;
|
||||||
if (!ReadHeaders(reader))
|
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(),
|
Debug.Write(String.Format("Opened WAVE/RIFF file: ({0}, {1}, {2}, {3}) ", sample_rate.ToString(), bits_per_sample.ToString(),
|
||||||
channels.ToString(), audio_format.ToString()));
|
channels.ToString(), audio_format.ToString()));
|
Loading…
Reference in a new issue