Code Monkey home page Code Monkey logo

Comments (3)

alnitak avatar alnitak commented on May 25, 2024

Hi @LeventeAsztalos, thanks for your findings.

I did some experiments using Soloud.play() and Soloud.playClocked().
On C side I wrote a thread which plays your given sample 200 times. The result is this:
2024-04-20_13-46

The upper graph is made using Soloud.playClocked(), the bottom with Soloud.play() with a microseconds scale.
As you can see there are a lot of delays around 40ms which is the buffer length as stated in Soloud.playClocked() doc:

Note that if your "physics time" granularity is low, playClocked is not really useful. Audio buffers tend to be 40ms long at most.

To test this, I used this code on C side:

ActiveSound *sound = sounds[0].get();
std::thread th(
    [sound, time, this]
    {
        for (int i = 0; i < 200; i++)
        {
            std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
            this->soloud.playClocked(time, *sound->sound.get());
            // this->soloud.play(*sound->sound.get());
            usleep(time*1000000);
            std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
            std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << std::endl;
        }
    });
th.detach();

There is no much difference doing the same on Flutter side with a code similar to yours. So the problem could be on SoLoud lib, but as you stated, the lib is not meant to be used as a music sequencer.

I have to investigate further, maybe there is some compiler args to pass or some other tips I missed.

from flutter_soloud.

alnitak avatar alnitak commented on May 25, 2024

Digging further I tried lowering the buffer size to 1024 or 512 instead of 2048 (which stores the previously mentioned 40ms).
This is the result:

2024-04-20_17-48

There is not much difference between playClocked() and play(), anyway some better results.

Currently is not possible to change player initializing parameters, but you can try to manually modify it here

from flutter_soloud.

LeventeAsztalos avatar LeventeAsztalos commented on May 25, 2024

Thanks for the quick and detailed analysis! I tried with 512 buffer size, and the result were much better. It would be nice if we could set these params from the flutter side. On the other hand with this approach there will always be some latency. My original problem is not related to the package itself, it rather a technical method question, so I close this issue.

from flutter_soloud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.