Showing posts with label Roland. Show all posts
Showing posts with label Roland. Show all posts

Wednesday, February 11, 2026

A deepdive into the JP8000 and TC170C140 ESP

This post sums up everything I've learned about the Roland/Toshiba TC170C140 ESP. Some of it comes from the Usual Suspects' presentation at 39C3, some from studying and running the JE-8086 code, and a little bit from the JP8000 service manual

 

Hardware

The TC170C140 ESP, from now on referred to as 'the DSP', has the following specs:

Two cores, each with:
- 24 x 8bit multiplier *
- Two accumulators
- Programs of 768 instructions
- 256 words of 24 bit internal RAM
- 3 pipeline slots for IRAM write **

One of the cores can communicate with external DRAM, referred to as ERAM. It looks like this is core 2.


Separate program memory areas per core
PR0: 24 bit, starts at 0x0000 in emulator. Used by core 1
PR1: 28 bit, starts at 0x0400 in emulator. Used by core 2

* The DSP does multiply high, so in practice multiplication can be thought of as multiplying two 24bit numbers but only using the 8MSBs of the second number, then keeping the upper 24 bits of the result. 

**  Not sure what they mean by this, perhaps the accumulators as they are pipelines with length 3 

 

Memory

IRAM - Internal RAM

- 256 words of 24 bit internal RAM, addressed as delay line/circular buffer 

GRAM - Probably global RAM

- 256 words of 24 bit shared internal RAM (GRAM), also used for audio I/O and communications between the DSPs, at least in the emulator 

- Shared between cores

IRAM/GRAM is not accessible from the host interface, but in the emulator at least, values are copied between DSPs directly from GRAM to GRAM.

ERAM - External Ram (DRAM)

- Only one core can access external RAM, from the program memory formats it looks like it's core 2

Accumulators

- both circular buffers with 3 steps

 

Instruction/bytecode format:

E = ERAM control, only found on core 2

P = op
M = mem
S = shiftbits
C = coefficient, a signed 8-bit integer
x = unused?


Bit format (28 bits) - usually only 23 are used:

EEEE EPPPPPMM MMMMMMSS CCCCCCCC

- In the DSP code, 

op = (instr >> 16) & 0x7C

e.g.

0b0PPPPP00

so all op codes are shown as * 4


Each instruction performs a multiply and accumulate (MAC) with variable shift right (3,5,6,7 bits):
 

acc += (mulInputA * mulInputB) >> shift

or 

acc  = (mulInputA * mulInputB) >> shift

 

Special instruction:
0x372800 -> sends result to CP // WHAT IS CP
 

 

Other instructions: 

  • Store accA or accB to IRAM
  • Store saturated or unsaturated (unsigned)
  • Read/write GRAM
  • Multiplication per variable
  • Double precision multiplication ("DMAC") 
  • Rectify clamp, interpolate helpers
  • Control Flow
    •  Jump always/zero/pos/neg*
    •  Skip the following instructions based on condition

* Jump is never used in oscillator code/DSP 1 it seems, but perhaps in others?


The chip is in general extremely similar to LSP (See: "Sound Chip, whisper me your secrets", gulaschprogrammiernacht 23)
- same instruction format, memory addressing, external memory control, coefficient size 

 

MAC

Every instruction ends with a multiply and accumulate (MAC):

acc +=  factor1 * factor2 >> shift

The multiplication is 24 x 8 bits

 

To add a number without multiplying, one of the factors must be reduced to 1 by the shift operation. 

acc += factor * 1 

 

To not change anything, the second factor can be set to 0

acc += factor * 0 

This is used for most of the memory write functions.

 

The MAC result can either overwrite or be added to either of the accumulators.

The multiplier is usually used as a 24 x 24 bit multiply high where the second factor only has 7 bit precision (1 sign + 7 value bits + 16 0s). 

Can do 14bit precision with an additional instruction (DMAC). 

Can do up-to-24bit multiply-by-coefficient by running a special multCoeff instruction, then up to thee DMAC instructions with their separate 8 bit coefficients.

 

IRAM

IRAM is circular and the pointer to head is decremented for every full run of the program memory 

Within a single run you can read and write to the same position

Between runs you can get the previous version by reading the previous address


Accumulator

ACC is also a circular buffer, but a bit weird. For set and add the value from the previous instruction will be used directly, and the value is stored at the current head position

Reading saturated or raw however, reads the previous value at the same position as head, which is the result of MAC three instructions back. 

Also note, that if the accumulator is not changed by the instruction, the previous value is copied. After three steps, all the positions in the acc are the same, so in reality the value you read is the most recent write three OR MORE steps back. This also means that two additional changes to the accumulator may have happened since the value you read, you just don't have access to them yet - or, at least not the one two steps back, the previous one is available when doing MAC.

The pipeline is advanced for every instruction 

 

GRAM 

Communication between DSPs are through GRAM, output is found at x and inserted into y

 

Parameter changes

The code runs 88200 times per second, so it would be inefficient to always write parameters to IRAM. Instead, parameter changes happen directly by changing the instruction in program memory and are written to IRAM if needed. 

Each instruction can only take 8 data bits, so larger coefficients are set (and multiplied into one) by additional instructions.

 

How the JP8000 uses the DSP 

 

