/// <summary> /// Initializes a new instance of the <see cref="SoundBank"/> class from a soundbank stream. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="stream">The soundbank stream stream.</param> /// <unmanaged>HRESULT IXACT3Engine::CreateSoundBank([In] const void* pvBuffer,[In] unsigned int dwSize,[In] unsigned int dwFlags,[In] unsigned int dwAllocAttributes,[Out, Fast] IXACT3SoundBank** ppSoundBank)</unmanaged> public SoundBank(AudioEngine audioEngine, Stream stream) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; soundBankSourceStream = stream as DataStream ?? DataStream.Create(Utilities.ReadStream(stream), true, true); audioEngine.CreateSoundBank(soundBankSourceStream.DataPointer, (int)soundBankSourceStream.Length, 0, 0, this); }
/// <summary> /// Initializes a new instance of the <see cref="SoundBank"/> class from a soundbank stream. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="stream">The soundbank stream stream.</param> /// <unmanaged>HRESULT IXACT3Engine::CreateSoundBank([In] const void* pvBuffer,[In] unsigned int dwSize,[In] unsigned int dwFlags,[In] unsigned int dwAllocAttributes,[Out, Fast] IXACT3SoundBank** ppSoundBank)</unmanaged> public SoundBank(AudioEngine audioEngine, Stream stream) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; soundBankSourceStream = stream as DataStream ?? DataStream.Create(Utilities.ReadStream(stream), true, true); audioEngine.CreateSoundBank(soundBankSourceStream.PositionPointer, (int)(soundBankSourceStream.Length - soundBankSourceStream.Position), 0, 0, this); callback = OnNotificationDelegate; }
public static MyInMemoryWaveBank Create(AudioEngine engine, string filename) { DataStream ds; using (FileStream fs = File.OpenRead(filename)) { ds = new DataStream((int)fs.Length, true, true); fs.CopyTo(ds); ds.Position = 0; } var result = new MyInMemoryWaveBank(engine, ds); result.m_backingStore = ds; return result; }
/// <summary> /// Initializes a new instance of the <see cref="WaveBank"/> class from a wave bank stream. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="stream">The wave bank stream.</param> /// <unmanaged>HRESULT IXACT3Engine::CreateInMemoryWaveBank([In] const void* pvBuffer,[In] unsigned int dwSize,[In] unsigned int dwFlags,[In] unsigned int dwAllocAttributes,[Out, Fast] IXACT3WaveBank** ppWaveBank)</unmanaged> public WaveBank(AudioEngine audioEngine, Stream stream) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; if (stream is DataStream) { audioEngine.CreateInMemoryWaveBank(((DataStream) stream).PositionPointer, (int) (stream.Length - stream.Position), 0, 0, this); return; } rawBuffer = Utilities.ReadStream(stream); rawBufferHandle = GCHandle.Alloc(rawBuffer, GCHandleType.Pinned); audioEngine.CreateInMemoryWaveBank(rawBufferHandle.AddrOfPinnedObject(), rawBuffer.Length, 0, 0, this); }
/// <summary> /// SharpDX XACT3 sample. Plays a sound. /// </summary> static void Main(string[] args) { // Loading settings var settings = File.OpenRead("TestWithSharpDX.xgs"); var xact3 = new AudioEngine(CreationFlags.DebugMode, settings); // Loads WaveBank var waveBankStream = File.OpenRead("Ergon.xwb"); var waveBank = new WaveBank(xact3, waveBankStream); // Loads SoundBank var soundBankStream = File.OpenRead("Ergon.xsb"); var soundBank = new SoundBank(xact3, soundBankStream); // Prepare a cue var cue = soundBank.Prepare(soundBank.GetCueIndex("ergon")); // Register Notification for testing purpose cue.OnNotification += ((from,notif) => Console.WriteLine("Received event {0}", notif.Type) ); cue.RegisterNotification(NotificationType.CueStop); // Plays the cue cue.Play(); // Log a message Console.WriteLine("Playing ergon cue"); // Wait until its done int count = 0; while (cue.State != CueState.Stopped && !IsKeyPressed(ConsoleKey.Escape)) { xact3.DoWork(); Thread.Sleep(10); if (count == 50) { Console.Write("."); Console.Out.Flush(); count = 0; } Thread.Sleep(10); count++; } Thread.Sleep(2000); xact3.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="WaveBank"/> class from a wave bank stream. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="stream">The wave bank stream.</param> /// <unmanaged>HRESULT IXACT3Engine::CreateInMemoryWaveBank([In] const void* pvBuffer,[In] unsigned int dwSize,[In] unsigned int dwFlags,[In] unsigned int dwAllocAttributes,[Out, Fast] IXACT3WaveBank** ppWaveBank)</unmanaged> public WaveBank(AudioEngine audioEngine, Stream stream) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; if (stream is DataStream) { audioEngine.CreateInMemoryWaveBank(((DataStream) stream).DataPointer, (int) stream.Length, 0, 0, this); return; } var data = Utilities.ReadStream(stream); unsafe { fixed (void* pData = data) audioEngine.CreateInMemoryWaveBank((IntPtr)pData, data.Length, 0, 0, this); } }
/// <summary> /// Initializes a new instance of the <see cref="WaveBank"/> class from a file for async reading. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="fileName">Name of the file to load the wavebank from.</param> /// <param name="offset">The offset into the stream.</param> /// <param name="packetSize">Packet size used to load the stream.</param> public WaveBank(AudioEngine audioEngine, string fileName, int offset, short packetSize) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; var handle = NativeFile.Create(fileName, NativeFileAccess.Read, NativeFileShare.Read | NativeFileShare.Write, IntPtr.Zero, NativeFileMode.Open, NativeFileOptions.Normal | NativeFileOptions.NoBuffering | NativeFileOptions.Overlapped | NativeFileOptions.SequentialScan, IntPtr.Zero); if (handle == IntPtr.Zero || handle.ToInt32() == -1) throw new FileNotFoundException("Unable to open the specified file.", fileName); var streamingParameters = new StreamingParameters {File = handle, Flags = 0, Offset = offset, PacketSize = packetSize}; audioEngine.CreateStreamingWaveBank(streamingParameters, this); FileStreamHandle = new SafeFileHandle(handle, true); }
/// <summary> /// Initializes a new instance of the <see cref="WaveBank"/> class from a file for async reading. /// </summary> /// <param name="audioEngine">The engine.</param> /// <param name="fileName">Name of the file to load the wavebank from.</param> /// <param name="offset">The offset into the stream.</param> /// <param name="packetSize">Packet size used to load the stream.</param> public WaveBank(AudioEngine audioEngine, string fileName, int offset, short packetSize) { this.audioEngine = audioEngine; isAudioEngineReadonly = true; var handle = NativeFile.Create(fileName, NativeFileAccess.Read, NativeFileShare.Read | NativeFileShare.Write, IntPtr.Zero, NativeFileMode.Open, NativeFileOptions.Normal | NativeFileOptions.NoBuffering | NativeFileOptions.Overlapped | NativeFileOptions.SequentialScan, IntPtr.Zero); if (handle == IntPtr.Zero || handle.ToInt32() == -1) { throw new FileNotFoundException("Unable to open the specified file.", fileName); } var streamingParameters = new StreamingParameters { File = handle, Flags = 0, Offset = offset, PacketSize = packetSize }; audioEngine.CreateStreamingWaveBank(streamingParameters, this); FileStreamHandle = new SafeFileHandle(handle, true); }
public AudioCategory(AudioEngine audioEngine, string categoryName) { this.m_index = audioEngine.GetCategory(categoryName); this.m_audioEngine = audioEngine; this.m_name = categoryName; }
public MyX3DAudio(AudioEngine engine) { m_x3dAudio = new X3DAudio(engine.FinalMixFormat.ChannelMask); m_dsp = new DspSettings(1, engine.FinalMixFormat.Channels); }
private MyInMemoryWaveBank(AudioEngine engine, DataStream dataStream) : base(engine, dataStream) { }
public static void LoadData() { MyMwcLog.WriteLine("MyAudio.LoadData - START"); MyMwcLog.IncreaseIndent(); m_canPlay = true; try { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("new AudioEngine"); //TimeSpan timeSpan = TimeSpan.FromMilliseconds(250); //m_audioEngine = new AudioEngine(MyPlugins.GetAudioFolder() + "Audio.xgs", timeSpan, ""); using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Audio.xgs")) { m_audioEngine = new AudioEngine(file); m_cuePool = new MyCuePool(m_audioEngine); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyX3DAudio"); m_x3dAudio = new MyX3DAudio(m_audioEngine); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } catch (Exception ex) { MyMwcLog.WriteLine("Exception during loading audio engine. Game continues, but without sound. Details: " + ex.ToString(), LoggingOptions.AUDIO); // This exception is the only way I can know if we can play sound (e.g. if computer doesn't have sound card). // I didn't find other ways of checking it. m_canPlay = false; } if (m_canPlay) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyXactVariables.LoadData"); MyXactVariables.LoadData(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddWaveBanks"); // IMPORTANT!!! Currently, there is problem with multiple XACT projects, that when anything changes in Music.xap or Voice.xap, // it is necessary to open and save Sounds.xap also, in order to run the game properly(otherwise it has problem to load the SoundBank.xsb) // this will be solved later in future AddWaveBanks(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Adding sound banks"); MyMwcLog.WriteLine("Adding sound banks", LoggingOptions.AUDIO); using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Music.xsb")) { m_musicSoundBank = new SoundBank(m_audioEngine, file); } using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Sounds.xsb")) { m_sfxSoundBank = new SoundBank(m_audioEngine, file); } using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Dialogues.xsb")) { m_dialogueSoundBank = new SoundBank(m_audioEngine, file); } using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Voice.xsb")) { m_voiceSoundBank = new SoundBank(m_audioEngine, file); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Categories"); //m_voiceSoundBank = new SoundBank(m_audioEngine, MyPlugins.GetAudioFolder() + "Voice.xsb"); m_listener = new Listener(); m_listener.SetDefaultValues(); m_helperEmitter = new Emitter(); m_helperEmitter.SetDefaultValues(); m_defaultCategory = m_audioEngine.GetCategoryInstance("Default"); m_wep2DCategory = m_audioEngine.GetCategoryInstance("wep2d"); m_cockpitCategory = m_audioEngine.GetCategoryInstance("Cockpit"); m_musicCategory = m_audioEngine.GetCategoryInstance("Music"); m_guiCategory = m_audioEngine.GetCategoryInstance("Gui"); m_doorCategory = m_audioEngine.GetCategoryInstance("Door"); m_enginesCategory = m_audioEngine.GetCategoryInstance("Engines"); m_dialogueCategory = m_audioEngine.GetCategoryInstance("Dialogues"); m_shoutsCategory = m_audioEngine.GetCategoryInstance("Shouts"); m_hudCategory = m_audioEngine.GetCategoryInstance("VocHud"); m_ambCategory = m_audioEngine.GetCategoryInstance("Amb"); m_drillsCategory = m_audioEngine.GetCategoryInstance("Drills"); m_impCategory = m_audioEngine.GetCategoryInstance("Imp"); m_importantsCategory = m_audioEngine.GetCategoryInstance("IMPORTANTS"); m_sfxCategory = m_audioEngine.GetCategoryInstance("Sfx"); m_voiceCategory = m_audioEngine.GetCategoryInstance("Voice"); m_welcomeCategory = m_audioEngine.GetCategoryInstance("Welcomes"); m_wep3DCategory = m_audioEngine.GetCategoryInstance("Wep3D"); m_xCategory = m_audioEngine.GetCategoryInstance("X"); m_gameCategories = new List<AudioCategory>(); m_gameCategories.Add(m_defaultCategory); m_gameCategories.Add(m_wep2DCategory); m_gameCategories.Add(m_cockpitCategory); m_gameCategories.Add(m_doorCategory); m_gameCategories.Add(m_enginesCategory); m_gameCategories.Add(m_dialogueCategory); m_gameCategories.Add(m_shoutsCategory); m_gameCategories.Add(m_hudCategory); m_gameCategories.Add(m_ambCategory); m_gameCategories.Add(m_drillsCategory); m_gameCategories.Add(m_impCategory); m_gameCategories.Add(m_importantsCategory); m_gameCategories.Add(m_sfxCategory); m_gameCategories.Add(m_voiceCategory); m_gameCategories.Add(m_welcomeCategory); m_gameCategories.Add(m_wep3DCategory); m_gameCategories.Add(m_xCategory); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("WaitForWaveBanks"); // AudioEngine.Update needs to be called at least once before a streaming wave bank is ready MyMwcLog.WriteLine("Updating audio engine...", LoggingOptions.AUDIO); WaitForWaveBanks(); // This is reverb turned to off, so we hear sounds as they are defined in wav files ReverbControl = 100; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("PreloadCueInfo"); PreloadCueInfo(); // Takes about 26 ms MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("ValidateCues"); #if DEBUG ThreadPool.QueueUserWorkItem(ValidateCue_Thread); // Takes 4000 ms on background thread #endif MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitCueParameters"); InitCueParameters(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitNonLoopableCuesLimitRemoveHelper"); InitNonLoopableCuesLimitRemoveHelper(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyHudAudio.LoadData"); MyHudAudio.LoadData(); // Volume from config m_musicOn = true; m_gameSoundsOn = true; m_musicAllowed = true; VolumeMusic = MyConfig.MusicVolume; VolumeGame = MyConfig.GameVolume; VolumeGui = MyConfig.GameVolume; MyConfig.MusicVolume = VolumeMusic; MyConfig.GameVolume = VolumeGame; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Save"); MyConfig.Save(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } MyMwcLog.DecreaseIndent(); MyMwcLog.WriteLine("MyAudio.LoadData - END"); }
public static void SetVariable(AudioEngine engine, MyGlobalVariableEnum variableEnum, float value) { var varInfo = m_glovalVariables[(int)variableEnum]; if (varInfo.VariableIndex == -1 || CacheEnabled == false) { varInfo.VariableIndex = engine.GetGlobalVariableIndex(varInfo.VariableName); m_glovalVariables[(int)variableEnum].VariableIndex = varInfo.VariableIndex; } engine.SetGlobalVariable(varInfo.VariableIndex, value); }