public void BuildSeekTableOneChannel(Endianness endianness) { short[] expected = { 0, 0, 50, 49, 100, 99 }; GcAdpcmFormat adpcm = GetAscendingAdpcm(50, 112, 0); Assert.Equal(expected.ToByteArray(endianness), adpcm.BuildSeekTable(3, endianness)); }
public void AdpcmDataLengthIsCorrectAfterLooping(int sampleCount, bool looping, int loopStart, int loopEnd) { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmEmpty(sampleCount, 1, 48000) .WithLoop(looping, loopStart, loopEnd); Assert.Equal(SampleCountToByteCount(sampleCount), adpcm.Channels[0].GetAdpcmAudio().Length); }
public void Setup() { _adpcm = GenerateAudio.GenerateAdpcmEmpty((int)(_sampleRate * LengthSeconds), ChannelCount, _sampleRate); _brstm = new BrstmWriter().GetFile(_adpcm); _dsp = new DspWriter().GetFile(_adpcm); _idsp = new IdspWriter().GetFile(_adpcm); }
public void CreatingAudioDataWithAdpcm() { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmSineWave(200, 2, 48000); var audio = new AudioData(adpcm); Assert.Same(adpcm, audio.GetFormat <GcAdpcmFormat>()); }
public void AlignmentAlignsChildChannels() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmChannelsEmpty(100, 2); GcAdpcmFormat adpcm = GcAdpcmFormat.GetBuilder(channels, 32000).WithAlignment(15).WithLoop(true, 10, 100).Build(); Assert.All(adpcm.Channels, x => Assert.Equal(100, x.UnalignedSampleCount)); Assert.All(adpcm.Channels, x => Assert.Equal(105, x.SampleCount)); }
public void ChannelsAreSetAfterCreation() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmChannelsEmpty(100, 2); GcAdpcmFormat adpcm = GcAdpcmFormat.GetBuilder(channels, 32000).Build(); Assert.Equal(channels[0].Adpcm, adpcm.Channels[0].Adpcm); Assert.Equal(channels[1].Adpcm, adpcm.Channels[1].Adpcm); }
public void GettingChannelsThrowsWhenOutOfBounds() { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmSineWave(100, 4, 48000); Exception ex = Record.Exception(() => adpcm.GetChannels(4, 0)); Assert.IsType <ArgumentException>(ex); }
public void CloningAndModifyingDoesNotChangeFirstFormat() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmChannelsEmpty(100, 2); GcAdpcmFormat adpcm = GcAdpcmFormat.GetBuilder(channels, 32000).WithAlignment(15).WithLoop(true, 10, 100).Build(); GcAdpcmFormat unused = adpcm.GetCloneBuilder().WithAlignment(7).Build(); Assert.All(adpcm.Channels, x => Assert.Equal(100, x.UnalignedSampleCount)); Assert.All(adpcm.Channels, x => Assert.Equal(105, x.SampleCount)); }
protected override void SetupWriter(AudioData audio) { Adpcm = audio.GetFormat <GcAdpcmFormat>(new GcAdpcmParameters { Progress = Configuration.Progress }); if (Configuration.BlockSize != 0) { Adpcm = Adpcm.WithAlignment(ByteCountToSampleCount(Configuration.BlockSize)); } }
public void AdpcmDataLengthIsCorrectAfterAlignment(int sampleCount, bool looping, int loopStart, int loopEnd, int alignment) { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmEmpty(sampleCount, 1, 48000) .WithAlignment(alignment) .WithLoop(looping, loopStart, loopEnd); int extraSamples = Helpers.GetNextMultiple(loopStart, alignment) - loopStart; Assert.Equal(SampleCountToByteCount(loopEnd + extraSamples), adpcm.Channels[0].GetAdpcmAudio().Length); }
public void TracksAreSetAfterCreation() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmChannelsEmpty(100, 2); var tracks = new List <AudioTrack> { new AudioTrack(1, 0, 0), new AudioTrack(1, 1, 0) }; GcAdpcmFormat adpcm = GcAdpcmFormat.GetBuilder(channels, 32000).WithTracks(tracks).Build(); Assert.Equal(tracks, adpcm.Tracks); }
public void GettingSpecificChannels() { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmSineWave(100, 4, 48000); GcAdpcmFormat partial = adpcm.GetChannels(2, 0, 2); Assert.Equal(100, partial.SampleCount); Assert.Equal(3, partial.ChannelCount); Assert.Equal(adpcm.Channels[2], partial.Channels[0], new GcAdpcmChannelComparer()); Assert.Equal(adpcm.Channels[0], partial.Channels[1], new GcAdpcmChannelComparer()); Assert.Equal(adpcm.Channels[2], partial.Channels[2], new GcAdpcmChannelComparer()); }
public void AddingFormatsOfDifferentLengthThrows() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmSineWave(100, 2, 48000).Channels; GcAdpcmChannel[] channels2 = GenerateAudio.GenerateAdpcmSineWave(200, 2, 48000).Channels; var adpcm = new GcAdpcmFormat(new[] { channels[0] }, 48000); var adpcm2 = new GcAdpcmFormat(new[] { channels2[1] }, 48000); Exception ex = Record.Exception(() => adpcm.Add(adpcm2)); Assert.IsType <ArgumentException>(ex); }
public void AddingFormatsTogether() { GcAdpcmChannel[] channels = GenerateAudio.GenerateAdpcmSineWave(100, 2, 48000).Channels; var adpcm = new GcAdpcmFormat(new[] { channels[0] }, 48000); var adpcm2 = new GcAdpcmFormat(new[] { channels[1] }, 48000); GcAdpcmFormat combined = adpcm.Add(adpcm2); Assert.Equal(adpcm.Channels[0], combined.Channels[0], new GcAdpcmChannelComparer()); Assert.Equal(adpcm2.Channels[0], combined.Channels[1], new GcAdpcmChannelComparer()); }
public void LoopsProperlyAfterDecoding(int sampleCount, bool looping, int loopStart, int loopEnd) { GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmEmpty(sampleCount, 1, 48000) .WithLoop(looping, loopStart, loopEnd); IAudioFormat pcm = adpcm.ToPcm16(); Assert.Equal(looping, pcm.Looping); Assert.Equal(loopStart, pcm.LoopStart); Assert.Equal(loopEnd, pcm.LoopEnd); }
public void LoopsProperlyAfterEncoding(int sampleCount, bool looping, int loopStart, int loopEnd) { Pcm16Format pcm = GenerateAudio.GeneratePcmSineWave(sampleCount, 1, 48000) .WithLoop(looping, loopStart, loopEnd); IAudioFormat adpcm = new GcAdpcmFormat().EncodeFromPcm16(pcm); Assert.Equal(looping, adpcm.Looping); Assert.Equal(loopStart, adpcm.LoopStart); Assert.Equal(loopEnd, adpcm.LoopEnd); }
public void BuildSeekTableFourChannelsTruncated(Endianness endianness) { short[] expected = { 0, 0, 0, 0, 0, 0, 0, 0, 50, 49, 100, 99, 250, 249, 150, 149 }; GcAdpcmFormat adpcm = GetAscendingAdpcm(50, 112, 0, 50, 200, 100); Assert.Equal(expected.ToByteArray(endianness), adpcm.BuildSeekTable(2, endianness)); }
public void AddDifferentFormats() { Pcm16Format pcm = GenerateAudio.GeneratePcmSineWave(100, 1, 48000); GcAdpcmFormat adpcm = GenerateAudio.GenerateAdpcmSineWave(100, 1, 48000); var audio = new AudioData(pcm); var audio2 = new AudioData(adpcm); AudioData combined = AudioData.Combine(audio, audio2); Assert.Collection(combined.GetAllFormats(), x => Assert.True(x is Pcm16Format)); var pcmCombined = combined.GetFormat <Pcm16Format>(); Assert.Same(pcm.Channels[0], pcmCombined.Channels[0]); Assert.Equal(2, pcmCombined.ChannelCount); }
public void BrstmLoopAlignmentIsSet() { GcAdpcmFormat audio = GenerateAudio.GenerateAdpcmSineWave(BuildParseTestOptions.Samples, 1, BuildParseTestOptions.SampleRate); audio = audio.WithLoop(true, 1288, 16288); var writer = new BrstmWriter { Configuration = { LoopPointAlignment = 700 } }; byte[] builtFile = writer.GetFile(audio); IAudioFormat parsedAudio = new BrstmReader().ReadFormat(builtFile); Assert.Equal(1400, parsedAudio.LoopStart); Assert.Equal(16400, parsedAudio.LoopEnd); }
public static GcAdpcmFormat GenerateAdpcmEmpty(int sampleCount, int channelCount, int sampleRate, int samplesPerSeekTableEntry = 0x3800) { var channels = new GcAdpcmChannel[channelCount]; for (int i = 0; i < channelCount; i++) { var builder = new GcAdpcmChannelBuilder(new byte[GcAdpcmMath.SampleCountToByteCount(sampleCount)], new short[16], sampleCount); builder.WithSeekTable(new short[sampleCount.DivideByRoundUp(samplesPerSeekTableEntry) * 2], samplesPerSeekTableEntry, true); channels[i] = builder.Build(); } var adpcm = new GcAdpcmFormat(channels, sampleRate); return(adpcm); }
private GcAdpcmFormat GetAscendingAdpcm(int samplesPerEntry, int count, params int[] starts) { short[][] pcm = starts.Select(start => GenerateAudio.GenerateAscendingShorts(start, count)).ToArray(); Pcm16Format pcmFormat = Pcm16Format.GetBuilder(pcm, 48000).Build(); GcAdpcmFormat adpcm = new GcAdpcmFormat().EncodeFromPcm16(pcmFormat); for (int i = 0; i < adpcm.ChannelCount; i++) { adpcm.Channels[i] = adpcm.Channels[i] .GetCloneBuilder() .WithSamplesPerSeekTableEntry(samplesPerEntry) .Build(); } return(adpcm); }
public void IdspAlignsLoopToBlock(bool loops, int startIn, int endIn, int startOut, int endOut, int blockSize) { GcAdpcmFormat audio = GenerateAudio.GenerateAdpcmSineWave(BuildParseTestOptions.Samples, 2, BuildParseTestOptions.SampleRate); audio = audio.WithLoop(loops, startIn, endIn); var config = new IdspConfiguration { BlockSize = blockSize }; byte[] idsp = new IdspWriter().GetFile(audio, config); var decoded = (GcAdpcmFormat) new IdspReader().ReadFormat(idsp); Assert.Equal(startOut, decoded.LoopStart); Assert.Equal(endOut, decoded.LoopEnd); }
public void BcstmBuildAndParseEqual(int numChannels) { GcAdpcmFormat audio = GenerateAudio.GenerateAdpcmSineWave(BuildParseTestOptions.Samples, numChannels, BuildParseTestOptions.SampleRate); BuildParseTests.BuildParseCompareAudio(audio, new BCFstmWriter(NwTarget.Ctr), new BCFstmReader()); }
public void DspBuildAndParseEqual(int numChannels) { GcAdpcmFormat audio = GenerateAudio.GenerateAdpcmSineWave(BuildParseTestOptions.Samples, numChannels, BuildParseTestOptions.SampleRate); BuildParseTests.BuildParseCompareAudio(audio, new HpsWriter(), new HpsReader()); }
public void Setup() { _adpcmStream = GenerateAudio.GenerateAdpcmEmpty((int)(_sampleRate * LengthSeconds), 1, _sampleRate); }