Exemple #1
0
        public byte[] convertToBrstm(byte[] data)
        {
            string temppath = $"{DateTime.Now.ToFileTimeUtc()}.wav";

            using (var input = new WaveFileReader(new MemoryStream(data)))
            {
                if (input.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
                {
                    var outFormat = new WaveFormat(input.WaveFormat.SampleRate, input.WaveFormat.Channels);
                    using (var resampler = new MediaFoundationResampler(input, outFormat))
                    {
                        // resampler.ResamplerQuality = 48;
                        WaveFileWriter.CreateWaveFile(temppath, resampler);
                    }

                    data = File.ReadAllBytes(temppath);
                }
            }

            WaveReader    reader    = new WaveReader();
            WaveStructure structure = reader.ReadMetadata(new MemoryStream(data));
            AudioData     audio     = reader.Read(data);

            audio.SetLoop(true, 0, structure.SampleCount);
            byte[] brstmFile = new BrstmWriter().GetFile(audio);
            File.Delete(temppath);
            return(brstmFile);
        }
Exemple #2
0
        public void BrstmBuildAndParseEqualPcm8(int numChannels)
        {
            Pcm8SignedFormat audio = GenerateAudio.GeneratePcm8SignedSineWave(BuildParseTestOptions.Samples, numChannels, BuildParseTestOptions.SampleRate);
            var writer             = new BrstmWriter {
                Configuration = { Codec = NwCodec.Pcm8Bit }
            };

            BuildParseTests.BuildParseCompareAudio(audio, writer, new BrstmReader());
        }
Exemple #3
0
        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 void convertToBrstm(string path)
        {
            using (var input = new WaveFileReader(path))
            {
                if (input.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
                {
                    string temppath  = "temp.wav";
                    var    outFormat = new WaveFormat(input.WaveFormat.SampleRate, input.WaveFormat.Channels);
                    using (var resampler = new MediaFoundationResampler(input, outFormat))
                    {
                        // resampler.ResamplerQuality = 48;
                        WaveFileWriter.CreateWaveFile(temppath, resampler);
                    }
                }
            }

            if (File.Exists("temp.wav"))
            {
                File.Delete(path);
                File.Move("temp.wav", path);
            }

            WaveStructure structure;
            WaveReader    reader = new WaveReader();

            byte[] fs      = File.ReadAllBytes(path);
            string newpath = new string(path.Take(path.Length - 3).ToArray());

            newpath += "brstm";
            handleExistingFile(newpath);
            Stream stream = new MemoryStream(fs);

            structure = reader.ReadMetadata(stream);
            AudioData audio = reader.Read(fs);

            audio.SetLoop(true, 0, structure.SampleCount);
            byte[] brstmFile = new BrstmWriter().GetFile(audio);
            File.WriteAllBytes(newpath, brstmFile);
            Console.WriteLine($"Converted: {path} \n       --> {newpath}");
        }