mikeoliphant / neural-amp-modeler-lv2

Neural Amp Modeler LV2 plugin implementation
GNU General Public License v3.0
227 stars 28 forks source link

Regarding performance, is it usable on Android phones? #65

Closed djshaji closed 7 months ago

djshaji commented 7 months ago

Hi, first of all, thanks for your awesome work.

I'm trying to get this plugin to run on my Android app, which is a LADPSA/LV2 host for Android. It doesn't have LV2 workers support yet, so I've removed LV2 workers and instead load a NAM model via a JNI call from the UI thread. I've managed to compile it, but it doesn't work properly. I only get broken patchy sound. I ran my modified plugin on jalv, and it works perfectly there.

Here's what I get (I'm playing E, G, A on a Fender Bullet Mustang for reference) https://music.shaji.in/media/2024/nam.mp3

My phone is a Motorola g84, with a Qualcomm Snapdragon 695. My home PC (on which the plugin works perfectly) is a 4th generation i5 (which is quite old).

My theory is that since it works perfectly on the PC, then perhaps the phone isn't fast enough to run it. But I don't think that's the case, because it ought to be fast enough.

Is it a performance issue (and therefore hopeless), or is there something that can be done about this?

Here's my fork of the plugin. This is the app I'm trying to run it on.

PS: My host app passes the same pointer to input and output ports. Can that be the issue?

Much thanks.

piedpipr commented 7 months ago

Hi Shaji, Finally you're on board!! Remember I suggested adding this LV2, maybe you already thought. I love the amp-rack and am looking forward to having an absolutely minimal version only with NAM. I myself also trying to get into this territory but I never really developed an Android app. Hope to see something working soon! Kudos!✌️

djshaji commented 7 months ago

Hi, yes, you introduced me to NAM, and it is indeed amazing. I've actually got it up and running on Amp Rack, but it's not working properly. I don't know whether it doesn't work if (my?) phones are too slow to run NAM models, or whether the app itself runs plugins in such a way that the plugin doesn't work.

I've uploaded a build with the NAM plugin if you want to try it: https://github.com/djshaji/amp-rack/releases/tag/4.05

Something in me says that today's phones ought to be able to run NAM, right? I mean, I can debug till the end of time to make it work, but I would feel better if I know it's something fixable.

piedpipr commented 7 months ago

Surely, I'll try it and give feedback. I've heard from somebody that it requires processing power similar to a raspberry pi to handle one model and an IR. So accordingly our phones are more powerful. Also have a look at the GUI version of this LV2 and also one that comes with the MOD app. Try if any of the three works for the app. I'll try with my Pixel at once. Nice work man! 🔥

djshaji commented 7 months ago

Alas, but my hopes are dashed :disappointed:

So I did some profiling. On my Motorola g84, these are times in milliseconds when I add two plugins to the chain: GxSloopyBlue and the NAM plugin with no model loaded:

0 is GxSloopyBlue 1 is the NAM plugin

FullDuplexPass.h  D  [0: 192] 142 ms
FullDuplexPass.h  D  [1: 192] 141 ms
FullDuplexPass.h  D  [192] 314 ms
FullDuplexPass.h  D  [0: 192] 141 ms
FullDuplexPass.h  D  [1: 192] 138 ms
FullDuplexPass.h  D  [192] 304 ms
FullDuplexPass.h  D  [0: 192] 107 ms
FullDuplexPass.h  D  [1: 192] 103 ms
FullDuplexPass.h  D  [192] 231 ms
FullDuplexPass.h  D  [0: 192] 112 ms
FullDuplexPass.h  D  [1: 192] 124 ms
FullDuplexPass.h  D  [192] 254 ms
FullDuplexPass.h  D  [0: 192] 107 ms
FullDuplexPass.h  D  [1: 192] 173 ms
FullDuplexPass.h  D  [192] 299 ms
FullDuplexPass.h  D  [0: 192] 167 ms
FullDuplexPass.h  D  [1: 192] 140 ms
FullDuplexPass.h  D  [192] 332 ms

