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.
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.
- Keep lines 118 characters or shorter. Obviously sometimes you can't, but please try. Use 80 or 115 characters for Markdown files, though.
- Please use pascalCase for variable and method names. Use CamelCase for type names. Use UPPER_SNAKE_CASE for constants.
- Put parentheses around method parameters, except for these methods:
puts
,pp
,p
,raise
,sleep
,spawn
,loop
, andexit
. - Always the full
do |foo|...end
syntax with blocks, except when it's all on one line or an anonymous function, then use { and } or the normaldo |foo|...end
. - The type name for exceptions end with Error. For example,
ExternalProgramError
.
How do I contribute?
- Go to https://chiselapp.com/user/MistressRemilia/repository/remiportaudio and clone the Fossil repository.
- Create a new branch for your feature.
- Push locally to the new branch.
- Create a bundle with Fossil that contains your changes.
- Get in contact with me.
Contributors
- Remilia Scarlet - creator and maintainer
- Homepage: https://remilia.sdf.org/
- Mastodon: @MistressRemilia@social.sdf.org
- Email: zremiliaz@postzeoz.jpz My real address does not contain Z's
Links and Licenses
RemiPortAudio itself is under the GNU General Public License version 3.