Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong number of arguments when calling write_array_of_type #974

Open
nikolas-n opened this issue Oct 13, 2022 · 0 comments
Open

Wrong number of arguments when calling write_array_of_type #974

nikolas-n opened this issue Oct 13, 2022 · 0 comments

Comments

@nikolas-n
Copy link

Hello all, I'd like to ask your help. If you believe that this shouldn't be here, feel free to close it.
I'm trying to run sippy_cup and specifically this part of the code

# ffi interface to freeswitch's g711
require 'ffi'

module SippyCup
  module G711
    extend FFI::Library
    ffi_lib 'spandsp'

    enum :EncodeState, [
      :G711_ALAW, 0,
      :G711_ULAW, 1,
    ]

    class G711State < FFI::Struct
      layout :mode,  :EncodeState
    end

    attach_function :g711_encode, [ G711State, :pointer, :pointer, :int ], :int

    def encode(samples)
      state = G711State.new
      state[:mode] = :G711_ULAW # u-law only

      iptr = FFI::MemoryPointer.new(:int16, samples.size)
      optr = FFI::MemoryPointer.new(:uint8, samples.size)

	  #puts samples.join(' ')
      iptr.write_array_of_type(:int16, :write_int16, samples)
      g711_encode(state, optr, iptr, samples.size)
      output = optr.read_array_of_type(:uint8, :read_uint8, samples.size)
	  #puts output.join(' ')
      output
    end
    module_function :encode
  end
end

And I'm getting this

Compiling media to /home/nik/github/sippy_cup/play_audio.pcap...Traceback (most recent call last):
	15: from /usr/local/bin/sippy_cup:23:in `<main>'
	14: from /usr/local/bin/sippy_cup:23:in `load'
	13: from /home/nik/.gems/gems/sippy_cup-0.7.2/bin/sippy_cup:64:in `<top (required)>'
	12: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/scenario.rb:878:in `compile!'
	11: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/scenario.rb:975:in `compile_media'
	10: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/media.rb:44:in `compile!'
	 9: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/media.rb:44:in `each'
	 8: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/media.rb:95:in `block in compile!'
	 7: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/media.rb:95:in `times'
	 6: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/media.rb:109:in `block (2 levels) in compile!'
	 5: from /home/nik/.gems/gems/sippy_cup-0.7.2/lib/sippy_cup/g711.rb:28:in `encode'
	 4: from /var/lib/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/pointer.rb:134:in `write_array_of_type'
	 3: from /var/lib/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/pointer.rb:134:in `each_with_index'
	 2: from /var/lib/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/pointer.rb:134:in `each'
	 1: from /var/lib/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/pointer.rb:136:in `block in write_array_of_type'
/var/lib/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/pointer.rb:136:in `write_int16': wrong number of arguments (given 2, expected 1) (ArgumentError)

Do you know why this happens? I tried to check similar errors on the web and in the issues of this repo, but didn't find much...
Apologies if it's something you've already covered elsewhere.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant