void Update() { if (Input.GetKeyUp(KeyCode.Space)) { SfxrParams coinParams = new SfxrParams("0,,0.08,0.25,0.2193,0.5168,,,,,,0.3126,0.5738,,,,,,1,,,,,0.5"); //SfxrParams coinParams = new SfxrParams("0,,0.0736,0.4591,0.3858,0.5416,,,,,,0.5273,0.5732,,,,,,1,,,,,0.5"); coinParams.Mutate(0.1); _synth.CreateSound(coinParams, _blockSize); _synth.Play(); } else if (Input.GetKeyUp(KeyCode.Backspace)) { SfxrParams laserParams = new SfxrParams("0,,0.0359,,0.4491,0.2968,,0.2727,,,,,,0.0191,,0.5249,,,1,,,,,0.5"); laserParams.Mutate(0.15); _synth.CreateSound(laserParams, _blockSize); _synth.Play(); } else if (Input.GetKeyUp(KeyCode.Return)) { SfxrParams explosionParams = new SfxrParams("3,,0.3113,0.6514,0.0025,0.1876,,-0.363,,,,,,,,,,,1,,,,,0.5"); //explosionParams.Mutate(0.1); _synth.CreateSound(explosionParams, _blockSize); _synth.Play(); } }
void Update() { if(Input.GetKeyUp(KeyCode.Space)) { SfxrParams coinParams = new SfxrParams("0,,0.08,0.25,0.2193,0.5168,,,,,,0.3126,0.5738,,,,,,1,,,,,0.5"); //SfxrParams coinParams = new SfxrParams("0,,0.0736,0.4591,0.3858,0.5416,,,,,,0.5273,0.5732,,,,,,1,,,,,0.5"); coinParams.Mutate(0.1); _synth.CreateSound(coinParams, _blockSize); _synth.Play(); } else if(Input.GetKeyUp(KeyCode.Backspace)) { SfxrParams laserParams = new SfxrParams("0,,0.0359,,0.4491,0.2968,,0.2727,,,,,,0.0191,,0.5249,,,1,,,,,0.5"); laserParams.Mutate(0.15); _synth.CreateSound(laserParams, _blockSize); _synth.Play(); } else if(Input.GetKeyUp(KeyCode.Return)) { SfxrParams explosionParams = new SfxrParams("3,,0.3113,0.6514,0.0025,0.1876,,-0.363,,,,,,,,,,,1,,,,,0.5"); //explosionParams.Mutate(0.1); _synth.CreateSound(explosionParams, _blockSize); _synth.Play(); } }
/** * Plays a mutation of the sound. If the parameters are dirty, synthesises sound as it plays, caching it for later. * If they're not, plays from the cached sound. * Won't play if caching asynchronously. * @param mutationAmount Amount of mutation * @param mutationsNum The number of mutations to cache before picking from them */ public void PlayMutated(float __mutationAmount = 0.05f, uint __mutationsNum = 15) { Stop(); if (_cachingAsync) { return; } _mutation = true; _cachedMutationsNum = __mutationsNum; if (_params.paramsDirty || _cachedMutations == null) { // New set of mutations _cachedMutations = new float[_cachedMutationsNum][]; _cachingMutation = 0; } if (_cachingMutation != -1) { // Continuing caching new mutations Reset(true); // To get _envelopeFullLength _cachedMutation = new float[_envelopeFullLength]; _cachedMutationPos = 0; _cachedMutations[_cachingMutation] = _cachedMutation; _waveData = null; _original = _params.Clone(); _params.Mutate(__mutationAmount); Reset(true); } else { // Play from random cached mutation _waveData = _cachedMutations[(uint)(_cachedMutations.Length * getRandom())]; _waveDataPos = 0; } createGameObject(); }
public bool RenderLeftColumn(SfxrParams parameters) { bool soundChanged = false; // Begin generator column GUILayout.BeginVertical("box", GUILayout.Width(110)); GUILayout.Label("GENERATOR", EditorStyles.boldLabel); GUILayout.Space(8); if (GUILayout.Button("PICKUP/COIN")) { suggestedName = "PickupCoin"; parameters.GeneratePickupCoin(); soundChanged = true; } if (GUILayout.Button("LASER/SHOOT")) { suggestedName = "LaserShoot"; parameters.GenerateLaserShoot(); soundChanged = true; } if (GUILayout.Button("EXPLOSION")) { suggestedName = "Explosion"; parameters.GenerateExplosion(); soundChanged = true; } if (GUILayout.Button("POWERUP")) { suggestedName = "Powerup"; parameters.GeneratePowerup(); soundChanged = true; } if (GUILayout.Button("HIT/HURT")) { suggestedName = "HitHurt"; parameters.GenerateHitHurt(); soundChanged = true; } if (GUILayout.Button("JUMP")) { suggestedName = "Jump"; parameters.GenerateJump(); soundChanged = true; } if (GUILayout.Button("BLIP/SELECT")) { suggestedName = "BlipSelect"; parameters.GenerateBlipSelect(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("MUTATE")) { parameters.Mutate(); soundChanged = true; } if (GUILayout.Button("RANDOMIZE")) { suggestedName = "Random"; parameters.Randomize(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("COPY (OLD)")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsStringLegacy(); } if (GUILayout.Button("COPY")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsString(); } if (GUILayout.Button("PASTE")) { suggestedName = null; parameters.SetSettingsString(EditorGUIUtility.systemCopyBuffer); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("PLAY SOUND")) { PlaySound(); } GUILayout.Space(30); if (GUILayout.Button("EXPORT WAV")) { var path = EditorUtility.SaveFilePanel("Export as WAV", "", getSuggestedName() + ".wav", "wav"); if (path.Length != 0) { SfxrSynth synth = new SfxrSynth(); synth.parameters.SetSettingsString(parameters.GetSettingsString()); File.WriteAllBytes(path, synth.GetWavFile()); } } // End generator column GUILayout.FlexibleSpace(); GUILayout.EndVertical(); return(soundChanged); }
public bool RenderLeftColumn(SfxrParams parameters) { bool soundChanged = false; // Begin generator column GUILayout.BeginVertical("box", GUILayout.Width(110)); GUILayout.Label("合成器", EditorStyles.boldLabel); GUILayout.Space(8); if (GUILayout.Button("捡拾/金币")) { suggestedName = "PickupCoin"; parameters.GeneratePickupCoin(); soundChanged = true; } if (GUILayout.Button("激光/射击")) { suggestedName = "LaserShoot"; parameters.GenerateLaserShoot(); soundChanged = true; } if (GUILayout.Button("爆炸")) { suggestedName = "Explosion"; parameters.GenerateExplosion(); soundChanged = true; } if (GUILayout.Button("能量提升")) { suggestedName = "Powerup"; parameters.GeneratePowerup(); soundChanged = true; } if (GUILayout.Button("击中/受伤")) { suggestedName = "HitHurt"; parameters.GenerateHitHurt(); soundChanged = true; } if (GUILayout.Button("跳跃")) { suggestedName = "Jump"; parameters.GenerateJump(); soundChanged = true; } if (GUILayout.Button("选择/切换")) { suggestedName = "BlipSelect"; parameters.GenerateBlipSelect(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("MUTATE")) { parameters.Mutate(); soundChanged = true; } if (GUILayout.Button("随机")) { suggestedName = "Random"; parameters.Randomize(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("复制 (OLD)")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsStringLegacy(); } if (GUILayout.Button("复制")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsString(); } if (GUILayout.Button("黏贴")) { suggestedName = null; parameters.SetSettingsString(EditorGUIUtility.systemCopyBuffer); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("播放")) { PlaySound(); } GUILayout.Space(30); if (GUILayout.Button("导出")) { var path = EditorUtility.SaveFilePanel("导出为WAV", "", getSuggestedName() + ".wav", "wav"); if (path.Length != 0) { SfxrSynth synth = new SfxrSynth(); synth.parameters.SetSettingsString(parameters.GetSettingsString()); File.WriteAllBytes(path, synth.GetWavFile()); } } // End generator column GUILayout.FlexibleSpace(); GUILayout.EndVertical(); return(soundChanged); }
/// <summary> /// Renders the specified SFXR parameters in the editor. /// </summary> /// <param name="parameters">The current parameters to be rendered.</param> /// <remarks> /// This method is called automatically for the standalone editor window /// when a game-object with parameters is selected. However, this public /// method can also be called by CustomEditor implementations for specific /// game-components to render the editor in the Inspector window /// (see UnityEditor.Editor for details). Also, this method can be used /// from PropertyDrawer implementations; future releases of the code may /// include such a default drawer (once SfxrSynth and SfxrParams supports /// native serialization for Unity). /// </remarks> public static void RenderParameters(SfxrParams parameters) { if (parameters == null) { return; } if (waveTypeOptions == null) { waveTypeOptions = new GUIContent[] { new GUIContent("Square Wave", "Square (0)"), new GUIContent("Sawtooth", "Saw (1)"), new GUIContent("Sine Wave", "Sin (2)"), new GUIContent("Noise", "Noise (3)") }; } EditorGUI.BeginChangeCheck(); try { RenderHeading("General Settings"); RenderPopup(waveTypeOptions, ((int)(parameters.waveType)), (value => parameters.waveType = ((uint)(value))), new GUIContent("Wave Type", "Shape of the wave")); bool isSquareWaveType = (parameters.waveType == 0); RenderSlider(+0, +1, parameters.masterVolume, (value => parameters.masterVolume = value), new GUIContent("Volume", "Overall volume of the sound (0 to 1)")); RenderHeading("Wave Envelope"); RenderSlider(+0, +1, parameters.attackTime, (value => parameters.attackTime = value), new GUIContent("Attack Time", "Length of the volume envelope attack (0 to 1)")); RenderSlider(+0, +1, parameters.sustainTime, (value => parameters.sustainTime = value), new GUIContent("Sustain Time", "Length of the volume envelope sustain (0 to 1)")); RenderSlider(+0, +1, parameters.sustainPunch, (value => parameters.sustainPunch = value), new GUIContent("Sustain Punch", "Tilts the sustain envelope for more 'pop' (0 to 1)")); RenderSlider(+0, +1, parameters.decayTime, (value => parameters.decayTime = value), new GUIContent("Decay Time", "Length of the volume envelope decay (yes, I know it's called release) (0 to 1)")); RenderHeading("Frequency"); RenderSlider(+0, +1, parameters.startFrequency, (value => parameters.startFrequency = value), new GUIContent("Start Frequency", "Base note of the sound (0 to 1)")); RenderSlider(+0, +1, parameters.minFrequency, (value => parameters.minFrequency = value), new GUIContent("Minimum Frequency", "If sliding, the sound will stop at this frequency, to prevent really low notes (0 to 1)")); RenderSlider(-1, +1, parameters.slide, (value => parameters.slide = value), new GUIContent("Slide", "Slides the note up or down (-1 to 1)")); RenderSlider(-1, +1, parameters.deltaSlide, (value => parameters.deltaSlide = value), new GUIContent("Delta Slide", "Accelerates the slide (-1 to 1)")); RenderSlider(+0, +1, parameters.vibratoDepth, (value => parameters.vibratoDepth = value), new GUIContent("Vibrato Depth", "Strength of the vibrato effect (0 to 1)")); RenderSlider(+0, +1, parameters.vibratoSpeed, (value => parameters.vibratoSpeed = value), new GUIContent("Vibrato Speed", "Speed of the vibrato effect (i.e. frequency) (0 to 1)")); RenderHeading("Tone Change"); RenderSlider(-1, +1, parameters.changeAmount, (value => parameters.changeAmount = value), new GUIContent("Change Amount", "Shift in note, either up or down (-1 to 1)")); RenderSlider(+0, +1, parameters.changeSpeed, (value => parameters.changeSpeed = value), new GUIContent("Change Speed", "How fast the note shift happens (only happens once) (0 to 1)")); RenderHeading("Square Waves"); RenderSlider(+0, +1, parameters.squareDuty, (value => parameters.squareDuty = value), new GUIContent("Square Duty", "Controls the ratio between the up and down states of the square wave, changing the tibre (0 to 1)"), isSquareWaveType); RenderSlider(-1, +1, parameters.dutySweep, (value => parameters.dutySweep = value), new GUIContent("Duty Sweep", "Sweeps the duty up or down (-1 to 1)"), isSquareWaveType); RenderHeading("Repeats"); RenderSlider(+0, +1, parameters.repeatSpeed, (value => parameters.repeatSpeed = value), new GUIContent("Repeat Speed", "Speed of the note repeating - certain variables are reset each time (0 to 1)")); RenderHeading("Phaser"); RenderSlider(-1, +1, parameters.phaserOffset, (value => parameters.phaserOffset = value), new GUIContent("Phaser Offset", "Offsets a second copy of the wave by a small phase, changing the tibre (-1 to 1)")); RenderSlider(-1, +1, parameters.phaserSweep, (value => parameters.phaserSweep = value), new GUIContent("Phaser Sweep", "Sweeps the phase up or down (-1 to 1)")); RenderHeading("Filters"); RenderSlider(+0, +1, parameters.lpFilterCutoff, (value => parameters.lpFilterCutoff = value), new GUIContent("Low-Pass Cutoff", "Frequency at which the low-pass filter starts attenuating higher frequencies (0 to 1)")); RenderSlider(-1, +1, parameters.lpFilterCutoffSweep, (value => parameters.lpFilterCutoffSweep = value), new GUIContent("Low-Pass Cutoff Sweep", "Sweeps the low-pass cutoff up or down (-1 to 1)")); RenderSlider(+0, +1, parameters.lpFilterResonance, (value => parameters.lpFilterResonance = value), new GUIContent("Low-Pass Resonance", "Changes the attenuation rate for the low-pass filter, changing the timbre (0 to 1)")); RenderSlider(+0, +1, parameters.hpFilterCutoff, (value => parameters.hpFilterCutoff = value), new GUIContent("High-Pass Cutoff", "Frequency at which the high-pass filter starts attenuating lower frequencies (0 to 1)")); RenderSlider(-1, +1, parameters.hpFilterCutoffSweep, (value => parameters.hpFilterCutoffSweep = value), new GUIContent("High-Pass Cutoff Sweep", "Sweeps the high-pass cutoff up or down (-1 to 1)")); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); try { if (CanPlaySound()) { GUILayoutOption buttonHeight = GUILayout.MinHeight(40.0f); RenderButton("Play Sound", () => PlaySound(parameters, false), null, buttonHeight); } else { EditorGUILayout.HelpBox("To play the sound, the editor must be playing the game.", MessageType.Info, true); } } finally { EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); RenderHeading("Tools"); EditorGUILayout.BeginHorizontal(); try { GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); try { if (RenderButton("Randomize")) { parameters.Randomize(); PlaySound(parameters); } if (RenderButton("Mutate")) { parameters.Mutate(); // TODO: Allow for mutation-quantity parameter to be specified PlaySound(parameters); } } finally { EditorGUILayout.EndVertical(); } GUILayout.FlexibleSpace(); } finally { EditorGUILayout.EndHorizontal(); } RenderHeading("Generators"); EditorGUILayout.BeginHorizontal(); try { GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); try { bool play = false; play = (RenderButton("Pickup Coin", parameters.GeneratePickupCoin) || play); play = (RenderButton("Laser Shoot", parameters.GenerateLaserShoot) || play); play = (RenderButton("Explosion", parameters.GenerateExplosion) || play); play = (RenderButton("Powerup", parameters.GeneratePowerup) || play); play = (RenderButton("Hit Hurt", parameters.GenerateHitHurt) || play); play = (RenderButton("Jump", parameters.GenerateJump) || play); play = (RenderButton("Blip Select", parameters.GenerateBlipSelect) || play); if (play) { PlaySound(parameters); } } finally { EditorGUILayout.EndVertical(); } GUILayout.FlexibleSpace(); } finally { EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); RenderHeading("Clipboard"); EditorGUILayout.BeginHorizontal(); try { GUILayout.FlexibleSpace(); if (GUILayout.Button("Copy Parameters")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsString(); } if (GUILayout.Button("Paste Parameters")) { parameters.SetSettingsString(EditorGUIUtility.systemCopyBuffer); PlaySound(parameters); } GUILayout.FlexibleSpace(); } finally { EditorGUILayout.EndHorizontal(); } } finally { if (EditorGUI.EndChangeCheck()) { parameters.paramsDirty = true; } } }
public bool RenderLeftColumn(SfxrParams parameters) { bool soundChanged = false; // Begin generator column GUILayout.BeginVertical("box", GUILayout.Width(110)); GUILayout.Label("GENERATOR", EditorStyles.boldLabel); GUILayout.Space(8); if (GUILayout.Button("PICKUP/COIN")) { suggestedName = "PickupCoin"; parameters.GeneratePickupCoin(); soundChanged = true; } if (GUILayout.Button("LASER/SHOOT")) { suggestedName = "LaserShoot"; parameters.GenerateLaserShoot(); soundChanged = true; } if (GUILayout.Button("EXPLOSION")) { suggestedName = "Explosion"; parameters.GenerateExplosion(); soundChanged = true; } if (GUILayout.Button("POWERUP")) { suggestedName = "Powerup"; parameters.GeneratePowerup(); soundChanged = true; } if (GUILayout.Button("HIT/HURT")) { suggestedName = "HitHurt"; parameters.GenerateHitHurt(); soundChanged = true; } if (GUILayout.Button("JUMP")) { suggestedName = "Jump"; parameters.GenerateJump(); soundChanged = true; } if (GUILayout.Button("BLIP/SELECT")) { suggestedName = "BlipSelect"; parameters.GenerateBlipSelect(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("MUTATE")) { parameters.Mutate(); soundChanged = true; } if (GUILayout.Button("RANDOMIZE")) { suggestedName = "Random"; parameters.Randomize(); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("COPY (OLD)")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsStringLegacy(); } if (GUILayout.Button("COPY")) { EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsString(); } if (GUILayout.Button("PASTE")) { suggestedName = null; parameters.SetSettingsString(EditorGUIUtility.systemCopyBuffer); soundChanged = true; } GUILayout.Space(30); if (GUILayout.Button("PLAY SOUND")) { PlaySound(); } GUILayout.Space(30); if (GUILayout.Button("EXPORT WAV")) { var path = EditorUtility.SaveFilePanel("Export as WAV", "", getSuggestedName() + ".wav", "wav"); if (path.Length != 0) { SfxrSynth synth = new SfxrSynth(); synth.parameters.SetSettingsString(parameters.GetSettingsString()); File.WriteAllBytes(path, synth.GetWavFile()); } } GUILayout.Space(30); soundTitle = GUILayout.TextField(soundTitle); bool canSave = !string.IsNullOrEmpty(soundTitle) && !soundTitle.Contains(";") && !soundTitle.Contains(":"); bool mustReplace = canSave && SoundContainer.Contains(soundTitle); string buttonName = "SAVE"; if (!canSave) { buttonName = "INVALID NAME"; } else if (mustReplace) { buttonName = "REPLACE"; } else { buttonName = "SAVE"; } if (!canSave) { bool prevVal = GUI.enabled; GUI.enabled = false; GUILayout.Button(buttonName); GUI.enabled = prevVal; } else { if (GUILayout.Button(buttonName)) { string soundParams = parameters.GetSettingsString(); if (mustReplace) { SoundContainer.ReplaceSound(soundTitle, soundParams); } else { SoundContainer.AddSound(soundTitle, soundParams); } } } if (canSave && mustReplace) { if (GUILayout.Button("LOAD")) { string soundParams = SoundContainer.GetSound(soundTitle); parameters.SetSettingsString(soundParams); soundChanged = true; } } else { bool prevVal = GUI.enabled; GUI.enabled = false; GUILayout.Button("LOAD"); GUI.enabled = prevVal; } if (canSave && mustReplace) { if (GUILayout.Button("DELETE")) { SoundContainer.DeleteSound(soundTitle); } } else { bool prevVal = GUI.enabled; GUI.enabled = false; GUILayout.Button("DELETE"); GUI.enabled = prevVal; } // End generator column GUILayout.FlexibleSpace(); GUILayout.EndVertical(); return(soundChanged); }