public bool ReadCallback(float[] data) { currentDataIndex = 0; while (currentDataIndex < data.Length) { if (bufferedLength > 0) { int length = Math.Min(data.Length - currentDataIndex, bufferedLength); Array.Copy(dataBuffer, 0, data, currentDataIndex, length); currentDataIndex += length; bufferedLength -= length; if (bufferedLength > 0) { Array.Copy(dataBuffer, length, dataBuffer, 0, bufferedLength); } } else { EliasWrapper.elias_result_codes r = EliasWrapper.elias_read_samples(elias.Handle, Marshal.UnsafeAddrOfPinnedArrayElement(dataBuffer, 0)); bufferedLength = elias.FramesPerBuffer * elias.ChannelCount; EliasHelper.LogResult(r, "Failed to render"); if (r != EliasWrapper.elias_result_codes.elias_result_success) { return(false); } } } return(true); }
/// <summary> /// Run an action preset. /// </summary> public void RunActionPreset(string preset, bool ignoreRequiredThemeMissmatch = false) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_run_action_preset(elias.Handle, preset); if (ignoreRequiredThemeMissmatch == false || r != EliasWrapper.elias_result_codes.elias_error_requiredthememismatch) { EliasHelper.LogResult(r, "Problems running an action preset"); } }
/// <summary> /// Get the current theme. /// </summary> public string GetActiveTheme() { uint id = (uint)EliasWrapper.elias_get_active_theme_index(Handle, new double[0]); string name; EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_name_wrapped(Handle, id, out name); EliasHelper.LogResult(r, "Failed to get active theme"); return(name); }
/// <summary> /// Stop the rendering of the theme. This function must not be called while any other Elias calls are in progress with the same handle in another thread. /// The exception is if the engine has its own background threads; these will automatically be shut down. /// IMPORTANT: This function must never use thread unsafe calls, as it can be called from either the audio thread in case of failure to render, or the main thread, (game). /// </summary> public void Stop() { isEliasStarted = false; if (elias != null) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_stop(elias.Handle); EliasHelper.LogResult(r, "Problems stopping"); } }
/// <summary> /// Lock and unlock the mixer in order to allow many changes to be made without the risk of running one or more buffers ahead in between your changes. /// Note that multiple calls to elias_lock_mixer may be made in succession, as long as the same number of calls to elias_unlock_mixer are made (a recursive mutex, in other words). /// If you forget to unlock the mixer, the music will stop and you will get deadlocks. /// </summary> public void LockMixer() { if (elias.Handle == IntPtr.Zero) { return; } EliasWrapper.elias_result_codes r = EliasWrapper.elias_lock_mixer(elias.Handle); EliasHelper.LogResult(r, "Problems locking the mixer"); }
/// <summary> /// Stop the rendering of the theme. This function must not be called while any other Elias calls are in progress with the same handle in another thread. /// The exception is if the engine has its own background threads; these will automatically be shut down. /// IMPORTANT: This function must never use thread unsafe calls, as it can be called from either the audio thread in case of failure to render, or the main thread, (game). /// </summary> public void Stop() { shouldStop = false; isEliasStarted = false; if (elias.Handle != IntPtr.Zero) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_stop(elias.Handle); EliasHelper.LogResult(r, "Problems stopping"); } }
/// <summary> /// Queue an elias_event. /// </summary> public void QueueEvent(elias_event @event) { if (elias.Handle == IntPtr.Zero) { return; } EliasWrapper.elias_result_codes r = EliasWrapper.elias_queue_event_wrapped(elias.Handle, @event); EliasHelper.LogResult(r, "Problems queing an event"); }
/// <summary> /// Clear all queued events. /// </summary> public void ClearEvents() { if (elias.Handle == IntPtr.Zero) { return; } EliasWrapper.elias_result_codes r = EliasWrapper.elias_clear_events(elias.Handle); EliasHelper.LogResult(r, "Problems clearing events"); }
private bool StartWithActionPreset() { bool success; string name; EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_action_preset_name_wrapped(elias.Handle, (uint)actionPreset, out name); EliasHelper.LogResult(r, "Problems getting an action preset name"); string theme; r = EliasWrapper.elias_get_action_preset_required_initial_theme_wrapped(elias.Handle, name, out theme); EliasHelper.LogResult(r, "Problems with getting the required initial theme for an action preset"); success = StartWithActionPreset(name); return(success); }
/// <summary> /// Get the current theme. /// </summary> public string GetActiveTheme() { if (Handle == IntPtr.Zero) { return(""); } uint id = (uint)EliasWrapper.elias_get_active_theme_index(Handle, null); string name; EliasWrapper.elias_result_codes r = EliasWrapper.elias_get_theme_name_wrapped(Handle, id, out name); EliasHelper.LogResult(r, "Failed to get active theme"); return(name); }
/// <summary> /// Start ELIAS with a elias_event_set_level event. This function must not be called from more than one thread at the same time. /// </summary> public bool StartTheme(elias_event_set_level setLevel) { if (elias.Handle == IntPtr.Zero) { return(false); } if (AudioSettings.outputSampleRate == 0) { Debug.LogError("Unity's AudioSettings.outputSampleRate is reporting 0, so the Elias Plugin is unable to determine what sample rate would be correct to use! " + "This may cause the speed of the audio to play at the wrong rate. Please set a sample rate for Unity in the Project settings."); } EliasWrapper.elias_result_codes r = EliasWrapper.elias_start_background_wrapped(elias.Handle, setLevel, AudioSettings.outputSampleRate != 0 ? (uint)AudioSettings.outputSampleRate : (uint)eliasSampleRate, (uint)eliasFramesPerBuffer); EliasHelper.LogResult(r, setLevel.ToString()); return(r == EliasWrapper.elias_result_codes.elias_result_success); }
/// <summary> /// Clear all queued events. /// </summary> public void ClearEvents() { EliasWrapper.elias_result_codes r = EliasWrapper.elias_clear_events(elias.Handle); EliasHelper.LogResult(r, "Problems clearing events"); }
/// <summary> /// Lock and unlock the mixer in order to allow many changes to be made without the risk of running one or more buffers ahead in between your changes. /// Note that multiple calls to elias_lock_mixer may be made in succession, as long as the same number of calls to elias_unlock_mixer are made (a recursive mutex, in other words). /// If you forget to unlock the mixer, the music will stop and you will get deadlocks. /// </summary> public void UnlockMixer() { EliasWrapper.elias_result_codes r = EliasWrapper.elias_unlock_mixer(elias.Handle); EliasHelper.LogResult(r, "Problems unlocking the mixer"); }
/// <summary> /// Queue an elias_event. /// </summary> public void QueueEvent(elias_event @event) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_queue_event_wrapped(elias.Handle, @event); EliasHelper.LogResult(r, "Problems queing an event"); }
/// <summary> /// Start ELIAS with a elias_event_set_level event. This function must not be called from more than one thread at the same time. /// </summary> public bool StartTheme(elias_event_set_level setLevel) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_start_wrapped(elias.Handle, setLevel); EliasHelper.LogResult(r, setLevel.ToString()); return(r == EliasWrapper.elias_result_codes.elias_result_success); }
/// <summary> /// Start ELIAS with an action preset. This function must not be called from more than one thread at the same time. /// </summary> public bool StartWithActionPreset(string preset) { EliasWrapper.elias_result_codes r = EliasWrapper.elias_start_with_action_preset(elias.Handle, preset); EliasHelper.LogResult(r, preset); return(r == EliasWrapper.elias_result_codes.elias_result_success); }