From a95d0ba3b1c739b22bcff0ce4d1ac212957cd783 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 6 Aug 2018 02:32:32 +1000 Subject: [PATCH] fix vorbis decoding issues when multiple instances are run on different threads --- ClassicalSharp/Audio/AudioPlayer.Sounds.cs | 5 --- SharpWave/csvorbis/Block.cs | 4 +- SharpWave/csvorbis/CodeBook.cs | 2 +- SharpWave/csvorbis/DspState.cs | 9 ++-- SharpWave/csvorbis/FuncFloor.cs | 10 ++--- SharpWave/csvorbis/FuncMapping.cs | 6 +-- SharpWave/csvorbis/FuncResidue.cs | 13 +++--- SharpWave/csvorbis/Info.cs | 52 ++++++++++------------ 8 files changed, 45 insertions(+), 56 deletions(-) diff --git a/ClassicalSharp/Audio/AudioPlayer.Sounds.cs b/ClassicalSharp/Audio/AudioPlayer.Sounds.cs index 0b0eeaf70..d6194a13b 100644 --- a/ClassicalSharp/Audio/AudioPlayer.Sounds.cs +++ b/ClassicalSharp/Audio/AudioPlayer.Sounds.cs @@ -69,7 +69,6 @@ namespace ClassicalSharp.Audio { } } - IAudioOutput firstSoundOut; void PlayCurrentSound(IAudioOutput[] outputs, float volume) { for (int i = 0; i < monoOutputs.Length; i++) { IAudioOutput output = outputs[i]; @@ -116,10 +115,6 @@ namespace ClassicalSharp.Audio { void DisposeSound() { DisposeOutputs(ref monoOutputs); DisposeOutputs(ref stereoOutputs); - if (firstSoundOut != null) { - firstSoundOut.Dispose(); - firstSoundOut = null; - } } void DisposeOutputs(ref IAudioOutput[] outputs) { diff --git a/SharpWave/csvorbis/Block.cs b/SharpWave/csvorbis/Block.cs index db6f0ee1b..9cf19c6fb 100644 --- a/SharpWave/csvorbis/Block.cs +++ b/SharpWave/csvorbis/Block.cs @@ -83,8 +83,8 @@ namespace csvorbis } // unpack_header enforces range checking - int type = vi.map_type[vi.mode_param[mode].mapping]; - return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode])); + FuncMapping mapping = vi.map_funcs[vi.mode_param[mode].mapping]; + return mapping.inverse(this, vd.mode[mode]); } } } diff --git a/SharpWave/csvorbis/CodeBook.cs b/SharpWave/csvorbis/CodeBook.cs index 7917753d1..ad1a4c919 100644 --- a/SharpWave/csvorbis/CodeBook.cs +++ b/SharpWave/csvorbis/CodeBook.cs @@ -237,7 +237,7 @@ namespace csvorbis // given a list of word lengths, generate a list of codewords. Works // for length ordered or unordered, always assigns the lowest valued // codewords first. Extended to handle unused entries (length 0) - internal static int[] make_words(int[] l, int n) + internal int[] make_words(int[] l, int n) { int[] marker = new int[33]; int[] r = new int[n]; diff --git a/SharpWave/csvorbis/DspState.cs b/SharpWave/csvorbis/DspState.cs index 260da89d8..6f3cd76d6 100644 --- a/SharpWave/csvorbis/DspState.cs +++ b/SharpWave/csvorbis/DspState.cs @@ -31,7 +31,7 @@ namespace csvorbis { public class DspState { - static float M_PI = 3.1415926539f; + const float M_PI = 3.1415926539f; internal Info vi; internal int modebits; @@ -78,7 +78,7 @@ namespace csvorbis wnd[1][1][1] = new float[2]; } - internal static float[] window(int wnd, int left, int right) + internal float[] window(int wnd, int left, int right) { float[] ret = new float[wnd]; // The 'vorbis window' (window 0) is sin(sin(x)*sin(x)*2pi) @@ -158,10 +158,9 @@ namespace csvorbis for(int i = 0;i 2) throw new csorbisException("residue type must be <= 2"); + residue_funcs[i] = FuncResidue.make(type); + residue_param[i] = residue_funcs[i].unpack(this,opb); } maps = opb.read(6) + 1; - CheckEntries(ref map_param, ref map_type, maps); + map_funcs = new FuncMapping[maps]; + map_param = new object[maps]; for(int i = 0;i(ref T[] array, int count) { - if(array == null || array.Length != count) { - array = new T[count]; - } - } - - void CheckEntries(ref T[] array, ref int[] types, int count) { - if(array == null || array.Length != count) { - array = new T[count]; - types = new int[count]; - } - } public void synthesis_headerin(Comment vc, Packet op) { if(op == null) return;