1
0
mirror of https://github.com/sjlongland/atinysynth.git synced 2025-09-13 10:03:15 +10:00
Go to file
Stuart Longland 44e2d937d6
gensine: Add in sine wave generator.
I left this out because I thought the idea of modulus and division on a
MCU that lacks a hardware multiplier would be too much for it… and
indeed it was too much with my other project.

Thinking about it this afternoon, I had an idea.  If I have 2^N samples,
then the modulus can be optimised to:

```
	mod = sample & ((2**n)-1)
```

and the segment can be figured out by:

```
	segment = sample >> n
```

The segment is two bits.  A function that returns the scaled sine value
for a given scaled angle can be given as:

```
	int8_t fp_sine(uint8_t angle) {
		uint8_t segment = (angle >> POLY_SINE_SZ_BITS) & 3;
		uint8_t offset = angle & ((1 << POLY_SINE_SZ_BITS)-1);

		switch (segment) {
			case 0:
				return _poly_sine[offset];
			case 1:
				return _poly_sine[
					POLY_SINE_SZ - offset];
			case 2:
				return -_poly_sine[offset];
			case 3:
				return -_poly_sine[
					POLY_SINE_SZ - offset];
		}
	}
```

… or something like that.  If `POLY_SINE_SZ_BITS=6`, then `angle=255`
represents 360°.
2017-04-25 17:43:51 +10:00
ports ports/attiny85: Looping sound effects. 2017-04-09 10:17:49 +10:00
.gitignore gensine: Add in sine wave generator. 2017-04-25 17:43:51 +10:00
adsr.c adsr: Add functions for configuring the ADSR. 2017-04-09 08:17:03 +10:00
adsr.h adsr: Add debugging 2017-04-09 10:06:38 +10:00
debug.h debug.h: Add debug helper 2017-04-08 20:26:45 +10:00
gensine.py gensine: Add in sine wave generator. 2017-04-25 17:43:51 +10:00
LICENSE ADSR-based synthesizer for microcontrollers 2017-04-08 18:57:37 +10:00
Makefile gensine: Add in sine wave generator. 2017-04-25 17:43:51 +10:00
README.md ADSR-based synthesizer for microcontrollers 2017-04-08 18:57:37 +10:00
synth.h synth: Make enable/mute bits volatile. 2017-04-09 10:17:09 +10:00
voice.h voice: Add test for voice channel done. 2017-04-09 10:07:10 +10:00
waveform.c waveform: Fix logic errors in triangle synthesis 2017-04-09 07:26:16 +10:00
waveform.h waveform: Increase step to 16-bits. 2017-04-09 07:19:04 +10:00

ADSR-based Polyphonic Synthesizer

This project is intended to be a polyphonic synthesizer for use in embedded microcontrollers. It features multi-voice synthesis for multiple channels.

The synthesis is inspired from the highly regarded MOS Technologies 6581 "SID" chip, which supported up to 3 voices each producing either a square wave, triangle wave or sawtooth wave output and hardware attack/decay/sustain/release envelope generation.

This tries to achieve the same thing in software.

Code is presently a work-in-progress.