Algorithm changes

Since program memory is limited, only the program for the current type of oscillator is kept in the DSP. Whenever the user switches oscillator type (super saw, feedback oscillator etc), a whole code block is changed. 

 

Things that change the code in DSP 1:

0x006b to 0x00b9 - Oscillator 2 algorithm // Core 1

0x043c to 0x049e - Oscillator 1 algorithm // Core 2

0x0005 to 0x0008 - Ring modulator

0x0068 to 0x00b2 - Sync // surrounds osc 2 code

 

Input parameters, these are written as program code changes. 

0x0044: Oscillator balance

0x0400: X-mod depth

0x0404: Unknown coefficient 1

0x040e: Unknown coefficient 2

0x0420: Unknown coefficient 3

0x0425: Unknown coefficient 4

0x0430: Unknown coefficient 5

0x041b: Pitch, stored in IRAM pos 0x65 

0x043f: Detune

0x0442: Mix 

 

PS: LFOs and other pitch modifiers are done in the MCU and set as parameters after combination with the pitch. 

 

Other interesting addresses

0x0424: store pitch to iram1[0x65]
0x0454: Osc 1: Store updated value to iram1[0x05]
0x0455: Osc 2: Multiply pitch and detune, 14bit precision, and add
               pitch + previous value for osc.
0x0459: Osc 3: Multiply pitch and detune, 14bit precision
0x045b: Osc 2: Store updated value to iram1[0x07]
0x045c: Osc 3: Load pitch, add -1 * pitch * detune (from 0x0459++) 
               + previous value
0x045f: Osc 4: Multiply pitch and detune, 14bit precision
0x0461: Osc 3: Store updated value to iram1[0x09]
0x0462: Osc 4: Load pitch, add (pitch * detune (from 0x045f++) * 120)
               >> 5 + previous value
0x0465: Osc 5: Multiply pitch and detune, 14bit precision
0x0467: Osc 4: Store updated value to iram1[0x0b]
0x0468: Osc 5: Load pitch, add (pitch * detune (from 0x0465++) * 
               -102) >> 5 + previous value
0x046b: Osc 6: Multiply pitch and detune, 14bit precision
0x046d: Osc 5: Store updated value to iram1[0x0d]
0x046e: Osc 6: Load pitch, add (pitch * detune (from 0x046b++) * 
               44) >> 3 + previous value
0x0471: Osc 7: Multiply pitch and detune, 14bit precision
0x0473: Osc 6: Store updated value to iram1[0x0f]
0x0474: Osc 7: Load pitch, add (pitch * detune (from 0x0471++) *
               -45) >> 3 + previous value
0x0479: Osc 7: Store updated value to iram1[0x11]

0x047a: Set B = (Osc 7 * (mix >> 16)) >> 7
0x047b: B += (Osc 5 * (mix >> 16)) >> 7
0x047c: B += (Osc 3 * (mix >> 16)) >> 7
0x047d: B += (Osc 1 * 25) >> 7
0x047e: B += (Osc 2 * (mix >> 16)) >> 7
0x047f: B += (Osc 4 * (mix >> 16)) >> 7
0x0480: B += (Osc 6 * (mix >> 16)) >> 7
0x047a: Set B = (Osc 7 * (mix >> 16)) >> 7

 

Communication between DSPs 

DSPs are called asic in the code
 
3 addresses are copied, e.g. the output of 3 voices.
0x80 is in voice group 1, 0x82 and 0x84 in voice group 2 when starting up
 
DSP1.GRAM[0x80 + k] => DSP2.GRAM[k] 
  
6 addresses are copied, the output of the 3 first is equal to the input from DSP2 
0x86 and 0x8a  is in voice group 1, 0x88 in voice group 2 when starting up  
DSP2.GRAM[0x80 + k] => DSP3.GRAM[k]
 
Not sure what is copied here: 
DSP2.GRAM[0xa0] => DSP3.GRAM[0x20]
DSP2.GRAM[0xa2] => DSP3.GRAM[0x22] 
 
8 addresses are copied, likely the 8 voices. Not sure if the signal at this point contains envelopes and filter 
DSP3.GRAM[0x80 + k] => DSP3.GRAM[k]
 

Communication between DSP and DAC 

called postSample in the code, reads GRAM 0xe8 and 0xec from DSP3
 
To hear output of the other DSPs, change to 0x80 + k on DSP1/2/3. 
 
 

Where does the code run

On DSP1, and perhaps on the others as well:

Core 1 is oscillator 2

Core 2 is oscillator 1  

 

DSP 1 generates 3 voices

DSP 2 generates 3 voices and passes the three from DSP1 straight through to the output

DSP 3 generates the remaining 2 voices. Has 8 outputs, not sure if filter and envelopes are here or in DSP 4.

DSP 4 is likely FX and output summing. 

 

Pitfalls when trying to understand the code

Acc is a circular buffer, so the value read by sat/raw is not the previous value, it is the last time the accumulator changed three or more steps back.

IRAM is circular, so reading and writing to the same cell in different iterations happens at consecutive addresses. Important when searching for the source of a value that is read, it may be at address+1.

The DSP is 24bit, so all variables are 24bit and overflow as such. The multiplication intermediate result however, before shifting, is 32bit.

