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)) #define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr))
// Byteswap macros // Byteswap macros
#define BSWAP16(x) \ #define BSWAP16(x) (((x) & 0xFF) << 8 | (((x) >> 8) & 0xFF))
( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) )
#define BSWAP32(x) \ #define BSWAP32(x) \
( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \ ( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \
(((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) ) (((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 #endif
struct AdsrEnvelope gDefaultEnvelope[] = { struct AdsrEnvelope gDefaultEnvelope[] = {
{ BSWAP16(4), BSWAP16(32000) }, // go from 0 to 32000 over the course of 16ms { BE_TO_HOST16(4), BE_TO_HOST16(32000) }, // go from 0 to 32000 over the course of 16ms
{ BSWAP16(1000), BSWAP16(32000) }, // stay there for 4.16 seconds { BE_TO_HOST16(1000), BE_TO_HOST16(32000) }, // stay there for 4.16 seconds
{ BSWAP16(ADSR_HANG), 0 } // then continue staying there { BE_TO_HOST16(ADSR_HANG), 0 } // then continue staying there
}; };
#ifdef VERSION_EU #ifdef VERSION_EU

View File

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

View File

@ -3,6 +3,7 @@
#include "internal.h" #include "internal.h"
#include "platform_info.h" #include "platform_info.h"
#include "macros.h"
#define ADSR_STATE_DISABLED 0 #define ADSR_STATE_DISABLED 0
#define ADSR_STATE_INITIAL 1 #define ADSR_STATE_INITIAL 1
@ -24,12 +25,9 @@
#define ADSR_RESTART -3 #define ADSR_RESTART -3
// Envelopes are always stored as big endian, to match sequence files which are // Envelopes are always stored as big endian, to match sequence files which are
// byte blobs and can embed envelopes. Hence this byteswapping macro. // byte blobs and can embed envelopes.
#if IS_BIG_ENDIAN // BSWAP16() definition has been moved to macros.h. Use BE_TO_HOST16() for the
#define BSWAP16(x) (x) // same effect in the future.
#else
#define BSWAP16(x) (((x) & 0xff) << 8 | (((x) >> 8) & 0xff))
#endif
void sequence_player_process_sound(struct SequencePlayer *seqPlayer); void sequence_player_process_sound(struct SequencePlayer *seqPlayer);
void note_vibrato_update(struct Note *note); 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) #if defined(VERSION_JP) || defined(VERSION_SH) || defined(VERSION_EU)
#ifdef 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 #else
#define CHCACHE_BUFLEN (8 * 16) // JP only converts 8x16 or 16x8 characters #define CHCACHE_BUFLEN (8 * 16) // JP only converts 8x16 or 16x8 characters
#endif #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 // so that it won't be reconverted every time a character is rendered
static struct CachedChar { u8 used; u8 data[CHCACHE_BUFLEN]; } charCache[256]; static struct CachedChar { u8 used; u8 data[CHCACHE_BUFLEN]; } charCache[256];
#endif // VERSION #endif // VERSION
@ -279,7 +279,7 @@ void render_generic_char(u8 c) {
} }
#ifdef VERSION_EU #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; u32 size = (u32) width * (u32) height;
s32 inPos; s32 inPos;
s16 outPos = 0; 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) { if (!charCache[c].used) {
charCache[c].used = 1; charCache[c].used = 1;
alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h); alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h);