IEnumerator ShotLoop() { while (true) { if (Shot && !IsShooting && lockOn.LockedEnemys.Count > 0) { int BulletCount = lockOn.LockedEnemys.Count; Debug.Log("Shot [x" + BulletCount.ToString() + "]"); Addressables.InstantiateAsync(BulletSound).Completed += op => { op.Result.GetComponent <BulletSound>().Initialize(BulletCount); }; IsShooting = true; for (int i = 0; i < BulletCount; i++) { IndexDirection = new Vector3(Random.value, Random.value, Random.value); Addressables.InstantiateAsync(BulletAsset).Completed += op => { if (lockOn.LockedEnemys.Count > 0) { op.Result.GetComponent <Bullet>()?.Initialize(transform.position, IndexDirection, lockOn.LockedEnemys[0]); lockOn.LockedEnemys.RemoveAt(0); } }; if (i == lockOn.LockOnLimit - 1) { Quantize.QuantizePlay(MaxShot); } yield return(new WaitForSeconds(ShotInterval)); } IsShooting = false; } yield return(new WaitForSeconds(ShotInterval)); } }
void EnemyLock() { if (enemy.Enemys.Count == 0) { return; } var enemysInSight = enemy.Enemys. Where(x => Mathf.Cos(Mathf.PI * LockOnDegreeThreshold / 90) < Vector3.Dot(transform.forward, (x.transform.position - transform.position).normalized)); for (int i = 0; i < enemysInSight.Count(); i++) { GameObject LockTarget = enemysInSight.ElementAt(i); bool IsExistSameObjectInList = false; foreach (Transform t in LockedEnemys) { IsExistSameObjectInList = IsExistSameObjectInList | t == LockTarget.transform; } if (LockedEnemys.Count < LockOnLimit && !IsExistSameObjectInList && LockTarget.GetComponent <IEnemy>().Health > 0) { LockedEnemys.Add(LockTarget.transform); LockTarget.GetComponent <IEnemy>().Health--; LockTarget.GetComponent <IEnemy>().KillSelf(); LockTarget.GetComponent <IEnemy>().lockOn = this; onLockOnEvent.Invoke(LockTarget.transform.position); Quantize.QuantizePlay(audio); break; } else { onLockOnFailedEvent.Invoke(LockTarget.transform.position); } } }
public override void Process(TransformContext context) { var concat = (ExclusiveConcatenation)context.MatchedLayers[0]; var output = concat.Output; var exConcat = new QuantizedExclusiveConcatenation(concat.Inputs.Select(x => new ReadOnlyMemory <int>(x.Dimensions.ToArray()))); for (int i = 0; i < exConcat.Inputs.Count; i++) { var input = concat.Inputs[i].Connection.From; var quantize = new Quantize(input.Dimensions); var requantize = new Requantize(quantize.Output.Dimensions); quantize.Input.SetConnection(input); requantize.Input.SetConnection(quantize.Output); exConcat.Inputs[i].SetConnection(requantize.Output); } var dequantize = new Dequantize(exConcat.Output.Dimensions); dequantize.Input.SetConnection(exConcat.Output); var oldOuts = output.Connections.Select(o => o.To).ToList(); foreach (var oldOut in oldOuts) { oldOut.SetConnection(dequantize.Output); } }
public override void Process(TransformContext context) { var space = (SpaceToBatchNd)context.MatchedLayers[0]; var dwConv2d = (DepthwiseConv2d)context.MatchedLayers[1]; var conv2d = (Conv2d)context.MatchedLayers[2]; var input = space.Input.Connection.From; var output = conv2d.Output; space.Input.ClearConnection(); var newDwConv2d = new DepthwiseConv2d(input.Dimensions, dwConv2d.Weights, dwConv2d.Bias, Padding.Same, 1, 1, dwConv2d.FusedActivationFunction); var quantize = new Quantize(newDwConv2d.Output.Dimensions); var upload = new K210Upload(quantize.Output.Dimensions); var newConv2d = new K210Conv2d(upload.Output.Dimensions, K210Conv2dType.Conv2d, conv2d.Weights, conv2d.Bias, K210PoolType.LeftTop, conv2d.FusedActivationFunction, null); var dequantize = new Dequantize(newConv2d.Output.Dimensions); newDwConv2d.Input.SetConnection(input); quantize.Input.SetConnection(newDwConv2d.Output); upload.Input.SetConnection(quantize.Output); newConv2d.Input.SetConnection(upload.Output); dequantize.Input.SetConnection(newConv2d.Output); var oldOuts = output.Connections.Select(o => o.To).ToList(); foreach (var oldOut in oldOuts) { oldOut.SetConnection(dequantize.Output); } }
public override void Process(TransformContext context) { K210Conv2d newLayer; OutputConnector output; OutputConnector input; var conv = context.MatchedLayers[0]; if (conv is Conv2d conv2d) { newLayer = new K210Conv2d(conv2d.Input.Dimensions, K210Conv2dType.Conv2d, conv2d.Weights, conv2d.Bias, K210PoolType.LeftTop, conv2d.FusedActivationFunction, null); input = conv2d.Input.Connection.From; output = conv2d.Output; } else { throw new InvalidOperationException(); } var quantize = new Quantize(input.Dimensions); var upload = new K210Upload(input.Dimensions); var dequantize = new Dequantize(newLayer.Output.Dimensions); quantize.Input.SetConnection(input); upload.Input.SetConnection(quantize.Output); newLayer.Input.SetConnection(upload.Output); dequantize.Input.SetConnection(newLayer.Output); var oldOuts = output.Connections.Select(o => o.To).ToList(); foreach (var oldOut in oldOuts) { oldOut.SetConnection(dequantize.Output); } }
void Awake() { quantize = GetComponentInParent <Quantize>(); BackgroundMusic = GetComponents <AudioSource>(); gameManager = FindObjectOfType <GameManager>(); quantize.Play(BackgroundMusic[currentLoop], Beatcodes[currentLoop], true); }
public void Initialize(Vector3 StartPos, Vector3 IndexDirection, Transform _target) { transform.position = StartPos; rigidbody = gameObject.GetComponent <Rigidbody>(); rigidbody.useGravity = false; rigidbody.velocity = IndexDirection * 10f; Quantize.QuantizePlay(GetComponent <AudioSource>()); target = _target; IsInitialized = true; IsHit = false; }
public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata) { var clips = new Clip[incomingClips.Length]; for (var i = 0; i < incomingClips.Length; i++) { clips[i] = new Clip(incomingClips[i]); } return(command.Id switch { TokenType.Arpeggiate => Arpeggiate.Apply(command, clips), TokenType.Concat => Concat.Apply(clips), TokenType.Crop => Crop.Apply(command, clips), TokenType.Filter => Filter.Apply(command, clips), TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips), TokenType.Legato => Legato.Apply(clips), TokenType.Mask => Mask.Apply(command, clips), TokenType.Monophonize => Monophonize.Apply(clips), TokenType.Padding => Padding.Apply(command, clips), TokenType.Quantize => Quantize.Apply(command, clips), TokenType.Ratchet => Ratchet.Apply(command, clips), TokenType.Relength => Relength.Apply(command, clips), TokenType.Remap => Remap.Apply(command, clips), TokenType.Resize => Resize.Apply(command, clips), TokenType.Scale => Scale.Apply(command, clips), TokenType.Scan => Scan.Apply(command, clips), TokenType.SetLength => SetLength.Apply(command, clips), TokenType.SetPitch => SetPitch.Apply(command, clips), TokenType.SetRhythm => SetRhythm.Apply(command, clips), TokenType.Shuffle => Shuffle.Apply(command, clips), TokenType.Skip => Skip.Apply(command, clips), TokenType.Slice => Slice.Apply(command, clips), TokenType.Take => Take.Apply(command, clips), TokenType.Transpose => Transpose.Apply(command, clips), TokenType.VelocityScale => VelocityScale.Apply(command, clips), TokenType.InterleaveEvent => ((Func <ProcessResultArray <Clip> >)(() => { var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options); if (!success) { return new ProcessResultArray <Clip>(msg); } options.Mode = InterleaveMode.Event; return Interleave.Apply(options, targetMetadata, clips); }))(), _ => new ProcessResultArray <Clip>($"Unsupported command {command.Id}") });
void EnemyDestroyWithScore() { score.score += 500; Vector3 pos = transform.position; Addressables.InstantiateAsync(DestroyEffect_ref).Completed += op => { op.Result.transform.position = pos; Quantize.QuantizePlay(op.Result.GetComponent <AudioSource>()); }; if (lockOn && lockOn.LockedEnemys.Contains(transform)) { lockOn.LockedEnemys.Remove(transform); } }
public static ProcessResult <Clip[]> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata) { var clips = new Clip[incomingClips.Length]; for (var i = 0; i < incomingClips.Length; i++) { clips[i] = new Clip(incomingClips[i]); } return(command.Id switch { TokenType.Arpeggiate => Arpeggiate.Apply(command, clips), TokenType.Concat => Concat.Apply(clips), TokenType.Crop => Crop.Apply(command, clips), TokenType.Echo => Echo.Apply(command, clips), TokenType.Extract => Take.Apply(command, clips, true), TokenType.Filter => Filter.Apply(command, clips), TokenType.Invert => Invert.Apply(command, clips), TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.NotSpecified), TokenType.InterleaveEvent => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.Event), TokenType.Legato => Legato.Apply(clips), TokenType.Loop => Loop.Apply(command, clips), TokenType.Mask => Mask.Apply(command, clips), TokenType.Monophonize => Monophonize.Apply(clips), TokenType.Padding => Padding.Apply(command, clips), TokenType.Quantize => Quantize.Apply(command, clips), TokenType.Ratchet => Ratchet.Apply(command, clips), TokenType.Relength => Relength.Apply(command, clips), TokenType.Remap => Remap.Apply(command, clips), TokenType.Resize => Resize.Apply(command, clips), TokenType.Scale => Scale.Apply(command, clips), TokenType.Scan => Scan.Apply(command, clips), TokenType.SetLength => SetLength.Apply(command, clips), TokenType.SetPitch => SetPitch.Apply(command, clips), TokenType.SetRhythm => SetRhythm.Apply(command, clips), TokenType.Shuffle => Shuffle.Apply(command, clips), TokenType.Skip => Skip.Apply(command, clips), TokenType.Slice => Slice.Apply(command, clips), TokenType.Take => Take.Apply(command, clips), TokenType.Transpose => Transpose.Apply(command, clips), TokenType.VelocityScale => VelocityScale.Apply(command, clips), _ => new ProcessResult <Clip[]>($"Unsupported command {command.Id}") });
public override void Process(TransformContext context) { var space = (SpaceToBatchNd)context.MatchedLayers[0]; var input = space.Input.Connection.From; space.Input.ClearConnection(); K210Conv2d newLayer; OutputConnector output; var conv = context.MatchedLayers[1]; if (conv is Conv2d conv2d) { newLayer = new K210Conv2d(input.Dimensions, K210Conv2dType.Conv2d, conv2d.Weights, conv2d.Bias, conv2d.StrideWidth == 2 ? K210PoolType.LeftTop : K210PoolType.None, conv2d.FusedActivationFunction, null); output = conv2d.Output; } else if (conv is DepthwiseConv2d dwConv2d) { newLayer = new K210Conv2d(input.Dimensions, K210Conv2dType.DepthwiseConv2d, dwConv2d.Weights, dwConv2d.Bias, K210PoolType.None, dwConv2d.FusedActivationFunction, null); output = dwConv2d.Output; } else { throw new InvalidOperationException(); } var quantize = new Quantize(input.Dimensions); var upload = new K210Upload(input.Dimensions); var dequantize = new Dequantize(newLayer.Output.Dimensions); quantize.Input.SetConnection(input); upload.Input.SetConnection(quantize.Output); newLayer.Input.SetConnection(upload.Output); dequantize.Input.SetConnection(newLayer.Output); var oldOuts = output.Connections.Select(o => o.To).ToList(); foreach (var oldOut in oldOuts) { oldOut.SetConnection(dequantize.Output); } }
void MultiLock() { if (enemy.MultiLockEnemy.Count == 0) { return; } var enemysInSight = enemy.MultiLockEnemy .Where(x => Mathf.Cos(Mathf.PI * LockOnDegreeThreshold / 90) < Vector3.Dot(transform.forward, (x.transform.position - transform.position).normalized)) .OrderByDescending(x => Mathf.Cos(Mathf.PI * LockOnDegreeThreshold / 90) < Vector3.Dot(transform.forward, (x.transform.position - transform.position).normalized)); if (enemysInSight.Count() == 0) { return; } var e = enemysInSight.First().GetComponent <IEnemy>(); if (LockedEnemys.Count < LockOnLimit && e.Health > 0) { LockedEnemys.Add(enemysInSight.First().transform); e.Health--; if (e.Health <= 0) { e.KillSelf(); } e.lockOn = this; if (enemysInSight.Count() > 0) { onLockOnEvent.Invoke(enemysInSight.First().transform.position); } Quantize.QuantizePlay(audio); } else { onLockOnFailedEvent.Invoke(enemysInSight.First().transform.position); } }
// private int currentLoop = 0; void Awake() { Quantize quantize = GetComponentInParent <Quantize>(); AudioSource click = GetComponent <AudioSource>(); }
internal static extern uint ColorQuantize(uint dib, Quantize quantize);
public Mp3Decoder(string mp3File) { // encoder modules lame = new Lame(); gaud = new GetAudio(); ga = new GainAnalysis(); bs = new BitStream(); p = new Presets(); qupvt = new QuantizePVT(); qu = new Quantize(); vbr = new VBRTag(); ver = new Mp3Version(); id3 = new ID3Tag(); rv = new Reservoir(); tak = new Takehiro(); parse = new Parse(); mpg = new MPGLib(); intf = new Interface(); common = new Mpg.Common(); lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg); bs.setModules(ga, mpg, ver, vbr); id3.setModules(bs, ver); p.Modules = lame; qu.setModules(bs, rv, qupvt, tak); qupvt.setModules(tak, rv, lame.enc.psy); rv.Modules = bs; tak.Modules = qupvt; vbr.setModules(lame, bs, ver); gaud.setModules(parse, mpg); parse.setModules(ver, id3, p); // decoder modules mpg.setModules(intf, common); intf.setModules(vbr, common); gfp = lame.lame_init(); /* * turn off automatic writing of ID3 tag data into mp3 stream we have to * call it before 'lame_init_params', because that function would spit * out ID3v2 tag data. */ gfp.write_id3tag_automatic = false; /* * Now that all the options are set, lame needs to analyze them and set * some more internal options and check for problems */ lame.lame_init_params(gfp); parse.input_format = GetAudio.sound_file_format.sf_mp3; var inPath = new StringBuilder(mp3File); var enc = new Enc(); gaud.init_infile(gfp, inPath.ToString(), enc); var skip_start = 0; var skip_end = 0; if (parse.silent < 10) { Console.Write( "\rinput: {0}{1}({2:g} kHz, {3:D} channel{4}, ", inPath, inPath.Length > 26 ? "\n\t" : " ", gfp.in_samplerate / 1000, gfp.num_channels, gfp.num_channels != 1 ? "s" : ""); } if (enc.enc_delay > -1 || enc.enc_padding > -1) { if (enc.enc_delay > -1) { skip_start = enc.enc_delay + 528 + 1; } if (enc.enc_padding > -1) { skip_end = enc.enc_padding - (528 + 1); } } else { skip_start = gfp.encoder_delay + 528 + 1; } Console.Write("MPEG-{0:D}{1} Layer {2}", 2 - gfp.version, gfp.out_samplerate < 16000 ? ".5" : "", "III"); Console.Write(")\noutput: (16 bit, Microsoft WAVE)\n"); if (skip_start > 0) { Console.Write("skipping initial {0:D} samples (encoder+decoder delay)\n", skip_start); } if (skip_end > 0) { Console.Write("skipping final {0:D} samples (encoder padding-decoder delay)\n", skip_end); } wavsize = -(skip_start + skip_end); parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize; Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2); }
public Mp3Decoder(Stream mp3Stream) { // encoder modules lame = new Lame(); gaud = new GetAudio(); ga = new GainAnalysis(); bs = new BitStream(); p = new Presets(); qupvt = new QuantizePVT(); qu = new Quantize(); vbr = new VBRTag(); ver = new Mp3Version(); id3 = new ID3Tag(); rv = new Reservoir(); tak = new Takehiro(); parse = new Parse(); mpg = new MPGLib(); intf = new Interface(); common = new Mpg.Common(); lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg); bs.setModules(ga, mpg, ver, vbr); id3.setModules(bs, ver); p.Modules = lame; qu.setModules(bs, rv, qupvt, tak); qupvt.setModules(tak, rv, lame.enc.psy); rv.Modules = bs; tak.Modules = qupvt; vbr.setModules(lame, bs, ver); gaud.setModules(parse, mpg); parse.setModules(ver, id3, p); // decoder modules mpg.setModules(intf, common); intf.setModules(vbr, common); gfp = lame.lame_init(); /* * turn off automatic writing of ID3 tag data into mp3 stream we have to * call it before 'lame_init_params', because that function would spit * out ID3v2 tag data. */ gfp.write_id3tag_automatic = false; /* * Now that all the options are set, lame needs to analyze them and set * some more internal options and check for problems */ lame.lame_init_params(gfp); parse.input_format = GetAudio.sound_file_format.sf_mp3; var enc = new Enc(); gaud.init_infile(gfp, mp3Stream, enc); SkipStart = 0; SkipEnd = 0; if (enc.enc_delay > -1 || enc.enc_padding > -1) { if (enc.enc_delay > -1) { SkipStart = enc.enc_delay + 528 + 1; } if (enc.enc_padding > -1) { SkipEnd = enc.enc_padding - (528 + 1); } } else { SkipStart = gfp.encoder_delay + 528 + 1; } WavSize = -(SkipStart + SkipEnd); parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize; Framesize = parse.mp3input_data.framesize; SampleRate = parse.mp3input_data.samplerate; Length = parse.mp3input_data.nsamp; Channels = gfp.num_channels; Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2); }
public override void Process(TransformContext context) { var space = context.MatchedLayers[0]; var dwConv2d = (DepthwiseConv2d)context.MatchedLayers[1]; var conv2d = (Conv2d)context.MatchedLayers.Last(); var input = space.InputConnectors[0].Connection.From; var output = conv2d.Output; space.InputConnectors[0].ClearConnection(); var newDwConv2d = new DepthwiseConv2d(input.Dimensions, dwConv2d.Weights, dwConv2d.Bias, Padding.Same, 1, 1, dwConv2d.FusedActivationFunction); var quantize = new Quantize(newDwConv2d.Output.Dimensions); var upload = new K210Upload(quantize.Output.Dimensions); var newConv2d = new K210Conv2d(upload.Output.Dimensions, K210Conv2dType.Conv2d, conv2d.Weights, conv2d.Bias, K210PoolType.LeftTop, conv2d.FusedActivationFunction, null); var dequantize = new Dequantize(newConv2d.Output.Dimensions); newDwConv2d.Input.SetConnection(input); quantize.Input.SetConnection(newDwConv2d.Output); upload.Input.SetConnection(quantize.Output); newConv2d.Input.SetConnection(upload.Output); dequantize.Input.SetConnection(newConv2d.Output); var oldOuts = output.Connections.Select(o => o.To).ToList(); if (context.MatchedLayers.Count == 3) { foreach (var oldOut in oldOuts) { oldOut.SetConnection(dequantize.Output); } } else { var newOutput = dequantize.Output; foreach (var middleLayer in context.MatchedLayers.Skip(2).Take(context.MatchedLayers.Count - 3)) { Layer newLayer; switch (middleLayer) { case Quantize _: newLayer = new Quantize(newOutput.Dimensions); break; case Dequantize _: newLayer = new Dequantize(newOutput.Dimensions); break; case LeakyRelu l: newLayer = new LeakyRelu(newOutput.Dimensions, l.Slope); break; default: throw new NotImplementedException(); } newLayer.InputConnectors[0].SetConnection(newOutput); newOutput = newLayer.OutputConnectors[0]; } foreach (var oldOut in oldOuts) { oldOut.SetConnection(newOutput); } } }
void Start() { Quantize.QuantizeRowPlay(GetComponent <AudioSource>()); }
public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata) { var clips = new Clip[incomingClips.Length]; for (var i = 0; i < incomingClips.Length; i++) { clips[i] = new Clip(incomingClips[i]); } ProcessResultArray <Clip> resultContainer; switch (command.Id) { case TokenType.Arpeggiate: resultContainer = Arpeggiate.Apply(command, clips); break; case TokenType.Concat: resultContainer = Concat.Apply(clips); break; case TokenType.Crop: resultContainer = Crop.Apply(command, clips); break; case TokenType.Filter: resultContainer = Filter.Apply(command, clips); break; case TokenType.Interleave: resultContainer = Interleave.Apply(command, targetMetadata, clips); break; case TokenType.InterleaveEvent: var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options); if (!success) { return(new ProcessResultArray <Clip>(msg)); } options.Mode = InterleaveMode.Event; resultContainer = Interleave.Apply(options, targetMetadata, clips); break; case TokenType.Legato: resultContainer = Legato.Apply(clips); break; case TokenType.Mask: resultContainer = Mask.Apply(command, clips); break; case TokenType.Monophonize: resultContainer = Monophonize.Apply(clips); break; case TokenType.Quantize: resultContainer = Quantize.Apply(command, clips); break; case TokenType.Ratchet: resultContainer = Ratchet.Apply(command, clips); break; case TokenType.Relength: resultContainer = Relength.Apply(command, clips); break; case TokenType.Resize: resultContainer = Resize.Apply(command, clips); break; case TokenType.Scale: resultContainer = Scale.Apply(command, clips); break; case TokenType.Scan: resultContainer = Scan.Apply(command, clips); break; case TokenType.SetLength: resultContainer = SetLength.Apply(command, clips); break; case TokenType.SetRhythm: resultContainer = SetRhythm.Apply(command, clips); break; case TokenType.Shuffle: resultContainer = Shuffle.Apply(command, clips); break; case TokenType.Skip: resultContainer = Skip.Apply(command, clips); break; case TokenType.Slice: resultContainer = Slice.Apply(command, clips); break; case TokenType.Take: resultContainer = Take.Apply(command, clips); break; case TokenType.Transpose: resultContainer = Transpose.Apply(command, clips); break; default: return(new ProcessResultArray <Clip>($"Unsupported command {command.Id}")); } return(resultContainer); }
/// <summary> /// Quantizes bitmap. /// </summary> /// <param name="b">Bitmap with pixel bit count 32 or 24. If 32, alpha is ignored.</param> /// <param name="nColors">Max count of colors desired. Must be 2 to 256 inclusive. For example a 4-bit bitmap can have max 16 colors; 8-bit - max 256 colors.</param> /// <returns>Quantized bitmap.</returns> /// <exception cref="ArgumentException"></exception> public static Bitmap QuantizeB(Bitmap b, int nColors) => new(new MemoryStream(Quantize(b, nColors)));