The DSP is fixed point, so think of numbers as decimal numbers having a range +/-1.0 even if they're represented as ints.

The multiplication is usually thought of as a multiply high 24 x 24 bits, but with bit 15:0 of the second factor set to 0 - it has 7 bit precision.

 

How I debugged the code 

I approached the code in two different ways: Disassembling/reading the machine code, step debugging and looking at the output wave files

I used the jeTestConsole app as a an entry point - it boots the JE8086 in headless mode and outputs the display text to the terminal. I extended it with keyboard event handling to be able to change stuff on the fly.

On startup of the script, I set the je8086 to a known state. It boots up as a normal JP8000, so by pressing EXIT and WRITE at the same time it enters manual mode:

device.getJe8086().setButton(devices::kSwitch_Exit, true); device.getJe8086().setButton(devices::kSwitch_Write, true);

The device boots up in split keyboard mode. While I tried to change this, for some reason it prevented detune/mix param values from arriving at the correct positions in the DSP. I have not investigated this further and I don't know if it was true when using midi to set the params (I exposed a setFader method similar to the setButton). Changing keyboard mode was however useful when figuring out what voices are calculated in what DSP.

I then switched to a known midi note so I could look at the pitch parameter.

The rest of the control was done interactively - setting detune and mix to known values, dumping memory etc. 

 

Things I did to make debugging easier

  • Added asicId, coreId and the current value of the program counter, including the address offset for core 2, to the esp code. That made it possible to set conditional breakpoints in a single core on a single DSP, and easier to visually match the pc to a print out of the program memory.
  • Added auto-calculation of high-res coefficients, iram contents before and after execution to make it easier to read when running the debugger. 
  • Added debug output to writeuC, the function where MCU writes to DSP. There are three modes of writing to the program memory:
    • Mode 0x54: Raw Program Memory Write (program changes)
    • Mode 0x55: Coefficient Update (parameter values)
    • Mode 0x56: ERAM Control Bits Update 
  • Added way to dump/print disassembled pcmem on demand. The dump function is already included in both je8086devices.h and the DSP code. 
  • Extended the disassembler. 
    • Per-line comments, so running dump repeatedly added my own comments at the right lines
    • More accurate description of what happens per instruction type, including multi-line comments if more than one thing happens.
    • Human readable coefficient values as comments and directly in descriptions of instructions
    • Hiding lines with opcode 0
    • Adding blank lines when the accumulator was cleared, to automatically group instructions that belong together. 
    • Auto-calculation of address of the last write to an accumulator when reading sat/raw, as these are often way back in the program memory.
  • Added a way to get midi commands to the je8086
  • Added a keyboard handler that could change parameters like detune, mix, pitch etc through midi parameterChange, as well as execute dump.
  • For interactive debugging I switched from the JIT to interpreter version of the ESP, as it's way easier to read the full code than the JIT version. This change is done on line 149 in je8086devices.h

 

Example of disassembled output 

 

Fields, left to right: address in program memory, hex representation of instruction, [] = instruction split into fields, o=op code, m=memory address, s=shift bits, c=coefficient. Then store-to-ram operation if any. After the first |: op code and op code name, then the original disassembly-comment. Finally, my own description of the code. For sat(A) etc, there's an additional @ [0xXXXX], that's the address in program memory where the value of A was calculated.

Multi-line comment to make it easier to see exactly how kMulCoef is calculated


Opcodes w. description

The instructions are as described earlier in this post. This tells how to interpret each of them. 

List of all opcodes

 


 

Normal opcodes  

All codes except for 0x20 to 0x34 follow these rules:
 
shift is always set by shiftbits 
mulInputB is always coefficient
mulInputA has a default mapping, but may also be set more explicitly
result is written to either accumulator A or B
result either clears the current value of (A=) or adds to (A+=) the accumulator at the end
 
Each operation ends by doing 
acc = mulInputA * mulInputB >> shift (or +=)
 
Defaults for mulInputA
 
mem


10x1016
20x4001024
30x1000065536
40x4000004194304
default
iram[mempos]
 
Shiftbits 
 
the value of shiftbits selects the number of places to right-shift the result: 
0: 7
1: 6
2: 5
3: 3
 
Illustration of the three interp functions:
 
The the three variations of interp are a bit hard to understand. Here is a plot of each one:
 
interpStorePos

interpStoreNeg

interp

 

0x30 - special

Coefficient decides operation:
 
Coefficient format:
B = source for mulInputB - mulcoeffs, eram eller mulcoeffs 5??
F = Flips B amplitude around a midpoint between 0 and 1 (1-x) 
I = invert B 
L = If 1: Load mulInputA, if "weird"*: detect sign. 
    Save to iram[mempos]. 
    If 0: uses default mulInputA
A = Accumulator 
C = !Clear

Coeff: BBBFILAC 

* weird: Coeff =xxx111xx
 

0x34 - special

Mem decides operation:
 
mem & 0xF0 = 0xA0: 
 
4 LSB: MMMA, M = mulcoeff index, A = Accumulator 
Stores saturated accumulator to mulCoeffs 

mem > 0xC0:
 
Mem format: 
C: Clear
A: Accumulator
P: Operation
 
11CAPPPP 
 
