SUBTOTAL
DISCOUNT
VAT
TOTAL
In this tutorial, I'll continue the work from last week, building an NES emulator in...

# Building an NES Emulator in Reaktor, Part II

In this tutorial, I’ll continue the work from last week, building an NES emulator in Reaktor from scratch (well, the audio parts anyway!). In the previous tutorial, I explained many of the difficulties around the emulation process, and designed a simple device to calculate the number of NES clock cycles to process for each tick of the sample clock in Reaktor.

##### THE APU CLOCK

In my work last week, I forgot that there are actually a couple different clocks used for the oscillators in the NES. The triangle oscillator uses the CPU Clock which we made last week, the pulse and noise oscillators use the APU clock, which runs at half the speed of the CPU clock. It is easy enough to add this:

Now we are ready to get on with making the oscillators, beginning with some common elements.

##### CREATING A TIMER

A timer, or divider, is a component used by all of the sound generators in the NES. It has a fairly simple operation: it outputs a single clock event for every T+1 events received. The value, T, is given by a simple equation:

T = CPU/(16*F) – 1

Where CPU is the clock speed in Hz, and F is the frequency of the oscillator. In Reaktor, this looks like so:

You may have noticed that T is an integer. This leads to a rounding error in regards to frequency, usually small enough to pass unnoticed.

With a T value of 8 or less, the oscillator shuts off entirely. Since this translates to a frequency of over 12KHz, which is rarely used in synthesis, so I have omitted this detail for the time being, however this would be easy to implement if desired.

Let’s talk for a moment about the exact operation of the timer. It stores a value called the counter, that is initialized to the value of T. For each incoming clock, the counter is checked. If it is greater than zero, the value is decreased by one. If it is equal to zero, it is reset to T, and a clock is sent to the output.

Depending on the value of T, the Timer might send out several triggers per Reaktor sample. We are receing either 20 or 21 APU clocks per sample. With a mininum T value of 8, this means that there could be as many as three outputs from the Timer that we need to calculate at once.

With this in mind, I developed the following timer device:

Here, we are receiving three pieces of information: the current value of the timer (Cnt), the number of APU clocks left to process (Clk), and our previously calculated value of T.

If the counter is higher than the number of events, we simply pass the number of clock values to the ‘Events’ output, subtract it from the counter, and send zero clock events to the next Timer macro.

Otherwise, the ‘Events’ output get the number held by the counter, the counter is reset to T, and whatever clock events remain are sent to the next Timer macro.

Three of these macros connected together will give us the all of the information we need to continue:

Okay, so the values Clk and Cnt are being passed from macro to macro, as they are changing each time. The output ‘Events’ is the number of events to calculate at a given position.

This whole setup can be pretty confusing. The numbers coming out the ‘Zero’ output are events that occured before anything changed with the oscillator, IE before it received any events from the timer. The outputs ‘One’ and ‘Two’ require that the oscillator be clocked.

##### CONCLUSION

Next week, I’ll show how these Timers can be used to control NES oscillators. If you have any questions, suggestions, or comments, please leave them below!

## RELATED COURSES

### Reaktor Core Masterclass

×
PLAYLIST
Clear all
WISHLISTS
Create an account to use wishlists
×
SAVE TUTORIALS
Create an account to save tutorials
×
Follow your favourite labels, formats and genre's and ADSR will show what's new in those on your next visit.
×
• Create product wishlist
• Save your favorite tutorials
• Regular discounts and exclusives
• Never miss a sound! Follow your favorite labels.
Sign up to My ADSR to ensure you're ahead of the pack. Save your favorite content and be notified of new content. You'll never miss a thing!
CREATE ACCOUNT
Sign up to My ADSR to ensure you're ahead of the pack. Save your favorite content and be notified of new content. You'll never miss a thing!
• Get days all ADSR courses free
• Create product wishlist
• Save your favorite tutorials
• Regular discounts and exclusives
Remember me
DON'T HAVE AN ADSR ACCOUNT?

2. Click "Send info"
3. Check your inbox for an activation link
4. Visit activation link and enter set new password
DON'T HAVE AN ADSR ACCOUNT?
IMPORTANT: Is this product compatible with your system? Please check the product system requirements tab before purchasing. To proceed with this purchase you must check the box to confirm you have checked the requirements.

I have read the system requirements and agree to the return policy. I understand that refunds will not be given due to limitation of my software or operating system.

, you have loyalty credit available. To redeem click the button to claim !
Claim
Claim your free sounds

For every \$5 you spend on ADSR receive 1 free credit for Sample Manager.

Even better, we have back-dated this so any purchases you made since 2017 have also been credited to your account!

Click the button below to claim your free credit.

Get my free credits
Loyalty credits
1Every purchase you make on ADSR* now earns you 1 loyalty credit for every \$5 spent
2Once you make a purchase your credits are added to your account
3Credits can be redeemed in ADSR Sample Manager to download individual loops and samples