<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title></title>
  <link href="http://chromedshark.com/atom.xml" rel="self"/>
  <link href="http://chromedshark.com/"/>
  <updated>2011-09-25T12:26:37-04:00</updated>
  <id>http://chromedshark.com/</id>
  <author>
    <name>Stephen</name>
    
  </author>

  
  <entry>
    <title>Installing Ruby 1.9.2 Using RVM and Homebrew on Lion</title>
    <link href="http://chromedshark.com/blog/2011/09/installing-ruby-1-9-2-using-rvm-and-homebrew-on-lion.html"/>
    <updated>2011-09-25T11:43:00-04:00</updated>
    <id>http://chromedshark.com/blog/2011/09/installing-ruby-1-9-2-using-rvm-and-homebrew-on-lion</id>
    <content type="html">&lt;p&gt;There seem to be a lot of people having trouble installing Ruby 1.9.2-p290 under
Lion, based off of the many blog posts about changing the C compiler and using
MacPorts, Homebrew, and/or RVM to install a bunch of dependencies. Below is the
process that I used to install it. I'm not quite sure why RVM automatically used
&lt;code&gt;/usr/bin/gcc-4.2&lt;/code&gt; to compile everything on my computer, and why some people need
to set some environment flags to change their default compiler to this. If you
are getting compiler errors, you may need to run &lt;code&gt;export CC=gcc-4.2&lt;/code&gt; before
the &lt;code&gt;rvm install&lt;/code&gt; step.&lt;/p&gt;

&lt;p&gt;First, we're going to install a newer version of the readline library. I used
Homebrew for this, but you should be able to use &lt;code&gt;rvm pkg install readline&lt;/code&gt; as
well.&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;brew install readline
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Once that is finished, take note of where Homebrew said it installed readline.
For me, that path was &lt;code&gt;/usr/local/Cellar/readline/6.2.1&lt;/code&gt; (minus the lib directory).&lt;/p&gt;

&lt;p&gt;Next, we're going to update RVM to make sure there aren't any issues with Lion
and Ruby 1.9.2 that haven't been solved in the latest release.&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rvm get latest
# rvm get head upgrades to the latest dev release
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;The last step in this process is to install Ruby 1.9.2-p290. If you used RVM to
install readline, your path for readline should be changed to &lt;code&gt;$rvm_path/usr&lt;/code&gt;.
If you are using MacPorts, your readline path should be changed to &lt;code&gt;/opt/local&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rvm install 1.9.2 -C --enable-shared,--with-readline-dir=/usr/local/Cellar/readline/6.2.1 \
--with-iconv-dir=/usr --with-zlib-dir=/usr --with-openssl-dir=/usr,\
--build=x86_64-apple-darwin10
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Update On ruby-audio</title>
    <link href="http://chromedshark.com/blog/2010/03/update-on-ruby-audio.html"/>
    <updated>2010-03-25T19:10:00-04:00</updated>
    <id>http://chromedshark.com/blog/2010/03/update-on-ruby-audio</id>
    <content type="html">&lt;p&gt;As a lot has changed over the past two weeks with ruby-audio, I thought an update
would be in order.&lt;/p&gt;

&lt;p&gt;After trying to put the existing version (0.2.0) into production code, I ran into
a whole bunch of issues with the API. It was not ruby-like at all, which made the
code I was writing look ugly. In addition, reading into a small buffer and writing
out to a new sound wasn't possible to do without a lot of unnecessary object
instantiation, as there was no API for writing only a portion of a buffer out to
the sound. Hence, a rewrite was in order. Armed with copies of the ruby 1.8 and
1.9 source code, I set out to re-write the C extension with a prettier API and
without the previous version's issues. The result is ruby-audio version 1.0
(now 1.2.0 as of this writing).&lt;/p&gt;

