Sound player for KeenWiki

This is where you can post your Commander Keen related stories, artwork, or other stuff that is related to Commander Keen but otherwise doesn't belong in another forum.
User avatar
Nisaba
Janitress
Posts: 1597
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: The Incredible Machine (TIM) 1992 music format

Post by Nisaba »

ok then, now that we've sorted out these background info, what can we actually do to get a step closer to a wiki playback feature?! which particular steps are ahead of us? what is needed? and who could be the guy with good skills and good expertise in this section?

"issue an invitation to tender"
out now (link) : Image
User avatar
Malvineous
Shikadi Webmaster
Posts: 382
Joined: Wed Oct 31, 2007 21:48
Location: Brisbane, Australia
Contact:

Re: The Incredible Machine (TIM) 1992 music format

Post by Malvineous »

At present I'm attempting to compile Camoto's libgamemusic to Javascript with Emscripten, which seems to have been mostly successful, so now I need to work out how to call it from within native Javascript code. Then I can write a small HTML5 audio player to play IMF files in a browser. If that works then I will write a Mediawiki extension to allow IMF files to be uploaded to the wiki and embedded into pages in the same way that image files are uploaded and embedded now.

Might I also suggest moving this into a new topic? It's not really related to the TIM music any more :-)
User avatar
Fleexy
Tool Smith
Posts: 1432
Joined: Fri Dec 12, 2008 1:21
Location: Abiathar C&C

Re: Sound player for KeenWiki

Post by Fleexy »

Topics split; this one is now located in Other Keen Stuff. 8)
User avatar
Nisaba
Janitress
Posts: 1597
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Sound player for KeenWiki

Post by Nisaba »

Malvineous wrote: Sat Nov 18, 2017 23:38 At present I'm attempting to compile Camoto's libgamemusic to Javascript with Emscripten, which seems to have been mostly successful, so now I need to work out how to call it from within native Javascript code. Then I can write a small HTML5 audio player to play IMF files in a browser. If that works then I will write a Mediawiki extension to allow IMF files to be uploaded to the wiki and embedded into pages in the same way that image files are uploaded and embedded now. [...]
that sounds like a real good plan! if you could, please keep us informed about the projects current status every now an then. unfortunately I cannot help out with anything code related. but if there's anything else, don't hesitate to ask. I'll see what I can do.
cheers

@Fleexy: thanks for the splitting service.
out now (link) : Image
User avatar
Malvineous
Shikadi Webmaster
Posts: 382
Joined: Wed Oct 31, 2007 21:48
Location: Brisbane, Australia
Contact:

Re: Sound player for KeenWiki

Post by Malvineous »

Well since you asked for updates, I have managed to get things to a point where I can actually play a song entirely in the browser, although it does use about 75% CPU power (of a single core/thread) @ 2.8GHz but that's to be expected.

Next step is to tidy up the code a bit and see if there are any easy optimisations that can be done, and then write some kind of UI for the player.

I'm thinking maybe it would be better to have it synthesize in the background, with a little progress bar showing how much of the song is ready to play - a bit like the progress bar you see on YouTube showing you how much of the video has downloaded so far. This would at least allow people with slow computers to wait while the song is generated, then play it when it's done so that it plays without interruption.
User avatar
Nisaba
Janitress
Posts: 1597
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Sound player for KeenWiki

Post by Nisaba »

thanks for the update. sounds like a good amount of progress even though it's a lot of CPU power in usage... why is that so? anyways, looking forward for those optimizations. I second the progress bar idea. this might be a really helpful feature.
out now (link) : Image
User avatar
Malvineous
Shikadi Webmaster
Posts: 382
Joined: Wed Oct 31, 2007 21:48
Location: Brisbane, Australia
Contact:

Re: Sound player for KeenWiki

Post by Malvineous »

Actually rather embarrassingly it turned out that it wasn't the OPL synth using such high CPU - although playing songs used 75% CPU, when the songs weren't playing Firefox was still using 60% CPU :barf

One of the issues is that because the Web Audio API wasn't designed with this sort of thing in mind, it's a bit less efficient as the audio data has to be copied multiple times before it can be played (and interestingly a lot of people are critical of the API, which has been marked as deprecated and due for replacement since 2014!) Another issue is that passing large chunks of data between the C++ code and the JavaScript code isn't well handled either. The C++ code can't see the Web Audio API's funny buffers, and the Web Audio API can't see any C++ buffers. So the JS code in the middle has to do a lot of data copying back and forth.

So anyway I spent this weekend writing a UI for it and although there are still a couple of minor issues, it seems to work well enough. CPU usage is now about 10% on my PC. I've put up a demo page so it'd be interesting to find out whether it works for anyone else. I've only tested it on Firefox and Chromium under Linux. It uses Javascript ES6 so it's only compatible with recent browsers which looks like most of them except for Internet Explorer, if anybody still uses that.
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 781
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Sound player for KeenWiki

Post by K1n9_Duk3 »

I also get around 10% CPU usage (Win10, Firefox 57.0, cheapo AMD A8-7410 running at 1.5 GHz at the moment).
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net
User avatar
Nisaba
Janitress
Posts: 1597
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Sound player for KeenWiki

Post by Nisaba »

thanks for the demo page. and thanks a lot for the documentation as well. great work so far!

while testing things I also get ~10% CPU usage (Linux, Vivaldi 1.11.917.43, Firefox 57.0.1, TorBrowser, Intel i5-2410M, 2.30GHz × 4 / Android 7.1, Firefox 57.0, ARM Cortex-A9, 1.4GHz x 4).
It's not running via Lightning 4.4.1. but to be honest, I wasn't expecting it to run fluently with this "bare-bone" web browser.

The looping feature is neat! (even though in Vivaldi + Firefox the drum loop in Zone 66 m01gmuz.670 doesn't repeat cleanly.) Is there a reason why uploaded tracks are much more quiet than the provided example tunes?

with excitement I'm looking forward for the next update.
out now (link) : Image
User avatar
Malvineous
Shikadi Webmaster
Posts: 382
Joined: Wed Oct 31, 2007 21:48
Location: Brisbane, Australia
Contact:

Re: Sound player for KeenWiki

Post by Malvineous »

Interesting. Thanks for the reports! Seems bizarre it always seems to use around 10% CPU regardless of platform or speed :confused The code compiles down to asm.js which is a special type of JavaScript that web browsers can further compile into machine code and execute at near native speeds, so you'd think the result would be more dependent on CPU speed.

Interesting Vivaldi can be added to the list where the Z66 drum loop is out. How weird that it works in Firefox. I'll have to delve deeper into that particular song as the quick look I had made it seem like Firefox is the one not playing it correctly (which then suggests that I'm reading the file incorrectly.)

All the tracks are played at the same volume, but many IMF files are nowhere near the maximum volume available. In theory if you capture the audio in DOSBox of two of the games and then play the resulting .wav files one after the other, you should hear the same difference in volume. It's been a longstanding issue for me but I can't really think of a way to fix it that doesn't affect the way the music sounds.

The next update might be a while in coming, as in order to write a MediaWiki extension I'll probably have to upgrade the KeenWiki and ModdingWiki to the latest release of MediaWiki first. There are a number of customisations on the KeenWiki in particular so that might not be quite so straightforward. I would also like to install Semantic MediaWiki onto both wikis, as I've used it on a few others and it makes it much easier to use the wiki more like a database. It's possible to do things like autogenerate the lists of mods based on what's entered into the infoboxes on each page, so you don't need to keep things up to date in two places. You can run queries and use the results to generate lists, so if you wanted a list of mods that were full trilogies for example then you can easily do that too. At the very least it should let me get rid of the dodgy hack I made to generate the pictorial list of mods, which is one of the tricky things to handle during an upgrade.
User avatar
Nisaba
Janitress
Posts: 1597
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Sound player for KeenWiki + play mods online

Post by Nisaba »

ok, after more extensive tests, I have found more accurate results.
Firefox => 5-8% CPU usage
Vivaldi => 12-20% CPU usage

Another note: on my side the Z66 drum loop is out in Vivaldi as well as in Firefox. both give strange results. starting the tune, the drum track has a ~11 sec delay. after the first loop the drums seem to be in sync. skipping forward the drum track results in a 2-3 sec delay...

concerning the difference in volume. if you could please also add a Commander Keen IMF file to your website. this should demonstrate the difference in volume best.
in theory this web-tool need an additional amplifier, which adjusts the volume in a second step, after the output of your player, so to speak. know what I mean? but I don't think that something like this is really needed.

out of curiosity: which KeenWiki customisations are you talking about?
I'd like to offer my help if things need to be converted manually (regarding stultifying work).
the auto-generate feature sounds like a real neat improvement! would make things so much easier/faster.

while talking about improvements I'd like to point your attention towards Spleens effort to create an option to play mods online using emdosbox. As I understand an implementation to the Wiki would just be some basic PHP stuff for the page itself. The heavy scripting is client side Javascript. and as Spleen stated, this shouldn't have any notable impact on the server. to save bandwidth Fleexy offered to host the script which can be found here: http://live.keenmodding.org/dosbox.js
Here is the discussion:
https://pckf.com/viewtopic.php?f=2&t=40 ... 852#p83852
what's your opinion on all that?!

https://jimage.org/keen/mods/play/
out now (link) : Image
Post Reply