Giter Club home page Giter Club logo

Comments (6)

 avatar commented on May 8, 2024

Hello,

For a first try, the perf utility on Linux could be used to determine which function use the most resources. I'll give it a quick try to see precisely where the bottleneck is.

from pyxel.

irmen avatar irmen commented on May 8, 2024

How is your oscillator being a bottleneck?

It looks very similar to what I'm doing myself in my own software synthesizer (however, mine is using a generator to produce the soundwave values) see https://github.com/irmen/synthesizer/blob/master/synthplayer/synth.py#L899
I think your oscillator inner loop may suffer from the fact that you're calling a function to get every individual value.

Another thing, which is a problem with Python, is that your sound generator code from the stream callback will run in a separate thread but this will block other Python code from executing. The only easy way around this is to either move all of your sound generation code into a C extension module that can release the GIL, or use a separate process

I assume you need realtime sound synthesis because the program seems to be able to change the sound notes and parameters on the fly? If not you can also consider generating whole audio clips in advance and playing those, rather than generating every individual sample value on the fly

from pyxel.

kitao avatar kitao commented on May 8, 2024

@irmen
Regarding oscillator. Actually I didn't measure the performance of it, but on my MacBook, sometimes noise occurs and I think it may be caused by the under flow of the oscillator.

As you wrote, the reason generating sound in real time is to control it from applications flexibly. So if possible, I'd like to keep this style.

Your code is very helpful! So should I use generator to reduce function calling overhead?

from pyxel.

kitao avatar kitao commented on May 8, 2024

@marespiaut It would be great help! I expect that the measurement result will be come out.

from pyxel.

irmen avatar irmen commented on May 8, 2024

@kitao benchmark/measure your oscillator code first to know its limits now.

As an indication, my FastTriangle oscillator performs like this on my computer:

testing FastTriangle ... 1960 K iterations/sec (44.5 x realtime @ 44100 hz)

If you create a sounddevice with half the output hz (22050) the speed will be almost twice as high because only half of the audio data has to be generated. That may also be an easy fix.

from pyxel.

kitao avatar kitao commented on May 8, 2024

For now, there's no request for performance improvement. So I close this issue once.

from pyxel.

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.