private void InitializeManager(int numOfChannels, int buffersPerChannel, int bytesPerBuffer, bool threadCall) { // Set the local variables to parameters NumOfChannels = numOfChannels; //BuffersPerChannel = buffersPerChannel; //BytesPerBuffer = bytesPerBuffer; needsUpdate = threadCall; AudioSources = new AudioSource[numOfChannels]; // Create a new Audio channel for every channel specified in local array for (int i = 0; i < numOfChannels; i++) { AudioSources[i] = new AudioSource(buffersPerChannel, bytesPerBuffer); } Manager = this; // If we are looking for a threaded call, create a new thread if (threadCall) { // Create a new thread ThreadCall = new Thread(UpdateLoop); // Thread should be background ThreadCall.IsBackground = true; // Start the thread ThreadCall.Start(); } else { // No thread so NULL ThreadCall = null; } }
public void PlayFile(VorbisFileInstance audioFile, out AudioSource currentSource) { currentSource = null; foreach (AudioSource source in AudioSources) { try { if (source.IsFree) { Thread.Sleep(500); source.PlaySource(audioFile); currentSource = source; return; } } catch (Exception e) { //Console.WriteLine("AudioManager threw exception!"); //Console.WriteLine(e.StackTrace); //currentSource = null; } } }