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

Speed problems #2

Closed
jimm opened this issue May 30, 2016 · 3 comments
Closed

Speed problems #2

jimm opened this issue May 30, 2016 · 3 comments

Comments

@jimm
Copy link

jimm commented May 30, 2016

I'm using what I think is the simplest "through" configuration in PortMidi, but the throughput is very slow. Am I doing something wrong?

defmodule Sysex do
  def main(in_name \\ "MidiPipe Output 1", out_name \\ "SimpleSynth virtual input") do
    {:ok, input} = PortMidi.open(:input, in_name)
    {:ok, output} = PortMidi.open(:output, out_name)
    listener = spawn_link(Sysex, :loop, [input, output])
    PortMidi.listen(input, listener)
    :timer.sleep(20_000)       # this will be Process.sleep in future Elixir
    send(listener, :stop)
    PortMidi.close(:input, input)
    PortMidi.close(:output, output)
  end

  def loop(input, output) do
    receive do
      {^input, bytes} ->
        PortMidi.write(output, bytes)
        loop(input, output)
      :stop ->
        :ok
    end
  end
end

When I connect MidiPipe (http:https://www.subtlesoft.square7.net/MidiPipe.html) directly to SimpleSynth (http:https://notahat.com/simplesynth/) by connection MidiPipe's output to the SimpleSynth virtual input, the output keeps up with me as I play a virtual keyboard in MP with my mouse, running the mouse over the keyboard back and forth.

When I switch MP to use its own virtual output and connect to that as an input, and use the code above, it can only keep up with four or five notes a second.

What am I doing wrong?

Also, since this may not be an issue with PortMidi, please let me know if there is a better place to be asking these questions.

@lucidstack
Copy link
Owner

Hi @jimm, sorry for taking so long to reply!

I think I've tackled the issue. As I had initially built this library for a very trivial use case, I hadn't considered performance, and didn't properly fiddle with the buffer size values.

Now I have (hopefully!) set up all the proper values, and playing SimpleSynth from MidiPipe works perfectly on my Macbook. Thank you for pointing me to those apps by the way, really nice stuff for debugging.

Could you give a try to the with-buffer-size branch? You can fetch that branch by having this in your mix.exs:

  defp deps do
    [{:portmidi, github: "lucidstack/ex-portmidi", branch: "with-buffer-size"}]
  end

Please let me know how it goes, and don't hesitate to contact me for further questions or issues of any kind.

@jimm
Copy link
Author

jimm commented Jun 1, 2016

That did it! Thank you, @lucidstack.

@lucidstack
Copy link
Owner

lucidstack commented Jun 1, 2016

Fantastic! I've just merged to master and pushed to Hex, so feel free to...

  defp deps do
    [{:portmidi, "~> 5.0.0"}]
  end

Have a nice day! 👋

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

2 participants