Jay McGavren's Journal

2009-11-16

Sound waves on acid...

Looks like I’ll be talking on using Ruby on Acid for audio at a meetup in San Francisco during RubyConf. So, time to make sure it can actually do audio. :)

This would probably horrify anyone with audio programming experience, but: I just write a bunch of bytes ranging 0-255 to a file, then import into audacity as raw 8-bit PCM data.

require 'rubygems'
require 'rubyonacid/factories/meta'
require 'rubyonacid/factories/constant'
require 'rubyonacid/factories/flash'
require 'rubyonacid/factories/loop'
require 'rubyonacid/factories/modulo'
require 'rubyonacid/factories/random'
require 'rubyonacid/factories/repeat'
require 'rubyonacid/factories/sine'
require 'rubyonacid/factories/skip'

def generate_factories

  random_factory = RubyOnAcid::RandomFactory.new

  factory_pool = []

  #Loop factories loop from 0.0 to 1.0 (or 1.0 to 0.0 if the increment value is negative).
  factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.01, 0.01))
  #Constant factories always return the same value,
  factory_pool << RubyOnAcid::ConstantFactory.new(rand)
  factory_pool << RubyOnAcid::ConstantFactory.new(rand)
  factory_pool << RubyOnAcid::FlashFactory.new(rand(100))
  #Sine factories produce a "wave" pattern.
  factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.01, 0.01))
  factory_pool << RubyOnAcid::RepeatFactory.new(
    RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
    random_factory.within(:interval, 2, 100)
  )
  factory_pool << RubyOnAcid::RepeatFactory.new(
    RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
    random_factory.within(:interval, 2, 100)
  )
  factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
  factory_pool
end

#A skip factory, in charge of randomly resetting the meta factory.
@resetter = RubyOnAcid::SkipFactory.new(0.99995)

factory = RubyOnAcid::MetaFactory.new
factory.factory_pool = generate_factories
File.open("raw_audio.dat", "w") do |file|
  loop do
    channel_count = factory.within(:chanel_count, 0, 3).to_i
    channel_count.times do |i|
      file.putc factory.within(i, 0, 255).to_i
    end
    if @resetter.boolean(:reset)
      factory.factory_pool = generate_factories
      factory.reset_assignments
    end
  end
end

The result is a tour of every sound ever emitted by an Atari 2600:

Ruby On Acid 8-bit raw sound…

I also have a MIDI experiment going. Neither is spectacular, but the nice part is that the programs needn’t change; I just need better generators.

Read more...
2009-11-14

My Scratch talk at Ignite Phoenix 5...

Huzzah, they posted my Ignite Phoenix presentation on Scratch!

http://www.youtube.com/watch?v=FSHTLuQqAtE

Couple slips, but I’ll be the main one to notice those. If RubyConf goes this well, I’ll be really happy.

Read more...
2009-11-11

ZOMG giant cat!

Gave a talk on Scratch at Ignite Phoenix 5… Well received, and it seemed to spark a lot of interest. (Heard from Brian Carson that his kid downloaded it as soon as he saw the talk on the video stream.)

Jay on Scratch at Ignite Phoenix 5Jay on Scratch at Ignite Phoenix 5Jay on Scratch at Ignite Phoenix 5Jay on Scratch at Ignite Phoenix 5

Photos by Sheila Dee: <div>http://www.flickr.com/photos/sheila_dee/ / CC BY-NC-ND 2.0</div>

Read more...
2009-11-02

Life simulation ideas...

Just watched the Nature episode “Born Wild: The First Days of Life”, and got a dangerously large number of ideas for an artificial life simulation.

Here are (some of) the forces that seem to be in play:

  • Food and energy affect all aspects of birthing strategies. All these make it more likely at least some young will survive, but take energy in return:
    • Producing more than one fetus.
    • Long gestation periods.
    • Making yolk inside eggs.
    • Producing milk.
  • If you're not top of the food chain, your babies need to be born ready to run. A longer gestational period is in order.
  • A baby can be left to fend for itself, if it's born smart enough to find food. This means no milk production or babysitting, but probably also means longer gestation.
  • Birds let the strongest infant feed first - it's most likely to survive. The others get the scraps and if they live too, great. Sometimes the strongest sibling kills the weaker ones. Sometimes the parents themselves do.
  • If the father stays to help, it brings extra food energy into the equation - he feeds the kids or sometimes the mother. Sometimes this means bigger litters, or in the case of emperor penguins, it simply means survival.
  • Sometimes the mother herself is the food energy - one species of spider willingly lets the babies eat her alive.
  • For males, killing the cubs of your rivals is a good way to get their harems ready to mate with you. Of course, you have to prove your genetic superiority by fighting off the father first.
  • Social animals help defend each others' young, IF they're from the same father. Children from other groups get attacked, though.

Read more...
2009-10-27

Ruby on Acid: YAML says it all...

00021_random.png

--- !ruby/object:RubyOnAcid::MetaFactory
assigned_factories:
  :x2: &id001 !ruby/object:RubyOnAcid::LoopFactory
    counters:
      :x2: 0.0809003150016822
      :x: 0.0809003150016822
    interval: 0.0431080448196972
  :y: &id005 !ruby/object:RubyOnAcid::SineFactory
    counters:
      :y: -47.6973132292325
    interval: -0.0661543872804878
  :blue: &id004 !ruby/object:RubyOnAcid::SineFactory
    counters:
      :blue: -49.6672530194527
    interval: -0.0688866199992418
  :y2: &id006 !ruby/object:RubyOnAcid::SineFactory
    counters:
      :y2: -48.3512112649079
    interval: -0.067061319368805
  :alpha: &id002 !ruby/object:RubyOnAcid::LoopFactory
    counters:
      :alpha: 0.026577401239561
    interval: 0.0735458771168371
  :width: &id008 !ruby/object:RubyOnAcid::RepeatFactory
    repeat_count: 73.7486871161379
    repeat_counts:
      :width: 55
    source_factory: !ruby/object:RubyOnAcid::SineFactory
      counters:
        :width: -0.763070310680217
      interval: -0.0763070310680217
    values:
      :width: 0.154428166901605
  :red: &id003 !ruby/object:RubyOnAcid::FlashFactory
    counters:
      :red: 35
    interval: 48.2819400095083
    values:
      :red: 1.0
  :x: *id001
  :green: &id007 !ruby/object:RubyOnAcid::RepeatFactory
    repeat_count: 92.57504008154
    repeat_counts:
      :green: 70
    source_factory: !ruby/object:RubyOnAcid::LoopFactory
      counters:
        :green: 0.389712742634083
      interval: -0.0762859071707396
    values:
      :green: 0.389712742634083
factory_pool:
- !ruby/object:RubyOnAcid::LoopFactory
  counters: {}

  interval: 0.00689322163990813
- *id002
- !ruby/object:RubyOnAcid::LoopFactory
  counters: {}

  interval: -0.0330245624043419
- *id001
- !ruby/object:RubyOnAcid::ConstantFactory
  value: 0.799727962512452
- *id003
- *id004
- *id005
- !ruby/object:RubyOnAcid::SineFactory
  counters: {}

  interval: -0.04853454869413
- *id006
- *id007
- !ruby/object:RubyOnAcid::RepeatFactory
  repeat_count: 385.71501513496
  repeat_counts: {}

  source_factory: !ruby/object:RubyOnAcid::RandomFactory {}

  values: {}

- *id008
- !ruby/object:RubyOnAcid::ModuloFactory
  prior_values: {}

  source_factory: !ruby/object:RubyOnAcid::LoopFactory
    counters: {}

    interval: 1.0e-05

Read more...