Exemple #1
0
        public void TestIncrement(string arg, double expectation)
        {
            var args = CreateArgs(arg);
            var obj  = new NoiseOption(args);

            Assert.AreEqual(expectation, obj.Increment);
        }
Exemple #2
0
        public void TestType(string arg, string expectation)
        {
            var args = CreateArgs(arg);
            var obj  = new NoiseOption(args);

            Assert.AreEqual(expectation, obj.Type);
        }
Exemple #3
0
        public void TestWidth(string arg, int expectation)
        {
            var args = CreateArgs("--width=200");
            var obj  = new NoiseOption(args);

            Assert.AreEqual(200, obj.Width);
        }
Exemple #4
0
        public void TestHeight(string arg, int expectation)
        {
            var args = CreateArgs(arg);
            var obj  = new NoiseOption(args);

            Assert.AreEqual(expectation, obj.Height);
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the improved noise generator!\n");

            var arguments = new Docopt().Apply(Usage, args, version: $"{nameof(ImprovedNoise)} 0.0.1", exit: true);
            var options   = new NoiseOption(arguments);

            var generator = new Generator(new ImprovedPerlin(), options.Height, options.Width, options.Increment,
                                          options.Type);
            var image = generator.Generate();

            string imageName = $"/tmp/{DateTime.Now.Ticks}.png";

            image.Save(new FileStream(imageName, FileMode.CreateNew), new PngEncoder());
            Console.WriteLine($"Done. Image generated at local folder: {imageName}\n");
        }
		public Mssf(short[] w, int a, int d, byte s, int r, int pan, NoiseOption noise)
		{
			Wave = w;
			A = a;
			D = d;
			S = s;
			R = r;
			Pan = pan;
			Noiseoption = noise;
		}
        public static int SetWave(short[] wave, int oct, int pan, NoiseOption no)
        {
            var hz = GetRelativeFreq(Math.Min(oct, 6));
            var length = 0;
            //string debug = "";
            var sheed = 0x8000;
            /*for (int i = 0; i < 44100; i++)
                if ((decimal)Math.PI * 2 / (decimal)44100 * i * (hz + (hz / 440m)) > (decimal)Math.PI * 2)
                {
                    //Console.Write(Math.PI * 2 / 44100 * i * hz * 180 / Math.PI);
                    length = i;
                    break;
                }
             */
            length = (int) (44100 / hz + 0.5);
            //length++;
            //length *= 10;
            //		Hz = 1 / s
            //×s	s × Hz = 1
            //÷Hz	s = 1 / Hz
            //if (hz >= 1046)
            //	length = 11025;
            float t = 0;

            if (no != NoiseOption.None)
                length = 11025;

            var hSSnd = DX.MakeSoftSound1Ch16Bit44KHz(length);

            //int[] sikis = new int[length];
            var y = new ushort[length];

            var noise = new ushort[length];
            if (no != NoiseOption.None)
                noise = SetNoise(hz, no == NoiseOption.Short ? true : false, ref sheed, length);
            for (var i = 0; i < length; i++)
            {
                //t = wave[(int)((Math.PI * 2 / 44100 * i * hz * 180 / Math.PI) % 360 / (359 / 31.0))]+32768; // divided by 10 means volume control
                var siki = (int) Math.Round(2 / 44100.0 * i * hz * 180 % 360 / (360 / 31.0));
                t = wave[siki] + 32768;
                //var siki = Math.PI * 2 / 44100 * i * hz;
                //t = (float)Math.Sin(siki) * 32768 + 32767;
                //	t = (float)(Math.Sin(Math.PI * 2 / 44100 * i * hz) * 32768 + 32768);
                //sikis[i] = siki;
                //t = wave[(int)(i * (32.0 / length))] + 32768;

                t = (noise[i] + t) / 2;

                /*if (i > 0)
                y[i] = (ushort)(0.9f * (ushort)y[i - 1] + 0.1f*t);
                else*/
                y[i] = (ushort) t;
                //debug += (int)((Math.PI * 2 / 44100 * i * hz * 180 / Math.PI) % 360 / (359 / 31.0)) + " ";
                /*
                if (i > 1)
                    y[i] = (ushort)((y[i - 2] + y[i - 1] + t) / 3);
                if (i > 0)
                    y[i] = (ushort)((y[i - 1] + t) / 3);
                else
                    y[i] = (ushort)t;
                */
                DX.WriteSoftSoundData(hSSnd, i, (ushort) t, (ushort) t);
            }

            var retval = DX.LoadSoundMemFromSoftSound(hSSnd);
            DX.DeleteSoftSound(hSSnd);

            return retval;
        }
        public Tone(string pitch, int octave, short[] wave, Envelope env, int vol, int pan, int vel, NoiseOption noiseflag)
        {
            if (DX.DxLib_IsInit() == 0)
                throw new Exception("DXLib が初期化されていません。");

            Pitch = pitch;
            Octave = octave;
            Wave = wave;
            Freq = GetFreq(pitch, octave);
            Handle = SetWave(wave, octave, pan, noiseflag);
            Envelope = env;

            Volume = vol;

            Velocity = vel;

            Playing = false;
        }
 public static void SaveFileVer2(string path, short[] wave, int a, int d, byte s, int r, int pan, NoiseOption noiseoption)
 {
     BinaryWriter bw = null;
     try
     {
         bw = new BinaryWriter(new FileStream(path, FileMode.Create));
     }
     catch (UnauthorizedAccessException)
     {
         throw new Exception("ERR:0003");
     }
     bw.Write(new[] {'M', 'S', 'S', 'F', '_', 'V', 'E', 'R', '0', '0', '2'}, 0, 11); //ヘッダー
     foreach (var wav in wave)
         bw.Write(wav); //波形データ
     bw.Write(a); //アタックタイム
     bw.Write(d); //ディケイタイム
     bw.Write(s); //サスティンレベル
     bw.Write(r); //リリースタイム
     bw.Write(pan); //パンポット
     bw.Write((byte) noiseoption);
     bw.Close(); //ストリームを閉じる
 }
