コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        static void WriteLinearBlastStereo16( )
        {
            Int32 i;
            Int32 val;

            for (i = 0; i < snd_linear_count; i += 2)
            {
                val = snd_p.Get(i) >> 8;
                if (val > 0x7fff)
                {
                    snd_out.Put(i, unchecked (( Int16 )0x7fff));
                }
                else if (val < unchecked (( Int16 )0x8000))
                {
                    snd_out.Put(i, unchecked (( Int16 )0x8000));
                }
                else
                {
                    snd_out.Put(i, unchecked (( Int16 )val));
                }
                val = snd_p.Get(i + 1) >> 8;
                if (val > 0x7fff)
                {
                    snd_out.Put(i + 1, unchecked (( Int16 )0x7fff));
                }
                else if (val < unchecked (( Int16 )0x8000))
                {
                    snd_out.Put(i + 1, unchecked (( Int16 )0x8000));
                }
                else
                {
                    snd_out.Put(i + 1, unchecked (( Int16 )val));
                }
            }
        }
コード例 #4
0
        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;
                    }
                }
            }
        }