&lt;p&gt;ruby-audio now has three data classes - &lt;code&gt;Sound&lt;/code&gt;, &lt;code&gt;Buffer&lt;/code&gt;, and &lt;code&gt;SoundInfo&lt;/code&gt;. These
correspond to their C parents - &lt;code&gt;CSound&lt;/code&gt;, &lt;code&gt;CBuffer&lt;/code&gt;, and &lt;code&gt;CSoundInfo&lt;/code&gt;. &lt;code&gt;SoundInfo&lt;/code&gt; maps
to the &lt;code&gt;SF_INFO&lt;/code&gt; struct, providing information like sound length, channel count,
and format. &lt;code&gt;Buffer&lt;/code&gt; is a thin wrapper around a C array of one of the four
datatypes supported for read and write by libsndfile. Finally, &lt;code&gt;Sound&lt;/code&gt; provides
all the standard functions you would expect from an &lt;code&gt;IO&lt;/code&gt; object, including seeks,
reads, and writes.&lt;/p&gt;

&lt;p&gt;With that out of the way, let's look at some code. The following example takes
an array of compatible sound files and numbers and turns it into a single
one-channel wav.&lt;/p&gt;

&lt;p&gt;``` ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'ruby-audio'

# Create wav output file
info = RubyAudio::SoundInfo.new :channels =&amp;gt; 1, :samplerate =&amp;gt; 44100,
                                :format =&amp;gt; RubyAudio::FORMAT_WAV|RubyAudio::FORMAT_PCM_16
out = RubyAudio::Sound.open('out.wav', 'w', info)

# Initialize read/write and pause buffers
one_sec = RubyAudio::Buffer.double(44100)
one_sec.real_size = 44100
buf = RubyAudio::Buffer.double(10000)

# For numbers, insert a pause for the given number of milliseconds
# For strings, open the sound file and append
wavs.each do |wav|
  if wav.is_a?(Numeric) # Pause
    secs = (wav/1000).to_i
    millisecs = wav % 1000

    # Handle milliseconds
    if millisecs &amp;gt; 0
      one_sec.real_size = (44100 * millisecs/1000).to_i
      out.write(one_sec)
      one_sec.real_size = 44100
    end
    secs.times { out.write(one_sec) }
  else
    RubyAudio::Sound.open(wav, 'r') do |snd|
      out.write(buf) while snd.read(buf) &amp;gt; 0
    end
  end
end

out.close
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;If you have any issues with the API or features you'd like to see implemented,
don't hesitate to fork and fix it on &lt;a href=&quot;https://github.com/warhammerkid/ruby-audio&quot;&gt;github&lt;/a&gt;,
add it to the issues, or send me an e-mail.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Revival of ruby/audio</title>
    <link href="http://chromedshark.com/blog/2010/02/revival-of-rubyaudio.html"/>
    <updated>2010-02-09T13:33:00-05:00</updated>
    <id>http://chromedshark.com/blog/2010/02/revival-of-rubyaudio</id>
    <content type="html">&lt;p&gt;I needed to do some audio concatenation for a project I'm working on, and after
much research, came to the conclusion that &lt;a href=&quot;http://www.mega-nerd.com/libsndfile/&quot;&gt;libsndfile&lt;/a&gt;
would be the easiest to work with. However, with all of the overhead of calling
out to a command-line program for every file I wanted to join, I figured it would
be better to write a C-based gem wrapper around it. Thus, ruby/audio.&lt;/p&gt;

&lt;p&gt;Google quickly led me to &lt;a href=&quot;https://github.com/fugalh/ruby-audio&quot;&gt;Hans' ruby-audio&lt;/a&gt;,
which hadn't had any major modifications since November of 2006. Looking at the
forks lead to the most recent fixes by others. After finding and fixing a bug
noticed in my audio concatenation project, I decided to turn it into a gem and
put it up on Gemcutter.&lt;/p&gt;

&lt;p&gt;If you'd like to get started using it, first install ruby-audio from gemcutter:
&lt;code&gt;gem install ruby-audio --source=&quot;http://gemcutter.org&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Afterwards, simply require audio/sndfile and start writing code. Here's an
example that concatenates a list of files and writes the final file to out.wav.&lt;/p&gt;

&lt;p&gt;``` ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require 'rubygems'
require 'audio/sndfile'

