It is currently Wed Dec 13, 2017 11:50 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Fri Jul 17, 2015 7:45 am 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
I'm having a bit of trouble getting VRC7 audio to function properly. I translated the ubiquitous emu2413.c to Java (supposedly emu2413.c exists under the zlib license). I used the version in Rainwarrior's awesome NSF player as a reference. Unfortunately, only channel 5 plays when I run Lagrange Point. I reviewed the translation several times and I can't pinpoint the problem. Debugging reveals that the output of the remaining channels is 0. I do not know the details of how the code works, but logging indicates that the muted channels are processing changing numerical values. The output seems to get muted when the volume envelope is applied. For anyone who is familiar with the code, can you please suggest areas that might be mistranslated or even just mis-configured (e.g. there is a mask that can shutoff individual channels, but I don't think that's the issue here.) Thanks.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 10:45 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5894
Location: Canada
Can't tell much from what you said. All I can really say is the code works as-is in NSFPlay. If you're only getting output from one channel, check where the output is updated in a debugger. I don't think anybody can debug your code from just what you described, it's a problem with your implementation.

The only configuration stuff I know with emu2413.c is done in nes_VRC7.cpp so there's not really much to mess up, in that respect. Even the channel mixing/masking is all done in nes_VRC7.cpp completely outside emu2413.c, so you should be able to rule that part out easily.

If you've got one channel working, I expect it's a very simple bug, but if it's not I can't really much with a Java port of Mitsutaka Okazaki's emu2413.c, as it's not my code, but good luck.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 10:57 am 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
rainwarrior wrote:
Can't tell much from what you said. All I can really say is the code works as-is in NSFPlay. If you're only getting output from one channel, check where the output is updated in a debugger. I don't think anybody can debug your code from just what you described, it's a problem with your implementation.

The only configuration stuff I know with emu2413.c is done in nes_VRC7.cpp so there's not really much to mess up, in that respect. Even the channel mixing/masking is all done in nes_VRC7.cpp completely outside emu2413.c, so you should be able to rule that part out easily.

If you've got one channel working, I expect it's a very simple bug, but if it's not I can't really much with a Java port of Mitsutaka Okazaki's emu2413.c, as it's not my code, but good luck.


Thanks for the reply. I saw another thread where you did research on the instrument patches. Did you somehow extend the number of instruments from 16 to 19?


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 12:23 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5894
Location: Canada
zeroone wrote:
Did you somehow extend the number of instruments from 16 to 19?

No. I'm very curious why you might think that, though?


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 12:31 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
rainwarrior wrote:
zeroone wrote:
Did you somehow extend the number of instruments from 16 to 19?

No. I'm very curious why you might think that, though?


The wiki shows an instruments table with 16 rows, but the code seems to contain 19 rows.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 12:37 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5894
Location: Canada
Hmm, the two patch sets by Mitsutaka Okazaki have 19 patches in them? That's very odd. The register that selects the patch is only 4 bits wide!


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 12:39 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5894
Location: Canada
Oh, it seems they can be accessed by the "rhythm mode" that is present on the YM2413 but not on the VRC7.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 1:01 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
Does each row represent a musical instrument, kind of like MIDI? Is only 1 patch set necessary for VRC7? I'm trying to figure out how much of this code is unnecessary for VRC7. Maybe some of it can be dropped to speed things up.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 1:34 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5894
Location: Canada
Each patch is 8 bytes, corresponding to the 8 patch registers: http://wiki.nesdev.com/w/index.php/VRC7_audio#Custom_Patch

There are 15 ROM patches, and then 1 customizable RAM patch (whose registers you can write). Each channel can choose any of these 16 patches at will.

I have no comment on what can be pruned from emu2143.c, as its not my code. I plan on re-implementing VRC7 from scratch in the next NSFPlay.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 7:08 pm 
Offline

Joined: Thu Apr 14, 2011 9:27 pm
Posts: 85
The instrument patches are different on the VRC7 and real YM2413, and the percussion mode is missing on the VRC7.

You could try looking at my Java code, I reimplemented the VRC7 from scratch because a lot of emu2413 depends on macros expanded 3 levels deep and it didn't make much sense when I'd expanded all that. It's running at a higher sample rate than the original chip and the envelopes are not exactly bit-accurate but it still sounds pretty close. If you have some moral objection to the GPL, let me know.

https://github.com/andrew-hoffman/halfn ... dChip.java


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 7:48 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
Grapeshot wrote:
The instrument patches are different on the VRC7 and real YM2413, and the percussion mode is missing on the VRC7.

You could try looking at my Java code, I reimplemented the VRC7 from scratch because a lot of emu2413 depends on macros expanded 3 levels deep and it didn't make much sense when I'd expanded all that. It's running at a higher sample rate than the original chip and the envelopes are not exactly bit-accurate but it still sounds pretty close. If you have some moral objection to the GPL, let me know.

https://github.com/andrew-hoffman/halfn ... dChip.java


What source of information did you use to create this? The wiki is incomplete.


Top
 Profile  
 
PostPosted: Fri Jul 17, 2015 8:51 pm 
Offline

Joined: Thu Apr 14, 2011 9:27 pm
Posts: 85
zeroone wrote:

What source of information did you use to create this? The wiki is incomplete.


Programmer's guide to the YM2413 from SMSPower (where my envelope information came from):
http://www.smspower.org/maxim/Documents/YM2413ApplicationManual

This document on the OPL2 for how the logsin and exp tables were generated, the number format that is used, and the basic idea of using logarithmic attenuation values for all calculations so multiplication can be replaced by addition followed by a LUT at the end:
https://docs.google.com/Doc?id=dd8kqn9f_13cqjkf4gp

Several threads on sega-16 and spritesmind about the exact bit widths of buses in Yamaha FM chips
http://gendev.spritesmind.net/forum/viewtopic.php?t=386

The last time the subject of the VRC7 came up on these forums:
http://forums.nesdev.com/viewtopic.php?f=3&t=9102

the DOSBox OPL emulator source (it's still easier to read than emu2413):
https://github.com/Henne/dosbox-svn/blob/ac06986809899ea5f922cb29a194e0770169e1ad/src/hardware/opl.cpp

Those documents together still don't really provide enough information to precisely implement vibrato, key scaling, or the exponential attack on the envelopes, and I wrote most of my version around the beginning of 2012 so I'm not entirely sure that I understand it myself now. That should get you started though.

e: definitely don't trust me on the envelopes; what was I even thinking there


Top
 Profile  
 
PostPosted: Sat Jul 18, 2015 8:48 am 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
Wow. Those are great resources. Thanks.

Hopefully, one day, we'll get this all assembled nicely into a wiki article.


Top
 Profile  
 
PostPosted: Sat Jul 18, 2015 1:46 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 750
Location: New York, NY
I finally fixed my Java port of emu2413.c. It was a typo that took quite a while to track down. Thanks for your help everyone.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group