コード例 #1
0
 public void GetNext(byte[] buffer)
 {
     CrossPlatformHelper.Assert(sampleBuffer.Length * 2 == buffer.Length, "Output buffer length must equal RawBufferSize!");
     Array.Clear(sampleBuffer, 0, sampleBuffer.Length);
     FillWorkingBuffer();
     ConvertWorkingBuffer(buffer, sampleBuffer);
 }
コード例 #2
0
        public SampleDataAsset(string name, WaveFile wave)
        {
            if (name == null)
            {
                throw new ArgumentNullException("An asset must be given a valid name.");
            }
            assetName = name;
            SamplerChunk smpl = wave.FindChunk <SamplerChunk>();

            if (smpl != null)
            {
                sampleRate = (int)(44100.0 * (1.0 / (smpl.SamplePeriod / 22675.0)));
                rootKey    = (short)smpl.UnityNote;
                tune       = (short)(smpl.PitchFraction * 100);
                if (smpl.Loops.Length > 0)
                {
                    CrossPlatformHelper.Assert(smpl.Loops[0].Type == SamplerChunk.SampleLoop.LoopType.Forward, "Warning: Unsupported LoopType in " + assetName);
                    loopStart = smpl.Loops[0].Start;
                    loopEnd   = smpl.Loops[0].End + smpl.Loops[0].Fraction + 1;
                }
            }
            else
            {
                sampleRate = wave.Format.SampleRate;
            }
            sampleData = WaveHelper.GetSampleData(wave, audioChannels);
            start      = 0;
            end        = sampleData.Length;
        }
コード例 #3
0
ファイル: WaveFileWriter.cs プロジェクト: MSylvia/DoomEngine
 public void Write(float[] left_buffer, float[] right_buffer)
 {
     CrossPlatformHelper.Assert(channels == 2, "Mismatched channels! Output expects : " + channels + " channels.");
     if (left_buffer == null || right_buffer == null)
     {
         throw new ArgumentException("One or more input buffers were null!");
     }
     Write(WaveHelper.GetRawData(left_buffer, right_buffer, bits));
 }
コード例 #4
0
ファイル: WaveHelper.cs プロジェクト: MSylvia/DoomEngine
        public static float[] Deinterleave(float[] data, int channelCount, int channel)
        {
            CrossPlatformHelper.Assert(channel >= 0 && channel < channelCount, "Channel must be non-negative and less than the channel count.");
            CrossPlatformHelper.Assert(data != null && data.Length % channelCount == 0, "The data provided is invalid or channel count is incorrect.");

            float[] sampleData = new float[data.Length / channelCount];

            for (int x = 0; x < sampleData.Length; x++)
            {
                sampleData[x] = data[x * channelCount + channel];
            }
            return(sampleData);
        }