예제 #1
0
        public void Resample_8To8()  //broken only on Linux?
        {
            //-- 1. Create a raw sine sample which shall be 44100 Hz and 16 Bit
            int sampleLength = 500;

            byte[] buffer = new byte[sampleLength];
            for (int i = 0; i < sampleLength; i++)
            {
                buffer [i] = (byte)(128 + 120.0f * Math.Sin(((float)i / (float)sampleLength) * (Math.PI * 2.0f)));
            }

            using (BinaryWriter writerRaw = new BinaryWriter(File.Open("test2_in_sine_44100_8.raw", FileMode.Create))) {
                for (uint i = 0; i < sampleLength; i++)
                {
                    writerRaw.Write(buffer [i]);
                }
            }

            GCHandle _hGCFile;

            // now create a pinned handle, so that the Garbage Collector will not move this object
            _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            int handle = Bass.BASS_StreamCreate(44100, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS, BASSStreamProc.STREAMPROC_PUSH);

            int ret = Bass.BASS_StreamPutData(handle, _hGCFile.AddrOfPinnedObject(), buffer.Length * sizeof(byte) | (int)BASSStreamProc.BASS_STREAMPROC_END);

            Assert.AreEqual(buffer.Length * sizeof(byte), ret);


            //-- 2. Mix it
            int mixer = BassMix.BASS_Mixer_StreamCreate(11025, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_8BITS);

            // add channel to mixer
            bool isMixerGood = BassMix.BASS_Mixer_StreamAddChannel(mixer, handle, BASSFlag.BASS_MIXER_NORAMPIN);

            Assert.AreEqual(true, isMixerGood);

            //-- 3. grab Stream and compare
            byte[] buffer2 = new byte[1000];

            // total data written to the new byte[] buffer
            int totalDataWritten = Bass.BASS_ChannelGetData(mixer, buffer2, (int)1000);

            Console.WriteLine("totalDataWritten " + totalDataWritten);

            using (BinaryWriter writerRaw = new BinaryWriter(File.Open("test2_out_sine_11025_8.raw", FileMode.Create))) {
                for (uint i = 0; i < totalDataWritten; i++)
                {
                    writerRaw.Write(buffer2 [i]);
                }
            }

            string hashGen = MD5Utils.GenerateMd5Hash(buffer2);

            Bass.BASS_StreamFree(handle);
            Bass.BASS_StreamFree(mixer);

            Assert.AreEqual("50bce9c536e98667534747f0a5f06ebd", hashGen);
        }
예제 #2
0
        public void ConversionTest(string path, string hash)
        {
            songDataFactory = new SongDataFactory();
            songDataFactory.ReportProgress += ReportProgress;

            //Console.WriteLine("ConversionTest....");

            //string input = this.TestContext.Properties["resource_path"].ToString() + resourceAttribute.Path;
            string      input       = "resources/examples/" + path;
            RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(input);

            songData = songDataFactory.ExtractSongData(renoiseSong, input);

            converter = new ModConverter(input);
            converter.EventProgress += ReportProgress;

            settings = new ModSettings();
            settings.ForceProTrackerCompatibility = PROTRACKER_COMPATIBILITY_MODE.NONE;
            settings.NtscMode = true;
            settings.PortamentoLossThreshold = 2;
            settings.VolumeScalingMode       = VOLUME_SCALING_MODE.SAMPLE;



            converter.Settings = settings;

            byte[] bytes = converter.Convert(songData);

            string hashGen = MD5Utils.GenerateMd5Hash(bytes);


            //Write file for later investigation
            string outputFile = input.Remove(input.Length - 5);  // default output file, same as input without .xrns extension

            outputFile = System.Text.RegularExpressions.Regex.Match(outputFile, @"(?:(?!\.(mod|xm)$).)*").Value;

            string outputFileExt = System.Text.RegularExpressions.Regex.Match(outputFile, @"\.(mod | xm)$").Value;
            string destType      = "mod";

            // add extension to output file in case user has not already specified it
            if (!outputFileExt.Equals("." + destType, StringComparison.CurrentCultureIgnoreCase))
            {
                outputFile += '.' + destType;
            }

            Utility.SaveByteArrayToFile(outputFile, bytes);

            //So is it what we wanted?
            Assert.AreEqual(hash, hashGen);
        }
