Slide 1

Slide 1 text

Music for Game Developers 2019 Levi D. Smith

Slide 2

Slide 2 text

Overview • Math and science behind music theory • Music generation tools • Adding to game engine • Music composition tips

Slide 3

Slide 3 text

Notes • Pitch (frequency) • C, D, E, F, G, A, B, C • Do, Re, Mi, Fa, Sol, La, Ti • Octave • Length (time) • In 4/4 time • Whole = 4 beats • Half = 2 beats • Quarter = 1 beat • Eighth = 1/2 beat • Sixteenth = 1/4 beat • See powers of two from previous talk

Slide 4

Slide 4 text

Time • Actual length of note depends on tempo and time signature • 60 beats a minute in 4/4 time • Quarter note = 1 second • Meter – first note is (supposed to be) stressed • top number = notes in meter • bottom number = what note gets the beat • 4/4 time – common time, four quarter notes in a meter, quarter note gets the beat • also written as c • 3/4 time – waltz time • 2/4 time – march time • 2/2 time – half note gets the beat

Slide 5

Slide 5 text

Scales • Bass clef – ACEG (all cows eat grass) • Trombone, Baritone, Tuba • Treble clef – FACE • Trumpet, Saxophone, Clarinet, Flute • Full range of tones (12 half tones) • A, B♭, B, C, D♭, D, E♭, E, F, G♭, G, A♭ • No C♭ or F♭ • Or: A, A♯, B, C, C♯, D, D♯, E, F, F♯, G, G♯ • No B♯ or E♯ • Scale is a subset (7 tones) • Whole, Whole, Half, Whole, Whole, Whole, Half • Can construct any major scale • Minor scale: Whole, Half, Whole, Whole, Half, Whole, Whole • C major scale • Flats / Sharps (black keys on piano) • White keys on the piano

Slide 6

Slide 6 text

Real Instruments

Slide 7

Slide 7 text

Scales • Meaning and feeling are really subjective • Major • B flat – Zelda title theme, Final Fantasy prelude, first one we learned in band • E flat – Final Fantasy victory • C – Super Mario Bros, Super Mario Bros 2 • Minor • A minor – Final Fantasy IV battle theme, Final Fantasy VI battle theme • C minor – Final Fantasy VI Celes theme (beginning) • Concert pitch vs transposing instruments • Resources • https://www.hooktheory.com/theorytab/view/nintendo/legend-of-zelda-main- theme • http://www.gradfree.com/kevin/some_theory_on_musical_keys.htm

Slide 8

Slide 8 text

Frequency • Human ears detect notes by sound waves • Air isn’t just for breathing, longitudinal waves • Based on A (fifth) = 440 Hz • Speakers, Faraday’s Law Sine, amplitude 1.0 Square, amplitude 0.5 Sawtooth, amplitude 0.5

Slide 9

Slide 9 text

Frequency • Move up a half tone • Multiply by twelfth root of 2 • N * 21/12 • Move up a whole tone • Multiply by sixth root of 2 (2/12 = 1/6) • N * 21/6 • A to C • A > B♭ > B > C • 3 half tones • 440 Hz * 2(3/12) = 523.2511 Hz https://en.wikipedia.org/wiki/Piano_key_frequencies

Slide 10

Slide 10 text

Frequency • Go up one octave, multiply by 2 • Down one octave, divide by 2 • A4 to A3 = 440 Hz / 2 = 220 Hz • A4 to A5 = 440 Hz * 2 = 880 Hz • C5 to C6 = 523.25 Hz * 2 = 1,046.50 Hz • C major scale

Slide 11

Slide 11 text

Converting Voice to Notes Samples between peaks = 169 Project Rate = 44,100 Hz Period = 169/44,100 = 0.003832 seconds Frequency = 260.95 Hz B3 = 246.9417 C4 = 261.6256 C♯4 = 277.1826 “Ahhhh” “Ooooo” Samples between peaks = 167 Project Rate = 44,100 Hz Period = 167/44,100 = 0.003787 seconds Frequency = 264.07 Hz

