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

Fix Exception: Only able to fetch buffer data directly from an internal server. Try #'buffer-read instead. #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

markus-wa
Copy link

heyya!

First off, very cool project!

So I was trying to run the example from https://github.com/rogerallen/sot on Windows 64 bit which requires an external server for overtone but it seems like this isn't supported by shadertone right now.

lein repl
(use 'overtone.core)
(connect-external-server 2345)
(require '[shadertone.tone :as t])
(t/start "src/sot/throb.glsl")

gives:

Loading shader from file: src\sot\throb.glsl
Exception in thread "Thread-10" java.lang.Exception: Only able to fetch buffer data directly from an internal server. Try #'buffer-read instead.
        at overtone.sc.buffer$buffer_data.invokeStatic(buffer.clj:572)
        at overtone.sc.buffer$buffer_data.invoke(buffer.clj:568)
        at shadertone.tone$tone_fftwave_fn.invokeStatic(tone.clj:127)
        at shadertone.tone$tone_fftwave_fn.invoke(tone.clj:98)
        at shadertone.tone$tone_default_fn.invokeStatic(tone.clj:205)
        at shadertone.tone$tone_default_fn.invoke(tone.clj:172)
        at shadertone.shader$draw.invokeStatic(shader.clj:585)
        at shadertone.shader$draw.invoke(shader.clj:548)
        at shadertone.shader$update_and_draw.invokeStatic(shader.clj:697)
        at shadertone.shader$update_and_draw.invoke(shader.clj:664)
        at shadertone.shader$run_thread.invokeStatic(shader.clj:728)
        at shadertone.shader$run_thread.invoke(shader.clj:722)
        at shadertone.shader$start_shader_display$fn__14093.invoke(shader.clj:935)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.base/java.lang.Thread.run(Thread.java:835)
 Only able to fetch buffer data directly from an internal server. Try #'buffer-read instead.

This change fixes that by adding and using a new function buffer-data-read which will use buffer-data or buffer-read depending on server/internal-server?.

This is the first time of using Clojure, Overtone and Shadertone, so I hope I did everything right 😅.
I was also not exactly sure on the naming of the function. LMK if you'd prefer some other name.

Happy holidays ❄️!

@rogerallen
Copy link
Member

Thanks for the PR! I would like to try to get setup on Win10 to try this out. Might take me some time as I have a few higher priority things going on, but I will give this a try when I can. Thanks!

@markus-wa
Copy link
Author

No worries @rogerallen, with the holidays and all going on I was already expecting it would take some time. For now I'm good just using a locally installed snapshot 🙂.

I'm also not sure if this is a performance issue / bottleneck since I'm getting stuttery output / low FPS. It could be that the throughput / delay that reading from the external server is causing it - but at least it's an improvement over not working at all.

@markus-wa
Copy link
Author

markus-wa commented Dec 30, 2019

Regarding my performance issues - I've been playing around a bit more and decreasing WAVE-BUF-SIZE from 4096 to 1024 quadrupled my FPS (at the cost of the waveform/FFT detail). That made a whole lot of sense when I noticed that we always re-read a full buffer - one buffer seems to be around 50 ms of audio with my sampling rate etc (x2 for FFT + WAVE -> 100 ms -> 10 FPS).

I think I will look into finding a good sampling rate + WAVE-BUF-SIZE combo for my purposes 🙂.
Another idea would be to have a 'rolling' buffer which is updated in a separate thread so we don't need to block the rendering thread to read data from SC. If you think that's a good idea I might give it a shot to implement it (if it's not too difficult for a newbie like me, anyway).

But maybe we should move that to a separate issue.

@rogerallen
Copy link
Member

Now that you mention it, I think I recall trying an external server in the past & ran into the same performance issues. I wonder if they are something that cannot be fixed? Likely the better answer is to use shadertone with an internal server only and get your issue overtone/overtone#447 fixed?

@markus-wa
Copy link
Author

Unfortunately overtone/overtone#447 is not looking like an easy fix from the little investigation I did - but if it can be fixed it would be great of course. I also saw in some places that it's actually generally recommended to use the external server, even on other platforms overtone/overtone#315 (comment) (I also had trouble running the internal one on Linux, actually).

As it stands now the workaround with reduced buffer size is enough for me.
If we cannot fix it completely, maybe a variable buffer size would be another solution.

@markus-wa
Copy link
Author

Do you think we should merge this as is @rogerallen ?

It should at least be an improvement over the current situation of not working at all, even if using the external server will be slow by default.

@rogerallen
Copy link
Member

Thanks for keeping on this. I've been meaning to get a Win64 system setup to test this, but haven't made the time yet. I really wish overtone setup on either Windows or Linux was as straightforward as the Mac...I need to set aside a day to read up & get it working and while I will do this as soon as I can, it is not at the top of my priority list, sorry. This weekend it is taxes!

@markus-wa
Copy link
Author

No worries, otherwise I might give you another ping here in a month or so 😄

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

Successfully merging this pull request may close these issues.

2 participants