예제 #3
0
        public void ConversionTest(string path, string hash)
        {
            songDataFactory = new SongDataFactory();
            songDataFactory.ReportProgress += ReportProgress;

            string input = "resources/examples/" + path;

            RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(input);

            songData  = songDataFactory.ExtractSongData(renoiseSong, input);
            converter = new XMConverter(input);

            settings           = new XmSettings();
            settings.Tempo     = songData.InitialBPM;
            settings.TicksRow  = songData.TicksPerLine;
            converter.Settings = settings;

            converter.EventProgress += ReportProgress;

            byte[] bytes = converter.Convert(songData);

            string hashGen = MD5Utils.GenerateMd5Hash(bytes);

            //Write file for later investigation
            string outputFile = input.Remove(input.Length - 5);  // default output file, same as input without .xrns extension

            outputFile = System.Text.RegularExpressions.Regex.Match(outputFile, @"(?:(?!\.(mod|xm)$).)*").Value;

            string outputFileExt = System.Text.RegularExpressions.Regex.Match(outputFile, @"\.(mod | xm)$").Value;
            string destType      = "xm";

            // add extension to output file in case user has not already specified it
            if (!outputFileExt.Equals("." + destType, StringComparison.CurrentCultureIgnoreCase))
            {
                outputFile += '.' + destType;
            }

            Utility.SaveByteArrayToFile(outputFile, bytes);

            //So is it what we wanted?
            Assert.AreEqual(hash, hashGen);
        }
예제 #4
0
        public void Resample_16To16()
        {
            //-- 1. Create a raw sine sample which shall be 44100 Hz and 16 Bit
            int sampleLength = 500;

            short[] buffer = new short[sampleLength];
            for (int i = 0; i < sampleLength; i++)
            {
                buffer [i] = (short)(30000.0f * Math.Sin(((float)i / (float)sampleLength) * (Math.PI * 2.0f)));
            }

            using (BinaryWriter writerRaw = new BinaryWriter(File.Open("test1_in_sine_44100_16.raw", FileMode.Create))) {
                for (uint i = 0; i < sampleLength; i++)
                {
                    writerRaw.Write(buffer [i]);
                }
            }

            GCHandle _hGCFile;

            // now create a pinned handle, so that the Garbage Collector will not move this object
            _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            int handle = Bass.BASS_StreamCreate(44100, 1, BASSFlag.BASS_STREAM_DECODE, BASSStreamProc.STREAMPROC_PUSH);

            int ret = Bass.BASS_StreamPutData(handle, _hGCFile.AddrOfPinnedObject(), buffer.Length * sizeof(short) | (int)BASSStreamProc.BASS_STREAMPROC_END);

            Assert.AreEqual(buffer.Length * sizeof(short), ret);


            //-- 2. Mix it
            int mixer = BassMix.BASS_Mixer_StreamCreate(11025, 1, BASSFlag.BASS_STREAM_DECODE);

            // add channel to mixer
            bool isMixerGood = BassMix.BASS_Mixer_StreamAddChannel(mixer, handle, BASSFlag.BASS_MIXER_NORAMPIN);

            Assert.AreEqual(true, isMixerGood);

            //-- 3. grab Stream and compare
            short[] buffer2 = new short[1000];

            // total data written to the new byte[] buffer
            int totalDataWritten = Bass.BASS_ChannelGetData(mixer, buffer2, (int)1000);

            Console.WriteLine("totalDataWritten " + totalDataWritten);

            using (BinaryWriter writerRaw = new BinaryWriter(File.Open("test1_out_sine_11025_16.raw", FileMode.Create))) {
                for (uint i = 0; i < totalDataWritten / 2; i++)
                {
                    writerRaw.Write(buffer2 [i]);
                }
            }

            byte[] buffer3 = new byte[2000];
            Buffer.BlockCopy(buffer2, 0, buffer3, 0, totalDataWritten);

            string hashGen = MD5Utils.GenerateMd5Hash(buffer3);

            Bass.BASS_StreamFree(handle);
            Bass.BASS_StreamFree(mixer);

            Assert.AreEqual("2c61dc0767698eb28c7735cb073cea6c", hashGen);
        }