Fixed SoundReader prermissions.

Fixed a problem with SoundReader.EndOfFile.
Removed a Dispose() call i Playback.cs (was not necessecary).
Streaming code updates.
This commit is contained in:
the_fiddler 2008-04-04 22:14:42 +00:00
parent 98ded8fd9e
commit 2fa1330f3b
4 changed files with 33 additions and 19 deletions

View file

@ -50,8 +50,6 @@ namespace Examples
AL.SourceStop(source); AL.SourceStop(source);
AL.DeleteSource(source); AL.DeleteSource(source);
AL.DeleteBuffer(buffer); AL.DeleteBuffer(buffer);
sound.Dispose();
} }
} }
} }

View file

@ -19,7 +19,7 @@ namespace Examples.OpenAL
public class StreamingPlayback public class StreamingPlayback
{ {
const string filename = "Data\\Audio\\the_ring_that_fell.wav"; const string filename = "Data\\Audio\\the_ring_that_fell.wav";
const int buffer_size = 8096; const int buffer_size = 18096;
static object openal_lock = new object(); static object openal_lock = new object();
@ -39,12 +39,16 @@ namespace Examples.OpenAL
SoundStreamer streamer = new SoundStreamer(sound, source, buffers); SoundStreamer streamer = new SoundStreamer(sound, source, buffers);
streamer.Start(); streamer.Start();
lock (openal_lock)
{
AL.SourcePlay(source);
}
// Query the source to find out when it stops playing. // Query the source to find out when it stops playing.
do do
{ {
Thread.Sleep(100); //Thread.Sleep(100);
Console.Write("."); //Console.Write(".");
lock (openal_lock) lock (openal_lock)
{ {
AL.GetSource(source, ALGetSourcei.SourceState, out state); AL.GetSource(source, ALGetSourcei.SourceState, out state);
@ -52,13 +56,15 @@ namespace Examples.OpenAL
} }
while ((ALSourceState)state == ALSourceState.Playing); while ((ALSourceState)state == ALSourceState.Playing);
Console.WriteLine(); Console.WriteLine("asd");
AL.SourceStop(source); lock (openal_lock)
AL.DeleteSource(source); {
AL.DeleteBuffers(buffers); AL.SourceStop(source);
AL.DeleteSource(source);
AL.DeleteBuffers(buffers);
}
sound.Dispose();
} }
} }
@ -67,6 +73,7 @@ namespace Examples.OpenAL
SoundReader reader; SoundReader reader;
int source; int source;
int[] buffers; int[] buffers;
Thread thread;
public SoundStreamer(SoundReader sound, int source, int[] buffers) public SoundStreamer(SoundReader sound, int source, int[] buffers)
{ {
@ -85,7 +92,8 @@ namespace Examples.OpenAL
public void Start() public void Start()
{ {
new Thread(new ThreadStart(StartStreaming)).Start(); thread = new Thread(new ThreadStart(StartStreaming));
thread.Start();
} }
void StartStreaming() void StartStreaming()
@ -106,6 +114,7 @@ namespace Examples.OpenAL
Thread.Sleep(5); Thread.Sleep(5);
} }
Console.WriteLine("booh");
} }
} }
} }

View file

@ -50,7 +50,7 @@ namespace OpenTK.Audio
/// <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.SoundReader, which can be used to read from the specified sound file.</returns>
public SoundReader(string filename) public SoundReader(string filename)
: this(new FileStream(filename, FileMode.Open)) : this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{ } { }
#endregion #endregion
@ -170,13 +170,18 @@ namespace OpenTK.Audio
#endregion #endregion
#region public bool EndOfFile #region public virtual bool EndOfFile
public bool EndOfFile public virtual bool EndOfFile
{ {
get { return stream.Position >= stream.Length; } get
} {
if (implementation != null)
return implementation.EndOfFile;
return this.Stream.Position >= this.Stream.Length;
}
}
#endregion #endregion
#endregion #endregion

View file

@ -44,9 +44,11 @@ namespace OpenTK.Audio
internal WaveReader(Stream s) internal WaveReader(Stream s)
{ {
if (s == null) throw new ArgumentNullException();
if (!s.CanRead) throw new ArgumentException("Cannot read from specified Stream.");
reader = new BinaryReader(s); reader = new BinaryReader(s);
if (!ReadHeaders(reader)) this.Stream = s;
throw new NotSupportedException("The specified stream is not supported by this decoder.");
} }
#if false #if false
@ -163,7 +165,7 @@ namespace OpenTK.Audio
decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate), decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
reader.ReadBytes((int)samples)); reader.ReadBytes((int)samples));
throw new NotImplementedException(); return decoded_data;
} }
#endregion #endregion