LibKSS ported to Google Native Client

Por niek

Expert (108)

Imagen del niek

29-07-2016, 20:39

I got LibKSS running in Google Native Client! It's alpha quality, but if you like you can have a look at msxmusic.royalwebhosting.net/nacl/. Chrome only, they're the only ones supporting Native Client (which is a pity imo). No Chromium either it seems for now.

Google Native Client is a sandbox in your browser which makes it possible to run C(++) code in your browser with 99% of the native performance. So why do I want this raw speed? Because I can calculate the wave audio of an entire KSS audio track when clicking it in about a second for most tracks. On my not-amazingly-fast 2009 iMac! :D Having the entire wave audio means I can click around in the track. So that's what it can do now.

Who needs VGM? :)

Todo:
- Temporary space is not cleared (it will be by Chrome, no idea when, that's the thing. :) )
- Calculating Pumpkin Adventure 3 audio is something else. I might pre-calculate some tracks in the background when playing others.
- Volume increase
- Normalising volumes
- Buttons
- Tracks without titles in the m3u file are not displayed now
- Display track length
- Make it look nice...
- Maybe incorporate it with the Javascript version. But I might redo that one too, I want to see how quick that'll run when calculating entire tracks beforehand.

Login sesión o register para postear comentarios

Por giangiacomo.zaffini

Champion (267)

Imagen del giangiacomo.zaffini

30-07-2016, 12:57

Genius!

Por ren

Paragon (1877)

Imagen del ren

30-07-2016, 19:37

Cool Cool
Working in Chromium (Portable, Windows).

Wouldn't this also be feasible using Emscripten?
Have you had a look already at WebAssembly?

Por niek

Expert (108)

Imagen del niek

30-07-2016, 22:44

@Ren; nice that Native Client in Chromium on Windows just works! Some googling showed me problems... maybe only on Linux?

About Emscripten; the normal site (without /nacl) is based on it. But Emscripten is a big performance hit, about 50% I've heard, or more; this says native is 5x to 10x faster for what they're doing. Of course it depends on what you're doing... I've read a bit about WebAssembly, but afaik we should not expect that big performance increases.

But as I said in my initial message, I want to try with Javascript too, by which I meant Emscripten. :) Currently it works with live generating; a bit of audio is generated, played back, and during playback the next part is generated. Now I want to see how quick the Emscripten based version can generate a whole track. It'll be interesting to compare it with Native Client!

BTW, I also got LibKSS running using the NDK on Android, which works with JNI. Roughly same principal as Native Client; run compiled C(++) code in your Java based Android App. Status is just a proof of concept. But on my Nexus 5 I can generate roughly 10 seconds of audio every second.

So the best solution would be to have those all; native in Android app, native in Chrome with Native Client, and Emscripten for everything else. Not sure I'll have the time/energy to make that all!

Por ren

Paragon (1877)

Imagen del ren

31-07-2016, 12:05

Yes, of course, current library is already Emscripten based.. Smile
As far as I understand WebAssembly will be somewhat/-thing between Emscripten (asm.js) & Nacl. It seems Nacl will remain Chrome/Chromium only, and Wasm is supposed to be/become the web standard solution.

Quote:

Not sure I'll have the time/energy to make that all!

I know that problem.. Wink

Have you taken note of msxplay-js already, Okazaki's own (Emscripten based) web/js libkss player?

Por niek

Expert (108)

Imagen del niek

01-08-2016, 18:46

Hmm, I've read some more articles about Wasm and it seems we should expect a lot more performance with Wasm compared to Javascript. Some say 70% to native, some say near-native, we'll have to wait and see. It's already an experimental plugin in Chrome and it seems I can use Emscripten to create Wasm, so I might give it a try.

And yes, I have seen msxplay-js before, but now I noticed that already supports buffering while playing, I was thinking about that too!

Por niek

Expert (108)

Imagen del niek

06-08-2016, 00:21

New version online. Looks exactly the same but I've changed libkss to return the highest int (== highest volume) generated in every second of audio. With that information I can calculate the highest gain to use for the Web Audio playback before exceeding 32768. So I have a nice normaliser. Cool

Next step is keeping track of all separate channels, to get an equalizer...

Por niek

Expert (108)

Imagen del niek

18-08-2016, 21:49

I've managed to modify Libkss to export per channel volume data! It's currently implemented for SCC and PSG, and I've added a spectrum analyser kinda thing to the site. OPL(L) is coming and a way to know for what chips the export contains data.