0.0
No commit activity in last 3 years
No release in over 3 years
A collection of building blocks for making music in pure ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.14
~> 13.0

Runtime

~> 1.1
 Project Readme

Synth Blocks

Synth blocks is a proper extraction of the synthesizer/sequncer I built for my Ruby Synth talk an Euruko and RubyConf.by

It is a gem and can be used for writing electronic music in ruby. See examples for more info on how to use this.

Blocks

The code is divided into 7 sections:

  • Core contains things like Oscillators and filters, a base class for all generators as well as a class that uses the wavefile gem to write out sound files
  • Mod contains modulators, currently two Envelopes
  • Drum and Synth contains Drum and Synthesizer generators respectively
  • Fx contains Audio effects such as Reverb, Chorus, Delay, Waveshaper and more
  • Mixer contains utilities to build a mixing system
  • Sequencer contains a DSL for building songs

The code is super unoptimised, as it is written for learning purposes. This means, for example, that the full song contained in examples/a_song.rb takes a couple of hours to render. I'm relatively sure that there are some low hanging fruits for optimisation, especially in the sequencer code that does a lot of useless lookups on quite large data structures that hold the automation data, but I haven't yet gotten around to take a look at it.

Opal

Since my presentation runs in a browser I thought it could be fun to try to make this library run in Opal and thus in the browser.

It works but obviously long running code that will block the main thread is not something that makes browsers (and users) happy, but for small demonstrations, it's probably good enough.

There are two modules that do not work:

  • GVerb uses prime numbers but Opal does not implement Stdlib::Prime.
  • To prevent adding WaveFile as an additional dependency (and because it doesn't make a ton of sense for my usecase), WaveWriter is not functional in Opal.

Examples

The easiest way to test the example code is to check out the repo and then execute the code directly.

Each example has a line on the bottom:

SynthBlocks::Core::WaveWriter.write_if_name_given(out)

This will write out a wave file if you run the file with a wav-file as the last argument like so:

ruby -Ilib examples/waveshaper_demo.rb test.wav

License

All code here is licensed under the AGPL 3.0 license as documented at LICENSE unless stated otherwise.