disable threaded upate for theora streaming sound
parent
93fe59fb15
commit
7014400d12
|
@ -27,7 +27,7 @@ namespace MoonWorks.Audio
|
|||
}
|
||||
|
||||
private readonly HashSet<WeakReference> resources = new HashSet<WeakReference>();
|
||||
private readonly HashSet<WeakReference> streamingSoundReferences = new HashSet<WeakReference>();
|
||||
private readonly HashSet<WeakReference> autoUpdateStreamingSoundReferences = new HashSet<WeakReference>();
|
||||
|
||||
private AudioTweenManager AudioTweenManager;
|
||||
|
||||
|
@ -150,16 +150,15 @@ namespace MoonWorks.Audio
|
|||
previousTickTime = TickStopwatch.Elapsed.Ticks;
|
||||
float elapsedSeconds = (float) tickDelta / System.TimeSpan.TicksPerSecond;
|
||||
|
||||
foreach (var weakReference in streamingSoundReferences)
|
||||
foreach (var weakReference in autoUpdateStreamingSoundReferences)
|
||||
{
|
||||
var target = weakReference.Target;
|
||||
if (target == null)
|
||||
if (weakReference.Target is StreamingSound streamingSound)
|
||||
{
|
||||
streamingSoundReferences.Remove(weakReference);
|
||||
streamingSound.Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
(target as StreamingSound).Update();
|
||||
autoUpdateStreamingSoundReferences.Remove(weakReference);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +170,6 @@ namespace MoonWorks.Audio
|
|||
FAudio.FAudio_CommitChanges(Handle, 1);
|
||||
}
|
||||
|
||||
|
||||
internal void CreateTween(
|
||||
SoundInstance soundInstance,
|
||||
AudioTweenProperty property,
|
||||
|
@ -206,9 +204,9 @@ namespace MoonWorks.Audio
|
|||
{
|
||||
resources.Add(resource.weakReference);
|
||||
|
||||
if (resource is StreamingSound streamingSound)
|
||||
if (resource is StreamingSound streamingSound && streamingSound.AutoUpdate)
|
||||
{
|
||||
AddDynamicSoundInstance(streamingSound);
|
||||
AddAutoUpdateStreamingSoundInstance(streamingSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,21 +217,21 @@ namespace MoonWorks.Audio
|
|||
{
|
||||
resources.Remove(resource.weakReference);
|
||||
|
||||
if (resource is StreamingSound streamingSound)
|
||||
if (resource is StreamingSound streamingSound && streamingSound.AutoUpdate)
|
||||
{
|
||||
RemoveDynamicSoundInstance(streamingSound);
|
||||
RemoveAutoUpdateStreamingSoundInstance(streamingSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddDynamicSoundInstance(StreamingSound instance)
|
||||
private void AddAutoUpdateStreamingSoundInstance(StreamingSound instance)
|
||||
{
|
||||
streamingSoundReferences.Add(instance.weakReference);
|
||||
autoUpdateStreamingSoundReferences.Add(instance.weakReference);
|
||||
}
|
||||
|
||||
private void RemoveDynamicSoundInstance(StreamingSound instance)
|
||||
private void RemoveAutoUpdateStreamingSoundInstance(StreamingSound instance)
|
||||
{
|
||||
streamingSoundReferences.Remove(instance.weakReference);
|
||||
autoUpdateStreamingSoundReferences.Remove(instance.weakReference);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace MoonWorks.Audio
|
|||
|
||||
if (audioTween.Time >= audioTween.DelayTime)
|
||||
{
|
||||
// set the tween start value to the current value of the property
|
||||
switch (audioTween.Property)
|
||||
{
|
||||
case AudioTweenProperty.Pan:
|
||||
|
@ -104,6 +105,7 @@ namespace MoonWorks.Audio
|
|||
private void AddTween(
|
||||
AudioTween audioTween
|
||||
) {
|
||||
// if a tween with the same sound and property already exists, get rid of it
|
||||
if (AudioTweens.TryGetValue((audioTween.SoundInstanceReference, audioTween.Property), out var currentTween))
|
||||
{
|
||||
AudioTweenPool.Free(currentTween);
|
||||
|
|
|
@ -13,6 +13,9 @@ namespace MoonWorks.Audio
|
|||
// How big should each buffer we consume be?
|
||||
protected abstract int BUFFER_SIZE { get; }
|
||||
|
||||
// Should the AudioDevice thread automatically update this class?
|
||||
public abstract bool AutoUpdate { get; }
|
||||
|
||||
// Are we actively consuming buffers?
|
||||
protected bool ConsumingBuffers = false;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace MoonWorks.Audio
|
|||
private FAudio.stb_vorbis_info Info;
|
||||
|
||||
protected override int BUFFER_SIZE => 32768;
|
||||
public override bool AutoUpdate => true;
|
||||
|
||||
public unsafe static StreamingSoundOgg Load(AudioDevice device, string filePath)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace MoonWorks.Video
|
|||
{
|
||||
private IntPtr VideoHandle;
|
||||
protected override int BUFFER_SIZE => 8192;
|
||||
// Theorafile is not thread safe, so let's update on the main thread.
|
||||
public override bool AutoUpdate => false;
|
||||
|
||||
internal StreamingSoundTheora(
|
||||
AudioDevice device,
|
||||
|
|
|
@ -124,12 +124,9 @@ namespace MoonWorks.Video
|
|||
|
||||
Video = video;
|
||||
|
||||
lock (AudioDevice.StateLock)
|
||||
{
|
||||
InitializeTheoraStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
|
@ -184,12 +181,9 @@ namespace MoonWorks.Video
|
|||
lastTimestamp = 0;
|
||||
timeElapsed = 0;
|
||||
|
||||
lock (AudioDevice.StateLock)
|
||||
{
|
||||
DestroyAudioStream();
|
||||
|
||||
Theorafile.tf_reset(Video.Handle);
|
||||
}
|
||||
|
||||
State = VideoState.Stopped;
|
||||
}
|
||||
|
@ -200,6 +194,16 @@ namespace MoonWorks.Video
|
|||
Video = null;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Video == null) { return; }
|
||||
|
||||
if (audioStream != null)
|
||||
{
|
||||
audioStream.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
if (Video == null || State == VideoState.Stopped)
|
||||
|
@ -207,9 +211,6 @@ namespace MoonWorks.Video
|
|||
return;
|
||||
}
|
||||
|
||||
// Theorafile is not thread safe so we have to do this. Fun!
|
||||
lock (AudioDevice.StateLock)
|
||||
{
|
||||
timeElapsed += (timer.Elapsed.TotalMilliseconds - lastTimestamp) * PlaybackSpeed;
|
||||
lastTimestamp = timer.Elapsed.TotalMilliseconds;
|
||||
|
||||
|
@ -251,7 +252,6 @@ namespace MoonWorks.Video
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRenderTexture()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue