Next Broadcast

Synthesized Instruments for MIDI playback.

hakkthazard Code and Eng DK30 Spring 2021 0 0

Description

I programmed MIDI playback into my game engine for a previous DK30, but the instruments don’t sound great. Instead of the sine-wave sounding instruments that I have now, I want to learn about how better instrument sounds are synthesized and implement some of them into my engine.

Recent Updates

hakkthazard 4 years ago

I came up with a basic way to synthesize sounds by connecting different types of nodes. Each node produces an output based on its type, and the calculation to produce that output might require input from other nodes. The code starts at the last node in the graph and follows input pointers back until all the nodes have been processed.

struct synth_node {
    synth_node *inputs[MAX_INPUT_NODES];
    synth_node_type type;

    union {
        oscillator_node oscillator;
        contour_generator_node contourGenerator;
        filter_node filter;
        pitch_scaler_node pitchScaler;
        low_freq_oscillator_node lowFreqOscillator;
        mixer_node mixer;
    }; 
};

With this system, I implemented a subset of the node graph for a trumpet in the article here: https://www.soundonsound.com/techniques/synthesizing-brass-instruments

My version is incomplete and less complex than that example, but it already produces pretty convincing results, at least compared to the old version of the synthesizer:

Old version (turn on audio): https://imgur.com/a/p9htZrt

New version: https://imgur.com/a/JzgEpQw

In addition to refining the trumpet, I’d like to also try to synthesize some other instruments. Then I am going to try to test my instruments on a few MIDI files to see how they sound together.

hakkthazard 4 years ago

I started off by trying to find some resources on building a synthesizer from scratch, but I couldn’t find much. It seems like most books and guides require that the programmer use a particular framework or plugin, and tutorials that start from scratch are typically too basic.

I did, however, find a very useful collection of articles here: https://www.soundonsound.com/synthesizers/synth-secrets. While they are mainly about analog synthesizers, they seem very applicable to what I want to do: they describe the principles of synthesis, various synthesizer components, and even show examples of how you might create reasonable reproductions of various instruments.

So I’m going to pick one of the instruments they describe (maybe a trumpet) and aim at synthesizing that. I’ll start by removing or refactoring my current synthesizer code from the last project, and I’m going to try to build each synthesizer component as a module that receives inputs and sends outputs to other modules.

Estimated Timeframe

Mar 2nd - Apr 1st

Week 1 Goal

Week 2 Goal

Week 3 Goal

Week 4 Goal

Tags

  • code
  • midi
  • music
  • instrument
  • synthesize
  • c
  • c++
  • audio
  • gamedev
  • sound
  • windows
  • javascript
  • webassembly
  • programming
  • filter