public void RawSamples(int samples, int rate, int width, int channels, ByteBuffer data) { int format; if (channels == 2) { format = (width == 2) ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_STEREO8; } else { format = (width == 2) ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_MONO8; } if (format == AL10.AL_FORMAT_MONO8) { Int16Buffer sampleData = streamBuffer; int value; for (int i = 0; i < samples; i++) { value = (data.Get(i) & 0xFF) - 128; sampleData.Put(i, (short)value); } format = AL10.AL_FORMAT_MONO16; width = 2; data = sfxDataBuffer.Slice(); } Channel.UpdateStream(data, samples * channels * width, format, rate); }
public void RawSamples(Int32 samples, Int32 rate, Int32 width, Int32 channels, ByteBuffer data) { ALFormat format; if (channels == 2) { format = (width == 2) ? ALFormat.Stereo16 : ALFormat.Stereo8; } else { format = (width == 2) ? ALFormat.Mono16 : ALFormat.Mono8; } if (format == ALFormat.Mono8) { Int16Buffer sampleData = streamBuffer; Int32 value; for (var i = 0; i < samples; i++) { value = (data.Get(i) & 0xFF) - 128; sampleData.Put(i, ( Int16 )value); } format = ALFormat.Mono16; width = 2; data = sfxDataBuffer.Slice(); } Channel.UpdateStream(data, samples * channels * width, format, rate); }
static void PaintChannelFrom16(channel_t ch, sfxcache_t sc, Int32 count, Int32 offset) { Int32 data; Int32 left, right; Int32 leftvol, rightvol; Int32 sfx; Int32 i; portable_samplepair_t samp; leftvol = ch.leftvol * snd_vol; rightvol = ch.rightvol * snd_vol; ByteBuffer bb = ByteBuffer.Wrap(sc.data); bb.Order = ByteOrder.LittleEndian; sb = bb.AsInt16Buffer(); sfx = ch.pos; for (i = 0; i < count; i++, offset++) { left = paInt32Buffer.Get(offset * 2); right = paInt32Buffer.Get(offset * 2 + 1); data = sb.Get(sfx + i); left += (data * leftvol) >> 8; right += (data * rightvol) >> 8; paInt32Buffer.Put(offset * 2, left); paInt32Buffer.Put(offset * 2 + 1, right); } ch.pos += count; }
static void TransferStereo16(ByteBuffer pbuf, Int32 endtime) { Int32 lpos; Int32 lpaintedtime; snd_p = paInt32Buffer; lpaintedtime = paintedtime; while (lpaintedtime < endtime) { lpos = lpaintedtime & ((dma.samples >> 1) - 1); snd_out = pbuf.AsInt16Buffer(); snd_out.Position = lpos << 1; snd_out = snd_out.Slice(); snd_linear_count = (dma.samples >> 1) - lpos; if (lpaintedtime + snd_linear_count > endtime) { snd_linear_count = endtime - lpaintedtime; } snd_linear_count <<= 1; WriteLinearBlastStereo16(); paInt32Buffer.Position = snd_linear_count; snd_p = paInt32Buffer.Slice(); lpaintedtime += (snd_linear_count >> 1); } }
public override void SetUp() { base.SetUp(); buf = Int16Buffer.Allocate(BUFFER_LENGTH); base.loadTestData1(buf); buf = buf.AsReadOnlyBuffer(); baseBuf = buf; }
public override void SetUp() { base.SetUp(); buf = Int16Buffer.Wrap(new short[BUFFER_LENGTH]); base.loadTestData1(buf); buf = buf.AsReadOnlyBuffer(); baseBuf = buf; }
public StreamingBuffer(WaveFormat waveformat) { _SamplingRate = waveformat.SampleRate; _Channels = waveformat.Channels; bufwaveprovider16 = new BufferedWaveProvider(new WaveFormat(_SamplingRate, 16, _Channels)); volume = new VolumeWaveProvider16(bufwaveprovider16); volume.Volume = 0.1F; ChannelBuffers = new Int16Buffer[2]; ChannelBuffers[0] = new Int16Buffer(); ChannelBuffers[1] = new Int16Buffer(); }
public StreamingBuffer(WaveFormat waveformat) { _SamplingRate = waveformat.SampleRate; _Channels = waveformat.Channels; bufwaveprovider16 = new BufferedWaveProvider(new WaveFormat(_SamplingRate, 16, _Channels)); volume = new VolumeWaveProvider16(bufwaveprovider16); //volume.Volume = 0.1F; ChannelBuffers = new Int16Buffer[2]; ChannelBuffers[0] = new Int16Buffer(); ChannelBuffers[1] = new Int16Buffer(); _streambuffermsec = 500;//小さいほど良いが正常動作する限界値をセットしたい。この値を下回るタイミングでbufwaveproviderにバッファを追加していく }
public override Int16Buffer Put(Int16Buffer buffer) { throw new ReadOnlyBufferException(); }
static void TransferPaInt32Buffer(Int32 endtime) { Int32 out_idx; Int32 count; Int32 out_mask; Int32 p; Int32 step; Int32 val; ByteBuffer pbuf = ByteBuffer.Wrap(dma.buffer); pbuf.Order = ByteOrder.LittleEndian; if (SND_DMA.s_testsound.value != 0F) { Int32 i; Int32 count2; count2 = (endtime - paintedtime) * 2; Int32 v; for (i = 0; i < count2; i += 2) { v = ( Int32 )(Math.Sin((paintedtime + i) * 0.1) * 20000 * 256); paInt32Buffer.Put(i, v); paInt32Buffer.Put(i + 1, v); } } if (dma.samplebits == 16 && dma.channels == 2) { TransferStereo16(pbuf, endtime); } else { p = 0; count = (endtime - paintedtime) * dma.channels; out_mask = dma.samples - 1; out_idx = paintedtime * dma.channels & out_mask; step = 3 - dma.channels; if (dma.samplebits == 16) { Int16Buffer out_renamed = pbuf.AsInt16Buffer(); while (count-- > 0) { val = paInt32Buffer.Get(p) >> 8; p += step; if (val > 0x7fff) { val = 0x7fff; } else if (val < unchecked (( Int16 )0x8000)) { val = unchecked (( Int16 )0x8000); } out_renamed.Put(out_idx, ( Int16 )val); out_idx = (out_idx + 1) & out_mask; } } else if (dma.samplebits == 8) { ByteBuffer out_renamed = pbuf; while (count-- > 0) { val = paInt32Buffer.Get(p) >> 8; p += step; if (val > 0x7fff) { val = 0x7fff; } else if (val < unchecked (( Int16 )0x8000)) { val = unchecked (( Int16 )0x8000); } out_renamed.Put(out_idx, ( Byte )(val >> 8)); out_idx = (out_idx + 1) & out_mask; } } } }