public SDLAudio () { this.on = Settings.Audio_PlaybackEnabled; if (on) { try { Mixer.Initialize (); // TODO: find another way to adjust volume this.Volume = Settings.Audio_PlaybackVolume; callback = new AudioCallback (Signed16BigCallback); audio_stream = new AudioStream (Settings.Audio_PlaybackFrequency, AudioFormat.Signed16Big, SoundChannel.Mono, 2205, callback, "My Nes Sound"); samples_buffer = new short[samples_count]; Mixer.OpenAudio (audio_stream); audio_stream.Paused = true; r_pos = w_pos = 0; } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } } recorder = new WaveRecorder (); }
//static void CheckOpenStatus() //{ // if (!audioOpen) // { // throw new AudioException(Events.StringManager.GetString("OpenAudioNotInit", CultureInfo.CurrentUICulture)); // } //} internal static void CheckOpenStatus(AudioStream stream) { if (!audioOpen) { Mixer.OpenAudio(stream); audioOpen = true; } }
/// <summary> /// Open Audio device /// </summary> /// <param name="stream">stream to open</param> public static void OpenAudio(AudioStream stream) { Close(); if (stream == null) { throw new ArgumentNullException("stream"); } IntPtr pSpec = Marshal.AllocHGlobal(Marshal.SizeOf(stream.Spec)); try { Marshal.StructureToPtr(stream.Spec, pSpec, false); if (Sdl.SDL_OpenAudio(pSpec, IntPtr.Zero) < 0) { throw new AudioException(); } stream.Spec = (Sdl.SDL_AudioSpec)Marshal.PtrToStructure(pSpec, typeof(Sdl.SDL_AudioSpec)); if (((ushort)stream.Spec.format & 0x8000) == 0x8000) // signed { stream.Offset = 0; } else { stream.Offset = 2 << ((byte)stream.Spec.format - 2); } Mixer.AudioOpen = true; } finally { Marshal.FreeHGlobal(pSpec); } }
private void Go() { if (File.Exists(fileName)) { filePath = ""; fileDirectory = ""; } else if (File.Exists(Path.Combine(fileDirectory, fileName))) { filePath = ""; } string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName); textDisplay = new TextSprite(" ", new SdlDotNet.Graphics.Font(file, 20), Color.Red); Video.WindowIcon(); Video.WindowCaption = "SDL.NET - StreamingAudio"; screen = Video.SetVideoMode(width, height); switch (streamChoice) { case StreamChoice.InternalCallback: stream = new AudioStream(playbackFreq, AudioFormat.Unsigned16Little, SoundChannel.Mono, samples); buffer16 = new short[samples]; break; case StreamChoice.CustomCallback: callback = new AudioCallback(Unsigned16LittleCallback); stream = new AudioStream(playbackFreq, AudioFormat.Unsigned16Little, SoundChannel.Mono, samples, callback, "Hello World"); buffer16 = new short[samples]; break; case StreamChoice.CustomCallback8Bit: callback = new AudioCallback(Unsigned8Callback); stream = new AudioStream(playbackFreq, AudioFormat.Unsigned8, SoundChannel.Mono, samples, new AudioCallback(Unsigned8Callback), "Hello World"); buffer8 = new byte[samples]; break; default: stream = new AudioStream(playbackFreq, AudioFormat.Unsigned16Little, SoundChannel.Mono, samples); buffer16 = new short[samples]; break; } offset = stream.Offset; volume = 0.9 * 32768; buffer16 = new short[samples]; osc.Rate = 20; osc.Amplitude = 1; osc2.Rate = 3; osc2.Amplitude = 10; stream.Paused = false; textDisplay.Text = SdlDotNetExamplesBrowser.StringManager.GetString( "StreamingAudioDirections", CultureInfo.CurrentUICulture); textDisplay.TextWidth = 350; Events.Run(); }
/// <summary> /// /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.textDisplay != null) { this.textDisplay.Dispose(); this.textDisplay = null; } if (this.stream != null) { this.stream.Dispose(); this.stream = null; } } this.disposed = true; } }