nesdev.com
http://forums.nesdev.com/

A constant-cycle music engine
http://forums.nesdev.com/viewtopic.php?f=6&t=16111
Page 1 of 1

Author:  pubby [ Sun Jun 18, 2017 5:15 pm ]
Post subject:  A constant-cycle music engine

Over the weekend I wrote a music engine that runs in a constant number of cycles per frame. The intention was to have an engine that could be hidden in timing-critical code such as parallax effects, and also to avoid the dreaded lag spikes. Currently, the cycle count is 766, which makes it far faster than other open-source engines. For comparison, Famitone peaks at 3000+ cycles and GGSound peaks at 5000+. I think Pently peaks at 2500+, but I'm not sure.

The converter converts from Famitracker and supports instruments with Pitch/Volume/Arpeggio/Duty. Nothing else is supported; no effects nor volume columns. DMC is not supported, nor are sound effects or PAL pitches.

It uses 12 bytes of zeropage and $100-$156 in stack space. The converted songs are not as space efficient as other engines, but they're small enough for my purposes.

Anyway, you can find the code here: https://github.com/pubby/penguin Keep in mind this is not a library; I wrote the code for myself.

I'll attach a ROM that plays Ralph 4's music.

Attachments:
penguin_demo.nes [24.02 KiB]
Downloaded 51 times

Author:  tokumaru [ Sun Jun 18, 2017 7:40 pm ]
Post subject:  Re: A constant-cycle music engine

Cool, the idea of running the sound code at times you'd otherwise not do anything (e.g. while waiting for raster effects) is very interesting. And 766 cycles is pretty fast, about 7 scanlines only. Will take a better look at this when I get to my PC.

Author:  Bregalad [ Sun Jun 18, 2017 11:49 pm ]
Post subject:  Re: A constant-cycle music engine

Quote:
nor are sound effects or PAL pitches.

PAL pitches are usually as simple as adapting the pitch table to PAL values.

As for sound effects, the lack of them would really make your engine unsuitable for a game, although the concept of a constance-cycle music engine still apply.

Personally I was wondering how feasible was a fully constant-cycle game engine feasible. This could ease raster split a lot, perhaps impressive parallax scrolling could be done in-game without even needed neither sprite-zero hits nor IRQs.

Author:  Memblers [ Mon Jun 19, 2017 8:20 pm ]
Post subject:  Re: A constant-cycle music engine

Very cool, and very impressive too! Less than 7 scanlines of time, that fits well within a row of background tiles.

Author:  pubby [ Sun Jun 25, 2017 1:02 pm ]
Post subject:  Re: A constant-cycle music engine

Thanks.

The newest update adds sound effects and PAL pitches.

Sound effects were implemented as one-off instruments that play single notes. This makes them zero-cost; memory and cycles were not increased. PAL pitches on the other hand added 24 cycles and 2 bytes zeropage. The current cycle count is now 790 per frame.

Author:  Bregalad [ Sun Jun 25, 2017 11:31 pm ]
Post subject:  Re: A constant-cycle music engine

pubby wrote:
PAL pitches on the other hand added 24 cycles and 2 bytes zeropage. The current cycle count is now 790 per frame.

They should come at zero costs, really. All you need is to change the pitch table's values. Sound engines needs not supporting PAL or NTSC pitches at runtimes - they should just be configured at compile time to run either version.

Yes, technically you *could* have a runtime check and this comes with some advantages (only one version of the ROM), however that's not how it's typically done - most of the time you'd want to have one NTSC version and one PAL version of the ROM, and all the difference is made compile-time only.

Author:  rainwarrior [ Mon Jun 26, 2017 12:20 am ]
Post subject:  Re: A constant-cycle music engine

This is an interesting idea. Though it's not something I think I would ever want to do, it's always interesting to see a different approach to the problem. Thanks for sharing the source code.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/