1
0
mirror of https://github.com/sjlongland/atinysynth.git synced 2025-09-13 18:13:16 +10:00
Commit Graph

52 Commits

Author SHA1 Message Date
cf587e3fd8
attiny861 port: Clear button hit/release events at power-on.
This prevents all the notes being played all at once on power-on.
2017-05-28 11:01:32 +10:00
e75d75d20b
attiny861: Enable pull resistors when reading.
Set PORTA to all ones to enable the pull resistors on all pins.
2017-05-28 10:43:27 +10:00
762b07177b
adsr: Fix "infinite" delay/sustain.
Seems `~value` doesn't quite have the intended effect.  The intent was
that, being the 1s compliment of `value`, the expression would return
zero if `value` was all ones, and non-zero.

This doesn't quite work the way I'd like it to.  A comparison should be
the same number of CPU cycles, and is more readable, so we'll do that.
2017-05-28 10:33:52 +10:00
0bed82802b
attiny861 port: Bump sample rate
Seems we can handle 16kHz sampling… but not 32kHz.
2017-05-28 10:25:21 +10:00
75fe949f27
attiny861 port: Semi-working version.
This implements detection of the pressed buttons, with software
debouncing, and plays a note indefinitely until the button is released.
The corresponding LED's amplitude is modulated by the ADSR envelope.
2017-05-28 10:19:05 +10:00
d9bfcb7991
adsr: Support "infinite" delay and sustain.
This is useful if you don't know how long a given note will be held for…
you can just trigger the note upon pressing the button and have it
progress to the "sustain" state, at which point it'll hold the note.

You can then call `adsr_continue` to "release" that note when you detect
the button release and have it decay.
2017-05-27 15:19:40 +10:00
f2fac87ba3
main: timer: Invert button states
There's a pull-up with the button asserting a logic low, so invert the
inputs.
2017-05-27 15:01:41 +10:00
f8346cdea9
Add ATTiny861 port.
The ATTiny85, as good as it is, has too few pins to really do a lot.
You can buy I²C GPIO expanders, but many cost more than programming an
ATTiny24A (which has more brains).

