mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-02 19:51:10 +00:00
Moved streaming code to StreamingPlayback.cs.
This commit is contained in:
parent
01106c7a0e
commit
6ab0b92ea3
|
@ -48,8 +48,8 @@ namespace Examples
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
AL.SourceStop(source);
|
AL.SourceStop(source);
|
||||||
AL.DeleteSources(ref source);
|
AL.DeleteSource(source);
|
||||||
AL.DeleteBuffers(ref buffer);
|
AL.DeleteBuffer(buffer);
|
||||||
|
|
||||||
sound.Dispose();
|
sound.Dispose();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,8 @@ namespace Examples.OpenAL
|
||||||
|
|
||||||
Console.Write("Playing");
|
Console.Write("Playing");
|
||||||
|
|
||||||
//new Thread().Start(buffers
|
SoundStreamer streamer = new SoundStreamer(sound, source, buffers);
|
||||||
|
streamer.Start();
|
||||||
|
|
||||||
|
|
||||||
// Query the source to find out when it stops playing.
|
// Query the source to find out when it stops playing.
|
||||||
do
|
do
|
||||||
|
@ -50,12 +49,13 @@ namespace Examples.OpenAL
|
||||||
{
|
{
|
||||||
AL.GetSource(source, ALGetSourcei.SourceState, out state);
|
AL.GetSource(source, ALGetSourcei.SourceState, out state);
|
||||||
}
|
}
|
||||||
} while ((ALSourceState)state == ALSourceState.Playing);
|
}
|
||||||
|
while ((ALSourceState)state == ALSourceState.Playing);
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
AL.SourceStop(source);
|
AL.SourceStop(source);
|
||||||
AL.DeleteSources(ref source);
|
AL.DeleteSource(source);
|
||||||
AL.DeleteBuffers(buffers);
|
AL.DeleteBuffers(buffers);
|
||||||
|
|
||||||
sound.Dispose();
|
sound.Dispose();
|
||||||
|
@ -64,9 +64,33 @@ namespace Examples.OpenAL
|
||||||
|
|
||||||
class SoundStreamer
|
class SoundStreamer
|
||||||
{
|
{
|
||||||
|
SoundReader reader;
|
||||||
|
int source;
|
||||||
|
int[] buffers;
|
||||||
|
|
||||||
public SoundStreamer(SoundReader sound, int source, int[] buffers)
|
public SoundStreamer(SoundReader sound, int source, int[] buffers)
|
||||||
{
|
{
|
||||||
while (!sound.EndOfFile)
|
reader = sound;
|
||||||
|
this.source = source;
|
||||||
|
this.buffers = buffers;
|
||||||
|
|
||||||
|
lock (openal_lock)
|
||||||
|
{
|
||||||
|
foreach (int buffer in buffers)
|
||||||
|
AL.BufferData(buffer, sound.ReadSamples(buffer_size));
|
||||||
|
|
||||||
|
AL.SourceQueueBuffers(source, buffers.Length, buffers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
new Thread(new ThreadStart(StartStreaming)).Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartStreaming()
|
||||||
|
{
|
||||||
|
while (!reader.EndOfFile)
|
||||||
{
|
{
|
||||||
lock (openal_lock)
|
lock (openal_lock)
|
||||||
{
|
{
|
||||||
|
@ -75,10 +99,12 @@ namespace Examples.OpenAL
|
||||||
while (processed_count-- > 0)
|
while (processed_count-- > 0)
|
||||||
{
|
{
|
||||||
int buffer = AL.SourceUnqueueBuffer(source);
|
int buffer = AL.SourceUnqueueBuffer(source);
|
||||||
AL.BufferData(buffer, sound.ReadSamples(buffer_size));
|
AL.BufferData(buffer, reader.ReadSamples(buffer_size));
|
||||||
AL.SourceQueueBuffer(source, buffer);
|
AL.SourceQueueBuffer(source, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue