Chat

Author Topic: Implementing YM2151 emulation in a game - testing it?  (Read 1921 times)

Offline KillaMaaki

  • Jr. Member
  • Posts: 80
Implementing YM2151 emulation in a game - testing it?
« on: June 12, 2016, 11:57:03 PM »
Hello, thought I'd ask here to see if Delek or somebody has any insights on this,
I'm working on a "fantasy console" called Sparc, the idea being it's a platform with limitations and features inspired by consoles of the 16-bit era (SNES and MegaDrive primarily) but still relatively easy to develop for (it's scripted in Javascript).

I've got the graphics core, input, IO, and scripting engine all basically done so now I'm onto audio. After some thinking I have decided to take a crack at getting YM2151 emulation working in it (this is an SDL2 app, mind you). I found these code files:

ftp://ftp.oregonstate.edu/.2/nslu2/sources/cvs/xmms-embedded/xmms-embedded/xmms/Input/xymms-0.9.1/src/ym2151.c
ftp://ftp.oregonstate.edu/.2/nslu2/sources/cvs/xmms-embedded/xmms-embedded/xmms/Input/xymms-0.9.1/src/ym2151.h

And I *think* I've got it integrated into SDL's audio callback system, but as for how to test this thing I'm sort of at a loss. Thus far, the only link I've found for the YM2151's registers is this one:

http://www.cx5m.net/fmunit.htm

But I don't really know how to actually generate sound with this thing. Is there some sort of minimum set of registers I can write to just get any sound out of this thing at all (any noise, I don't care which as long as it doesn't blow out my ear drums lol), because I tried setting a few TL parameters and writing some note on registers but I'm just getting complete silence.

Offline JXC

  • Newbie
  • Posts: 11
  • Delek FTW
Implementing YM2151 emulation in a game - testing it?
« Reply #1 on: June 13, 2016, 01:11:37 AM »
I'm no expert, but if you don't know how to emulate, then perhaps generate FM with something like CSound or SuperCollider.

Offline KillaMaaki

  • Jr. Member
  • Posts: 80
Implementing YM2151 emulation in a game - testing it?
« Reply #2 on: June 13, 2016, 01:57:05 AM »
One of the things I was hoping is that, if I supported a chip that DefleMask also supported, I could add support for directly playing DMF files and then just point people to DefleMask rather than having to make my own tracker or something.

Offline Delek

  • SalĂ­ para ver
  • Administrator
  • Hero Member
  • Posts: 1809
    • Delek's Website
    • Email
Implementing YM2151 emulation in a game - testing it?
« Reply #3 on: June 13, 2016, 03:01:42 AM »
Did you see this? http://www.wothke.ch/webvgm/
It plays YM2151 .vgm files very well. I think it is the shortest path between your game and a chiptune player.

The good thing is that you can also point people to DefleMask or another .vgm capable software.

Offline KillaMaaki

  • Jr. Member
  • Posts: 80
Implementing YM2151 emulation in a game - testing it?
« Reply #4 on: June 13, 2016, 03:17:34 AM »
Hm, I hadn't seen that. Awful lot of chips in the source there... XD
I wonder how much of an effort it would be to trim out the chips I don't need/want. Ideally I'd just want the YM2151 and Sega PCM.

I also wonder if it would be possible to modify it to let me play SFX through the Sega PCM chip on demand... It's late where I am so I will probably come back to this in the morning.

EDIT: Also, to clarify, this isn't an HTML5/Javascript app. It's actually a C++ SDL2 app. I'm using Duktape to provide support for Javascript, but it has no support for multi-threading, web workers, or asm.js so all audio code will be implemented on the C++ side with a few functions exposed to JS.

EDIT2: You know, supporting and emulating actual existing chips might be more trouble than it's worth, LOL... I may just bite the bullet and implement my own audio engine from scratch. I didn't really want to have to write a custom tracker for it, but it looks like it might still be faster than trying to work with audio chip emulation.
« Last Edit: June 13, 2016, 09:07:24 PM by KillaMaaki »