Reputation: 1214
I'm trying to get an audio player working with Crystal. The internet indicated that portaudio was the best C library for playing audio, and seeing as there are no native Crystal libraries, it seems like the best option.
Someone already put in most of the work for binding the portaudio API to Crystal, but the project is out of date and seems to have been broken by a Crystal update. I'm thinking it will be easier to fix someone else's bindings, than do the whole things from scratch.
That was an unnecessarily long introduction. When I try to compile crystal-portaudio
, I get the following error:
$ crystal src/portaudio.cr ~/sw/crystal/crystal-portaudio (master)
Error in src/portaudio.cr:1: while requiring "./portaudio/*"
require "./portaudio/*"
^
in src/portaudio/device.cr:2: while requiring "./host_api"
require "./host_api"
^
in src/portaudio/host_api.cr:5: can't use instance variables at the top level
delegate :device_count, :default_input_device, :default_output_device, :type, @info
^~~~~
Upvotes: 0
Views: 600
Reputation: 4857
Here's the minimal patch to get crystal spec
and crystal samples/list.cr
to compile and run with Crystal 0.22, however the shard seems to need a lot more work still to be really usable.
diff --git a/spec/portaudio_spec.cr b/spec/portaudio_spec.cr
index d8171a9..049a294 100644
--- a/spec/portaudio_spec.cr
+++ b/spec/portaudio_spec.cr
@@ -1,6 +1,6 @@
require "./spec_helper"
-describe Portaudio do
+describe Pa do
# TODO: Write tests
it "works" do
diff --git a/src/portaudio/device.cr b/src/portaudio/device.cr
index f5ec4f3..cf999ee 100644
--- a/src/portaudio/device.cr
+++ b/src/portaudio/device.cr
@@ -3,13 +3,13 @@ require "./host_api"
module Pa
class Device
- delegate :max_input_channels, :max_output_channels, @info
- delegate :default_low_input_latency, :default_low_output_latency, @info
- delegate :default_high_input_latency, :default_high_output_latency, @info
- delegate :default_sample_rate, @info
+ delegate :max_input_channels, :max_output_channels, to: @info
+ delegate :default_low_input_latency, :default_low_output_latency, to: @info
+ delegate :default_high_input_latency, :default_high_output_latency, to: @info
+ delegate :default_sample_rate, to: @info
getter id
- def initialize(@id, @info)
+ def initialize(@id : Pa::DeviceIndex, @info : LibPortAudio::DeviceInfo)
end
def name
diff --git a/src/portaudio/host_api.cr b/src/portaudio/host_api.cr
index de3b521..9a95ec2 100644
--- a/src/portaudio/host_api.cr
+++ b/src/portaudio/host_api.cr
@@ -2,9 +2,9 @@ require "./lib"
module Pa
class HostApi
- delegate :device_count, :default_input_device, :default_output_device, :type, @info
+ delegate :device_count, :default_input_device, :default_output_device, :type, to: @info
- def initialize(@info)
+ def initialize(@info : LibPortAudio::HostApiInfo)
end
def name
Upvotes: 3