Page 1 of 2
How much CPU time a sound engine uses
Posted: Mon Dec 20, 2010 3:37 pm
by Shiru
Work on a NES sound engine raised my interest, how much CPU time sound engines from commercial games take. I got idea that I could measure it if I mod a NSF plugin, and tried it. I took Nosefart (was easy to compile, no other reasons) and added a cycle counter into it. I'm not sure it gives correct results, though, because some numbers are somewhat strange. I would understand if the numbers were too large (some non-sound code leaved in a NSF), but they are actually unbeliveable small.
For comparsion, numbers for my engine are <2000 cycles average, 3866 max (measured with VirtuaNES mod).
Some results for some games:
Batman, first stage - 1085, 3780
Battletoads, title song - 482, 1820
Battletoads and Double Dragons, title song - 726, 3344
Contra, first stage - 1090, 4554
Megaman, Cutman stage - 2311, 7639
Ferrari Grand Prix Challenge, title screen - 1583, 4317
Average here is per 1000 frames.
Would be interesting to compare this with results from VirtuaNES, through hacking. Experienced NSF ripper could do that rather easily.
If you want the modded plugin, it is
here. It creates a text file after you stop song. When used with Winamp, seems you have to restart the Winamp to reset min/max (by some reason).
Posted: Mon Dec 20, 2010 5:09 pm
by Shiru
Results from the Megaman are confirmed by Gil, who tested it with the game and VirtuaNES (his results are 2075, 8252). jsr also confirms he getting similar numbers with his tests.
I can only wonder how Rare programmers managed to make so fast player in Battletoads then. And how Capcom programmers managed to make so slow player (at times) with rather simple sound.
Posted: Mon Dec 20, 2010 5:47 pm
by Memblers
I remember Bananmos had also looked into Megaman and said the sound engine was really inefficient.
It seems like the maximum would be the main thing to worry about. With Megaman, Cutman stage that comes out to over 67 NTSC scanlines. That's a lot of time.
Posted: Mon Dec 20, 2010 6:15 pm
by Shiru
My guess is that Megaman engine optimized by data size. Let's say, Contra has 8 songs by ~1 minute long, and three jingles, and it's NSF is 17K. Megaman 1 has about 10 songs with similar durations, and few jingles, and it is just 11K. Battletoads has about 20 songs, but it's NSF is 32K - probably optimized for speed.
Posted: Mon Dec 20, 2010 6:22 pm
by Dwedit
Famitracker is ~1800 cycles on average, DragNSF v1 is ~1050 cycles on average.
Posted: Mon Dec 20, 2010 6:59 pm
by tepples
I guess one way to reduce the worst-case time for a music engine is to process loading the next pattern in a separate frame on each channel. Do any music engines in commercial games do this?
Posted: Mon Dec 20, 2010 7:41 pm
by Shiru
Don't know about commercial games, but it was used in some players on home computers. Drawback of this method is limitation for max song speed/tempo, but you can have at least one additional frame, because speed 1 is surely not common.
Posted: Tue Mar 15, 2011 8:52 am
by thefox
I added NSF init/play timing to Nintendulator and got very similar results. Also worth noting is that Tim Follin tunes (Solstice, Silver Surfer, Tom & Jerry) are there in the same ballpark with Rare tunes with around 500-700 cycles avg. SMB3 also isn't too bad, only ~700 cycles on avg.
Darkwing Duck title tune uses 3,7k cycles on avg.

Posted: Thu Mar 17, 2011 6:39 am
by RushJet1
Dwedit wrote:Famitracker is ~1800 cycles on average, DragNSF v1 is ~1050 cycles on average.
Playing around with this, it seems very dependent on the song.
Famitracker:
(FCM7) Dimension-Reversing Dualities: Min 1404 Max 7554 Average 2966
SundayAfternoonJam (No DPCM): Min 21 Max 6663 Average 1830
Greensleeves (No DPCM): Min 1196 Max 5604 Average 1870
(FCM7) Identity: Min 1050 Max 6824 Average 2840
PPMCK:
Fugue/Prelude in C minor: Min 425 Max 6790 Average 2376
Out There: Min 561 Max 5455 Average 1264
Secret of Mana/Grim Determination: Min 361 Max 5230 Average 1285
Posted: Thu Mar 17, 2011 10:27 am
by Bregalad
It creates a text file after you stop song.
May I ask where ? Because I can't find any in Winamp nor in the NSF's folder.
Posted: Thu Mar 17, 2011 7:35 pm
by Shiru
In WinAmp (or other player you use) folder.
Posted: Fri Mar 18, 2011 12:18 am
by thefox
It may not have write rights to the application folder if it's not run as an administrator.
Posted: Fri Mar 18, 2011 6:14 am
by tepples
thefox wrote:It may not have write rights to the application folder if it's not run as an administrator.
Then can you modify it to spit out the text file somewhere in the user's profile?
I really need to profile my own music engine sometime.
Posted: Fri Mar 18, 2011 6:28 am
by Bregalad
Found it !
I think my "simple" sound engine kicks all other's (including Battletoads') butt

:
Min 136 Max 4076 Average 479
Then the semi-completed more complex sound engine I've done (with support of more effects such as vibratoes) has this :
Min 136 Max 7595 Average 3257
Which is MUCH less good. It wasn't finished or optimized anyway so that's why.
Posted: Fri Mar 18, 2011 7:00 am
by Shiru
tepples, I can modify it if you have certain request - like 'put the file in .. dir' or 'display message box'. Also, I can't check if it works under non-administrator rights.
Bregalad, low average time is important thing, but peak time is also important, because usually it is few times greater than average, and it could introduce noticeable lag into the gameplay. Battletoads is 482 average vs 472 of your engine, but it has 1820 peak time, which is noticeably lower than 4076, so it has less chances to introduce the lag.