The nearest equivalent is the ATTiny861, it is basically the same core
as the ATTiny85, features the same PLL for high-speed PWM, but comes in
a 20-pin package.  They cost ~AU$3 in individual quantities.  (An
ATTiny85 costs AU$1.74, an ATTiny24A costs AU$1.57; thus you save about
20c and a lot of interfacing effort in going to the '861.)

Thus it can interface to 8 individual switches with ease.

The circuit here uses a 74374 D-latch to drive up to 8 LEDs with PWM and
two 4066s to isolate the 8 inputs.  Idea being, when the GPIO_EN signal
is high, the 4066s are turned on and port A sees the 8 GPIO lines on the
other side of the 4066s.

4066s were used because I have 4066s up the wazoo… bought a box of
random ICs off eBay many years ago and it came with 5 (!) tubes of
MM74HC4066s with 25 ICs each (amongst other parts, some hard-to-find).
The bonus being these can be ADC inputs too if desired, allowing sensing
of piezo sensors.

When we want to switch which LEDs are turned on, we bring GPIO_EN low,
switch port A's pins to outputs, assert the desired LEDs, then bring
GPIO_EN high again.  The 74374 latches those pins, and we are free to
put port A back to being inputs.

This happens with each sample from the synthesizer, alternating between
input and output.  Thus the effective rate seen on the LEDs and inputs
is half the sample rate.

A spare GPIO is available for turning on and off an amplifier (I use the
NJR NJM2113D) to save power.

The 74374's nOE pin is connected to the PWM output for the lights, thus
using pull resistors, one is able to use the one PWM channel for all 8
lights.  The lights are turned on in round-robin fashion, so effective
duty cycle is ⅛ and the refresh rate is ~500Hz.
2017-05-20 20:48:19 +10:00
6ddaad18f2
attiny85: Add ADC-based keyboard support.
This is a work-in-progress, but we're now able to play some notes by
pressing keys.
2017-05-01 17:38:17 +10:00
3ff3e349f5
attiny85 Makefile: Add main.o and adckbd.o to object list. 2017-05-01 17:37:48 +10:00
8333f32d26
pc Makefile: Add main.o to port object list for PC 2017-05-01 17:37:22 +10:00
01a1bc8b70
Makefile: Make object list configurable.
Allow ports to insert their own object files to the list.
2017-05-01 17:36:56 +10:00
aa3771dc78
adckbd: Add first stab at ADC-based keyboard.
This works by relying on a resistor ladder that is part-shorted-out by a
button to Vcc.  The ADC detects the button pressed from the voltage seen
on the ADC.

There's some work to be done on this yet.
2017-05-01 17:35:19 +10:00
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
2fe3ea766c
fifo: Drop unused library 2017-04-09 10:53:57 +10:00
17599177cb
ports/attiny85: Looping sound effects.
It sounds like the crappiest doorbell you've ever heard, but we now get
a crude "ding dong" effect with this code, on a loop.
2017-04-09 10:17:49 +10:00
7214ae7d78
synth: Make enable/mute bits volatile.
Otherwise the optimiser doesn't bother to re-check them.
2017-04-09 10:17:09 +10:00
fb59c52b71
ports/pc: Start playback when enable ≠ 0.
After configuring the voices, we start playback until all channels stop.
2017-04-09 10:13:29 +10:00
ba7d0598c9
synth: Turn off channels that are "done". 2017-04-09 10:07:27 +10:00
dd483630d7
voice: Add test for voice channel done. 2017-04-09 10:07:10 +10:00
57769d477a
adsr: Add debugging 2017-04-09 10:06:38 +10:00
5855eb3da0
adsr: Add test for "ADSR done" event. 2017-04-09 10:06:11 +10:00
093b6dd888
ports/attiny85: Set sample rate to 8kHz 2017-04-09 09:17:28 +10:00
3f7c6353c1
ports/attiny85: Remove debugging #if blocks 2017-04-09 09:17:04 +10:00
b1ddd0c099
ports/attiny85: Define program target 2017-04-09 09:16:50 +10:00
38bf5a4261
Makefile: Remove .dep output definitions.
This confuses `make` and it winds up telling `gcc` to write the compiled
binary to the `.dep` output.
2017-04-09 09:09:53 +10:00
9bba7c0c19
ports/attiny85: Work in progress ATTiny85 port 2017-04-09 08:24:14 +10:00
301f5d0b8c
fifo: Add FIFO buffer library 2017-04-09 08:23:52 +10:00
9f3cd37109
ports/pc: Set default target in Makefile 2017-04-09 08:23:33 +10:00
4bad2a4c91
Makefile: Re-work build system
Running `make PORT=...` should be all that's required to build one of
the ports.
2017-04-09 08:22:54 +10:00
67bf582ee4
adsr: Add functions for configuring the ADSR. 2017-04-09 08:17:03 +10:00
286caebd67
adsr: Consider sustain time in initialisation. 2017-04-09 07:45:32 +10:00
54f47795ac
waveform: Fix logic errors in triangle synthesis 2017-04-09 07:26:16 +10:00
aff9a6c00b
waveform: Flip phase of sawtooth wave. 2017-04-09 07:22:32 +10:00
6f7749c0fb
waveform: Increase step to 16-bits.
Integer overflow was breaking sawtooth output.
2017-04-09 07:19:04 +10:00
2a9c5ac4dd
waveform: Fix square wave generation. 2017-04-08 22:02:02 +10:00
06199b7da8
pc/main: Tweak output 2017-04-08 21:53:12 +10:00
2236e9eda8
synth: Show channel output in debug 2017-04-08 21:53:00 +10:00
d7ae5000ca
adsr: Tweak attack/release envelope computation. 2017-04-08 21:52:27 +10:00
2281f8b0e3
voice: Debugging 2017-04-08 21:52:10 +10:00
ba94adbfd1
adsr: Fix attack envelope. 2017-04-08 21:41:02 +10:00
b77e364f53
adsr: Define "done" state 2017-04-08 21:40:49 +10:00
e24cf7376e
ports/pc: Debugging, bugfixes. 2017-04-08 20:56:03 +10:00
c512e5e6ef
synth: Add debugging 2017-04-08 20:55:47 +10:00
5c90525e01
waveform: Add debugging 2017-04-08 20:55:38 +10:00
c7accf26d9
adsr: Add debugging 2017-04-08 20:55:18 +10:00
30e11101c4
Makefile: Add LIBS, INCLUDES 2017-04-08 20:54:50 +10:00
90b100c23f
debug.h: Add debug helper 2017-04-08 20:26:45 +10:00
3dc6a8f55f
Add bin and obj directories. 2017-04-08 20:24:17 +10:00
be44d90dae
synth.h: Remove const keyword.
`gcc` doesn't like me assigning it there.
2017-04-08 20:23:48 +10:00