Skip to content

Commit

Permalink
Noise channel updates
Browse files Browse the repository at this point in the history
- Use synth_state struct for consistency
- Fix sustain
  • Loading branch information
tstirrat committed Aug 23, 2024
1 parent 4eeddba commit d951d3c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
11 changes: 5 additions & 6 deletions Source/io/midi_asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

.globl _addressByte
.globl _dataSet
.globl _noiEnv
.globl _noiSus
.globl _noiState
.globl _parameterLock
.globl _pbRange
.globl _pbWheelIn
Expand Down Expand Up @@ -912,7 +911,7 @@ _asmNoiEnv$::
RRCA
AND #0x0F

ld hl,#_noiEnv
ld hl,#_noiState + 0 ; noiState.envelope
ld (hl),A

ld de,#_dataSet + 21
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Source/synth/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions Source/synth/noi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions Source/synth/noi.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#pragma once

#include "common.h"
#include <gbdk/platform.h>
#include <stdbool.h>

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);

0 comments on commit d951d3c

Please sign in to comment.