Slide 12

Slide 12 text

Middle C on Various Instruments Trombone Samples between peaks = 165 Period = 165 / 44,100 = 0.003741 Frequency = 267.27 Hz B3 = 246.9417 C4 = 261.6256 C♯4 = 277.1826 Harmonica Samples between peaks = 167 Period = 167 / 44,100 = 0.003787 Frequency = 264.07 Hz Guitar Samples between peaks = 169 Period = 169 / 44,100 = 0.003832 Frequency = 260.95 Hz

Slide 13

Slide 13 text

Hearing Range • Humans: 20 Hz to 20,000 Hz • Cats: 55 Hz to 79,000 Hz • Dogs: 67 Hz to 45,000 Hz • Personal test (Computer speakers may not be capable of making all pitches) • 21 Hz – lowest noticeable sound, but faint • 40 Hz – physical shaking from speaker • 10,000 Hz - unpleasant to ears • 15,000 Hz - last noticeable sound https://en.wikipedia.org/wiki/Hearing_range

Slide 14

Slide 14 text

PxTone • Website is in Japanese • ピストンコラージュ(v.0.9.2.5) Download • Read the for_english.txt • Delete japanese.ico for English menus • Run the ptCollage.exe file • Add voice, add unit, then Keyboard to write notes • Left click drag to make notes • Right click to delete notes • Output in WAV, but many options • Convert WAV to MP3 or OGG in Audacity • Sharps / flats are different color, but only C is displayed • Keyboard is helpful

Slide 15

Slide 15 text

Bosca Ceoil • Free to use • Simple interface • Constant looping • Pick Scale Major to only show the notes on the current scale • MIDI style sound effects • No undo, copy, paste • Esc kicks you out • Doesn’t remember working directory • Can only export to WAV or MIDI • Left click – add note • Right click – delete note • Mouse wheel – make note longer / shorter

Slide 16

Slide 16 text

Garage Band • Free, but Mac only • Lots of configurable instruments, especially electronic / dubstep • Generated drum tracks • Command + Left Click to add regions • Command + Left Click to add notes • Composition methods • Piano roll – Like PxTone, Bosca Ceoil • Score – Traditional sheet music • Record • Turn off metronome (will be included on export) • To make MP3 or WAV • Share > Export Song to Disk • Transfer using SMB protocol, thumb drive, file hosting service (Dropbox/Google Drive)

Slide 17

Slide 17 text

GarageBand

Slide 18

Slide 18 text

Personal tips • Stay on scale • Melody (group of notes) creation • Pitch step up • Pitch step down • Pitch stay the same • Think of music as walking up and down stairs • The more steps you skip the wonkier it sounds • Rests • Note picker is my style; Not a chord guy • Once you have a melody • Modify the pitch of the notes • Change instruments • Dueling banjo method • Start or stop on the first note in the scale

Slide 19

Slide 19 text

Background tracks • Generally longer notes • Generally lower notes • Try to match the pitch of note in the background track to corresponding pitch of note in melody • Drum track – can be generated in GarageBand

Slide 20

Slide 20 text

More tricks • Title screen music • Take main melody and slow tempo • Reduce number of instruments / tracks • Get the same feel, but not intense as the in-game music

Slide 21

Slide 21 text

Unity • Set audio source to loop and play on awake • Don’t have to worry about starting stopping if only using one music file per scene • Steps • Create GameObject • Drag WAV/MP3 into project • Drag Audio resource onto GameObject • Check Loop • Leave Spatial Blend set to 2D unless you know what you’re doing • Trim ending of Audio resource in Audacity if needed

Slide 22

Slide 22 text

GameMaker • Create new Sound • Select music file • Make music Object • Add Event Create • Add audio_play_sound code • Important to stop any other music • Drag music object into your room