Пример #1
0
        public void AlignedAdpcmIsCorrect(int multiple, int loopStart, int sineCycles, int tolerance)
        {
            int loopEnd = sineCycles * 4 * SamplesPerFrame + loopStart;

            short[] pcm       = GenerateSineWave(GetNextMultiple(loopEnd, SamplesPerFrame), 1, SamplesPerFrame * 4);
            short[] coefs     = GcAdpcmCoefficients.CalculateCoefficients(pcm);
            byte[]  adpcm     = GcAdpcmEncoder.Encode(pcm, coefs);
            var     alignment = new GcAdpcmAlignment(multiple, loopStart, loopEnd, adpcm, coefs);

            short[] pcmAligned = GcAdpcmDecoder.Decode(alignment.AdpcmAligned, coefs, new GcAdpcmParameters {
                SampleCount = alignment.SampleCountAligned
            });
            short[] pcmExpected = GenerateSineWave(alignment.SampleCountAligned, 1, SamplesPerFrame * 4);

            var diff = new double[alignment.SampleCountAligned];

            //Skip the first sine cycle and last ADPCM frame due to history samples
            int end = GetNextMultiple(alignment.SampleCountAligned, SamplesPerFrame) - SamplesPerFrame;

            for (int i = SamplesPerFrame * 4; i < end; i++)
            {
                double dist = Math.Abs(pcmExpected[i] - pcmAligned[i]);
                diff[i] = dist;
            }

            Assert.All(diff, x => Assert.InRange(x, 0, tolerance));
        }
Пример #2
0
        public void PassedInDataIsSet(int multiple, int loopStart, int loopEnd, int adpcmLength)
        {
            var alignment = new GcAdpcmAlignment(multiple, loopStart, loopEnd, new byte[adpcmLength], new short[16]);

            int[] expected = new[] { multiple, loopStart, loopEnd };
            int[] actual   = new[] { alignment.AlignmentMultiple, alignment.LoopStart, alignment.LoopEnd };
            Assert.Equal(expected, actual);
        }
Пример #3
0
        public void AlignedLoopPointsAreCorrect(int multiple, int loopStart, int loopEnd, int adpcmLength,
                                                int expectedLoopStart, int expectedLoopEnd)
        {
            var alignment = new GcAdpcmAlignment(multiple, loopStart, loopEnd, new byte[adpcmLength], new short[16]);

            int[] expected = new[] { expectedLoopStart, expectedLoopEnd };
            int[] actual   = new[] { alignment.LoopStartAligned, alignment.SampleCountAligned };
            Assert.Equal(expected, actual);
        }
Пример #4
0
        public void PreviousAlignmentIsValidTest(bool looping, int multiple, int loopStart, int loopEnd, bool expected)
        {
            var previous = new GcAdpcmAlignment(10, 20, 30, new byte[20], new short[16]);
            var builder  = GetBuilder()
                           .WithPrevious(null, null, previous)
                           .WithLoop(looping, loopStart, loopEnd);

            builder.LoopAlignmentMultiple = multiple;

            Assert.Equal(expected, builder.PreviousAlignmentIsValid());
        }
Пример #5
0
        public void SetPreviousAssignsProperly()
        {
            var seekTable   = new GcAdpcmSeekTable(new short[10], 2);
            var loopContext = new GcAdpcmLoopContext(1, 2, 3, 4, true);
            var alignment   = new GcAdpcmAlignment(0, 0, 10, new byte[10], new short[16]);
            var builder     = GetBuilder().WithPrevious(seekTable, loopContext, alignment);

            Assert.Equal(seekTable, builder.PreviousSeekTable);
            Assert.Equal(loopContext, builder.PreviousLoopContext);
            Assert.Equal(alignment, builder.PreviousAlignment);
        }
Пример #6
0
        public void AlignedPcmIsCorrect(int multiple, int loopStart, int sineCycles)
        {
            int loopEnd     = sineCycles * 4 * SamplesPerFrame + loopStart;
            var pcm         = GenerateSineWave(GetNextMultiple(loopEnd, SamplesPerFrame), 1, SamplesPerFrame * 4);
            var coefs       = GcAdpcmCoefficients.CalculateCoefficients(pcm);
            var adpcm       = GcAdpcmEncoder.Encode(pcm, coefs);
            var alignment   = new GcAdpcmAlignment(multiple, loopStart, loopEnd, adpcm, coefs);
            var pcmAligned  = alignment.PcmAligned;
            var pcmExpected = GcAdpcmDecoder.Decode(alignment.AdpcmAligned, coefs, new GcAdpcmParameters {
                SampleCount = alignment.SampleCountAligned
            });

            Assert.Equal(pcmExpected, pcmAligned);
        }
Пример #7
0
        public void CreateAlignmentReplacePreviousWhenLoopChanges(int multiple, int loopStart, int loopEnd)
        {
            var sampleCount = 100;

            var(adpcm, coefs) = GenerateAudio.GenerateAdpcmEmpty(sampleCount);
            var previous = new GcAdpcmAlignment(multiple, loopStart, loopEnd, adpcm, coefs);

            var builder = new GcAdpcmChannelBuilder(adpcm, coefs, sampleCount)
                          .WithLoop(true, loopStart + 1, loopEnd + 1)
                          .WithPrevious(null, null, previous);

            builder.LoopAlignmentMultiple = multiple;
            var alignment = builder.GetAlignment();

            Assert.NotEqual(previous, alignment);
        }
Пример #8
0
        public void CreateAlignmentWithPrevious(int multiple, int loopStart, int loopEnd)
        {
            int sampleCount = 100;

            (byte[] adpcm, short[] coefs) = GenerateAudio.GenerateAdpcmEmpty(sampleCount);
            var previous = new GcAdpcmAlignment(multiple, loopStart, loopEnd, adpcm, coefs);

            GcAdpcmChannelBuilder builder = new GcAdpcmChannelBuilder(adpcm, coefs, sampleCount)
                                            .WithLoop(true, loopStart, loopEnd)
                                            .WithPrevious(null, null, previous);

            builder.LoopAlignmentMultiple = multiple;
            GcAdpcmAlignment alignment = builder.GetAlignment();

            Assert.Equal(previous, alignment);
        }
Пример #9
0
        public void AlignmentNeeded(int multiple, int loopStart, int loopEnd, int adpcmLength)
        {
            var alignment = new GcAdpcmAlignment(multiple, loopStart, loopEnd, new byte[adpcmLength], new short[16]);

            Assert.True(alignment.AlignmentNeeded);
        }