Login
RemiPortAudio
Login

RemiPortAudio

NOTE: This library has been merged into RemiAudio and is no longer updated or maintained. Please migrate to RemiAudio instead.

RemiPortAudio is a set of Crystal bindings for PortAudio.

Wanna support Remilia? Buy me a coffee on Ko-Fi, or support me through Liberapay.

Buy Me a Coffee at ko-fi.com Donate using Liberapay

How do I get set up?

You will need Fossil installed to clone this repo. You will also need Shards v0.17.1 or later. If you have an earlier version of Shards, you will need to to build the latest version manually.

Add this to your shard.yml file:

dependencies:
  remiportaudio:
    fossil: https://chiselapp.com/user/MistressRemilia/repository/remiportaudio

You will need a version of Shards that is at least 0.17.0. If you have an earlier version, you will need to build the latest version of Shards by hand to get Fossil support.

Usage

There are a few examples in the examples directory in this repository. This one is taken from examples/generate-sine.cr:

require "math"
require "../src/remiportaudio"

# Generate a sine WAV at 440hz for 5 seconds at 44.1KHz
seconds = 3
sampleRate = 44100
freq = 440.0
buf = Array(Float32).new(seconds * sampleRate, 0.0)
sampleFormat = RemiPA::SampleFormat::Float32

RemiPA.withPA do
  # 1 output channel, no input channels, Float32 format
  RemiPA::PaStream.withDefaultStream(nil, 1,
                                     sampleFormat: sampleFormat,
                                     sampleRate: sampleRate.to_f64,
                                     framesPerBuffer: buf.size.to_u64) do |strm|
    puts "\nPortAudio initialized.  Any warnings/errors above were from PortAudio"
    puts "#{seconds} second sine wave at #{freq}"

    # Fill buffer
    buf.size.times do |i|
      sample = Math.sin(i * freq * 2 * Math::PI / sampleRate).to_f32!
      buf[i] = sample
    end

    # Send to PortAudio
    strm << buf
    sleep seconds.seconds
  end
end

Development

Style info

I use a somewhat non-standard style for my code.

How do I contribute?

  1. Go to https://chiselapp.com/user/MistressRemilia/repository/remiportaudio and clone the Fossil repository.
  2. Create a new branch for your feature.
  3. Push locally to the new branch.
  4. Create a bundle with Fossil that contains your changes.
  5. Get in contact with me.

Contributors

Links and Licenses

RemiPortAudio itself is under the GNU General Public License version 3.