Skip to content
This repository was archived by the owner on Oct 11, 2020. It is now read-only.

Commit eb354bd

Browse files
committed
Merge branch 'bfxr-params'
2 parents f8f34ed + a655c5a commit eb354bd

25 files changed

+2698
-962
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
_temp
22
_assets
3+
_todo.txt
34
_*.bat
45
samples/main/Assets/AssetStoreTools
56
samples/main/Assets/AssetStoreTools.*

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
usfxr
22
=====
33

4-
usfxr is a C# library used to generate game-like procedural audio effects inside Unity. With usfxr, one can easily synthesize sound in real time for actions such as item pickups, jumps, lasers, hits, explosions, and more.
4+
usfxr is a C# library used to generate and play game-like procedural audio effects inside Unity. With usfxr, one can easily synthesize original sound in real time for actions such as item pickups, jumps, lasers, hits, explosions, and more, without ever leaving the Unity editor.
55

6-
usfxr is a port of Thomas Vian's [as3sfxr](https://code.google.com/p/as3sfxr/), which itself is an ActionScript 3 port of Tomas Pettersson's [sfxr](http://www.drpetter.se/project_sfxr.html).
6+
usfxr comes with code that allows for real-time audio synthesizing in games, and an in-editor interface for creating and testing effects before you use them in your code.
77

8-
[This video](https://vimeo.com/15769163) explains the ideas behind as3sfxr, and the ideas that I want to support with usfxr.
8+
usfxr is a port of Thomas Vian's [as3sfxr](https://code.google.com/p/as3sfxr/), which itself is an ActionScript 3 port of Tomas Pettersson's [sfxr](http://www.drpetter.se/project_sfxr.html). And as if the acronym collection is not enough, it also supports additional features first introduced by [BFXR](http://www.bfxr.net/) such as new waveform types and filters.
99

10-
Despite my name not being Thomas or a variant of it, I found myself wishing for a (free) library to procedurally generate audio inside Unity in real time, and usfxr is the result. Since it is a Unity project, usfxr also includes an in-editor window to easily generate and test sounds without leaving the Unity.
10+
[This video](https://vimeo.com/15769163) explains the ideas behind as3sfxr, and the ideas supported by usfxr.
1111

1212

1313
Introduction
@@ -20,7 +20,7 @@ However, by using a runtime library like usfxr, you can generate the same audio
2020
* Audio is generated in real time; there's no storage of audio files as assets necessary, making compiled project sizes smaller
2121
* Easily play variations of every sound you play; adds more flavor to the gameplay experience
2222

23-
I make no claims in regards to the source code or interface, since it was simply adapted from Thomas Vian's own code and (elegant) interface. As such, usfxr contains the same features offered by as3sfxr, such as caching of generated audio and ability to play sounds with variations. But because it is adapted to work on a different platform, however, it has advantages of its own:
23+
I make no claims in regards to the source code or interface, since it was simply adapted from Thomas Vian's own code and (elegant) as3sfxr interface, as well as Stephen Lavelle's BFXR additional features. As such, usfxr contains the same features offered by these two ports, such as caching of generated audio and ability to play sounds with variations. But because the code is adapted to work on a different platform (Unity), it has advantages of its own:
2424

2525
* Fast audio synthesis
2626
* Ability to cache sounds the first time they're played
@@ -31,7 +31,9 @@ I make no claims in regards to the source code or interface, since it was simply
3131
Installation
3232
------------
3333

34-
Download the latest "usfxr" zip file from the "/build" folder of the GitHub repository and extract the contents of this file into the "Scripts" (or equivalent) folder of your Unity project. After doing that, you should have the usfxr interface available inside Unity, as well as being able to instantiate and play SfxrSyth objects inside your project.
34+
Download the latest "usfxr" zip file from the "/build" folder of the GitHub repository and extract the contents of this file into the "Scripts" (or equivalent) folder of your Unity project. Alternatively, you can also download and install usfxr [from the asset store](https://www.assetstore.unity3d.com/en/#!/content/18619).
35+
36+
After doing that, you should have the usfxr interface available inside Unity, as well as being able to instantiate and play SfxrSyth objects inside your project.
3537

3638

3739
Usage
@@ -138,7 +140,6 @@ To-do/ideas
138140
* Show final duration in GUI
139141
* Undo/Redo
140142
* Add option to "lock" GUI items like BFXR's interface
141-
* Implement BFXR's new parameters (new waveforms, new filters)
142143

143144

144145
Acknowledgments
@@ -147,12 +148,22 @@ Acknowledgments
147148
* Tomas Pettersson created the original [sfxr](http://www.drpetter.se/project_sfxr.html), where all the concepts for usfxr come from.
148149
* Thomas Vian created [as3sfxr](https://code.google.com/p/as3sfxr/), the original code that was ported to C# for usfxr.
149150
* [Tiaan Geldenhuys](http://tiaan.com/) contributed to usfxr by cleaning the code and creating the original version of the in-editor window that I bastardized later.
150-
151+
* [Stephen Lavelle](http://www.increpare.com/) created [BFXR](http://www.bfxr.net/), an AS3 port of SFXR with several new features of its own, many of which have been adopted by usfxr.
151152

152153
Changelog
153154
---------
154155

155-
#### 2014-06-10
156+
#### 2014-07-12
157+
158+
* Added support for BFXR's new filters: compression, harmonics, and bitcrusher
159+
* Added support for BFXR's expanded pitch jump effects
160+
* Added support for BFXR's parameter strings (standard SFXR parameter strings still work)
161+
162+
#### 2014-07-08
163+
164+
* Added support for BFXR's new waveform types: triangle, breaker, tan, whistle, and pink noise
165+
166+
#### 2014-06-10 ([1.1](https://github.com/zeh/usfxr/releases/tag/v2014-06-10))
156167

157168
* Small internal optimizations: generates audio samples in about 9% less time
158169

samples/SpaceGame/Assets/Scripts/usfxr/Editor/SfxrGenerator.cs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ public class SfxrGenerator : EditorWindow {
3838
/// </summary>
3939

4040
// Enums
41-
enum WaveType : uint {
41+
public enum WaveType : uint {
4242
Square = 0,
4343
Sawtooth = 1,
4444
Sine = 2,
45-
Noise = 3
45+
Noise = 3,
46+
Triangle = 4,
47+
PinkNoise = 5,
48+
Tan = 6,
49+
Whistle = 7,
50+
Breaker = 8
4651
}
4752

4853
// Properties
@@ -146,6 +151,9 @@ public bool RenderLeftColumn(SfxrParams parameters) {
146151

147152
GUILayout.Space(30);
148153

154+
if (GUILayout.Button("COPY (OLD)")) {
155+
EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsStringLegacy();
156+
}
149157
if (GUILayout.Button("COPY")) {
150158
EditorGUIUtility.systemCopyBuffer = parameters.GetSettingsString();
151159
}
@@ -203,15 +211,17 @@ public bool RenderSettingsColumn(SfxrParams parameters) {
203211
public bool RenderParameters(SfxrParams parameters) {
204212
bool mustPlaySound = false;
205213

214+
GUIStyle waveTypeStyle = EditorStyles.popup;
215+
waveTypeStyle.fontSize = 12;
216+
waveTypeStyle.fixedHeight = 22;
217+
206218
EditorGUI.BeginChangeCheck();
207219
try {
208-
GUILayout.BeginHorizontal();
209-
GUILayout.FlexibleSpace();
210-
parameters.waveType = (uint)GUILayout.Toolbar((int)parameters.waveType, new string[] { "Squarewave", "Sawtooth", "Sinewave", "Noise" }, GUILayout.MinWidth(300), GUILayout.MaxWidth(400), GUILayout.Height(24), GUILayout.ExpandWidth(true));
211-
GUILayout.FlexibleSpace();
212-
GUILayout.EndHorizontal();
220+
WaveType waveTypeAsEnum = (WaveType)parameters.waveType;
221+
waveTypeAsEnum = (WaveType)EditorGUILayout.EnumPopup(new GUIContent("Wave Type", "Shape of the wave"), waveTypeAsEnum, waveTypeStyle);
222+
parameters.waveType = (uint)waveTypeAsEnum;
223+
GUILayout.Space(12);
213224

214-
//RenderToolbar(new string[] { "Square Wave", "Sawtooth", "Sine wave", "Noise" }, (value => parameters.waveType = ((uint)value)), new GUIContent("Wave Type", "Shape of the wave"));
215225
//RenderPopup(waveTypeOptions, ((int)(parameters.waveType)), (value => parameters.waveType = ((uint)(value))), new GUIContent("Wave Type", "Shape of the wave"));
216226
bool isSquareWaveType = (parameters.waveType == 0);
217227
RenderSlider(+0, +1, parameters.masterVolume, (value => parameters.masterVolume = value), new GUIContent("Volume", "Overall volume of the sound (0 to 1)"));
@@ -222,6 +232,9 @@ public bool RenderParameters(SfxrParams parameters) {
222232
RenderSlider(+0, +1, parameters.sustainPunch, (value => parameters.sustainPunch = value), new GUIContent("Sustain Punch", "Tilts the sustain envelope for more 'pop' (0 to 1)"));
223233
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)"));
224234

235+
// BFXR
236+
RenderSlider(+0, +1, parameters.compressionAmount, (value => parameters.compressionAmount = value), new GUIContent("Compression", "Pushes amplitudes together into a narrower range to make them stand out more. Very good for sound effects, where you want them to stick out against background music (0 to 1)"));
237+
225238
RenderHeading("Frequency");
226239
RenderSlider(+0, +1, parameters.startFrequency, (value => parameters.startFrequency = value), new GUIContent("Start Frequency", "Base note of the sound (0 to 1)"));
227240
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)"));
@@ -230,9 +243,20 @@ public bool RenderParameters(SfxrParams parameters) {
230243
RenderSlider(+0, +1, parameters.vibratoDepth, (value => parameters.vibratoDepth = value), new GUIContent("Vibrato Depth", "Strength of the vibrato effect (0 to 1)"));
231244
RenderSlider(+0, +1, parameters.vibratoSpeed, (value => parameters.vibratoSpeed = value), new GUIContent("Vibrato Speed", "Speed of the vibrato effect (i.e. frequency) (0 to 1)"));
232245

233-
RenderHeading("Tone Change");
234-
RenderSlider(-1, +1, parameters.changeAmount, (value => parameters.changeAmount = value), new GUIContent("Change Amount", "Shift in note, either up or down (-1 to 1)"));
235-
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)"));
246+
// BFXR
247+
RenderSlider(+0, +1, parameters.overtones, (value => parameters.overtones = value), new GUIContent("Harmonics", "Overlays copies of the waveform with copies and multiples of its frequency. Good for bulking out or otherwise enriching the texture of the sounds (warning: this is the number 1 cause of usfxr slowdown!) (0 to 1)"));
248+
RenderSlider(+0, +1, parameters.overtoneFalloff, (value => parameters.overtoneFalloff = value), new GUIContent("Harmonics falloff", "The rate at which higher overtones should decay (0 to 1)"));
249+
250+
RenderHeading("Tone Change/Pitch Jump");
251+
// BFXR
252+
RenderSlider(+0, +1, parameters.changeRepeat, (value => parameters.changeRepeat = value), new GUIContent("Change Repeat Speed", "Larger Values means more pitch jumps, which can be useful for arpeggiation (0 to 1)"));
253+
254+
RenderSlider(-1, +1, parameters.changeAmount, (value => parameters.changeAmount = value), new GUIContent("Change Amount 1", "Shift in note, either up or down (-1 to 1)"));
255+
RenderSlider(+0, +1, parameters.changeSpeed, (value => parameters.changeSpeed = value), new GUIContent("Change Speed 1", "How fast the note shift happens (only happens once) (0 to 1)"));
256+
257+
// BFXR
258+
RenderSlider(-1, +1, parameters.changeAmount2, (value => parameters.changeAmount2 = value), new GUIContent("Change Amount 2", "Shift in note, either up or down (-1 to 1)"));
259+
RenderSlider(+0, +1, parameters.changeSpeed2, (value => parameters.changeSpeed2 = value), new GUIContent("Change Speed 2", "How fast the note shift happens (only happens once) (0 to 1)"));
236260

237261
RenderHeading("Square Waves");
238262
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);
@@ -251,11 +275,14 @@ public bool RenderParameters(SfxrParams parameters) {
251275
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)"));
252276
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)"));
253277
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)"));
254-
}
255-
finally
256-
{
257-
if (EditorGUI.EndChangeCheck())
258-
{
278+
279+
RenderHeading("Bit Crushing");
280+
281+
// BFXR
282+
RenderSlider(+0, +1, parameters.bitCrush, (value => parameters.bitCrush = value), new GUIContent("Bit Crush", "Resamples the audio at a lower frequency (0 to 1)"));
283+
RenderSlider(-1, +1, parameters.bitCrushSweep, (value => parameters.bitCrushSweep = value), new GUIContent("Bit Crush Sweep", "Sweeps the Bit Crush filter up or down (-1 to 1)"));
284+
} finally {
285+
if (EditorGUI.EndChangeCheck()) {
259286
parameters.paramsDirty = true;
260287
mustPlaySound = true;
261288
}
@@ -264,8 +291,7 @@ public bool RenderParameters(SfxrParams parameters) {
264291
return mustPlaySound;
265292
}
266293

267-
protected static void RenderHeading(string heading)
268-
{
294+
protected static void RenderHeading(string heading) {
269295
EditorGUILayout.LabelField(heading, EditorStyles.boldLabel);
270296
}
271297

@@ -274,7 +300,7 @@ protected static bool RenderButton(
274300
Action valueChangeAction = null,
275301
bool? isEnabled = null,
276302
params GUILayoutOption[] options)
277-
{
303+
{
278304
if (content == null)
279305
{
280306
content = GUIContent.none;

samples/SpaceGame/Assets/Scripts/usfxr/SfxrAudioPlayer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SfxrAudioPlayer : MonoBehaviour {
2626
/**
2727
* SfxrAudioPlayer
2828
* This is the (internal) behavior script responsible for streaming audio to the engine
29-
*
29+
*
3030
* @author Zeh Fernando
3131
*/
3232

@@ -38,11 +38,11 @@ public class SfxrAudioPlayer : MonoBehaviour {
3838

3939
// Instances
4040
private SfxrSynth sfxrSynth; // SfxrSynth instance that will generate the audio samples used by this
41-
41+
4242

4343
// ================================================================================================================
4444
// INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
45-
45+
4646
void Start() {
4747
// Creates an empty audio source so this GameObject can receive audio events
4848
AudioSource soundSource = gameObject.AddComponent<AudioSource>();
@@ -65,7 +65,7 @@ void OnAudioFilterRead(float[] __data, int __channels) {
6565

6666
if (!isDestroyed && !needsToDestroy && sfxrSynth != null) {
6767
bool hasMoreSamples = sfxrSynth.GenerateAudioFilterData(__data, __channels);
68-
68+
6969
// If no more samples are needed, there's no more need for this GameObject so schedule a destruction (cannot do this in this thread)
7070
if (!hasMoreSamples) {
7171
needsToDestroy = true;
@@ -78,7 +78,7 @@ void OnAudioFilterRead(float[] __data, int __channels) {
7878
}
7979
}
8080
}
81-
81+
8282

8383
// ================================================================================================================
8484
// PUBLIC INTERFACE -----------------------------------------------------------------------------------------------

samples/SpaceGame/Assets/Scripts/usfxr/SfxrCacheSurrogate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SfxrCacheSurrogate : MonoBehaviour {
2626
/**
2727
* SfxrCacheSurrogate
2828
* This is the (internal) behavior script responsible for calling Coroutines for asynchronous audio generation
29-
*
29+
*
3030
* @author Zeh Fernando
3131
*/
3232

0 commit comments

Comments
 (0)