Made Audio.value unsigned

This commit is contained in:
Andrew Alderwick 2021-04-13 21:54:18 +01:00
parent 43cde08b68
commit 253c2b8906
4 changed files with 15 additions and 11 deletions

View File

@ -470,24 +470,24 @@ RTN
RTN RTN
@adsr-envelope ( -- ) @adsr-envelope ( -- )
#7f ,adsr #00 ~Audio.play #04 MUL ADD2 PEK2 SOUND #ff ,adsr #00 ~Audio.play #04 MUL ADD2 PEK2 SOUND
#40 ,adsr #00 ~Audio.play #04 MUL ADD2 #0001 ADD2 PEK2 SOUND #80 ,adsr #00 ~Audio.play #04 MUL ADD2 #0001 ADD2 PEK2 SOUND
#40 ,adsr #00 ~Audio.play #04 MUL ADD2 #0002 ADD2 PEK2 SOUND #80 ,adsr #00 ~Audio.play #04 MUL ADD2 #0002 ADD2 PEK2 SOUND
#00 ,adsr #00 ~Audio.play #04 MUL ADD2 #0003 ADD2 PEK2 SOUND #00 ,adsr #00 ~Audio.play #04 MUL ADD2 #0003 ADD2 PEK2 SOUND
SOUND_FINISH SOUND_FINISH
BRK BRK
@square-wave ( -- ) @square-wave ( -- )
#5800 SOUND
#5880 SOUND
#a800 SOUND #a800 SOUND
#a880 SOUND #a880 SOUND
#5800 SOUND
#5880 SOUND
BRK BRK
@triangle-wave ( -- ) @triangle-wave ( -- )
#7f40 SOUND #ff40 SOUND
#8180 SOUND #0080 SOUND
#0040 SOUND #8040 SOUND
BRK BRK
@ch1_txt [ CHN0 00 ] @ch1_txt [ CHN0 00 ]

View File

@ -87,9 +87,10 @@ apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volu
for(i = 0; i < 2; ++i) { for(i = 0; i < 2; ++i) {
note->volume[i] = 0xf & (volume >> 4 * (1 - i)); note->volume[i] = 0xf & (volume >> 4 * (1 - i));
note->wv[i].count = note->wv[i].period = 0; note->wv[i].count = note->wv[i].period = 0;
note->wv[i].end_value = 0; note->wv[i].end_value = 0x8000 * (1 - i);
note->wv[i].queue.n = note->wv[i].queue.i = 0; note->wv[i].queue.n = note->wv[i].queue.i = 0;
note->wv[i].queue.finishes = 0; note->wv[i].queue.finishes = 0;
note->wv[i].queue.is_envelope = i;
} }
note->wv[0].vector = wave_vector; note->wv[0].vector = wave_vector;
note->wv[0].advance = note_advances[pitch % 12] >> (8 - pitch / 12); note->wv[0].advance = note_advances[pitch % 12] >> (8 - pitch / 12);

View File

@ -17,7 +17,7 @@ typedef signed int Sint32;
typedef struct { typedef struct {
Uint16 *dat; Uint16 *dat;
Uint8 i, n, sz, finishes; Uint8 i, n, sz, finishes, is_envelope;
} Queue; } Queue;
typedef struct { typedef struct {

View File

@ -253,7 +253,10 @@ audio_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2; apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2;
apu.queue->dat = SDL_realloc(apu.queue->dat, apu.queue->sz * sizeof(*apu.queue->dat)); apu.queue->dat = SDL_realloc(apu.queue->dat, apu.queue->sz * sizeof(*apu.queue->dat));
} }
apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc]; if(apu.queue->is_envelope)
apu.queue->dat[apu.queue->n++] = (m[0xb] << 7) + (m[0xc] >> 1);
else
apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc] + 0x8000;
apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1; apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1;
} else if(b0 == 0xf && apu.queue != NULL) } else if(b0 == 0xf && apu.queue != NULL)
apu.queue->finishes = 1; apu.queue->finishes = 1;