Skip to content

Commit c58fa09

Browse files
committed
wwise sound string hasher
1 parent 2098538 commit c58fa09

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

CathodeLib/Scripts/CATHODE/SoundBankData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace CATHODE
1313
/* DATA/ENV/PRODUCTION/x/WORLD/SOUNDBANKDATA.DAT */
1414
public class SoundBankData : CathodeFile
1515
{
16+
//NOTE: you can use Utilities.SoundHashedString to hash these strings and get the Wwise ID used in other places like SoundEventData
17+
1618
public List<string> Entries = new List<string>();
1719
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
1820
public SoundBankData(string path) : base(path) { }

CathodeLib/Scripts/CATHODE/SoundEventData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ override protected bool SaveInternal()
7575
#region STRUCTURES
7676
public class Soundbank
7777
{
78-
public uint id;
78+
public uint id; //This is the hashed soundbank string name (hashed via Utilities.SoundHashedString)
7979
public List<Event> events = new List<Event>();
8080

8181
public class Event

CathodeLib/Scripts/Utilities.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
using System.Linq;
77
using System.Numerics;
88
using System.Runtime.InteropServices;
9-
using System.Runtime.Serialization.Formatters.Binary;
9+
using System.Runtime.Serialization.Formatters.Binary;
10+
using System.Text;
1011

1112
namespace CathodeLib
1213
{
@@ -212,6 +213,21 @@ public static uint AnimationHashedString(string str)
212213
return hash;
213214
}
214215

216+
//Generate a hashed string for use in sound system (wwise FNV-1)
217+
public static uint SoundHashedString(string str)
218+
{
219+
byte[] namebytes = Encoding.UTF8.GetBytes(str.ToLower());
220+
uint hash = 2166136261;
221+
for (int i = 0; i < namebytes.Length; i++)
222+
{
223+
byte namebyte = namebytes[i];
224+
hash = hash * 16777619;
225+
hash = hash ^ namebyte;
226+
hash = hash & 0xFFFFFFFF;
227+
}
228+
return hash;
229+
}
230+
215231
//Read a PAK
216232
public static List<PAKContent> ReadPAK(string path, FileIdentifiers type)
217233
{

0 commit comments

Comments
 (0)