Browse code

Audio.pitch MSB must be 1 to use current synth

Andrew Alderwick authored on 13/04/2021 20:52:54
Showing 4 changed files
... ...
@@ -120,7 +120,7 @@ BRK
120 120
 
121 121
 @play ( pitch -- )
122 122
 
123
-	=Audio.pitch
123
+	#80 ORA =Audio.pitch
124 124
 	,triangle-wave =Audio.wave
125 125
 	~track.active =Audio.play
126 126
 
... ...
@@ -190,7 +190,7 @@ BRK
190 190
 	DUP #ff NEQ ^$skip1 JNZ
191 191
 		POP ^$listen2 JMP
192 192
 	$skip1
193
-	#00 SWP ,notes ADD2 PEK2 =Audio.pitch
193
+	#00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch
194 194
 	~volume.ch1 =Audio.volume
195 195
 	,square-wave =Audio.wave
196 196
 	#00 =Audio.play
... ...
@@ -200,7 +200,7 @@ BRK
200 200
 	DUP #ff NEQ ^$skip2 JNZ
201 201
 		POP ^$listen3 JMP
202 202
 	$skip2
203
-	#00 SWP ,notes ADD2 PEK2 =Audio.pitch
203
+	#00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch
204 204
 	~volume.ch2 =Audio.volume
205 205
 	,square-wave =Audio.wave
206 206
 	#01 =Audio.play
... ...
@@ -210,7 +210,7 @@ BRK
210 210
 	DUP #ff NEQ ^$skip3 JNZ
211 211
 		POP ^$end JMP
212 212
 	$skip3
213
-	#00 SWP ,notes ADD2 PEK2 =Audio.pitch
213
+	#00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch
214 214
 	~volume.ch3 =Audio.volume
215 215
 	,triangle-wave =Audio.wave
216 216
 	#02 =Audio.play
... ...
@@ -78,10 +78,12 @@ apu_render(Apu *apu, Uxn *u, Sint16 *samples, int n_samples)
78 78
 }
79 79
 
80 80
 void
81
-apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch)
81
+apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch, Uint8 impl)
82 82
 {
83 83
 	int i;
84
+	if(pitch >= 108 || impl == 0) return;
84 85
 	note->playing = 1;
86
+	note->impl = impl;
85 87
 	for(i = 0; i < 2; ++i) {
86 88
 		note->volume[i] = 0xf & (volume >> 4 * (1 - i));
87 89
 		note->wv[i].count = note->wv[i].period = 0;
... ...
@@ -29,7 +29,8 @@ typedef struct {
29 29
 
30 30
 typedef struct {
31 31
 	WaveformGenerator wv[2];
32
-	Sint8 volume[2], playing;
32
+	Sint8 volume[2];
33
+	Uint8 playing, impl;
33 34
 } Note;
34 35
 
35 36
 typedef struct {
... ...
@@ -40,4 +41,4 @@ typedef struct {
40 41
 } Apu;
41 42
 
42 43
 void apu_render(Apu *apu, Uxn *u, Sint16 *samples, int n_samples);
43
-void apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch);
44
+void apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch, Uint8 impl);
... ...
@@ -247,7 +247,7 @@ audio_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
247 247
 	if(b0 == 0xa) {
248 248
 		if(b1 >= apu.n_notes) apu.notes = SDL_realloc(apu.notes, (b1 + 1) * sizeof(Note));
249 249
 		while(b1 >= apu.n_notes) SDL_zero(apu.notes[apu.n_notes++]);
250
-		apu_play_note(&apu.notes[b1], (m[0x0] << 8) + m[0x1], (m[0x2] << 8) + m[0x3], m[0x8], m[0x9]);
250
+		apu_play_note(&apu.notes[b1], (m[0x0] << 8) + m[0x1], (m[0x2] << 8) + m[0x3], m[0x8], m[0x9] & 0x7f, m[0x9] > 0x7f);
251 251
 	} else if(b0 == 0xe && apu.queue != NULL) {
252 252
 		if(apu.queue->n == apu.queue->sz) {
253 253
 			apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2;