public void Play(ALBuffer buffer, int channel) { ALSource source = sources[channel]; source.Queue(buffer); source.Play(); }
public override bool Decode(ALBuffer buffer) { if (this.EndOfStream) { return(false); } var read = this.stream.Read(this.sampleBuffer); buffer.Write(sampleBuffer.AsSpan().Slice(0, read), (short)this.channels, (short)this.sampleSize, this.sampleRate); return(true); }
public override bool Decode(ALBuffer buffer) { if (this.EndOfStream) { return(false); } var samplesWritten = 0; Span <float> readBuffer = stackalloc float[ReadSampleCount]; while (samplesWritten < this.sampleBuffer.Length && !this.EndOfStream) { var read = this.reader.ReadSamples(readBuffer); var readSamples = readBuffer.Slice(0, read); for (int readIndex = 0; readIndex < readSamples.Length; readIndex++) { var temp = (int)(short.MaxValue * readSamples[readIndex]); if (temp > short.MaxValue) { temp = short.MaxValue; } else if (temp < short.MinValue) { temp = short.MinValue; } this.sampleBuffer[samplesWritten++] = (short)temp; } } unsafe { fixed(short *bufferedPtr = this.sampleBuffer) { var buffered = new Span <byte>(bufferedPtr, sizeof(short) * samplesWritten); buffer.Write(buffered, (short)this.Channels, (short)this.SampleSize, this.SampleRate); } } return(true); }
public override void Load(ALBuffer buffer) { if (stream is UnmanagedMemoryStream ums) { ReadOnlySpan <byte> umsData; unsafe { umsData = new ReadOnlySpan <byte>(ums.PositionPointer, (int)ums.Length); } buffer.Write(umsData, (short)this.channels, (short)this.sampleSize, this.sampleRate); } else { var sampleData = new byte[this.totalSamples * (this.sampleSize / 8)]; stream.Write(sampleData); buffer.Write(sampleData, (short)this.channels, (short)this.sampleSize, this.sampleRate); } }
public override void Load(ALBuffer buffer) { var channels = this.reader.Channels; var sampleRate = this.reader.SampleRate; var samples = new float[this.reader.TotalSamples]; var totalSamples = this.reader.ReadSamples(samples); var samplesIn16Bit = new short[totalSamples]; for (int i = 0; i < totalSamples; i++) { var temp = (int)(short.MaxValue * samples[i]); if (temp > short.MaxValue) { temp = short.MaxValue; } else if (temp < short.MinValue) { temp = short.MinValue; } samplesIn16Bit[i] = (short)temp; } unsafe { fixed(short *samplesPtr = samplesIn16Bit) { checked { var sampleData = new ReadOnlySpan <byte>(samplesPtr, samples.Length * sizeof(ushort)); buffer.Write(sampleData, (short)channels, (short)this.SampleSize, sampleRate); } } } }
public void Play(ALBuffer buffer) { Play(buffer, nextSource); nextSource = (nextSource + 1) % sources.Length; }
private void _addSoundSourceToolStripButton_Click(object sender, EventArgs e) { if (_openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { var source = new ALSource(); var buffer = new ALBuffer(); buffer.LoadWavFile(_openFileDialog.FileName); source.Buffer = buffer; source.Position = new Vector3(50, 50, 50); source.Looping = true; _sources.Add(source); InvalidateViews(); } }