A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AudioTools.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using FMODUnity;
  7. using FMOD.Studio;
  8. namespace GamecraftModdingAPI.Utility
  9. {
  10. /// <summary>
  11. /// Common operations on audio objects
  12. /// </summary>
  13. public static class AudioTools
  14. {
  15. /// <summary>
  16. /// Retrieve the list of mixers (aka VCAs)
  17. /// </summary>
  18. /// <returns>The names of the mixers (without "vca:/")</returns>
  19. public static string[] GetMixers()
  20. {
  21. Bank masterBank;
  22. RuntimeManager.StudioSystem.getBank("bank:/Master Bank", out masterBank);
  23. VCA[] masterVCAs;
  24. int count;
  25. masterBank.getVCAList(out masterVCAs);
  26. masterBank.getVCACount(out count);
  27. string[] result = new string[count];
  28. string path;
  29. for (int i = 0; i < count; i++)
  30. {
  31. masterVCAs[i].getPath(out path);
  32. result[i] = path.Replace("vca:/", "");
  33. }
  34. return result;
  35. }
  36. /// <summary>
  37. /// Get the volume of an audio mixer
  38. /// </summary>
  39. /// <param name="mixer">The name of the mixer</param>
  40. /// <returns>The volume</returns>
  41. public static float GetVolume(string mixer)
  42. {
  43. float volume, finalVolume;
  44. RuntimeManager.GetVCA($"vca:/{mixer}").getVolume(out volume, out finalVolume);
  45. return volume;
  46. }
  47. /// <summary>
  48. /// Get the volume of an audio mixer at output time (this is influenced by the mixer volume and master volume)
  49. /// </summary>
  50. /// <param name="mixer">The name of the mixer</param>
  51. /// <returns>The final volume</returns>
  52. public static float GetVolumeOutput(string mixer)
  53. {
  54. float volume, finalVolume;
  55. RuntimeManager.GetVCA($"vca:/{mixer}").getVolume(out volume, out finalVolume);
  56. return finalVolume;
  57. }
  58. /// <summary>
  59. /// Set the volume of an audio mixer (like a VCA aka Voltage-Controlled Amplifier)
  60. /// </summary>
  61. /// <param name="volume">The volume from 0.0 to 1.0 (1.0+ is valid too)</param>
  62. /// <param name="mixer">The name of the mixer, as retrieved from GetMixers()</param>
  63. public static void SetVolume(float volume, string mixer)
  64. {
  65. RuntimeManager.GetVCA($"vca:/{mixer}").setVolume(volume);
  66. }
  67. /// <summary>
  68. /// Set the volume for all future audio
  69. /// </summary>
  70. /// <param name="volume">The volume from 0.0 to 1.0 (1.0+ is valid too)</param>
  71. public static void SetVolumeMaster(float volume)
  72. {
  73. RuntimeManager.GetBus("bus:/").setVolume(volume);
  74. }
  75. }
  76. }