Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Music for Game Developers

LD Smith
April 14, 2019

Music for Game Developers

Video - https://www.youtube.com/watch?v=cTtiV9dxD88
This month will be a discussion on music for game developers. Learn the math and science behind music theory. We will cover tools that can be used for music composition, and how to apply the music resources in game engines.

LD Smith

April 14, 2019
Tweet

More Decks by LD Smith

Other Decks in Education

Transcript

  1. Overview • Math and science behind music theory • Music

    generation tools • Adding to game engine • Music composition tips
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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)
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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