out_conf = Sndfile::SF_INFO.new
out_conf.format = Sndfile::SF_FORMAT_WAV|Sndfile::SF_FORMAT_PCM_16
out_conf.channels = 1
out_conf.samplerate = 44100
out = Audio::Soundfile.open('out.wav', 'w', out_conf)

['audio1.wav', 'audio2.wav'].each do |file|
  snd = Audio::Soundfile.open(file)
  buf = Audio::Sound.float(1000)
  read = snd.read(buf)
  while read != 0
    out.write(buf)
    read = snd.read(buf)
  end
  snd.close
end

out.close
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;My code can be found Github at &lt;a href=&quot;https://github.com/warhammerkid/ruby-audio&quot;&gt;warhammerkid/ruby-audio&lt;/a&gt;,
and I expect to make a few more modifications to it to clean up the API and
improve the documentation over the next couple weeks.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Rack Middleware in Rails 2</title>
    <link href="http://chromedshark.com/blog/2009/10/rack-middleware-in-ruby.html"/>
    <updated>2009-10-09T10:00:00-04:00</updated>
    <id>http://chromedshark.com/blog/2009/10/rack-middleware-in-ruby</id>
    <content type="html">&lt;p&gt;If you have a rack middleware packaged as a gem that you would like to use in
your rails app, add these lines to your environment.rb file:&lt;/p&gt;

&lt;p&gt;``` ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;config.gem 'rack-amf', :lib =&amp;gt; 'rack/amf', :source =&amp;gt; &quot;http://gemcutter.org/&quot;
config.middleware.use 'Rack::AMF', :url =&amp;gt; '/amf'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Make sure you put the middleware name in a string, or rails initialization will
fail because the gem hasn't loaded yet.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Strings in AS3 and Memory</title>
    <link href="http://chromedshark.com/blog/2009/03/strings-in-as3-and-memory.html"/>
    <updated>2009-03-20T12:55:00-04:00</updated>
    <id>http://chromedshark.com/blog/2009/03/strings-in-as3-and-memory</id>
    <content type="html">&lt;p&gt;I was doing some experimenting to see whether having multiple references to a
string took up much space, and it turns out that Flash doesn't actually deep-copy
strings when you copy them around. Instead it copies by reference until a change
is made, which then forces a deep copy. This is similar to the way PHP works,
passing strings by value but not actually creating a new object until the value
is changed. Below is the code I used to determine this:&lt;/p&gt;

&lt;p&gt;``` as3&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import flash.system.System;
import flash.utils.ByteArray;

function clone(source:Object):* {
    var copier:ByteArray = new ByteArray();
    copier.writeObject(source);
    copier.position = 0;
    return(copier.readObject());
}

var str:String = &quot;This is a test of string copying&quot;;
var storeA:Array = [];
var storeB:Array = [];
var before:int;

// Test A
before = System.totalMemory;
for(var i:int = 0; i &amp;lt; 10000; i++) {
    storeA.push(clone(str) as String);
}
trace(System.totalMemory - before); // Total Mem Increase: 3280896

// Test B
before = System.totalMemory;
for(var j:int = 0; j &amp;lt; 10000; j++) {
    storeB.push(str);
}
trace(System.totalMemory - before); // Total Mem Increase: 49152

// Can you change str without affecting storeB?
str = &quot;New value&quot;;
trace(storeB[0]); // 'This is a test of string copying'

// Can you change storeB[0] without affecting storeB[1]?
storeB[0] += 'a';
trace(storeB[0]+&quot; vs &quot;+storeB[1]);
// 'This is a test of string copyinga vs This is a test of string copying'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;
</content>
  </entry>
  
</feed>