Commands reads coefficient to jump etc
 
0x0: Jump on 0
0x1: Jump on < 0
0x2: Jump on > 0
0x3: Jump
0x4: Set INT pins
0x6: DMAC - double precision multiplication
0x7: Sets ERAM address
0xa: Write saturated accumulator to readback reg, read by uC
0xb: Write to ERAM
0xc:
0xd:
0xe:
0xf: Read from ERAM to IRAM[mem|0xF0] and to mulInputA

 

Parameter values

The tables below show the values send to the DSP when setting a MIDI CC or NOTE value. They are also found in my previous post, in a more copy-paste friendly format.
 

Detune 

 
First column is the midi value, the second is what the uC probably works on while the last, ESP, is what is sent to the DSP. 


 

Mix

First column is the midi value, the second what is sent to the DSP. 
 




Pitch

First column is MIDI value, second is what is sent to the DSP. The third, "actual", is the result of the pitch formula in my post about the correct version of the supersaw code. The last column is the difference between the two, showing the pitch error. For the lowest notes it is 1/1647, well below what we're able to hear. It increases as we go up the scale, but that's not a big problem, the relative difference is probably not increasing
 

Monday, January 19, 2026

Roland/Toshiba TC170C140 ESP multiplication

The Roland/Toshiba TC170C140 ESP is a 24bit DSP, presumably fixed point. 24 bit fixed point DSPs store numbers as Q1.23, meaning one sign bit and 23 "value bits". The numbers, while strictly large integers, are treated as numbers from -1.0 to +0.9999999.

The ESP has an internal 24 x 8 multiplier, and does multiply-high, meaning it keeps a full multiplication result and then returns the upper 24 bits of the result (excluding any extended sign bits) by doing a bit shift right after the multiplication.

It is common for DSPs to do multiply high, as it makes the second factor behave like it's in the range -1 to 1 (which, I guess, is fixed point). It makes the multiplier a scaler, scaling the multiplicand between plus/minus the original value. 

Multiply high in a 24bit fixed point DSP would multiply two 24bit numbers, then shift >> 23 and store the result as a 24bit integer (keeping the sign bit and 23 MSB of the multiplication).

The fact that the ESP multiplier is 24 x 8 does not mean that the second factor of the multiplication, as seen from the system side, is 8bit. It is actually 24 bits, but only the upper 8 bits (sign + 7 bits) are used during multiplication. The rest of the bits are discarded beforehand using >> 16, to make it fit within an 8 bit variable. 

After the multiplication, the result is shifted a further 7 bits for a total of 23, making it a normal 24bit multiply high. However, the precision of the multiplier is only 7 bits + sign, e.g. only +127/-128 steps are available. This, of course, will often not be good enough.

 

Multiplication "by hand"

Let's take a step back and consider how multiplication is done by hand, to get a more intuitive feeling of what precision loss means:

67 * 52

First multiply 6 by 52 and align with the 10-place

6 * 52 = 312

Then multiply by the 7 and align with the 1-place, below 

7 * 52 = 364

Finally, take the sum:

  312_

+ _364  

= 3484

Now let's pretend we're doing a multiply-high in a decimal system. We only have two places available to store the result, so we're dividing the multiplication with 100 afterwards. The result would be 34.

Then consider a multiplication where the precision of the first factor is a single place only - the resolution is 10s, not 1s. 

In this case, the result of the multiplication would be 3120, and the final result 31. We've lost precision.

This is similar to what happens with the 24 x 8 >> 7 multiplication in the ESP.

But there is something interesting here. The full multiplication is done in two steps, one for the 1's and one for the 10's of the first factor, and the ESP is only doing one of them in its normal multiply and accumulate (MAC).


Double precision multiplication

Fortunately, the ESP provides a second multiplication instruction, called  DMAC (Double precision multiply and accumulate). This lets us calculate another part of the multiplication using the bits below the 8 MSB.

To see exactly how this works, let's go back to multiply-high:

With A and B being 24 bit, we want to do A * B >> 23.

But as B cannot be more than sign + 7 bits, we need to divide up the multiplication, just like how we did separate multiplications for 10s and 1s in the decimal example above.

Here are the bits of B grouped in chunks of 7 (X, Y, Z, R) preceded by a sign bit S:

SXXXXXXX YYYYYYYZ ZZZZZZRR 

Now we can write the expression as:

Product P = A * B >> 23 

P = (A * (B[22:16] << 16 + B[15:9] << 9 + B[8:2] << 2 + B[1:0])) >> 23 

 

Substituting the values for the B-bits:

B[22:16] = B >> 16 = b1

B[15:9]  = (B >> 9) & 0x7F = b2

B[8:2]   = (B >> 2) & 0x7F = b3

B[1:0]   = (B & 0x03) = b4

 

P = (A * ((b1 << 16) + (b2 << 9) + (b3 << 2) + b4)) >> 23 

P = (A * (b1 << 16)) >> 23 + (A * (b2 << 9)) >> 23 + (A * (b3 << 2)) >> 23 + (A * b4) >> 23

and finally

P = (A * b1) >> 7 + (A * b2) >> 14 + (A * b3) >> 21 + (A * b4) >> 23

We now have four separate 24 x 8 bit multiplications.

The ESP does not have support for doing all the four parts in hardware, but it can do b1 using MAC and then b2 using DMAC. This increases the precision to 15 bits (sign + 2 * 7 bits), at the cost of an additional cycle. 

  

Substituting b1 back to B shows us how:

MAC: 

acc = (A * (B >> 16)) >> 7

During MAC, both A and B are stored in their full 24bit representation so they are available to the next instruction. Then a flag is set that tells the next instruction that the previous one was MAC.

DMAC: 

Now, A and B are still available, and we can substitute b2 to get

acc += (A * ((B >> 9) & 0x7F) >> 14

We know that the ESP implicitly does a >> 7 after every multiplication*, so we have to keep that separate. That leaves us with 7 more shift rights. We cannot shift b2 7 bits - it is 7 bits only so the result would be 0. Instead, we have to shift A, leaving us with:

acc += ((A >> 7) * ((B >> 9) & 0x7F)) >> 7  

In other words, running MAC and DMAC on A and B means

acc =  (A * (B1 >> 16)) >> 7  + ((A >> 7) * ((B >> 9) & 0x7F)) >> 7

The precision has increased from 7 to 14 bits (+sign). It is still not a completely correct 24 x 24 bit multiplication, but it lets us work with a precision that is good enough for rock'n roll.

(* it can do 3,5,6,7 but default is 7)


PS: the accumulator in the ESP may be cleared between every instruction - the flag that decides this is set either in the instruction itself or in a memory location. For MAC + DMAC to work it has to be set to clear = true before MAC and clear = false before DMAC.

Tuesday, January 13, 2026

A closer look at the super saw code

In this post I try to understand most of the super saw code found by the Usual Suspects when reverse engineering the Roland/Toshiba TC170C140 ESP chip. Since I have no real DSP programming experience, it took some time to realize what is actually going on.
 
Presumably, this is the code for the ESP emulator itself: https://github.com/dsp56300/gearmulator/tree/main/source/ronaldo/esp 


Coefficients - floats 

The coefficients listed in the usual suspects' presentation, when represented as floats, are:

[0, 0.01953125, -0.01953125, 0.06225585, -0.0628662, 0.107421875, -0.10986328125]

if we multiply by 8192 we get

[0, 160,  -160, 509.9999, -514.99999, 880, -900]

and if we presume that the strings of nines are the result of a division somewhere, we get

[0, 160,  -160, 510, -515, 880, -900]

Pretty neat!

8192 is 2 to the power of 13. The real values may be that, or perhaps either 14 or 16 bits, so either  

[0, 320,  -320, 1020, -1030, 1760, -1800] 

or

[0, 1280, -1280, 4080, -4120, 7040, -7200] 

 

Coefficients - integers

The code example lists these integer coefficients

[0, 318, -318, 1020, -1029, 1760, -1800]

Now that's  really cool. Those are almost a prefect match for the 14 bit representation of the coefficients. 

There are some strange mismatches though - 318 and -1029 instead of -320 and 1030. 

I'm not sure WHY this is yet.

Chat GPT suggest:

The small mismatches (318 vs 320 etc) come from:

  • rounding
  • deliberate asymmetry to reduce beating regularity
  • truncation after multiplication
  • and accumulator overflow behavior

But the mismatches are there in the originals, not the calculated values, and if they had the originals, they would have used a shared factor of 16384 when dividing down to the floats (weirdly, even 1020 / 16384 is listed as 0.06225585, when the real value - without any rounding error - is 0.06225586).


Pitch value

The pitch value is how much we need to increase the saw wave for every sample. We now know that the JP8000 uses a sample rate of 88.2kHz, and 24bit accumulators that have a range of 16,777,216 (bipolar)

The exact pitch range of the JP8000 is not known, but let's for a start consider the midi standard.

Midi note 0 (C-1) has a frequency of approximately 8.18 Hz, while the highest note, MIDI 127 (G9), is around 12,544 Hz 

Running at 88200Hz, every cycle of

8.18Hz is 10782.396 samples long

12544Hz is 7.03125 samples long.

With a 24bit accumulator, each increment will be

for 8.18Hz:  1555.98, e.g. 1556

for 12554Hz: 2386092,942, e.g. 2386093.

 

From this, we can assume that, approximated

Pitch range is1556 to 2,386,093 

Knowing this, the only unknown in the detuning equation, is the int24_t detune parameter.

 

Detuning

Given the center oscillator frequency F0,

When using floats, the outer oscillators should have a frequency Fn:

Fn = F0 * (1 + floatCoefficient[n])

When using the integer coefficients, we instead get

Fn = F0 * (1 + integerCoefficient[n] / 2^14)

Or 

Fn = F0 * (1 + integerCoefficient[n] >> 14)

Now, doing the bitshift on the coefficient alone would lead to a massive loss of precision (or rather, all the coefficients would become 0), so at very least, we have to do the bitshift after multiplying with F0:

Fn = F0 + (F0 * integerCoefficient[n]) >> 14

Ah, this is starting to look like the code, exciting!  

 

Detune amount

There is a third number in the detune calculation. The code calls it "detune" but in reality it's detune amount. It says how much of the detune coefficient to apply. 

According to Szabo, pitch * coefficient is the _maximum_ amount to apply. That means the detune amount should be a ratio between 0 and 1. This, of course, is not possible using an integer, without a division following the multiplication. 

Let's take a look at the original equation:

int24_t voice_detune = (detune_table[i] * (pitch * detune)) >> 7 

We know that detune somehow should give us a scaling between 0 and 1, so let's ignore how we get there for a second and remove it. That leaves us with detune_table[i] * pitch. 

We also know that we should divide this result with 2^14, though that is not included in the equation. Let's include it still, it has to be there somehow.

A quick check of the multiplication and following bitshift in the detune frequency calculation:

The lowest possible value is (1550 * 318) >> 14, which is 30. (lowest frequency, lowest detune without detune amount scaling).

The highest possible value is  (2386093 * 1800) >> 14, which is 262144. (highest frequency, highest detune amount).

The results are within a 24bit int range. However, the intermediate value from the multiplication is 4,294,967,400, which is much higher than what can be stored in a 24 bit int. Under normal conditions, this would make everything overflow. To be able to properly store the multiplication result, we need a division, and one that happens before the result is stored. Something strange is clearly going on.

Side note: The max result is even slighty higher than what can be stored in an uint32 (4,294,967,295). At the same time, its so amazingly close that it's hard to believe that its just random? And actually, if we go back to the highest frequency, it's actually 2386092,942. With that fractional result, the product is 4,294,967,295.6 - a mere 0.6 above. This is too weird to be a coincidence? Also, it turns out that the max frequency isn't 12554, it's slightly lower. That would keep the detune within a uint32 range. Interesting.


Now, lets go back to the equation and reintroduce detune:

int24_t voice_detune = (detune_table[i] * (pitch * detune)) >> 7

pitch * detune, let's call it pitchWithDetuneAmount will be calculated first. Max pitch is 2386093, so detune may be up to 3 without overflowing. That doesn't make much sense.

Next,  detune_table[i] * pitchWithDetuneAmount is calculated. detune_table[i] is at most 1800, so it will overflow if pitchWithDetuneAmount is larger than 4660.

Finally, everything is divided by 128 

And all of this, with detune at max, should not be larger than 0.10986328125 * pitch.

In a normal situation, we should divide detune table by 2^14, and detune by a maxDetune to make it into a ratio between 0 and 1. It is highly probable that maxDetune would be a factor of 2 as well, to make division a bitshift here too.  

Side note: maxDetune needs to be high enough to represent the curve shown by Szabo, at least if there are 128 different values not linearly spaced apart.

But the mystery remains. Where have the remaining divisions gone? We see some division (>>7 is the same as / 128) but that's not enough and it's not in the right place to prevent overflow.

 

DSP magic

I admit it, I had to ask ChatGPT about this one. At first it was reluctant to admit that there are something that makes division/bitshifts superfluous, but then everything dropped into place!

Enter multiply-high

DSPs have two major tasks - summing and scaling. Summing is +, and scaling is multiplication followed by a division. 

In fact, scaling is so important that most DSPs do multiplications in a slightly different way. They multiply the two numbers into an accumulator with twice the bit count of the factors, but then it only returns _the high order_ bits. E.g. if it multiplies, say, two unsigned uint16_t variables a and b, it would store the intermediate result in a u32_t, but then only return the 16 MSB. This is equal to bit shifting >> 16 or dividing by 65536. If we let a be our signal value, and b a scaling factor, this turns b into a scaling between 0 and 1!

So there you go, we get free bit shifts, invisible in the code.

In other words, the code the Usual Suspects is showing is is not normal C code, it's DSP code (of course...) meaning the * does not do what it normally does, it also bit shifts.

 

Implicit bit shifts 

Lets go back to the code again and see how this works out

int24_t voice_detune = (detune_table[i] * (pitch * detune)) >> 7

 

First we do 

pitch * detune

which we called pitchWithDetuneAmount earlier.

By making detune max equal to the bitshift included in *, it becomes a ratio between 0 and 1. Hooray! 

Then we do 

detune_table[i] * pitchWithDetuneAmount

Again, * will introduce bitshifting.


If we go back to the paragraph about multiply-high, an int24_t * int24_t would result in a 48bit intermediate, of which the upper 24 are returned (it may be slight differences working with signed ints but the principle is the same).

Shifting >> 24 is fine for detune amount. It would mean we could use the full 24 bits as a factor, getting any detune amount curve we could possibly want.

But shifting detune_table * detuneAmount by 24 is too much. It should only be 14, and even then 7 of the shifts are done outside the parenthesis.

Now, it's not important exactly how the bit shifts are done to understand the code. We can just accept that the code

int24_t voice_detune = (detune_table[i] * (pitch * detune)) >> 7

is equal to

pitch * (detune / maxDetune)* detune_table[i] / 2^14

without overflows etc. It is only important if we want to run the exact code and use the same range for detune amount.


Different bit shift?

There is however a posibility that the DSP doesn't actually shift by 24. Maybe it shifts by 7? That would make  

(detune_table[i] * pitchWithDetuneAmount ) >> 7

the same as

detune_table[i] * pitchWithDetuneAmount >> 14 

in a normal system.

It would mean that detune amount has to be 7 bit if it uses the same multiplication-high, leaving 128 steps of detune amount. That does not work well with the Szabo curve, but it is possible. Or maybe the C code is just inaccurately translated from assembly and that they use different multiplication operations.


The DSP (ESP) emulator code for the JE-8086 is on github, so we can peak at what it actually does. I have not studied it in detail, but there are traces of a configurable bit shift multiplication.

Studying https://github.com/dsp56300/gearmulator/blob/main/source/ronaldo/esp/esp.hpp may shine some light on this.

multResult in esp.hpp shifts the result after multiplication, 5, 6 or 7 places. It uses two bits of the instruction to select the shift, and 0,0 will default to 7 bit shifts. That sounds exactly like what we are looking for.

So, while not proving that 7 is the correct answer here, at least it makes it plausible that the ESP does infact use a different shift than 24. 

UPDATE: The multiplication (kMAC in the code) does two bitshifts. First, it shifts the second term by >> 16, meaning it only uses the 8MSB. THEN it does an up-to 7 bit right shift). In other words, detune and spread are not 0-128, they are the full 24bit range but only the 8MSB are used. There is also a double precision multiplication available so it is possible that is used for higher resolution

Something that may support this theory is that on a slide about the ESP, it says that it has a 24 x 8 bit multiplier. This seems to indicate that it does NOT have a 24 x 24 bit multiplier, and that, combined with signed arithmetic where one bit of the 8 bit variable is used as sign, would make a shift of >> 7 quite plausible and 7 bit (positive value) detune the way to go. 

It does however leave a question as to how the multiplication of detune_table and pitch works since both are definitely > 128. Perhaps it does multiple 24 x 8 multiplications?

--> It looks like it is possible to do that. The final bitshift will always be >> 7 which makes the last >> 7 explainable. This would make the detune_table[i] * pitch >> 14 multiplication possible. Detune and spread would still have to be max 127.

Example: 24 × 24 multiply-high using three 24×8 blocks

According to ChatGPT. Test this!

Let the 24-bit multiplier be split into bytes:

B = b2·2^16 + b1·2^8 + b0

You compute:

P0 = (A·b0) >> 7 P1 = (A·b1) >> 7 P2 = (A·b2) >> 7

Then re-align:

Result = P0 + P1 << 8 + P2 << 16

Substituting:

= A·(b0 + b1·2^8 + b2·2^16) >> 7 = (A·B) >> 7 (approximately)

Update: Double precision multiplication

The ESP supports "double precision" multiplication. I have not yet fully understood the result but essentially it does exactly what is suggested above - it first multiplies A with the 8MSB of B. It then multiplies A >> 7 with (B >> 9) & 0x7F, or bits 15 to 8 (0 indexed) of B

first time: acc += ((mulInputA_24 * (mulInputB_24 >> 16)) >> shift)        

second time: acc += (((mulInputA_24 >> 7) * ((mulInputB_24 >> 9) & 0x7f)) >> shift)

... I am missing something here, TBC. 

Spread 

There is a third multiplication in the code, saw[i] * spread. Just as with detune, this looked very strange and would lead to an overflow in a normal system. But with multiply-high this too becomes a scaling from 0 to 1, just as we needed. It could, as detune, be a value between 0 and 127 and work fine with >> 7. Again, it's not important to the understanding of the code, we can just accept that it's a scaling factor.

 

Conclusion

There are some questions left unanswered. Shifting by 7 on * means that detune_table[i] * pitch may still overflow (that 32bit thing above, remember), and the curves of detune and spread can't be explained properly. And finally, as mentioned in the previous post, summing of the seven saws will overflow.

In general, however, the code looks like it could do exactly what we think. If we were to reimplement it we would just take care of these issues - increasing sum to 32bit and doing the appropriate bits shifts manually, and selecting whatever resolution for detune and spread that we want. 

The only thing I cannot explain at the moment is how Szabo could see a attenuation of the center oscillator when doing mix (spread), as that is not part of the code. Perhaps it is some kind of normalization effect, that the center oscillator contributes less to the total. Guess that one just has to remain a mystery for the time being. 

Thursday, December 9, 2021

Roland M-240 PSU

I have an old Roland mixer, the M240. I've had it for years, ever since some idiot screwed me over when i bought it, promising to send me the power supply but never doing so. I did a little research of the internals here: http://atosynth.blogspot.com/2013/07/roland-m-240-power-supply.html

Today I finally googled a bit about it again, and found two interesting posts made about a year after mine:


https://djjondent.blogspot.com/2014/10/roland-m-240-mixer-power-supply.html

https://djjondent.blogspot.com/2014/11/roland-mixer-power-supply-replacement.html


Basically it says that the PSU is a simple centre tapped transformer with a diode rectifier and two caps. From Jon's posts it is clear that at least the Boss PSU he uses has two large filter caps in it - it's hard to read the ratings - 35V is clear but is it 220uF or 2200uF? In any case there are two 2200uF caps in the M240 so anything (or nothing?) would be fine I guess.


Jon uses the Boss ACE-120 but that is not the original PSU for the mixer and it is 300mA, not 500mA. I couldn't find an ACE-240 anywere either, so I had a look in the owner's manual for the M240. It says the following:


Aha, so for my 240V mixer I need the ACC-240A or E, not sure what the difference is - and it is rated at 32VA