Now, when I load a model, these are the elapsed times (in ms) I get:

FullDuplexPass.h  D  [0: 192] 98 ms
FullDuplexPass.h  D  [1: 192] 27349 ms
FullDuplexPass.h  D  [192] 27622 ms
FullDuplexPass.h  D  [0: 192] 99 ms
FullDuplexPass.h  D  [1: 192] 27405 ms
FullDuplexPass.h  D  [192] 27663 ms
FullDuplexPass.h  D  [0: 192] 98 ms
FullDuplexPass.h  D  [1: 192] 27442 ms
FullDuplexPass.h  D  [192] 27695 ms
FullDuplexPass.h  D  [0: 192] 100 ms
FullDuplexPass.h  D  [1: 192] 27105 ms
FullDuplexPass.h  D  [192] 27354 ms
FullDuplexPass.h  D  [0: 192] 99 ms
FullDuplexPass.h  D  [1: 192] 27177 ms
FullDuplexPass.h  D  [192] 27392 ms
FullDuplexPass.h  D  [0: 192] 96 ms
FullDuplexPass.h  D  [1: 192] 27035 ms
FullDuplexPass.h  D  [192] 27190 ms
FullDuplexPass.h  D  [0: 192] 91 ms
FullDuplexPass.h  D  [1: 192] 27241 ms
FullDuplexPass.h  D  [192] 27425 ms
FullDuplexPass.h  D  [0: 192] 93 ms
FullDuplexPass.h  D  [1: 192] 26920 ms
FullDuplexPass.h  D  [192] 27121 ms
FullDuplexPass.h  D  [0: 192] 93 ms
FullDuplexPass.h  D  [1: 192] 27656 ms
FullDuplexPass.h  D  [192] 27828 ms
FullDuplexPass.h  D  [0: 64] 35 ms
FullDuplexPass.h  D  [1: 64] 9667 ms
FullDuplexPass.h  D  [64] 9754 ms
FullDuplexPass.h  D  [0: 128] 63 ms
FullDuplexPass.h  D  [1: 128] 18540 ms
FullDuplexPass.h  D  [128] 18709 ms
FullDuplexPass.h  D  [0: 192] 92 ms
FullDuplexPass.h  D  [1: 192] 27784 ms
FullDuplexPass.h  D  [192] 28010 ms
FullDuplexPass.h  D  [0: 192] 96 ms
FullDuplexPass.h  D  [1: 192] 27055 ms
FullDuplexPass.h  D  [192] 27319 ms
FullDuplexPass.h  D  [0: 192] 204 ms
FullDuplexPass.h  D  [1: 192] 27476 ms
FullDuplexPass.h  D  [192] 27825 ms

I think the most obvious conclusion here seems to be that indeed the phone is unable to run the model fast enough to be usable.

This is incredibly disappointing :cry:

Am I missing something here? I chain up all the run functions from the active plugin chain, connect the input and output ports, and iterate through them in the realtime thread. All other plugins work fine except for this. It must be the device performance issue, then, isn't it? But it means we've reached a dead end, and NAM on phones will not (yet?) be a possibility, would it?

mikeoliphant commented 7 months ago

Your phone should be plenty powerful enough to run NAM.

Maybe something is off with your compilation (ie: a debug build instead of an optimized release build)?

Btw, if you aren't using NAM as an LV2 plugin, then this repo isn't really applicable - everything you need is in the NAM Core repo:

https://github.com/sdatkinson/NeuralAmpModelerCore

djshaji commented 7 months ago

Yes, that was exactly the case. I rebuilt the plugins with the -DCMAKE_BUILD_TYPE="Release" flag and the plugins are working perfectly now.

I'm using the LV2 plugins, but since my host app doesn't support workers, I forked the plugins and am passing the entire model json via a port

Thanks :ok_hand:

mikeoliphant commented 7 months ago

👍