Exemple #10
0
        public static void LoadFileVer2(string path, out short[] wave, out int a, out int d, out byte s, out int r, out int pan, out NoiseOption noiseoption)
        {
            wave = new short[32];
            BinaryReader br = null;
            try
            {
                br = new BinaryReader(new FileStream(path, FileMode.Open));
            }
            catch (FileNotFoundException)
            {
                throw new Exception("ERR:0004");
            }
            var head = br.ReadChars(11);
            if (new string(head) != "MSSF_VER002")
                if (new string(head).Substring(0, 8) == "MSSF_VER")
                    throw new Exception("ERR:0001"); //指定した Music Sheet Sound File のバージョンが異なる。
                else
                    throw new Exception("ERR:0002"); //そのファイルは Music Sheet Sound File ではない。
            for (var i = 0; i < 32; i++)
                wave[i] = br.ReadInt16();

            a = br.ReadInt32();
            d = br.ReadInt32();
            s = br.ReadByte();
            r = br.ReadInt32();

            pan = br.ReadInt32();
            int tmp = br.ReadByte();
            if (tmp > 2)
                throw new Exception("ERR:0006");

            noiseoption = (NoiseOption) tmp;
            br.Close();
        }
Exemple #11
0
 public static void LoadFileDynamic(string path, out short[] wave, out int a, out int d, out byte s, out int r, out int pan, out NoiseOption noiseoption)
 {
     BinaryReader br = null;
     try
     {
         br = new BinaryReader(new FileStream(path, FileMode.Open));
     }
     catch (FileNotFoundException)
     {
         throw new Exception("ERR:0004");
     }
     var head = br.ReadChars(8);
     if (new string(head) != "MSSF_VER")
         throw new Exception("ERR:0002");
     var ver = 0;
     try
     {
         ver = int.Parse(new string(br.ReadChars(3)));
     }
     catch (Exception)
     {
         throw new Exception("ERR:0002");
     }
     br.Close();
     switch (ver)
     {
         case 1:
             LoadFileVer1(path, out wave, out a, out d, out s, out r, out pan);
             noiseoption = NoiseOption.None;
             break;
         case 2:
             LoadFileVer2(path, out wave, out a, out d, out s, out r, out pan, out noiseoption);
             break;
         default:
             throw new Exception("ERR:0005");
     }
 }