From d951d3c57ea9c8d7b51abaeace5f03370cd15868 Mon Sep 17 00:00:00 2001 From: Tim Stirrat Date: Fri, 23 Aug 2024 12:34:42 +0800 Subject: [PATCH] Noise channel updates - Use synth_state struct for consistency - Fix sustain --- Source/io/midi_asm.s | 11 +++++------ Source/synth/data.c | 8 ++++---- Source/synth/noi.c | 17 ++++++++--------- Source/synth/noi.h | 10 ++++------ 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Source/io/midi_asm.s b/Source/io/midi_asm.s index 0c62e30..3a8e86b 100644 --- a/Source/io/midi_asm.s +++ b/Source/io/midi_asm.s @@ -3,8 +3,7 @@ .globl _addressByte .globl _dataSet - .globl _noiEnv - .globl _noiSus + .globl _noiState .globl _parameterLock .globl _pbRange .globl _pbWheelIn @@ -912,7 +911,7 @@ _asmNoiEnv$:: RRCA AND #0x0F - ld hl,#_noiEnv + ld hl,#_noiState + 0 ; noiState.envelope ld (hl),A ld de,#_dataSet + 21 @@ -1021,14 +1020,14 @@ _asmNoiSusOn$:: ld A,#0x01 ld de,#_dataSet + 22 ld (de),A - ld hl,#_noiSus + ld hl,#_noiState + 1 ; noiState.sus ld (hl),A ret _asmNoiSusOff$:: ld A,#0x00 ld de,#_dataSet + 22 ld (de),A - ld hl,#_noiSus + ld hl,#_noiState + 1 ; noiState.sus ld (hl),A ld hl,#_noteStatus + 15 @@ -1045,7 +1044,7 @@ ret _asmNoiNf$:: ld A,#0x00 ld (#0xFF21),A - ld hl,#_noiSus + ld hl,#_noiState + 1 ; noiState.sus ld (hl),A ld de,#_dataSet + 22 ld (de),A diff --git a/Source/synth/data.c b/Source/synth/data.c index 62fbda2..58a59e2 100644 --- a/Source/synth/data.c +++ b/Source/synth/data.c @@ -116,14 +116,14 @@ void updateValueSynth(Parameter p) { setOutputPanBySynth(2, dataSet[p]); break; case NOI_Transpose: - noiOct = dataSet[p]; - noiOct = (noiOct - 2U) * 12U; + noiState.octave = dataSet[p]; + noiState.octave = (noiState.octave - 2U) * 12U; break; case NOI_Env: - noiEnv = dataSet[p]; + noiState.envelope = dataSet[p]; break; case NOI_Sustain: - noiSus = dataSet[p]; + noiState.sus = dataSet[p]; if (!dataSet[p] && !noteStatus[NOI].active) rAUD4ENV = 0U; break; diff --git a/Source/synth/noi.c b/Source/synth/noi.c index cc11f2e..830fa4b 100644 --- a/Source/synth/noi.c +++ b/Source/synth/noi.c @@ -11,12 +11,7 @@ uint8_t noiFreq[72] = { 0x6C, 0x5F, 0x5E, 0x5D, 0x5C, 0x4F, 0x4E, 0x4D, 0x4C, 0x3F, 0x3E, 0x3D, 0x3C, 0x2F, 0x2E, 0x2D, 0x2C, 0x1F, 0x1E, 0x1D, 0x1C, 0x0F, 0x0E, 0x08}; -uint8_t noiEnv; -uint8_t noiMode; -bool noiSus; - -bool noiNoteOffTrigger; -int8_t noiOct; +synth_state noiState; void updateNoi(void) { if (pbWheelIn[NOI] != PBWHEEL_CENTER) { @@ -46,14 +41,18 @@ void updateNoi(void) { } void playNoteNoi(void) { - uint8_t noteIndex = addressByte - 24U + noiOct; + uint8_t noteIndex = addressByte - 24U + noiState.octave; + + if (noteIndex >= MAX_NOI_FREQ) { + return; + } if (valueByte == 0) { // Note off if (noteStatus[NOI].note == noteIndex) { noteStatus[NOI].active = false; - if (!noiSus) { + if (!noiState.sus) { rAUD4ENV = 0x00; } } @@ -64,7 +63,7 @@ void playNoteNoi(void) { noteStatus[NOI].note = noteIndex; // Set envelope - uint8_t envelope = ((valueByte << 1) & 0xF0) | noiEnv; + uint8_t envelope = ((valueByte << 1) & 0xF0) | noiState.envelope; rAUD4ENV = envelope; // Set frequency diff --git a/Source/synth/noi.h b/Source/synth/noi.h index ce5149e..95e0a88 100644 --- a/Source/synth/noi.h +++ b/Source/synth/noi.h @@ -1,15 +1,13 @@ #pragma once +#include "common.h" #include #include -extern uint8_t noiFreq[72]; -extern uint8_t noiEnv; -extern uint8_t noiMode; -extern bool noiSus; +#define MAX_NOI_FREQ 72 -extern bool noiNoteOffTrigger; -extern int8_t noiOct; +extern uint8_t noiFreq[72]; +extern synth_state noiState; void updateNoi(void); void setPitchBendFrequencyOffsetNoise(void);