NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectSound emulation problems new  
Posted bysammael
Posted on10/21/03 3:09 PM
From IP129.241.146.203  



I'm having problems getting the audio output from my emulator to sound good..
So far I've only implemented to square and triangle channels, and tried to keep it as close to the specs from Brad Taylor's doc as possible. It seems to work, but it sounds awful!

Listen to this: http://www.stud.ntnu.no/~erlinga/nes_snd.mp3
How can I get rid of all that awful noise? What am I doing wrong?




SubjectRe: Sound emulation problems new  
Posted byDisch
Posted on10/21/03 8:09 PM
From IP66.127.105.177  



Looks like it might be an overflow problem... try lowering the volume of what you're outputting. And check to see if it overflows and clip if it does.




SubjectRe: Sound emulation problems new  
Posted bysammael
Posted on10/21/03 9:10 PM
From IP129.241.146.203  



It doesn't seem to overflow. But my linear counter doesn't seem to work as it should, and the decay is out of phase. Also, the tone produced sometimes is off key. However, I don't think fixing it would eliminate the noise. Should I perhaps apply some kind of filter to the output to interpolate between steps?




SubjectRe: Sound emulation problems  
Posted byDisch
Posted on10/21/03 9:57 PM
From IP66.127.105.177  



Try creating a wav (not MP3) of the sound you're producing... look at it in a wave editing program, like SoundForge (so you can see the generated wave). I tried this with the MP3 copy... but it was kind of sloppy looking (due to the compression probably).

Try looking at each individual channel. The generated waves of the NES are pretty simplistic... so if you're looking at the wave you should be able to see where any errors are occuring and that might help isolate the problem. If no problems occur in the individual waves... there's something wrong with how you're mixing them (which bring you back to overflow... but if that's not what's happening my money is on individual wave problems)


> But my linear counter doesn't seem to work as it should

There's a thread here about it:

http://nesdev.parodius.com/cgi-bin/wwwthreads/showpost.pl?Board=NESemdev&Number=960&page=1&view=collapsed&sb=5

There are a couple tweaks in there that get it working. You probably want to ignore the last tweak I gave, since it causes some problems with SMB1 (but fixes Manaic Mansion... meh).

> and the decay is out of phase

I doubt this would be the problem... but definatly try to get that working.

> Also, the tone produced sometimes is off key

What's your base frequency?

You should be generating a new output sample every (1789772.7272 / samplerate) CYCLES (don't measure it by frames or quarter frames, or whatever... do it by CPU cycles). Don't round off any decimals in any calculations.

> Should I perhaps apply some kind of filter to the output to interpolate between
> steps?

Filters are nice, but that wouldn't solve your problem.




SubjectRe: Sound emulation problems new  
Posted bysammael
Posted on10/21/03 11:12 PM
From IP129.241.146.203  



Thanks! When I instead of silencing the channel when the programmable timer is below 08, just halt the counter, the sound gets much better. There's still some clicks, though, seems to be abrupt steps that causes it. Maybe I should fade in and out when the channel is activated/silenced.

I'm using a counter clocked at twice the cpu frequency. When it reaches 14916, the frame counter is increased, so I produce the 240Hz frequency. I haven't, however, taken the extra cycles caused by page boundary crossing in the cpu into account yet, so this could have an effect on the resulting frequency. It's just one of the channels that is off key in relation to the others, though, otherwise I wouldn't have noticed.





SubjectRe: Sound emulation problems new  
Posted bysammael
Posted on10/22/03 10:11 AM
From IP129.241.146.203  



Sorry, I misinterpreted that about sample rate.. I had in fact rounded off a lot, and it seemed to help a bit correcting it. The triangle channel is still off key, though, it's probably a +-1 error in one of the counters, as it seems to be worse at high frequencies.
Example: http://www.stud.ntnu.no/~erlinga/smb2.wav


Ignoring linear counter mode change in writes to 0x4008 also helped.

About the envelope decay stuff: Is it true, as the doc says, that the volume should _always_ be decremented by one, regardless of whether the decay is enabled or not? It seems a bit strange to me, and makes Ducktales' music sound worse, as it gets a looping decay (not present in other emulators).
Example of this: http://www.stud.ntnu.no/~erlinga/ducktales.wav





SubjectRe: Sound emulation problems new  
Posted byDisch
Posted on10/22/03 5:00 PM
From IP66.127.105.177  



> I had in fact rounded off a lot, and it seemed to help a bit correcting it

Yeah... rounding off will throw the notes off tune when you get at higher frequencies. Especially true at lower sample rates.

> The triangle channel is still off key, though, it's probably a +-1 error in one
> of the counters

I hear it in both samples you uploaded... it also sounds like your linear counter still needs a little more work (the notes are playing too long on the tri channel in Duck Tales... and there are a few weird notes in SMB2 that seem out of place, but I could be imagining it).

Don't have any ideas on this one... I would say just review you triangle code... maybe there's a typo somewhere that's causing this odd behavior.

Your tri channel should be making another step in it's tri-step generator every 'freq+1' cycles.. also, there should be 32 steps for the complete wave (make sure you're going D,E,F,F,E,D instead of D,E,F,E,D... that could throw the tri off tune.. and also 2,1,0,0,1,2 instead of 2,1,0,1,2). If you're doing both of those the pitch should be right on.

> About the envelope decay stuff: Is it true, as the doc says, that the volume
> should _always_ be decremented by one, regardless of whether the decay is
> enabled or not?

Ah... from what I can tell the doc is accurate.. but the evelope/decay hardware does -not- change the volume level at all. There's actually an internal value aside from the volume... I think the doc refers to it as the envelope/decay counter, but it's been a while. This counter (not the volume) is decreased on decay clocks even if decay is enabled. It keeps counting down until it hits zero (in which case it stops counting.... or loops back to F if decay looping is on). The only register write that directly changes this value is a write to the 4th register of the channel (4003->Square 1, 4007->Square 2, 400F->Noise) which sets the value to F.

If decay is enabled, the volume level is IGNORED, and this internal counter is the output volume.
Otherwise, the internal counter is ignored, and the volume is output as normal.




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo