Skip to content

Commit

Permalink
Added Starpower SFX to Audio Engine (#102)
Browse files Browse the repository at this point in the history
* Add update check on startup (#91)

* Created update checker, runs on startup

* Add current version and update notification to main menu

* Update version back to 0.8.2

* Moved engine constants to `Constants`

* Awesomeness Detection (#89)

* Awesomeness detection

EXTREMLY IMPORTANT

* Awesomeness Detection

Very important!

* Pretty awesome if you ask me

* Add native bass library folders + READMEs for installation

* IAudioManager interface and BASS implementation

* Add ManagedBass to NuGet packages

* Change Play and AbstractTrack to use new audio engine

* Deleted old audio code and added StreamingAssets folder

* Add gitignore to ignore BASS libraries

* Adding generation of currentsong.text (#93)

This is mainly for OBS to show on twitch streams.
More stuff can be added but let's see if this works right first, ya? :)

* Added reverb to player stems when star power is active

* "ThirdParty" folder

* Fix lefty flip on 4 and 5 lane drums (#96)

* 4 lane drum lefty flip fix

* 5 lane drum lefty flip fix

* Updated credits

* Add PlasticBand-Unity for input mappings, and HIDrogen for Linux HID support (#95)

* Add PlasticBand-Unity package

* Switch Pro Guitar support to PlasticBand's

* Update input actions
Guitar actions now use PlasticBand
Removed most guitar UI actions, as they are covered by usages in PlasticBand

* Add HIDrogen package for HID support on Linux

* Fix lefty flip drum inputs (#99)

* fixed lefty flip drum inputs

* fixed bot drum lefty flip

* Re-enable incremental garbage collection (#101)

* Improve HO/PO overstrum forgiveness (#100)

* Allow anchoring chord HO/POs (togglable)

* Improve HO/PO overstrum forgiveness

* Small fix

* Add clap and starpower deploy sfx

* Add clap sfx to code

* Reverb keys stems and all drums stems

* Stem gain on SP and volume control settings

* Update and add new starpower SFX

* meta file update?

* Weird curly brace problem and 2 update checkers? Whats happening

---------

Co-authored-by: EliteAsian <lavasnakegaming@gmail.com>
Co-authored-by: TheFatBastid <tfb@sof.ws>
Co-authored-by: Rodrigo Oliveira <39157156+santorfo@users.noreply.github.com>
Co-authored-by: Nathan <nathanhurst03@gmail.com>
Co-authored-by: Raphael Goulart <contact@raphaelgoul.art>
  • Loading branch information
6 people authored Apr 16, 2023
1 parent ce27034 commit 766dd17
Show file tree
Hide file tree
Showing 51 changed files with 495 additions and 476 deletions.
Binary file modified Assets/Art/Textures/MainMenu/MetalShutter_Normal.exr
Binary file not shown.
3 changes: 3 additions & 0 deletions Assets/Credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Exoticri
raphaelgoulart
jnack
TheNathannator
muskit
Riley The Fox
Mia Berth
santorfo

<<COLUMN>>

Expand Down
47 changes: 46 additions & 1 deletion Assets/Scenes/PersistantScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1}
m_IndirectSpecularColor: {r: 0.12731713, g: 0.13414738, b: 0.121078536, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -284,6 +284,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b8241ed3bc1487244ba78808cf37d12e, type: 3}
m_Name:
m_EditorClassIdentifier:
updateChecker: {fileID: 0}
vocalGroup: {fileID: -541741410412472071, guid: d5f8521c55f50a44eb1e292204769821,
type: 2}
--- !u!114 &788257162
Expand Down Expand Up @@ -354,6 +355,50 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1179509444
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1179509446}
- component: {fileID: 1179509445}
m_Layer: 0
m_Name: Twitch Controller
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1179509445
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1179509444}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 43233795acd9ae84690111f3010c5413, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1179509446
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1179509444}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4560541903152539489
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
3 changes: 3 additions & 0 deletions Assets/Script/Audio/AudioEnums.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace YARG {
public enum SongStem {
Master = -1,
Song,
Guitar,
Bass,
Expand All @@ -20,7 +21,9 @@ public enum SongStem {
public enum SfxSample {
NoteMiss,
StarPowerAward,
StarPowerGain,
StarPowerDeploy,
StarPowerRelease,
Clap,
}
}
15 changes: 15 additions & 0 deletions Assets/Script/Audio/AudioHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ public static class AudioHelpers {
public static readonly IList<string> SfxPaths = new[] {
"note_miss",
"starpower_award",
"starpower_gain",
"starpower_deploy",
"starpower_release",
"clap"
};

public static readonly IList<double> SfxVolume = new[] {
0.5,
0.3,
0.5,
0.3,
0.4,
0.1,
};

public static IEnumerable<string> GetSupportedStems(string folder) {
Expand Down Expand Up @@ -91,10 +102,14 @@ public static SfxSample GetSfxFromName(string sfx) {
return SfxSample.NoteMiss;
case "starpower_award":
return SfxSample.StarPowerAward;
case "starpower_gain":
return SfxSample.StarPowerGain;
case "starpower_deploy":
return SfxSample.StarPowerDeploy;
case "starpower_release":
return SfxSample.StarPowerRelease;
case "clap":
return SfxSample.Clap;
default:
return SfxSample.NoteMiss;
}
Expand Down
77 changes: 56 additions & 21 deletions Assets/Script/Audio/BassAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public class BassAudioManager : MonoBehaviour, IAudioManager {

private int[] stemChannels;
private int[] sfxSamples;

private double[] stemVolumes;

private DSPProcedure dspGain;

private Dictionary<int, Dictionary<EffectType, int>> stemEffects;
private Dictionary<int, int> stemGainDsps;

private void Awake() {
SupportedFormats = new[] {
Expand All @@ -43,8 +48,11 @@ private void Awake() {
};

stemChannels = new int[AudioHelpers.SupportedStems.Count];
stemVolumes = new double[stemChannels.Length];

sfxSamples = new int[AudioHelpers.SfxPaths.Count];
stemEffects = new Dictionary<int, Dictionary<EffectType, int>>();
stemGainDsps = new Dictionary<int, int>();

opusHandle = 0;
mixerHandle = 0;
Expand All @@ -64,9 +72,10 @@ public void Initialize() {
Bass.DeviceNonStop = true;

Bass.Configure(Configuration.TruePlayPosition, 0);

Bass.Configure(Configuration.UpdateThreads, 2);
Bass.Configure(Configuration.FloatDSP, true);

Bass.Configure((Configuration) 68, 1);

Bass.Configure((Configuration) 70, false);

int deviceCount = Bass.DeviceCount;
Expand All @@ -77,8 +86,9 @@ public void Initialize() {
Debug.LogError($"Bass Error: {Bass.LastError}");
return;
}

LoadSfx();
dspGain += GainDSP;

Debug.Log($"BASS Successfully Initialized");
Debug.Log($"BASS: {Bass.Version}");
Expand Down Expand Up @@ -142,7 +152,7 @@ public void LoadSfx() {
}

int sampleIndex = (int) AudioHelpers.GetSfxFromName(sfx);

sfxSamples[sampleIndex] = sfxHandle;
Debug.Log($"Loaded {sfx}");
}
Expand All @@ -151,21 +161,24 @@ public void LoadSfx() {
}

public void LoadSong(IEnumerable<string> stems) {
Debug.Log("Loading song");
UnloadSong();

mixerHandle = BassMix.CreateMixerStream(44100, 2, BassFlags.Default);
StemsLoaded = 0;

foreach (string stemPath in stems) {
string stemName = Path.GetFileNameWithoutExtension(stemPath);

var stem = AudioHelpers.GetStemFromName(stemName);
int stemIndex = (int) AudioHelpers.GetStemFromName(stemName);

if (stemChannels[stemIndex] != 0) {
Debug.LogError($"Stem already loaded! {stemPath}");
continue;
}

int streamHandle = Bass.CreateStream(stemPath, 0, 0, BassFlags.Decode);
int streamHandle = Bass.CreateStream(stemPath, 0, 0, BassFlags.Prescan | BassFlags.Decode | BassFlags.AsyncFile);

// Stream failed to load
if (streamHandle == 0) {
Expand All @@ -174,6 +187,9 @@ public void LoadSong(IEnumerable<string> stems) {
continue;
}

// Apply volume setting to stream
Bass.ChannelSetAttribute(streamHandle, ChannelAttribute.Volume, stemVolumes[stemIndex]);

double stemLength = GetAudioLengthInSeconds(streamHandle);
if (stemLength > leadChannelLength) {
leadChannelHandle = streamHandle;
Expand All @@ -185,8 +201,6 @@ public void LoadSong(IEnumerable<string> stems) {

stemEffects.Add(streamHandle, new Dictionary<EffectType, int>());

//Debug.Log($"Loaded stem {stemPath}");

BassMix.MixerAddChannel(mixerHandle, streamHandle, BassFlags.Default);
}

Expand Down Expand Up @@ -240,10 +254,13 @@ public void Pause() {
}

public void PlaySoundEffect(SfxSample sample) {
if(sfxSamples[(int) sample] == 0)
if (sfxSamples[(int) sample] == 0) {
return;
}

int channel = Bass.SampleGetChannel(sfxSamples[(int) sample]);
Bass.ChannelSetAttribute(channel, ChannelAttribute.Volume, AudioHelpers.SfxVolume[(int) sample]);

Bass.ChannelPlay(channel);
}

Expand All @@ -256,7 +273,17 @@ public void SetStemVolume(SongStem stem, double volume) {
return;
}

Bass.ChannelSetAttribute(stemHandle, ChannelAttribute.Volume, volume);
// Multiply volume inputted by the stem's volume setting (e.g. 0.5 * 0.5 = 0.25)
Bass.ChannelSetAttribute(stemHandle, ChannelAttribute.Volume, volume * stemVolumes[(int)stem]);
}

public void UpdateVolumeSetting(SongStem stem, double volume) {
if (stem == SongStem.Master) {
Bass.GlobalStreamVolume = (int)(10_000 * volume);
return;
}

stemVolumes[(int)stem] = volume;
}

public void ApplyReverb(SongStem stem, bool reverb) {
Expand All @@ -275,31 +302,29 @@ public void ApplyReverb(SongStem stem, bool reverb) {

// Set reverb FX
int reverbHandle = Bass.ChannelSetFX(stemHandle, EffectType.DXReverb, 0);
int gainDspHandle = Bass.ChannelSetDSP(stemHandle, dspGain);

var reverbParams = new DXReverbParameters {
fInGain = 0.0f,
fReverbMix = -4f,
fReverbMix = -5f,
fReverbTime = 1000.0f,
fHighFreqRTRatio = 0.001f
};

// I don't think the volume works??? Might need a gain DSP function instead
Bass.ChannelSetAttribute(stemHandle, ChannelAttribute.Volume, 1.5f);

Bass.FXSetParameters(reverbHandle, reverbParams);

stemEffects[stemHandle].Add(EffectType.DXReverb, reverbHandle);
stemGainDsps.Add(stemHandle, gainDspHandle);
} else {
// No reverb is applied
if (!stemEffects[stemHandle].ContainsKey(EffectType.DXReverb))
return;

Bass.ChannelRemoveFX(stemHandle, stemEffects[stemHandle][EffectType.DXReverb]);

// Should set volume back to stem volume in settings when that is added
Bass.ChannelSetAttribute(stemHandle, ChannelAttribute.Volume, 1f);
Bass.ChannelRemoveDSP(stemHandle, stemGainDsps[stemHandle]);

stemEffects[stemHandle].Remove(EffectType.DXReverb);
stemGainDsps.Remove(stemHandle);
}
}

Expand All @@ -311,16 +336,26 @@ public void SetPosition(double position) {
throw new System.NotImplementedException();
}

private double GetAudioLengthInSeconds(int channel) {
private void OnApplicationQuit() {
Unload();
}

private static unsafe void GainDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user) {
var bufferPtr = (float*) buffer;
int samples = length / 4;

for (int i = 0; i < samples; i++) {
bufferPtr![i] *= 1.3f;
}
}

private static double GetAudioLengthInSeconds(int channel) {
long length = Bass.ChannelGetLength(channel);
double seconds = Bass.ChannelBytes2Seconds(channel, length);
return seconds;
}

private void OnApplicationQuit() {
Unload();
}


private static string GetBassDirectory() {
string pluginDirectory = Path.Combine(Application.dataPath, "Plugins");

Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/Audio/IAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface IAudioManager {
public void PlaySoundEffect(SfxSample sample);

public void SetStemVolume(SongStem stem, double volume);

public void UpdateVolumeSetting(SongStem stem, double volume);

public void ApplyReverb(SongStem stem, bool reverb);

Expand Down
10 changes: 9 additions & 1 deletion Assets/Script/Data/SongInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ public string SongName {
set => _songName = value;
get => _songName;
}
public string SongNameNoParen => SongName.Replace("(", "").Replace(")", "");
public string SongNameNoParen {
get {
if (string.IsNullOrEmpty(SongName)) {
return "";
}

return SongName.Replace("(", "").Replace(")", "");
}
}

/// <value>
/// Used for JSON. Compresses <see cref="partDifficulties"/> by getting rid of <c>-1</c>s.
Expand Down
Loading

0 comments on commit 766dd17

Please sign in to comment.