Wire synthesizer

From GMod Wiki

Jump to: navigation, search



Contents

Wire Synthesizer

Wire synthesizer: Wire Synthesizer
Page white text.png Description:A device that makes music using the wired sound emitter
User.png Original Author:Sillybear25
Calendar.png Created:Unknown
Page white text.png Notes:-



Description

The wire synthesizer allows you to play simple, one-note-at-a-time (chords don't work, sorry!) melodies using the wire add-on for Garry's Mod. It consists of only four entities, plus whatever you decide to mount it on (optional).

Construction

The "guts" of the device consist of a total of four pieces:

The following are optional add-ons you might consider building on your own. They will not be included in this tutorial:


Setting it up

Start by spawning the required parts (don't spawn the expression gate just yet, we're going to talk about that later.).

Use whatever model you like for the speaker, but make sure the sound is one of the following: sine.wav, saw.wav, square.wav, or tri.wav (sine.wav is the default. The others are in the same folder, so just replace the "sine" with whatever you'd like to change it to and leave the rest of the file the same). You can choose a different sound if you really want, but it will probably not sound as good.

Make sure the button is set to toggle, and use 1 for on and 0 for off. Again, use whatever model you want. I prefer one of the power buttons, but you can use MUFFIN! if you really want to...

At this point, you could also spawn a prop or build a contraption to mount it onto, but this tutorial assumes you don't really care what it looks like.

The Expression Gate

For those of you who don't know, the expression gate is a powerful tool which can be used to perform actions that would normally take many different wired components (In this case, LOTS of If/Then/Else gates, Equals gates, and constant value chips) using only the one part. Expression gates can be coded in-game, but it's much easier to simply create a text file for them (it should be in the steam/steamapps/.../garrysmod/garrysmod/data/expressiongate folder).

This tutorial will assume you are just going to use the text file method. Open notepad (or your text editor of choice) and enter the following code:

N@Type>Music
I@In
O@Out
In == 0 -> Out = 0;
In == 122 -> Out = ((261.63/440)/2);
In == 115 -> Out = ((277.18/440)/2);
In == 120 -> Out = ((293.66/440)/2);
In == 100 -> Out = ((311.13/440)/2);
In == 99 -> Out = ((329.63/440)/2);
In == 118 -> Out = ((349.23/440)/2);
In == 103 -> Out = ((369.99/440)/2);
In == 98 -> Out = ((392/440)/2);
In == 104 -> Out = ((415.3/440)/2);
In == 110 -> Out = (1/2);
In == 106 -> Out = ((466.16/440)/2);
In == 109 -> Out = ((493.88/440)/2);
In == 44 | In == 113 -> Out = (0.594614);
In == 108 | In == 50 -> Out = 0.629955;
In == 46 | In == 119 -> Out = 0.662409;
In == 59 | In == 51 -> Out = 0.707114;
In == 101 | In == 47 -> Out = 0.749159;
In == 114 -> Out = 0.793705;
In == 53 -> Out = 0.840966;
In == 116 -> Out = 0.890909;
In == 54 -> Out = (415.3/440);
In == 121 -> Out = 1;
In == 55 -> Out = (466.16/440);
In == 117 -> Out = (493.88/440);
In == 105 -> Out = (0.594614*2);
In == 57 -> Out = (0.629955*2);
In == 111 -> Out = (0.662409*2);
In == 48 -> Out = (0.707114*2);
In == 112 -> Out = (0.749159*2);
In == 91 -> Out = (0.793705*2);
In == 61 -> Out = (0.840966*2);
In == 93 -> Out = (0.890909*2);

I will be the first to say that my code is a bit messy (notice how about halfway through I just start using decimal values, then switch back again for some of the other ones), but it will definitely get the job done.

Explanation of the code -- skip this part if you just want to make music

Each of the possible input values the code tests for corresponds to one of the keys on your keyboard (possibly the ASCII code for the character, but DON'T quote me on that...). I believe it only works with a QWERTY keyboard, but I don't have an alternative to test with. The keys I selected correspond to those on a piano keyboard, with C4 (middle C) on Q and C3 (one octave lower) on Z. The Q and Z rows are white keys while the 1 and A rows are black keys. Each output value is a multiplier for the pitch of the sound emitter. The default pitch of the sound emitter (when using the previously mentioned sounds) is A4, or 440 Hertz. When 440 is multiplied by the output of this gate, it results in the frequency that corresponds to the key you pressed. (e.g.: when you press N, the wired keyboard registers 110. The expression gate changes this to 1/2, which is then multiplied by the default frequency of 440Hz, resulting in 220Hz, or A3.) When there is no input, it simply multiplies the pitch by 0, resulting in a sound with a frequency of 0 Hz (i.e.: no sound!).


Wiring it up

Expression Gate

Sound Emitter

You're Done!

Congratulations, you have just completed building a synthesizer for Garry's Mod. Looks pretty simple, doesn't it? Now, on to playing it!

To use the synthesizer, start by turning it on with the button. It should now be playing a steady 440Hz tone. Now, activate the wired keyboard (just look at it and press "use") and press any key (well, almost any key...) and it should stop.

Now you can play it like you would an electric keyboard, except using a typing keyboard instead. Start out with something simple like "Twinkle Twinkle Little Star" to get used to the typing keyboard interface and to get a feel for the way it makes sound (it doesn't let you switch notes very quickly...) before moving on to more advanced stuff. Enjoy!



Added(12/6/08): This is amazing to hook up to your favorite songs. After you have them put in your sound folder just put them to the sound emitter, everything else is the same.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox