Shruthi oscillator code

Hi guys…

I can not find the complete code from current shruthi firmware on GitHub.
It lacks metal, bowed, organ and other. Can anyone tell me where can I find this?

Link GitHub:

Greeting Rolf

Those are all wavetables. Perhaps the wavetables are stored somewhere else? In terms of oscillator code, I assume all the wavetables use one oscillator “mode” just playing different data.

EDIT: Maybe it’s shruthi/data/waves.bin?

I think its a special oscillator render code such as pad sound, zsaw sound, FM and more.

// ------- CzSaw synthesis -------------------------------------------

void Oscillator::RenderCzSaw(uint8_t* buffer) {

uint8_t phi = phase.integral >> 8;
uint8_t clipped_phi = phi < 0x20 ? phi << 3 : 0xff;

// Interpolation causes more aliasing here
*buffer++ = ReadSample(wav_res_sine,
U8MixU16(phi, clipped_phi, parameter_ << 1));


The oscillator functions are enumerated at the end of oscillator.c and the Render function in oscillator.h uses the appropriate oscillator function to generate audio. RenderInterpolatedWavetable is used to generate all wavetables by addressing different data in waves.bin (metal, bowed etc).


which rendering function is for organ ?

Metal, bowed, organ etc are all wavetables.

Rendering code here

You mean that:

// ------- Interpolation between two waveforms from two wavetables -----------

void Oscillator::RenderInterpolatedWavetable(uint8_t* buffer) { …

I have understand this. Thanks everyone :slight_smile:

The next problem: how can i do the variable declaration in C for that inline function ?

My struct is not function and cause an compiler error!

struct Oscillator1
__uint24 phase;
__uint24 phase_inc;
uint16_t integral;
uint8_t fractional;
uint8_t carry;

} Osc1;

static inline _uint24 U24AddC(uint24 a,_uint24 b) {
uint16_t a_int = a.integral;
uint16_t b_int = b.integral;
uint8_t a_frac = a.fractional;
uint8_t b_frac = b.fractional;
uint8_t a_carry = 0;
__uint24 result;
“add %0, %6” “\
“adc %A1, %A7” “\
“adc %B1, %B7” “\
“adc %2, r1” “\
: “=r” (a_frac), “=r” (a_int), “=r” (a_carry)
: “0” (a_frac), “1” (a_int), “2” (a_carry), “a” (b_frac), “a” (b_int)
result.integral = a_int;
result.fractional = a_frac;
result.carry = a_carry;
return result;

Thanks for help!

You mean the uint24_t? It’s defined in the avrlib/base.h like this:
struct uint24_t {
uint16_t integral;
uint8_t fractional;

No. There is not uint24 in gcc. its __uint24. My problem is the struct definitions in C (AVR ggc) for the results-variable

The orginal static inline _uint24 U24AddC(uint24 a,_uint24 b) is not function and cause an compiler error!

My struct:

struct Oscillator1
__uint24 phase;
__uint24 phase_inc;
uint16_t integral;
uint8_t fractional;
uint8_t carry;

} Osc1;

Sorry, but I don’t see anything suspicious in that definition (besides the two underscores before the uint24. I though you added those to show the places where your error is).

It would certainly be helpful to know what error you get.

EDIT: Just guessing here: Maybe all you need is a #define _uint24 uint24_t Or simply replace the_uint24 with uint24_t

I think the problem is the syntax for c-variable (,,

My Compiler error in Atmel Studio 7 (see pic).

Probably your definition of _uint24 is not right. The compiler thinks that variables of typeuint24 must be unions or structs, because otherwise the “xyz.integral” notation doesn’t make sense. So apparently your current definition of_uint24 is not the one from avrlib/base.h.

What is your current definition of __uint24?

I think you’re confusing uint24_t (a type that I have declared myself) with gcc’s __uint24_t

Also I don’t understand the purpose of the Oscillator1 struct you have declared.

Ok… i have create a new struct and typedef but its compiler error…

Error: “expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘U24AddC’ avr_synthi_30”

My struct:
typedef union {
uint16_t value;
uint8_t bytes[ 2];
} Word;

typedef union {
uint32_t value;
uint16_t words[ 2];
uint8_t bytes[ 4];
} LongWord;

struct {
uint16_t integral;
uint8_t fractional;
} uint24_t;

struct {
uint8_t carry;
uint16_t integral;
uint8_t fractional;
} uint24c_t;

sounds like you have a return type that’s not defined anywhere. like this:

static inline __xyz U24AddC( … )

where __xyz is the term thats not defined.

It same error with __uint24c_t

What about posting the code of the U24AddC function that causes errors?

It should return an uint24_t, right?


Osc1.phase = U24AddC( Osc1.phase, Osc1.phase_inc)

Osc1.phase and Osc1.phase_inc is declare as __uint24 in AVR gcc