Comments (6)
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.
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.
@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.
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.
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.
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)
- Line 59 of tsf.h HOT 1
- "conversion may change the value [-Werror=conversion]" compilation errors on MCST lcc compiler HOT 2
- Volume curve HOT 2
- this library wrote 3300 seconds of PCM audio in 4.9 seconds. (nice work) HOT 1
- Is it possible to use this library with SDL_mixer?
- How I can stop a note by fading the volume? HOT 2
- How many channels does this support? HOT 2
- white noise unexpected sound when playing the files HOT 2
- Stuck instrument with Windows XP onestop.mid HOT 1
- Incompatibility with ISO C++ HOT 2
- `TSF_MALLOC(...)` without non-NULL check/error handling HOT 3
- Design issue: having playback handling and soundfont in same structure incentivizes people to write memory hogs(?) HOT 3
- `tsf_set_max_voices()` should actually be enforced HOT 2
- Unicode open HOT 1
- Would be possible to sustain a note? HOT 2
- Is .sfz support something devs consider also thank you for the library HOT 6
- voices active for slightly longer than they should be
- Reading samples directly at runtime (port to STM32) HOT 1
- MIDI latency HOT 1
- Likely memory leak in use of TSF_REALLOC in new sf3 code in out of memory conditions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinysoundfont.