Skip to content

VGM web player in JavaScript, official topic

Technical discussion about the VGM format, and all the software you need to handle VGM files.

Moderator: Staff

Post by vampirefrog »

you say this, but then you say +1 for java, which even fewer people install.

I think flash is packed with Chrome nowadays, and it's easy to fall back to the mp3 player which is currently in place in the packs pages.

I've already managed to get Crossbridge to work, and I'm trying to compile vgmplay. Need to make it use SDL for sound. Later I can compile players for AY, NSF, RSN etc.
  • User avatar
  • MaliceX Offline
  • Posts: 226
  • Joined: 2012-09-29, 11:45:48
  • Location: Australia
  • Contact:

Post by MaliceX »

vampirefrog wrote:you say this, but then you say +1 for java, which even fewer people install.
I said +1 for cross-platform. Please learn to read before making an accusation as such.

Nowhere did I say Java specifically, and that Android player uses an ARM-compiled version of the VGMPlay C source code as part of it. Of course in the context of Android the only way it will work is by wrapping it with Java Native Interface code which is unfortunate.

Both JavaScript and SDL are cross-platform, so why would I be wrong there?
-dj.tuBIG/MaliceX

Post by vampirefrog »

for me, the cross-platformness of java was never a convincing argument, especially since I've already worked with cross-platform C/C++ toolkits, and the fact that it's owned by a corporation makes me run far far away from it.

it seems like it just panders to the lazy programmer, and most java apps I've tried (UI apps and even Minecraft) are slow and look horrible and often break the UI integration with its host OS.
  • User avatar
  • neologix Offline
  • Posts: 211
  • Joined: 2012-04-22, 4:03:45
  • Location: New York, NY, USA

Post by neologix »

If I ever have a massive amount of free time again to learn a language for fun, it'll likely be ActionScript.

In the meantime, JavaScript is the one I know the best (enough to plan to write a book on it when I graduate from college, actually) and the one I've so far been most successful with. The irony here is that my original intent with the entire VGM.js project was to create a web-based testbed for the procedures I planned to use when creating my YM2612 virtual instrument in C++. Then I looked at the state of VGM on the web and realized SMS Power and Project 2612 were and still are in dire need of web players and I wasn't on vgmrips yet. The visual redesign of the thing was a result of this realization.

I hate Java with a passion, and the reason for that one is a long story. ActionScript has its place and I've never been good with it or any Flash IDE in general, Flash/Flex being the primary usage of AS. Objective-C is the next language I'm learning because I want to make apps for money and the Apple App Store is the only one where any money at all can be made. JavaScript is a language I've known since 1998 and been expert-level at since 2009/2010 (the first time I read Crockford's JavaScript: The Good Parts and started specializing).

By all means, whatever languages y'all feel comfortable writing your tools and apps with should be the ones you use. In my case, if I could write everything in JavaScript or even PHP whenever I don't have access to C++ compilation, I would, and I do. Unless otherwise noted, the player that I wrote which code I will eventually transfer ownership of to the VGM organization I created on GitHub is JS and the cores I personally write are/will be JS.

Post by vampirefrog »

I've managed to get the SN76489 emulation going in my flash vgm player

http://chiptune.ninja/dev/chiptune/as3/main.php

the SN code was converted using my cxx2as3 tool, then small fixes were needed.
  • User avatar
  • neologix Offline
  • Posts: 211
  • Joined: 2012-04-22, 4:03:45
  • Location: New York, NY, USA

Post by neologix »

vampirefrog wrote:I've managed to get the SN76489 emulation going in my flash vgm player

http://chiptune.ninja/dev/chiptune/as3/main.php

the SN code was converted using my cxx2as3 tool, then small fixes were needed.
There are some pitch issues in the SN76489 emulation, it sounds detuned a bit low like the buffers don't quite fill up completely or the resampler is off or something.

Post by vampirefrog »

Yes, there are some pitch issues. But it proves the concept, and now all I have to do is enhance it so it can be directly embedded in smspower ^^.
  • User avatar
  • MaliceX Offline
  • Posts: 226
  • Joined: 2012-09-29, 11:45:48
  • Location: Australia
  • Contact:

Post by MaliceX »

vampirefrog wrote:Yes, there are some pitch issues. But it proves the concept, and now all I have to do is enhance it so it can be directly embedded in smspower ^^.
You probably might want to have a look at Shiru's AS3 SN VGM player he wrote ages ago.
http://shiru.untergrund.net/code.shtml
-dj.tuBIG/MaliceX

Post by vampirefrog »

MaliceX wrote: You probably might want to have a look at Shiru's AS3 SN VGM player he wrote ages ago.
http://shiru.untergrund.net/code.shtml
I've taken a quick look. It looks ok, but no FM. I also plan to emulate YM2413, and all the other chips too, so it will be a more complete VGM player. I do like how his code is more simply organized, that should help me clean up my project a bit too.

Thanks for the link!
  • User avatar
  • neologix Offline
  • Posts: 211
  • Joined: 2012-04-22, 4:03:45
  • Location: New York, NY, USA

Post by neologix »

vampirefrog wrote:I also plan to emulate YM2413
Let me know when you do, I have a few emulation inaccuracies in YM2413.js I need to fix and would like an EcmaScript (preferably JS, but AS will do here) variant to compare against, thx.

Those YM2413 inaccuracies are the last obstacle to giving SMS Power a working JS player to use.

Post by vampirefrog »

I've gotten BlackAura's vgm player working here. As you can see, without using any extra libraries, there is no stuttering when the tab is inactive.

I suggest you remove the XAudioJS dependency, and just write your own code based directly on the WebAudio API. Create an audio context and so on. I think relying on pointless libraries is what's keeping your project back. If you look in the code, they have some sort of timer-based mechanism, which is probably what's causing the problems in the first place.

Basically, a VGM player in JS is possible, without stuttering, if written correctly.

Web development is crap, the languages are inconsistent, and there are too many libraries, and nobody needs them. So get over it.
  • User avatar
  • neologix Offline
  • Posts: 211
  • Joined: 2012-04-22, 4:03:45
  • Location: New York, NY, USA

Post by neologix »

As mentioned by MaliceX in the IRC, I do have a tentative version that's only Web Audio but indeed I haven't yet published it. I gave it to MaliceX to try out the YM2413 VGMs and help give me some advice on them. When I get back to my Windows laptop which has the local copy I'll put it up for live beta testing.

The XAudioJS dependency was primarily when Web Audio was still in the early stages and Flash was still a thing. Most likely what I'll do is when packaging the whole thing have a Web Audio-only sample html and an XAudioJS-enabled sample html so people can choose whether old browsers are in their target demographics or not.

Post by vampirefrog »

I've taken a look at XAudioJS. It seems that they got the right idea - try a few backends, including flash as a fallback. However, they seem to have screwed up the implementation. It seems the sound is playing all the time, even when there is no VGM. I've looked into the code. I can't figure out where the bug that you're experiencing is coming from, but I have a better idea, and that is to implement a new sink library, which only supports WebAudio and a Flash fallback.

I've coded a very basic flash-based sound "sink" here: http://chiptune.ninja/dev/chiptune/as3/SndBridge.php
The JS just generates noise. AS3 code is here: view-source:http://chiptune.ninja/dev/chiptune/as3/SndBridge.as

Furthermore, the player should allow the user to select the sink they want to use.
Post Reply