It would be quite easy to build a power supply, but I will still have to find a matching plug and THAT won't be easy. 

Wednesday, July 14, 2021

Super saw analysis ideas

I found a post on Matrixsynth today that lead me to a second paper analysing the JP8000 super saw. 

The post: https://www.matrixsynth.com/2021/07/korg-nts-1-nutekt-digital-synthesizer.html

The project: https://github.com/GrahamJamesKeane/UberSaw

The project page: https://korgnts1beginnersguide.wordpress.com/

Adam Szabo: How to Emulate the Super Saw: https://korgnts1beginnersguide.files.wordpress.com/2021/07/szabo_adam_10131.pdf

Alex Shore - An Analysis of Roland’s Super Saw Oscillator and its Relation to Pads within Trance Music: https://korgnts1beginnersguide.files.wordpress.com/2021/07/ananalysisofrolandssupersawoscillatoranditsrelationtopadswithintrancemusic-researchproject-a.shore_.pdf


This got me thinking - I still think the detune response looks like it consists of three linear components instead of a 11th order polynom like Adam Szabo shows in his paper (I did in 2014 as well when making my analog 7-saw module).

I really want to test my theory in detail, but that requires some automation. Here's my idea:

- Control the JP through webMidi

- Loop through all midi values for detune

- Use a js spectrum analyzer, for example https://github.com/hvianna/audioMotion-analyzer to find the frequency components. We should be able to find 7 distinct maximums (the 7 oscillators). 

- For each maximum, record the pitch and amplitude, possibly as an average over several samples

- Build tables for each oscillator/detune setting and calculate spread and pot response to see what the actual response is.


Edit: I've been looking at the Web Audio API lately, and using it directly could be a good option. It works by chaining nodes, one of them being a FFT node. I assume that can be used for finding the maximums. 

Sunday, January 27, 2019

OTA filter cell

Fun fact - after looking for an explanation for the OTA used in the juno for a couple of years, I found it in my bookshelf because someone mentioned a circuit in the Musical Applications for Microprocessors book by Hal Chamberlin.

When trying to understand a circuit, I often look for visually similar circuits, but even though I have found several OTA filters, they are always different from the Juno one. But here is the clue: These are similar:

The typical Roland filter cell to the left, its equivalent to the right.
The left one is what you find in the Roland schematics, the right one is found in papers and OTA filter explanations elsewhere. It is explained in some detail in the section on voltage controlled filters, page 201 and onwards in 'Musical Applications for Microprocessors'.

The cell is really quite simple - the resistors, 68k and 560Ohm function as voltage dividers to reduce the input signal to the OTA. This is true for both the 68k on the input and the 68k in the feedback loop.

Sunday, March 6, 2016

Roland resistor nets for the IR3109

While researching IR3109 based filters I came across the schematics for the Jupiter 6. It has a neat multi mode filter, but the schematics show three resistor networks, and the resistor values for those are not shown.

Luckily, someone has figured out that the same resistors are used in the MKS80, which has most of the values - though not all of them.

From a bit of guessing I have come up with what I believe is the values and internal connections.

RM0688 - The schematics do not show the value for the resistor between 2 and 3, but it is rather safe to assume that it is a 100k resistor like all the others.

RM0690 - The MKS80 schematics shows a 7.7k resistor between 2 and 1. The Jupiter 6 schematics show two resistors without values, one from 1 to 2 and one from 1 to 3. As a 33k and a 10k resistor in parallel equals a 7.7k resistor, and these values are already used in the net, it is very likely that these are the missing values. If we at the same time assume that the positions are reverse those in the other half of the net, just like in the RM0688, we get the schematics above. PS: I have yet to see a usage of this net where 2 and 3 are not connected, so it is in reality only the combined value that matters.

RM0891
The resistor nets have different part numbers and designations in the various synths:

13919128 - RM0688 - RKM8C066
13919130 - RM0690 - RKM8C068
13919132 - RM0891 - RKM9F561/683GP

Monday, July 8, 2013

Roland M-240 power supply

Some time ago I bought a Roland M-240 24 channel line mixer. It looks like a nice and compact mixer, but the seller never got around to delivering the power supply / wall wart for it. I have tried googling to figure out what kind of power supply I could use, but have not found any info whatsoever.

So, today I opened the mixer and had a look at the power input board. It is quite simple - no bridge recitifier and no circuit breaker. It has a few huge caps though.

The connector on the back says +/-21.5V DC 500mA. The internal voltage regulators however - AN7812F / AN7815F / AN7912F / AN7915F - can all handle +/- 35V input, so anything between 21.5V and 35V should be fine - it might even work with 18V but this is not guaranteed. Beware that a different voltage than specified may make the voltage regulators run hotter than intended though!

I made a schema of the circuit, it looks like this:

I haven't figured out the value of the ceramic caps though...



Looking at the circut makes me think a bit - the two diodes look very much like they form a half-wave rectifier in conjunction with the 2200uF electrolytic capacitors. I do however take no responsibility if you connect an AC power supply to the mixer and it burns out!

Update, dec 2021: The input is in fact DC, but not well regulated, just rectified and filtered with two caps. I wrote a bit more here: https://atosynth.blogspot.com/2021/12/roland-m-240-psu.html