public XAudio2Driver(Configuration config) { IsDisposed = false; try { _isBusy = new WaitableBool(false); _device = new XAudio2(); _masterVoice = new MasteringVoice(_device); _sourceVoice = new SourceVoice(_device, new WaveFormat() { FormatTag = WaveFormatTag.Pcm, Channels = 2, BitsPerSample = 16, SamplesPerSecond = 32040, AverageBytesPerSecond = 2 * (16 / 8) * 32040, BlockAlignment = 2 * (16 / 8) }, VoiceFlags.None, 2.0F); _sourceVoice.BufferStart += (s, e) => { if (_sourceVoice.State.BuffersQueued < BufferCount) { _isBusy.Value = false; } }; _buffers = new byte[BufferCount][]; _bufferStreams = new DataStream[BufferCount]; for (int i = 0; i < BufferCount; i++) { _buffers[i] = new byte[Snes.MaxAudioBufferLength * 4]; _bufferStreams[i] = new DataStream(_buffers[i], true, false); } _bufferCursor = 0; _audioBuffer = new AudioBuffer(); _isPaused = true; } catch { Dispose(); throw; } }
public Direct3D11Driver(Form form, Configuration config) : base(form, new SwapChainDescription() { IsWindowed = true, BufferCount = 1, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, Flags = SwapChainFlags.None, SampleDescription = new SampleDescription(1, 0), ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(), Format.R8G8B8A8_UNorm) }) { IsDisposed = false; try { _workerThread = new WorkerThread(); _isBusy = new WaitableBool(false); _context = D3D11Device.ImmediateContext; _backBufferView = GetBackBufferView(); _context.OutputMerger.SetTargets(_backBufferView); Viewport viewPort = new Viewport() { X = 0, Y = 0, Width = form.ClientSize.Width, Height = form.ClientSize.Height, MinZ = 0.0F, MaxZ = 1.0F }; _context.Rasterizer.SetViewports(viewPort); _effectBytecode = ShaderBytecode.CompileFromFile("Effect.fx", " ", "fx_5_0", ShaderFlags.None, EffectFlags.None, null, null); _effect = new Effect(D3D11Device, _effectBytecode, EffectFlags.None); _technique = _effect.GetTechniqueByIndex(0); _pass = _technique.GetPassByIndex(0); InputElement[] elements = new InputElement[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0) }; _layout = new InputLayout(D3D11Device, _pass.Description.Signature, elements); DataStream stream = new DataStream(4 * Marshal.SizeOf(typeof(Vertex)), true, true); stream.Write(new Vector4(-1.0F, 1.0F, 0.5F, 1.0F)); stream.Write(new Vector2(0.0F, 0.0F)); stream.Write(new Vector4(1.0F, 1.0F, 0.5F, 1.0F)); stream.Write(new Vector2(1.0F, 0.0F)); stream.Write(new Vector4(-1.0F, -1.0F, 0.5F, 1.0F)); stream.Write(new Vector2(0.0F, 1.0F)); stream.Write(new Vector4(1.0F, -1.0F, 0.5F, 1.0F)); stream.Write(new Vector2(1.0F, 1.0F)); stream.Position = 0; _vertices = new Buffer(D3D11Device, stream, new BufferDescription() { SizeInBytes = (int)stream.Length, BindFlags = BindFlags.VertexBuffer, Usage = ResourceUsage.Default, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }); stream.Close(); _texture = new Texture2D(D3D11Device, new Texture2DDescription() { Width = 512, Height = 512, Format = Format.R8G8B8A8_UNorm, ArraySize = 1, MipLevels = 1, Usage = ResourceUsage.Dynamic, CpuAccessFlags = CpuAccessFlags.Write, BindFlags = BindFlags.ShaderResource, SampleDescription = SwapChainDescription.SampleDescription }); _textureView = new ShaderResourceView(D3D11Device, _texture); _effect.GetVariableByName("InputTexture").AsResource().SetResource(_textureView); } catch { Dispose(); throw; } }
public ReadOnlyWaitableBool(WaitableBool wBool) { if (wBool == null) { throw new ArgumentNullException("wBool"); } _wBool = wBool; }