private IResource CreateResource(eResourceType eType, string name, string assetpath, Object objresource, bool isAssetBundle) { IResource resource = null; switch (eType) { //case E_ResourceType.Actor: case eResourceType.UI: case eResourceType.Prefab: case eResourceType.Text: resource = new PrefabResource(objresource, eType, isAssetBundle); break; case eResourceType.Sound: resource = new SoundResource(objresource, isAssetBundle); break; } resource.InitLoad(name, assetpath); Dictionary <int, IResource> dicRes = GetDicResource(eType); if (dicRes.ContainsKey(resource.GetHashCode())) { // LogManager.GetInstance().LogDebug("CreateResource name error" + name); } else { dicRes.Add(resource.GetHashCode(), resource); } return(resource); }
private void AddSoundToListIfExists(SoundResource sound) { if (sound != null) { AvailableSounds.Add(sound); } }
public static HUDNotificationControl Create( string title, string message, Brush brushBackground, Brush brushForeground, ITextureResource icon, Action onClick, bool autoHide, SoundResource soundToPlay) { var iconBrush = icon != null ? Api.Client.UI.GetTextureBrush(icon) : null; return(new HUDNotificationControl() { ViewModel = new ViewModelHUDNotificationControl( title, message, brushBackground, brushForeground, iconBrush, onClick), IsAutoHide = autoHide, soundToPlay = soundToPlay }); }
public void ReadSoundEntry(ResourceEntry entry, XmlWriter resourceXML, string name, string soundDir) { // Create and deserialize the data. SoundResource resource = new SoundResource(); using (MemoryStream stream = new MemoryStream(entry.Data)) { resource.Deserialize(entry.Version, stream, _Endian); } entry.Data = resource.Data; // Create directories and then write the XML to finish it off. string fileName = name + ".fsb"; string[] dirs = name.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); string tempDir = soundDir; for (int z = 0; z < dirs.Length - 1; z++) { tempDir = Path.Combine(tempDir, dirs[z]); Directory.CreateDirectory(tempDir); } resourceXML.WriteElementString("File", fileName); }
private void PlaySound(SoundResource sound) { // Adjust the sound back to normal settings if it is a looping sound that is already playing if ((currentPlayHandle != null) && currentPlayHandle.IsPlaying() && Looping) { AdjustSound(Loudness, PitchOffset); return; } StopSound(false); PlaySettings playSettings = (Looping ? PlaySettings.Looped : PlaySettings.PlayOnce); playSettings.DontSync = false; playSettings.Loudness = LoudnessPercentToDb(Loudness + LoudnessVariance * RandomNegOneToOne()); playSettings.PitchShift = PitchOffset + PitchVariance * RandomNegOneToOne(); if (Spatialized) { if (audio != null) { currentPlayHandle = audio.PlaySoundOnComponent(sound, playSettings); } else { currentPlayHandle = ScenePrivate.PlaySoundAtPosition(sound, ObjectPrivate.Position, playSettings); } } else { currentPlayHandle = ScenePrivate.PlaySound(sound, playSettings); } }
public ResourceEntry WriteSoundEntry(ResourceEntry entry, XPathNodeIterator nodes, string sdsFolder, XmlNode descNode) { nodes.Current.MoveToNext(); string file = nodes.Current.Value.Remove(nodes.Current.Value.Length - 4, 4); // Combine path and add extension. string path = Path.Combine(sdsFolder, file); path += ".fsb"; // Get the Version and set the inner text (meta XML). nodes.Current.MoveToNext(); entry.Version = Convert.ToUInt16(nodes.Current.Value); descNode.InnerText = file; using (MemoryStream stream = new MemoryStream()) { byte[] fileData = File.ReadAllBytes(path); SoundResource resource = new SoundResource { Name = file, Data = fileData, FileSize = fileData.Length }; resource.Serialize(entry.Version, stream, _Endian); // Fill the remaining data for the entry. entry.SlotRamRequired = 40; entry.SlotVramRequired = (uint)resource.FileSize; entry.Data = stream.ToArray(); } return(entry); }
private IHudNotificationControl ShowInternal( string title, string message, Brush brushBackground, Brush brushBorder, ITextureResource icon, Action onClick, bool autoHide, SoundResource soundToPlay, bool writeToLog) { if (writeToLog) { Api.Logger.Important( string.Format( "Showing notification:{0}Title: {1}{0}Message: {2}", Environment.NewLine, title, message)); } var notificationControl = HudNotificationControl.Create( title, message, brushBackground, brushBorder, icon, onClick, autoHide, soundToPlay); var instance = this; if (notificationControl.IsAutoHide) { instance.HideSimilarNotifications(notificationControl); } instance.stackPanelChildren.Add(notificationControl); if (notificationControl.IsAutoHide) { // hide the notification control after delay ClientTimersSystem.AddAction( NotificationHideDelaySeconds, () => { if (notificationControl.IsAutoHide) // still configured as auto hide { notificationControl.Hide(quick: false); } }); } instance.HideOldNotificationsIfTooManyDisplayed(); return(notificationControl); }
private void PlaySound(SoundResource sound) { PlaySettings playSettings = PlaySettings.PlayOnce; playSettings.Loudness = LoudnessPercentToDb(Loudness); playSettings.PitchShift = PitchVariance * RandomNegOneToOne(); audio.PlaySoundOnComponent(sound, playSettings); }
public SoundResourceSet Add(SoundResource soundResource, double weight = 1) { if (soundResource == null) { throw new Exception("Sound resource is not provided"); } this.sounds.Add(new ValueWithWeight <SoundResource>(soundResource, weight)); return(this); }
protected override void CustomFileExport(ExportParameters exportParameters) { var outputPath = Path.GetFullPath(Path.Combine(exportParameters.OutputDirectory, exportParameters.FileRecord.Name + exportParameters.FileExtension)); var soundResource = SoundResource.Create(exportParameters.FileRecord.Info?.VersionHash ?? string.Empty); soundResource.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord); LibFSB.SaveAs(soundResource.Resource.Data.Data, outputPath); exportParameters.OnProgressReport?.Invoke(exportParameters.FileRecord, 0); }
public void Setup(SoundResource soundResource) { this.soundEmitter.Stop(); this.soundEmitter.SoundResource = soundResource; this.soundEmitter.IsLooped = true; this.soundEmitter.IsUseSoundVolumeOption = false; // we control ambient volume separately from other sounds this.soundEmitter.Volume = (float)(this.currentInterpolatedVolume = this.targetVolume = 0); // the ambient sound should never start from the beginning this.soundEmitter.Seek(RandomHelper.NextDouble() * 100); this.soundEmitter.Play(); }
private void PlayNote(SoundResource PlaySample, float PitchShiftIn) { bool NoLoop = true; playSettings = NoLoop ? PlaySettings.PlayOnce : PlaySettings.Looped; playSettings.Loudness = loudnessIn; // set in Configuration playSettings.DontSync = true; // TrackDont_Sync[LoopIn2]; playSettings.PitchShift = PitchShiftIn; //playHandle[LoopIn2] = ScenePrivate.PlaySound(TrackSamples[LoopIn2][PlayIndexIn], playSettings); playHandleSimple = ScenePrivate.PlaySound(PlaySample, playSettings); }
private static int SoundLoaderLoad(IntPtr path) { var pathstr = Marshal.PtrToStringUni(path); var res = new SoundResource(); if (res.Load(pathstr)) { EffekseerSystem.Instance.soundList.Add(res); return(EffekseerSystem.Instance.soundList.Count); } return(0); }
private void PlayNextSound() { SoundResource nextSound = AvailableSounds[NextSoundIndex]; if (LocalAudioComponent != null) { LocalAudioComponent.PlaySoundOnComponent(nextSound, PlaySettings.PlayOnce).OnFinished(OnSoundFinished); } else { ScenePrivate.PlaySound(nextSound, PlaySettings.PlayOnce).OnFinished(OnSoundFinished); } }
private void SendSampleInfoSelected(string sampleNameIn, SoundResource sampleSoundResourceIn, string TrackPanIn, string trackToUseIn, AgentInfo Jammer) { SendSampleToPlayInfo sendSampleInfo = new SendSampleToPlayInfo(); List <Object> SampleToPlay = new List <Object>(); sendSampleInfo.SampleName = sampleNameIn; sendSampleInfo.SampleSoundResource = sampleSoundResourceIn; sendSampleInfo.TrackPan = TrackPanIn; sendSampleInfo.TrackToUse = trackToUseIn; sendSampleInfo.Jammer = Jammer; //Log.Write("Sending Message: " + sampleNameIn + ", " + sampleSoundResourceIn.GetName() + ", " + trackToUseIn); PostScriptEvent(ScriptId.AllScripts, "PlaySample", sendSampleInfo); }
/// <param name="soundResource">Sound resource with ambient sound.</param> /// <param name="suppressionCoef">How much other ambient sounds should be suppressed?</param> /// <param name="isSupressingMusic">Should music pause when hearing this ambient sound?</param> public AmbientSoundPreset( SoundResource soundResource, double suppressionCoef = 0, bool isSupressingMusic = false, bool isUsingAmbientVolume = true) { this.SoundResource = soundResource; Api.Assert(suppressionCoef >= 0 && suppressionCoef <= 1, nameof(suppressionCoef) + " must be in [0;1] range"); this.SuppressionCoef = suppressionCoef; this.IsSupressingMusic = isSupressingMusic; this.IsUsingAmbientVolume = isUsingAmbientVolume; }
private IResource CreateResource(eResourceType eType, string name, string assetpath, Object objresource, bool isAssetBundle) { IResource resource = null; switch (eType) { //case E_ResourceType.Actor: case eResourceType.UI: case eResourceType.Prefab: resource = new PrefabResource(objresource, eType, isAssetBundle); break; // case E_ResourceType.UnitySprite: // resource = new SpriteResource(objresource); // break; case eResourceType.Script: resource = new ScriptResource(objresource, isAssetBundle); break; case eResourceType.SpriteAsset: SpritePackerAsset spritePackerAsset = (SpritePackerAsset)objresource; resource = new SpriteAssetResource(spritePackerAsset.AllSprites, isAssetBundle); break; case eResourceType.Scriptable: resource = new ScriptableResource(objresource, isAssetBundle); break; case eResourceType.Texture: resource = new TextureResouce(objresource, isAssetBundle); break; case eResourceType.Sound: resource = new SoundResource(objresource, isAssetBundle); break; } resource.InitLoad(name, assetpath); Dictionary <int, IResource> dicRes = GetDicResource(eType); if (dicRes.ContainsKey(resource.GetHashCode())) { // LogManager.GetInstance().LogDebug("CreateResource name error" + name); } else { dicRes.Add(resource.GetHashCode(), resource); } return(resource); }
private void ShuffleSounds(SoundResource previousSound = null) { // NOTE: not efficient for scaling but good enough for <= 5 elements AvailableSounds = AvailableSounds.OrderBy <SoundResource, int>((item) => Rnd.Next()).ToList( ); // make sure we won't play the same sound twice in a row. if (previousSound == AvailableSounds[0]) { // swap the next and last sound. int finalSoundIndex = AvailableSounds.Count - 1; AvailableSounds[0] = AvailableSounds[finalSoundIndex]; AvailableSounds[finalSoundIndex] = previousSound; } }
public void InitiateLoadedSound(SoundResource soundResource) { // set sound properties based on information in soundResource var sound = (JMOD.ISound)soundResource.SoundGlue.InnerSoundObject; soundResource.BaseFrequency = sound.Frequency; sound.Frequency = soundResource.PlaybackSpeed * soundResource.BaseFrequency; sound.DefaultVolume = soundResource.Volume; sound.Priority = (int)soundResource.Priority; if (soundResource.SoundGroupEnum != SoundGroups.Default) { sound.SoundGroupName = soundResource.SoundGroup.Name; } }
private static int SoundLoaderLoad(IntPtr path) { var pathstr = Marshal.PtrToStringUni(path); // HACK var combinedPath = CombinePathForResource(currentLoadingEffectPath, pathstr); var res = new SoundResource(); if (res.Load(combinedPath, pathstr, EffekseerSystem.Instance.assetBundle)) { EffekseerSystem.Instance.soundList.Add(res); return(EffekseerSystem.Instance.soundList.Count); } return(0); }
public void Setup( IComponentSkeleton skeleton, ICharacter characterRotationSource, SoundResource soundResourceAimingProcess) { this.skeleton = skeleton; this.characterPublicState = characterRotationSource.GetPublicState <ICharacterPublicState>(); this.soundEmitter = Api.Client.Audio.CreateSoundEmitter(this.SceneObject, soundResourceAimingProcess, is3D: !characterRotationSource .IsCurrentClientCharacter, isLooped: true, isPlaying: true, volume: 0); this.lastAngleRad = this.GetCurrentAngleRad(); }
public void InitiateLoadedSound(SoundResource soundResource) { float dummy = 0f; int dummyI = 0; float baseFrequency = 0; FMOD.Sound sound = (FMOD.Sound)soundResource.SoundGlue.InnerSoundObject; ERRCHECK(sound.set3DMinMaxDistance(minMaxDistance.X, minMaxDistance.Y)); ERRCHECK(sound.getDefaults(ref baseFrequency, ref dummy, ref dummy, ref dummyI)); ERRCHECK(sound.setDefaults(soundResource.PlaybackSpeed * baseFrequency, soundResource.Volume, 0f, (int)soundResource.Priority)); soundResource.BaseFrequency = baseFrequency; if (soundResource.SoundGroupEnum != SoundGroups.Default) { ERRCHECK(sound.setSoundGroup((FMOD.SoundGroup)SoundManager.Instance.GetSoundGroup(soundResource.SoundGroupEnum).SoundGroupGlue.InnerSoundGroupObject)); } }
public void OnSoundFinished() { if (AvailableSounds.Count > 1) { SoundResource previousSound = AvailableSounds[NextSoundIndex]; NextSoundIndex++; if (NextSoundIndex >= AvailableSounds.Count) { ShuffleSounds(previousSound); NextSoundIndex = 0; } } double randomDelay = MinDelayBetweenSounds + (DelayRange * Rnd.NextDouble()); Timer.Create(TimeSpan.FromSeconds(randomDelay), () => { PlayNextSound(); }); }
public void Setup( IDynamicWorldObject vehicle, SoundResource soundResourceEngine, double volume) { this.vehicle = vehicle; this.soundResourceEngine = soundResourceEngine; this.Volume = volume; this.ReleaseSubscriptions(); this.vehiclePublicState = vehicle.GetPublicState <VehiclePublicState>(); this.vehiclePublicState.ClientSubscribe(p => p.PilotCharacter, this.RebuildSoundEmitter, this); this.RebuildSoundEmitter(); }
void CharSound(UserData data, SoundResource snd) { float loud = 0.0f; PlaySettings psonce = PlaySettings.PlayOnce; psonce.Loudness = loud; AgentPrivate agent = ScenePrivate.FindAgent(data.User); ObjectPrivate obj = ScenePrivate.FindObject(agent.AgentInfo.ObjectId); if (snd != null) { agent.PlaySoundAtPosition(snd, obj.Position, psonce); } else { Log.Write(LogLevel.Error, GetType().Name, $"No Sound"); } }
private void getSamplescfg(ScriptEventData gotSamplescfg) { if (gotSamplescfg.Data == null) { Log.Write(LogLevel.Warning, Script.ID.ToString(), "Expected non-null event data"); return; } SendSamplescfg sendSamplescfg = gotSamplescfg.Data.AsInterface <SendSamplescfg>(); if (sendSamplescfg == null) { Log.Write(LogLevel.Error, Script.ID.ToString(), "Unable to create interface, check logs for missing member(s)"); return; } //Log.Write("Raver: Sample Count: " + sendSamplescfg.SendSampleLibrarycfg.Count()); Sample1 = sendSamplescfg.SendSampleLibrarycfg.ElementAt(0); BeatBlockSampleConfigSub.Unsubscribe(); }
public void Play(SoundResource resource) { if (resource == null) { throw new ArgumentNullException("resource"); } // Playing sounds on AppleIIgs is not supported if (this.Preferences.SoundHardwareEnabled && this.Interpreter.GameInfo.Platform != Platform.AppleIIgs) { this.soundChannels = this.Preferences.SoundSingleChannel ? new SoundChannel[1] : new SoundChannel[4]; for (int i = 0; i < this.soundChannels.Length; i++) { SoundChannel channel = new SoundChannel(); channel.Data = resource.GetChannelData(i); channel.DataIndex = 0; channel.Duration = 0; channel.DissolveCount = 0xffff; channel.Avail = 0xffff; channel.FreqCount = 0; channel.ToneHandle = this.SoundDriver.Open(i); if (channel.ToneHandle == 0) { Trace.WriteLine("sndgen_play: error opening tone channel."); this.Shutdown(); this.Preferences.SoundHardwareEnabled = false; return; } this.soundChannels[i] = channel; } this.soundPlaying = true; this.SoundDriver.SetState(true); } else { this.State.Flags[this.SoundFlag] = true; } }
private HUDNotificationControl ShowInternal( string title, string message, Brush brushBackground, Brush brushBorder, ITextureResource icon, Action onClick, bool autoHide, SoundResource soundToPlay) { Api.Logger.Important( string.Format( "Showing notification:{0}Title: {1}{0}Message: {2}", Environment.NewLine, title, message)); var notificationControl = HUDNotificationControl.Create( title, message, brushBackground, brushBorder, icon, onClick, autoHide, soundToPlay); this.HideSimilarNotifications(notificationControl); this.stackPanelChildren.Add(notificationControl); if (notificationControl.IsAutoHide) { // hide the notification control after delay ClientComponentTimersManager.AddAction( NotificationHideDelaySeconds, () => notificationControl.Hide(quick: false)); } this.HideOldNotificationsIfTooManyDisplayed(); return(notificationControl); }
public static HUDNotificationControl Show( string title, string message, Brush brushBackground, Brush brushBorder, ITextureResource icon, Action onClick, bool autoHide, SoundResource soundToPlay) { return(instance.ShowInternal(title, message, brushBackground, brushBorder, icon, onClick, autoHide, soundToPlay)); }
private FMOD.RESULT NonBlockCallbackMethod(IntPtr soundRaw, FMOD.RESULT result) { if (result != FMOD.RESULT.OK) { throw new Exception("FMOD Error: " + result); } int raw = soundRaw.ToInt32(); if (!loadingSoundResources.ContainsKey(raw)) { return(FMOD.RESULT.OK); } SoundResource soundResource = loadingSoundResources[raw]; loadingSoundResources.Remove(raw); InitiateLoadedSound(soundResource); return(FMOD.RESULT.OK); }
public void InitiateLoadedSound(SoundResource soundResource) { // set sound properties based on information in soundResource var sound = (JMOD.ISound)soundResource.SoundGlue.InnerSoundObject; soundResource.BaseFrequency = sound.Frequency; sound.Frequency = soundResource.PlaybackSpeed * soundResource.BaseFrequency; sound.DefaultVolume = soundResource.Volume; sound.Priority = (int)soundResource.Priority; if (soundResource.SoundGroupEnum != SoundGroups.Default) sound.SoundGroupName = soundResource.SoundGroup.Name; }
public void LoadAnySound(SoundResource soundResource, string fullPath) { // load sounds from harddrive based on information in soundResource #if JMOD_IGNORENOTIMPL if (fullPath.ToLower().EndsWith(".mp3")) return; #endif ISound sound; if (soundResource.IsStream) sound = SoundSystem.CreateStream(fullPath, soundResource.Is3DSound ? MODE._3D : MODE._2D); else sound = SoundSystem.CreateSound(fullPath, soundResource.Is3DSound ? MODE._3D : MODE._2D); soundResource.SoundGlue = new JMODSound(sound); InitiateLoadedSound(soundResource); }