blip buffer mixing channels?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Euyira
Posts: 4
Joined: Thu Aug 06, 2020 12:00 pm

blip buffer mixing channels?

Post by Euyira » Thu Aug 06, 2020 12:21 pm

Hi, confusion about using blip_buffer.

Is there a difference between pre-mixing the 5 NES channels and sending into blip -- vs sending each channel into individual blips and mixing each output? Also is there any use for it outside chip generators like (AD)PCM, OPL3, MT-32?

And after reading this, how does it compare to Ryphecha's Mednafen algorithm?
(ref: viewtopic.php?f=3&t=17567)

User avatar
Dwedit
Posts: 4350
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: blip buffer mixing channels?

Post by Dwedit » Thu Aug 06, 2020 1:36 pm

QuickNES uses two blip buffers for the 5 channels. One blip buffer for the square channels, and one blip buffer for the triangle, noise, DMC channels. This is done just because of the way the NES mixes channels. Square Waves are mixed together, Noise+Triangle+DMC are mixed together.

The triangle+noise+DMC channel is nonlinear, and setting the DMC sample value to a high number will actually quiet down the triangle channel. That wouldn't happen in a linear channel.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Euyira
Posts: 4
Joined: Thu Aug 06, 2020 12:00 pm

Re: blip buffer mixing channels?

Post by Euyira » Wed Aug 12, 2020 5:09 am

Sorry for the late reply but thanks! Went through lots of experiments and playtests.

- blip_buf.c < blip_buffer.cpp (better quality, noticeable)
- treble_eq: made "static float fimpulse" array to avoid stack crashes
- BLIP_BUFFER_ACCURACY: set mine at 32 but 48 works, seems to delay desyncing
- BLIP_PHASE_BITS: set mine at 12, I think edges are cleaner with values > 6
- BLIP_IMPULSES: something I added (128), blip_max_quality and expanded the impulse table
(combining all above changes not good for slower ARM, mobiles or potato devices)

Difference overall isn't much at all but I just went for the maximum. Default values seem very good already.


EDIT:
Forgot to say also tried the blip mixing method. So tried 1 blip buffer (mono) + 5 synth buffers. TBH, I couldn't hear a change but supposedly it should generate less interfering noises or something like. Having individual waveform synths is okay though if you want the OOP to keep track of deltas for you.

User avatar
Dwedit
Posts: 4350
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: blip buffer mixing channels?

Post by Dwedit » Wed Aug 12, 2020 8:51 am

Check what QuickNES actually uses. It uses the "Nonlinear" variant of blip buffer in order to emulate that quirk with the NES's sound.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Euyira
Posts: 4
Joined: Thu Aug 06, 2020 12:00 pm

Re: blip buffer mixing channels?

Post by Euyira » Thu Aug 13, 2020 7:56 pm

Thanks for your help! Took me some time to understand the quirk but have it working now, and fixed my blip usage while at it after studying QuickNES. Plus made my own copy method to avoid having to regenerate the exact same impulse tables for every new synth generator, which became a whole lot slower when adding the extra chips.

Also took some side-trips to read about DC bias, signed ranges, popping, high-pass, low-pass and other fun stuff. It's stuff I usually glossed over but now I'm actually getting it for once.

Euyira
Posts: 4
Joined: Thu Aug 06, 2020 12:00 pm

Re: blip buffer mixing channels?

Post by Euyira » Wed Aug 19, 2020 5:07 am

Have a different problem I noticed now. When using loadstates, the output somehow gets heavily biased. So normally I'm puffing out 0-25000, then loadstate can shift to -15000 to +10000, and sometimes I go 15000-32767. When I output raw instead of sending through blip, it's normal positive range.

Should I be worried about the "re-centering" affecting audio quality when it's not crashing against either signed 16-bit limit? And why is blip doing the range movement??


edit:
Solved by looking at @Dwedit work.
https://github.com/libretro/QuickNES_Co ... 2a6fa82d69

Needed audio cleaning to restore blip state. And told that DC Bias may actually give more headroom for +volume or extra channels.

Post Reply