Giter VIP home page Giter VIP logo

Comments (6)

adrianmcroft avatar adrianmcroft commented on June 8, 2024

So I've done a bit of digging....

I've duplicated my Bela code into a windows console application - this seems to run without any audio noise / trashing during render however many notes are played.

I'm guessing from this that my Bela is running out of CPU headroom (despite the CPU monitor never going over 50%). I've implemented some basic note stealing and limited Bela to 32 notes - I'm using the oldest note - and it works pretty well.

More when I've tidied the code a little.y

from tinysoundfont.

kode54 avatar kode54 commented on June 8, 2024

On what sort of device is the meter not going over 50%? On some platforms, the CPU usage percentage is across the whole CPU, and for a dual core CPU, 50% would be 100% of a single core. I think Linux and macOS both register percentage of individual CPU cores, rather than percentage of the entire CPU set available.

from tinysoundfont.

schellingb avatar schellingb commented on June 8, 2024

@adrianmcroft Do you know if the CPU in your Bela board has multiple cores? At least on Windows a reported 50% usage on a dual core CPU would mean one thread running at 100%. TSF itself runs only single threaded.

So yeah the current implementation doesn't limit max voices. In the function tsf_note_on on line 1251 it decides that it ran out of room for voices and allocates space for 4 more. You could fairly easy check if your maximum is reached and then just return; right there before the increase of voiceNum.
Adding something like a tsf_set_max_voices(...) function with a default of 0 (unlimited) voices would be a good idea I think.

from tinysoundfont.

adrianmcroft avatar adrianmcroft commented on June 8, 2024

Thanks Christopher and Bernhard, I'm still crossing over the stream to Linux and C++ from Windows and C# so thanks for any support.

So I'm running on a Beaglebone Black with a Bela Cape (BBB) which has a 1Ghz single Arm chip (http://bela.io/). Bela has very low latency which is why I've chosen it to play with.

So I've implemented some basic note stealing. As you say, before allocating new voices in [TSF_NOTE_ON] I'm counting playing voices and if its above my chosen maximum I steal. I'm using the oldest note - I've added a cycle counter INT to TSF_VOICE which is incremented during render and the biggest is the oldest. It's very rough but I'm just trying it as a POC. It actually works very well indeed.

Bela requires a funky cable to debug on the board and until them I'm stuck in suck and see land.

from tinysoundfont.

schellingb avatar schellingb commented on June 8, 2024

Ohh, yeah stealing old voices instead of just not playing new voices is a great idea.
You don't even need to count voices, you can just do the voice stealing inside the if (!voice) block as that means that all allocated voices are active. Also to find the oldest voice just check which voice has the oldest playIndex value. This value gets increased by one for every new voice.

from tinysoundfont.

adrianmcroft avatar adrianmcroft commented on June 8, 2024

Crumbs, that's a better tactic. I'll review the changes - I can now rip out half of my lines at least :)

from tinysoundfont.

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.