public override void Load(SoundProfile profile, ResultCallback callback, SoundDatabase soundDatabase) { try { IntPtr akbData = ReadAkbDataToUnmanagedMemory(profile); if (akbData == IntPtr.Zero) { _resourceLoader.Load(profile, callback, soundDatabase); return; } try { Int32 bankID = ISdLibAPIProxy.Instance.SdSoundSystem_AddData(akbData); profile.AkbBin = akbData; profile.BankID = bankID; } catch { Marshal.FreeHGlobal(akbData); throw; } callback(profile, soundDatabase); } catch (Exception ex) { Log.Error(ex, "Failed to import sound: " + profile.ResourceID); _resourceLoader.Load(profile, callback, soundDatabase); } }
public void Delete(SoundProfile profile) { if (this.soundIndexDictionary.ContainsKey(profile.SoundIndex)) { this.soundIndexDictionary.Remove(profile.SoundIndex); } }
public Boolean IsSoundEffectPlaying(Int32 soundIndex) { SoundDatabase[] array = new SoundDatabase[] { this.gameSoundDatabase, this.sceneSoundDatabase, this.onTheFlySoundDatabase }; SoundDatabase[] array2 = array; for (Int32 i = 0; i < (Int32)array2.Length; i++) { SoundDatabase soundDatabase = array2[i]; foreach (KeyValuePair <Int32, SoundProfile> keyValuePair in soundDatabase.ReadAll()) { SoundProfile value = keyValuePair.Value; if (value.SoundIndex == soundIndex) { Int32 soundID = value.SoundID; if (this.playedEffectSet.Contains(soundID)) { return(true); } SoundLib.Log("soundID: " + soundID + " not found"); } } } SoundLib.Log("soundIndex: " + soundIndex + " not found in DB"); return(false); }
//Public function that sends out an EVENT for all SoundEmitterExtraSettings components to receive public void ChangeSoundProfile(SoundProfile newProfile_) { //Changing the sound profile to the given one globalReference.currentSoundProfile = newProfile_; //Dispatching an EVT to change all ExtraSoundEmitterSettings to use the new profile this.DispatchSoundChangeEvt(); }
private void LimitPlayingSfx(Int32 soundIndex, Int32 limitNumber) { SoundProfile soundProfile = (SoundProfile)null; Single num = Single.MaxValue; Int32 num2 = 0; foreach (KeyValuePair <Int32, SoundProfile> keyValuePair in this.playingDict) { SoundProfile value = keyValuePair.Value; if (value.SoundIndex == soundIndex) { num2++; if (value.StartPlayTime < num) { soundProfile = value; num = value.StartPlayTime; } } } if (num2 >= limitNumber) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Stop(soundProfile.SoundID, 0); this.playingDict.Remove(soundProfile.SoundID); } }
public override void Load(SoundProfile profile, ISoundLoader.ResultCallback callback, SoundDatabase soundDatabase) { String text = AssetManagerUtil.GetStreamingAssetsPath() + "/Sounds/" + profile.ResourceID; SoundLib.Log("Load: " + text); FileInfo fileInfo = new FileInfo(text); Byte[] array = null; if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.IPhonePlayer) { array = File.ReadAllBytes(text); } else if (Application.platform == RuntimePlatform.Android) { } if (array != null) { IntPtr intPtr = Marshal.AllocHGlobal((Int32)fileInfo.Length); Marshal.Copy(array, 0, intPtr, (Int32)fileInfo.Length); Int32 bankID = ISdLibAPIProxy.Instance.SdSoundSystem_AddData(intPtr); profile.AkbBin = intPtr; profile.BankID = bankID; } else { SoundLib.Log("akbBytes is null"); } callback(profile, soundDatabase); }
private void RegisterBankAsCallback(SoundProfile profile, SoundDatabase soundDatabase) { if (profile != null && soundDatabase != null) { soundDatabase.Create(profile); this.resourceLoadingCounter--; if (this.resourceLoadingCounter == 0) { this.activeCallback(soundDatabase, false); } else { SoundLib.Log("resourceLoadingCounter > 0! resourceLoadingCounter: " + this.resourceLoadingCounter); this.activeCallback(soundDatabase, true); } } else { SoundLib.Log("either profile OR soundDatabase is null"); this.resourceLoadingCounter--; if (this.resourceLoadingCounter == 0) { this.activeCallback(soundDatabase, true); } else { SoundLib.Log("resourceLoadingCounter > 0! resourceLoadingCounter: " + this.resourceLoadingCounter); this.activeCallback(soundDatabase, true); } } }
public override void Load(SoundProfile profile, ISoundLoader.ResultCallback callback, SoundDatabase soundDatabase) { String text = String.Empty; if (profile.SoundProfileType == SoundProfileType.SoundEffect) { text = Application.persistentDataPath + "/SoundEffect/" + profile.ResourceID; } else if (profile.SoundProfileType == SoundProfileType.Music) { text = Application.persistentDataPath + "/Music/" + profile.ResourceID; } else { text = Application.persistentDataPath + "/" + profile.ResourceID; } FileInfo fileInfo = new FileInfo(text); Byte[] source = File.ReadAllBytes(text); IntPtr intPtr = Marshal.AllocHGlobal((Int32)fileInfo.Length); Marshal.Copy(source, 0, intPtr, (Int32)fileInfo.Length); Int32 bankID = ISdLibAPIProxy.Instance.SdSoundSystem_AddData(intPtr); profile.AkbBin = intPtr; profile.BankID = bankID; callback(profile, soundDatabase); }
public void PlayMusic(Int32 soundIndex, Int32 fadeIn, SoundProfileType type = SoundProfileType.Music) { SoundProfile soundProfile = this.soundDatabase.Read(soundIndex); if (soundProfile == null) { soundProfile = this.onTheFlySoundDatabase.Read(soundIndex); } if (soundProfile != null) { this.PlayMusic(soundProfile, fadeIn); } else { soundProfile = SoundMetaData.GetSoundProfile(soundIndex, type); this.onTheFlyLoadedSoundProfile = soundProfile; this.onTheFlyLoadedFadeIn = fadeIn; if (this.onTheFlySoundDatabase.ReadAll().Count >= 10) { SoundLib.Log("Unload on the fly sound database."); base.UnloadResource(this.onTheFlySoundDatabase); } base.LoadResource(soundProfile, this.onTheFlySoundDatabase, new SoundPlayer.LoadResourceCallback(this.LoadOnTheFlySoundResourceCallback)); } }
public void SetVolume(Single volume) { SoundDatabase[] array = new SoundDatabase[] { this.gameSoundDatabase, this.sceneSoundDatabase, this.onTheFlySoundDatabase }; SoundDatabase[] array2 = array; for (Int32 i = 0; i < (Int32)array2.Length; i++) { SoundDatabase soundDatabase = array2[i]; foreach (KeyValuePair <Int32, SoundProfile> keyValuePair in soundDatabase.ReadAll()) { SoundProfile value = keyValuePair.Value; Int32 soundID = value.SoundID; if (this.playedEffectSet.Contains(soundID)) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundID, volume, 0); SoundLib.Log("Set volume to soundID: " + soundID + " finished"); } else { SoundLib.Log("soundID: " + soundID + " not found"); } } } this.playerVolume = volume; }
public void StopSoundEffect(Int32 soundIndex) { SoundDatabase[] array = new SoundDatabase[] { this.gameSoundDatabase, this.sceneSoundDatabase, this.onTheFlySoundDatabase }; SoundDatabase[] array2 = array; for (Int32 i = 0; i < (Int32)array2.Length; i++) { SoundDatabase soundDatabase = array2[i]; foreach (KeyValuePair <Int32, SoundProfile> keyValuePair in soundDatabase.ReadAll()) { SoundProfile value = keyValuePair.Value; if (value.SoundIndex == soundIndex) { Int32 soundID = value.SoundID; if (this.playedEffectSet.Contains(soundID)) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Stop(soundID, 0); this.playedEffectSet.Remove(soundID); SoundLib.Log("Force stop success"); } else { SoundLib.Log("soundID: " + soundID + " not found"); } } } } }
public void PreviousSound() { Boolean isPlay = this.IsPlay; this.IsPlay = false; List <SoundProfile> list = this.playlist; Int32 count = list.Count; Int32 num = 0; SoundProfile soundProfile = (SoundProfile)null; foreach (SoundProfile soundProfile2 in list) { if (soundProfile2.Code == this.activeSound.Code && num != 0) { this.activeSound = soundProfile; break; } soundProfile = soundProfile2; num++; } if (isPlay) { this.PlayActiveSound(); } }
private void PlaySoundEffect(SoundProfile soundProfile) { base.CreateSound(soundProfile); base.StartSound(soundProfile, 1f); this.playedEffectSet.Add(soundProfile.SoundID); soundProfile.SoundProfileState = SoundProfileState.Released; this.gameSoundDatabase.Update(soundProfile); }
public SoundProfile Update(SoundProfile profile) { if (this.soundIndexDictionary.ContainsKey(profile.SoundIndex)) { this.soundIndexDictionary[profile.SoundIndex] = profile; return(profile); } return((SoundProfile)null); }
public SoundProfile Create(SoundProfile profile) { if (this.soundIndexDictionary.ContainsKey(profile.SoundIndex)) { return((SoundProfile)null); } this.soundIndexDictionary.Add(profile.SoundIndex, profile); return(profile); }
private void UpdatePlayingSoundVolume() { foreach (Int32 key in this.playingDict.Keys) { SoundProfile soundProfile = this.playingDict[key]; if (this.residentSoundDatabase.Read(soundProfile.SoundIndex) != null) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, soundProfile.SoundVolume * this.playerVolume, 0); } } }
protected void LoadResource(SoundProfile soundProfile, SoundDatabase soundDatabase, SoundPlayer.LoadResourceCallback callback) { if (this.resourceLoadingCounter > 0) { callback((SoundDatabase)null, true); return; } this.resourceLoadingCounter = 1; this.activeCallback = callback; SoundLoaderProxy.Instance.Load(soundProfile, new ISoundLoader.ResultCallback(this.RegisterBankAsCallback), soundDatabase); }
public void CreateSound(SoundProfile soundProfile) { Int32 num = ISdLibAPIProxy.Instance.SdSoundSystem_CreateSound(soundProfile.BankID); if (num == 0) { SoundLib.Log("CreateSound failure"); return; } soundProfile.SoundID = num; SoundLib.Log("CreateSound Success"); }
private static IntPtr ReadAkbDataFromOggViaCache(SoundProfile profile, String oggPath, String akbPath) { DateTime oggTime = File.GetLastWriteTimeUtc(oggPath); if (File.Exists(akbPath)) { if (oggTime == File.GetLastWriteTimeUtc(akbPath)) { return(ReadFileToUnmanagedMemory(akbPath)); } } return(ReadAkbDataFromOggAndCache(profile, oggPath, akbPath, oggTime)); }
public void UnregisterBank(SoundProfile soundProfile) { SoundLib.Log("UnregisterBank: " + soundProfile.Name); if (soundProfile.BankID != 0) { ISdLibAPIProxy.Instance.SdSoundSystem_RemoveData(soundProfile.BankID); soundProfile.BankID = 0; } if (IntPtr.Zero != soundProfile.AkbBin) { Marshal.FreeHGlobal(soundProfile.AkbBin); soundProfile.AkbBin = IntPtr.Zero; } }
protected void LoadResource(String metaData, SoundDatabase soundDatabase, SoundPlayer.LoadResourceCallback callback) { if (this.resourceLoadingCounter > 0) { callback((SoundDatabase)null, true); return; } this.resourceLoadingCounter = 0; this.activeCallback = callback; JSONNode jsonnode = JSONNode.Parse(metaData); JSONArray asArray = jsonnode["data"].AsArray; this.resourceLoadingCounter = asArray.Count; for (Int32 i = 0; i < asArray.Count; i++) { JSONClass asObject = asArray[i].AsObject; String text = asObject["name"]; Int32 asInt = asObject["soundIndex"].AsInt; String strA = asObject["type"]; SoundProfileType soundProfileType; if (String.Compare(strA, "SoundEffect") == 0) { soundProfileType = SoundProfileType.SoundEffect; } else if (String.Compare(strA, "Music") == 0) { soundProfileType = SoundProfileType.Music; } else if (String.Compare(strA, "MovieAudio") == 0) { soundProfileType = SoundProfileType.MovieAudio; } else if (String.Compare(strA, "Song") == 0) { soundProfileType = SoundProfileType.Song; } else { soundProfileType = SoundProfileType.Default; } SoundProfile soundProfile = new SoundProfile(); soundProfile.Code = asInt.ToString(); soundProfile.Name = text; soundProfile.SoundIndex = asInt; soundProfile.ResourceID = text; soundProfile.SoundProfileType = soundProfileType; SoundLoaderProxy.Instance.Load(soundProfile, new ISoundLoader.ResultCallback(this.RegisterBankAsCallback), soundDatabase); } }
public void StartSound(SoundProfile soundProfile, Single playerVolume = 1f) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Start(soundProfile.SoundID, 0); if (ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_IsExist(soundProfile.SoundID) == 0) { SoundLib.Log("failed to play sound"); soundProfile.SoundID = 0; return; } ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, soundProfile.SoundVolume * playerVolume, 0); SoundLib.Log("Panning: " + soundProfile.Panning); ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetPanning(soundProfile.SoundID, soundProfile.Panning, 0); ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetPitch(soundProfile.SoundID, soundProfile.Pitch, 0); SoundLib.Log("StartSound Success"); }
private void StartSoundCrossfadeIn(SoundProfile soundProfile) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Start(soundProfile.SoundID, 0); if (ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_IsExist(soundProfile.SoundID) == 0) { SoundLib.Log("failed to play sound"); soundProfile.SoundID = 0; return; } ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, 0f, 0); soundProfile.SoundVolume = this.playerVolume * this.optionVolume; ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, this.playerVolume * this.optionVolume, (Int32)(this.fadeInDuration * 1000f)); this.SetMusicPanning(this.playerPanning, soundProfile); this.SetMusicPitch(this.playerPitch, soundProfile); this.upcomingSoundProfile = soundProfile; }
public void NextLoopRegion(Int32 soundIndex) { SoundProfile soundProfile = this.soundDatabase.Read(soundIndex); if (soundProfile == null) { soundProfile = this.onTheFlySoundDatabase.Read(soundIndex); } if (soundProfile != null) { ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetNextLoopRegion(soundProfile.SoundID); } else { SoundLib.Log("NextLoopRegion(), soundProfile is null!"); } }
public void LoadAllResidentSoundData() { List <String> list = SoundMetaData.ResidentSfxSoundIndex[0]; for (Int32 i = 0; i < list.Count; i++) { Int32 soundIndex = i; String text = list[i]; String fileName = Path.GetFileName(text); SoundProfile soundProfile = new SoundProfile(); soundProfile.Code = soundIndex.ToString(); soundProfile.Name = fileName; soundProfile.SoundIndex = soundIndex; soundProfile.ResourceID = text; soundProfile.SoundProfileType = SoundProfileType.Sfx; this.residentSoundDatabase.Create(soundProfile); base.LoadResource(soundProfile, this.residentSoundDatabase, new SoundPlayer.LoadResourceCallback(this.LoadSoundResourceCallback)); } }
protected void PlaySoundEffect(Int32 soundIndex, Single soundVolume = 1f, Single panning = 0f, Single pitch = 1f, SoundProfileType type = SoundProfileType.SoundEffect) { SoundProfile soundProfile = this.gameSoundDatabase.Read(soundIndex); if (soundProfile == null) { soundProfile = this.sceneSoundDatabase.Read(soundIndex); } if (soundProfile == null) { soundProfile = this.onTheFlySoundDatabase.Read(soundIndex); } if (soundProfile != null) { soundProfile.SoundVolume = soundVolume * this.playerVolume; soundProfile.Panning = panning; soundProfile.Pitch = pitch; this.activeSoundEffect = soundProfile; this.PlaySoundEffect(soundProfile); } else { SoundLib.Log(String.Empty + soundIndex + " is not exist"); soundProfile = SoundMetaData.GetSoundProfile(soundIndex, type); soundProfile.SoundVolume = soundVolume * this.playerVolume; soundProfile.Panning = panning; soundProfile.Pitch = pitch; if (soundProfile == null) { SoundLib.LogError("soundIndex: " + soundIndex + " is not exist"); return; } this.activeSoundEffect = soundProfile; if (this.onTheFlySoundDatabase.ReadAll().Count >= 20) { SoundLib.Log("Unload on the fly sound database."); base.UnloadResource(this.onTheFlySoundDatabase); } base.LoadResource(soundProfile, this.onTheFlySoundDatabase, new SoundPlayer.LoadResourceCallback(this.LoadOnTheFlySoundResourceCallback)); } }
private static IntPtr ReadAkbDataFromOggAndCache(SoundProfile profile, String oggPath, String akbPath, DateTime oggTime) { IntPtr result = IntPtr.Zero; try { UInt32 resultSize; ReadAkbDataFromOgg(profile, oggPath, out result, out resultSize); WriteAkbDataToCache(akbPath, oggTime, result, resultSize); return(result); } catch { if (result != IntPtr.Zero) { Marshal.FreeHGlobal(result); } throw; } }
public SoundEffect GetSound() { float p = RangePercent; if (sounds.Length > 0) { SoundScale sp = Sound(p); SoundEffect s = sp.Sound(); return(s); } if (soundProfiles.Length > 0) { SoundProfile sp = soundProfiles[Mathf.RoundToInt(Mathf.Lerp(0, soundProfiles.Length - 1, clipSelect.Evaluate(p)))]; Debug.Log(sp.name); SoundEffect s = sp.GetSound(); return(s); } return(null); }
private static IntPtr ReadAkbDataToUnmanagedMemory(SoundProfile profile) { String akbPath = AudioResources.Import.GetSoundPath(profile.ResourceID); String oggPath = akbPath + ".ogg"; String fileName; String directoryPath; String alternativeOggPath; if (AudioResources.TryAppendDisplayName(akbPath, out directoryPath, out fileName, out alternativeOggPath)) { alternativeOggPath += ".ogg"; if (!File.Exists(alternativeOggPath) && File.Exists(oggPath)) { Log.Message("[SoundImporter] The file [{0}] will be renamed to [{1}].", akbPath, alternativeOggPath); File.Move(oggPath, alternativeOggPath); } } String[] oggFiles = Directory.GetFiles(directoryPath, fileName + "*.ogg"); if (oggFiles.Length == 1) { oggPath = oggFiles[0]; return(ReadAkbDataFromOggViaCache(profile, oggPath, akbPath)); } if (oggFiles.Length > 1) { oggPath = oggFiles.OrderByDescending(File.GetLastWriteTimeUtc).First(); Log.Warning("[SoundImporter] There is several files with the same internal name. The last modified will be used: {0}", oggPath); return(ReadAkbDataFromOggViaCache(profile, oggPath, akbPath)); } if (File.Exists(akbPath)) { return(ReadFileToUnmanagedMemory(akbPath)); } return(IntPtr.Zero); }
public override void Load(SoundProfile profile, ISoundLoader.ResultCallback callback, SoundDatabase soundDatabase) { String text = "Sounds/" + profile.ResourceID + ".akb"; TextAsset textAsset = AssetManager.Load <TextAsset>(text, false); SoundLib.Log("Load: " + text); if ((UnityEngine.Object)null == textAsset) { SoundLib.LogError("File not found AT path: " + text); callback((SoundProfile)null, (SoundDatabase)null); return; } Byte[] bytes = textAsset.bytes; IntPtr intPtr = Marshal.AllocHGlobal((Int32)textAsset.bytes.Length); Marshal.Copy(bytes, 0, intPtr, (Int32)textAsset.bytes.Length); Int32 bankID = ISdLibAPIProxy.Instance.SdSoundSystem_AddData(intPtr); profile.AkbBin = intPtr; profile.BankID = bankID; callback(profile, soundDatabase); }