unfuck BSWAP16 macro, replace it with BE_TO_HOST16() in audio

This commit is contained in:
fgsfds 2020-05-22 01:35:26 +03:00
parent aaf6eab582
commit a9d16ea76a
5 changed files with 17 additions and 20 deletions

View File

@ -52,8 +52,7 @@
#define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
// Byteswap macros
#define BSWAP16(x) \
( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) )
#define BSWAP16(x) (((x) & 0xFF) << 8 | (((x) >> 8) & 0xFF))
#define BSWAP32(x) \
( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \
(((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) )

View File

@ -175,9 +175,9 @@ s8 gVibratoCurve[16] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104,
#endif
struct AdsrEnvelope gDefaultEnvelope[] = {
{ BSWAP16(4), BSWAP16(32000) }, // go from 0 to 32000 over the course of 16ms
{ BSWAP16(1000), BSWAP16(32000) }, // stay there for 4.16 seconds
{ BSWAP16(ADSR_HANG), 0 } // then continue staying there
{ BE_TO_HOST16(4), BE_TO_HOST16(32000) }, // go from 0 to 32000 over the course of 16ms
{ BE_TO_HOST16(1000), BE_TO_HOST16(32000) }, // stay there for 4.16 seconds
{ BE_TO_HOST16(ADSR_HANG), 0 } // then continue staying there
};
#ifdef VERSION_EU

View File

@ -391,7 +391,7 @@ s32 adsr_update(struct AdsrState *adsr) {
// fallthrough
case ADSR_STATE_LOOP:
adsr->delay = BSWAP16(adsr->envelope[adsr->envIndex].delay);
adsr->delay = BE_TO_HOST16(adsr->envelope[adsr->envIndex].delay);
switch (adsr->delay) {
case ADSR_DISABLE:
adsr->state = ADSR_STATE_DISABLED;
@ -400,7 +400,7 @@ s32 adsr_update(struct AdsrState *adsr) {
adsr->state = ADSR_STATE_HANG;
break;
case ADSR_GOTO:
adsr->envIndex = BSWAP16(adsr->envelope[adsr->envIndex].arg);
adsr->envIndex = BE_TO_HOST16(adsr->envelope[adsr->envIndex].arg);
break;
case ADSR_RESTART:
adsr->state = ADSR_STATE_INITIAL;
@ -411,11 +411,11 @@ s32 adsr_update(struct AdsrState *adsr) {
if (adsr->delay >= 4) {
adsr->delay = adsr->delay * gAudioBufferParameters.updatesPerFrame / 4;
}
adsr->target = (f32) BSWAP16(adsr->envelope[adsr->envIndex].arg) / 32767.0;
adsr->target = (f32) BE_TO_HOST16(adsr->envelope[adsr->envIndex].arg) / 32767.0;
adsr->target = adsr->target * adsr->target;
adsr->velocity = (adsr->target - adsr->current) / adsr->delay;
#else
adsr->target = BSWAP16(adsr->envelope[adsr->envIndex].arg);
adsr->target = BE_TO_HOST16(adsr->envelope[adsr->envIndex].arg);
adsr->velocity = ((adsr->target - adsr->current) << 0x10) / adsr->delay;
#endif
adsr->state = ADSR_STATE_FADE;

View File

@ -3,6 +3,7 @@
#include "internal.h"
#include "platform_info.h"
#include "macros.h"
#define ADSR_STATE_DISABLED 0
#define ADSR_STATE_INITIAL 1
@ -24,12 +25,9 @@
#define ADSR_RESTART -3
// Envelopes are always stored as big endian, to match sequence files which are
// byte blobs and can embed envelopes. Hence this byteswapping macro.
#if IS_BIG_ENDIAN
#define BSWAP16(x) (x)
#else
#define BSWAP16(x) (((x) & 0xff) << 8 | (((x) >> 8) & 0xff))
#endif
// byte blobs and can embed envelopes.
// BSWAP16() definition has been moved to macros.h. Use BE_TO_HOST16() for the
// same effect in the future.
void sequence_player_process_sound(struct SequencePlayer *seqPlayer);
void note_vibrato_update(struct Note *note);

View File

@ -130,11 +130,11 @@ s32 gDialogResponse = 0;
#if defined(VERSION_JP) || defined(VERSION_SH) || defined(VERSION_EU)
#ifdef VERSION_EU
#define CHCACHE_BUFLEN (8 * 8) // EU only converts 8x8 characters
#define CHCACHE_BUFLEN (8 * 8) // EU only converts 8x8
#else
#define CHCACHE_BUFLEN (8 * 16) // JP only converts 8x16 or 16x8 characters
#endif
// stores char data unpacked from ia1 to ia8 or ia1 to ia4
// stores char data unpacked from ia1 to ia8 or ia4
// so that it won't be reconverted every time a character is rendered
static struct CachedChar { u8 used; u8 data[CHCACHE_BUFLEN]; } charCache[256];
#endif // VERSION
@ -279,7 +279,7 @@ void render_generic_char(u8 c) {
}
#ifdef VERSION_EU
static inline void alloc_ia4_tex_from_i1(u8 *out, u8 *in, s16 width, s16 height) {
static void alloc_ia4_tex_from_i1(u8 *out, u8 *in, s16 width, s16 height) {
u32 size = (u32) width * (u32) height;
s32 inPos;
s16 outPos = 0;
@ -297,7 +297,7 @@ static inline void alloc_ia4_tex_from_i1(u8 *out, u8 *in, s16 width, s16 height)
}
}
static inline u8 *convert_ia4_char(u8 c, u8 *tex, s16 w, s16 h) {
static u8 *convert_ia4_char(u8 c, u8 *tex, s16 w, s16 h) {
if (!charCache[c].used) {
charCache[c].used = 1;
alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h);