Quick Sound Engine Question
Moderator: Moderators
Quick Sound Engine Question
Is 320 bytes (including note table) unreasonably large for a sound engine? I know that is a relatively vague question, but I'm curious as to how small everyone else has managed to make their engines. I want to be sure it is not too bloated.
Drag's NSF engine is about 1.4k in size, minus data.
Famitracker's sound engine is 4.8k in size.
Famitracker's sound engine is 4.8k in size.
Last edited by Dwedit on Sun Oct 31, 2010 1:20 pm, edited 1 time in total.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Opinions will vary, but I believe that's way too small! That's less than 1% of even a 32kB ROM. I'm sure it could still sound decent, but it depends on the type of music you want, I guess.
In my experience, data is always the memory hog, I consider ROM usage by code to be basically free (unless you're writing a game to cram a lot into a small amount of memory, there's no reason to do that except 'for the hell of it', and minigame competitions though).
Nerdtracker 2 is quite a bit larger, around 3,000 bytes. If you look at NESnake 2 by MatrixZ, he used NT2 in there but also came up with his own compression for the music data, which works amazingly well. It's only 32kB of PRG for that entire game.
So my suggestion is if you're worried about memory usage, aim to make the data as compact as you need it to be, the code is practically nothing. Unless you only have one short song, or a couple jingles or something, the data will far outweigh the code.
But ROMs are cheap, and just continue getting cheaper. I guess maybe 512kB FlashROM costs about what a 64kB EPROM cost 10 years ago. Under a couple bucks.
In my experience, data is always the memory hog, I consider ROM usage by code to be basically free (unless you're writing a game to cram a lot into a small amount of memory, there's no reason to do that except 'for the hell of it', and minigame competitions though).
Nerdtracker 2 is quite a bit larger, around 3,000 bytes. If you look at NESnake 2 by MatrixZ, he used NT2 in there but also came up with his own compression for the music data, which works amazingly well. It's only 32kB of PRG for that entire game.
So my suggestion is if you're worried about memory usage, aim to make the data as compact as you need it to be, the code is practically nothing. Unless you only have one short song, or a couple jingles or something, the data will far outweigh the code.
But ROMs are cheap, and just continue getting cheaper. I guess maybe 512kB FlashROM costs about what a 64kB EPROM cost 10 years ago. Under a couple bucks.
Wow. My engine for my project, which supports music and sound effects but is very compact as I don't use PRG bankswitching, is exactly $358 bytes, 856 bytes in decimal. I wonder how you got one who is so small. I was under the impression that my was one of the smallest you could do.
However, if yours is smaller but takes larger songs data for an equivalent song, then you won't gain anything.
I have one byte per note (plus one byte if crossing an octave boundary). I also have "subroutine calls" that takes two bytes, and a repeat command which takes 3 bytes, which removes the need to repeat data in a song in most cases. That way I can keep most songs in something like 200 bytes (although it's very arbitrary).
EDIT : I just investigated more about the ROM usage of varying things in my project. WLA-DX is supposed to tell it to me with the .block bug it's bugged and doesn't print the correct numbers
What takes the palm of the most ROM eating stuff is sprite definitions ! I have barly done half of the sprites I'd like to see in the game, and this eats up about 7200 bytes !! This is about 12% of the total ROM space I want to use, with the sprites not already done it will take at least 20%. I might have compress those somehow if I want to use those 32k efficiently.
In comparison, I have a good half of songs and many sound effects done, which takes "only" 2800 bytes (about 3500 with the engine).
However, if yours is smaller but takes larger songs data for an equivalent song, then you won't gain anything.
I have one byte per note (plus one byte if crossing an octave boundary). I also have "subroutine calls" that takes two bytes, and a repeat command which takes 3 bytes, which removes the need to repeat data in a song in most cases. That way I can keep most songs in something like 200 bytes (although it's very arbitrary).
EDIT : I just investigated more about the ROM usage of varying things in my project. WLA-DX is supposed to tell it to me with the .block bug it's bugged and doesn't print the correct numbers
What takes the palm of the most ROM eating stuff is sprite definitions ! I have barly done half of the sprites I'd like to see in the game, and this eats up about 7200 bytes !! This is about 12% of the total ROM space I want to use, with the sprites not already done it will take at least 20%. I might have compress those somehow if I want to use those 32k efficiently.
In comparison, I have a good half of songs and many sound effects done, which takes "only" 2800 bytes (about 3500 with the engine).
Last edited by Bregalad on Sun Oct 31, 2010 2:02 pm, edited 1 time in total.
Useless, lumbering half-wits don't scare us.
-
UncleSporky
- Posts: 388
- Joined: Sat Nov 17, 2007 8:44 pm
Re: Quick Sound Engine Question
Perhaps you're referring to RAM usage and not the actual engine's size? As I recall, the Famitracker driver uses more than a whole page of memory. That seems closer to what you might be talking about.cartlemmy wrote:Is 320 bytes (including note table) unreasonably large for a sound engine? I know that is a relatively vague question, but I'm curious as to how small everyone else has managed to make their engines. I want to be sure it is not too bloated.
And in that case, it does sound like quite a lot.
Last edited by UncleSporky on Sun Oct 31, 2010 1:59 pm, edited 1 time in total.
Cool, I forgot to mention it does not do sound effects yet. But I was just making sure I wasn't going to run into trouble down the road. The data format I'm using uses 1 byte for most instructions.
So far it supports envelopes, octave set, looping, duty cycle, and DMC. I'm pretty happy with the results so far
So far it supports envelopes, octave set, looping, duty cycle, and DMC. I'm pretty happy with the results so far
Re: Quick Sound Engine Question
No, that is the engine's size. I did forget that it uses about 30 bytes of ram for the various variables. So it's at about 350 bytes.UncleSporky wrote:Perhaps you're referring to RAM usage and not the actual engine's size? As I recall, the Famitracker driver uses more than a whole page of memory. That seems closer to what you might be talking about.
And in that case, it does sound like quite a lot.
-
UncleSporky
- Posts: 388
- Joined: Sat Nov 17, 2007 8:44 pm
Definitely! I'm trying to make the song data as compact as possible as well. Also, I will be implementing functionality to allow certain loops to play under the main melody, so I can write the redundant parts of the music only once. That should save on memory quite a bit.blargg wrote:I take the point here to be that unless you're only having one short song, song data dominates, so you should spend some extra code on allowing a more compact song format, because each extra byte of code will result in the reduction of many bytes of music data.
Just to check with you guys, here is a working example of the sound engine. This short song uses 69 bytes, does that seem like too much?
http://www.yibbleware.com/nes/setest.nes
http://www.yibbleware.com/nes/setest.nes
Mmh, this song is REALLY simple and short, so yeah 69 bytes for it seems like quite big, IDK but maybe it'd be like ~25-30 bytes on my engine. (I just put in random numbers).
But yeah 300 bytes for a sound engine sounds like nothing. You should have done something either really efficient or really limited.
But yeah 300 bytes for a sound engine sounds like nothing. You should have done something either really efficient or really limited.
Useless, lumbering half-wits don't scare us.
Cool, thanks for the feedbackBregalad wrote:Mmh, this song is REALLY simple and short, so yeah 69 bytes for it seems like quite big, IDK but maybe it'd be like ~25-30 bytes on my engine. (I just put in random numbers).
But yeah 300 bytes for a sound engine sounds like nothing. You should have done something either really efficient or really limited.
You can store most note changes with 4-bits (or even 3-bit) as a relative value from the previous/current note. Since not a lot of melodies jump all over different octaves.
For a game too, performance is somewhat of an issue, just be careful with the 'worst case' path the execution can follow. In NT2 for example the CPU usage would jump higher on frames that it changed to a new pattern. There's always been enough CPU time when I've used it though.
Demo looks pretty cool!
For a game too, performance is somewhat of an issue, just be careful with the 'worst case' path the execution can follow. In NT2 for example the CPU usage would jump higher on frames that it changed to a new pattern. There's always been enough CPU time when I've used it though.
Demo looks pretty cool!