Skip to content

Commit

Permalink
#368 GBA remove experimental 9-bit audio support, move sound.h to pla…
Browse files Browse the repository at this point in the history
…tform dependent sound.cpp
  • Loading branch information
XProger committed Nov 1, 2021
1 parent 3b368ac commit f961161
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 345 deletions.
59 changes: 38 additions & 21 deletions src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define MODE4
#define USE_DIV_TABLE
#define ROM_READ
//#define USE_9BIT_SOUND

#include <tonc.h>
#elif defined(__TNS__)
Expand All @@ -41,8 +40,13 @@
#define USE_DIV_TABLE // TODO_3DO remove
#define CPU_BIG_ENDIAN

#define MAX_RAM (800 * 1024)
#define MAX_VRAM (640 * 1024)
#define MAX_RAM_LVL (800 * 1024)
#define MAX_RAM_TEX (640 * 1024)
#define MAX_RAM_CEL (MAX_FACES * sizeof(CCB))

extern void* RAM_LVL;
extern void* RAM_TEX;
extern void* RAM_CEL;

#include <displayutils.h>
#include <debug.h>
Expand Down Expand Up @@ -126,6 +130,8 @@
#define NAV_STEPS 1
// the maximum of active enemies
#define MAX_ENEMIES 3
// set the maximum number of simultaneously played channels
#define SND_CHANNELS 4
#endif

#ifndef NAV_STEPS
Expand Down Expand Up @@ -222,7 +228,7 @@ X_INLINE int32 abs(int32 x) {
extern int32 osGetSystemTimeMS();
extern void osJoyVibrate(int32 index, int32 L, int32 R);
extern void osSetPalette(const uint16* palette);
extern void osLoadLevel(const char* name);
extern void* osLoadLevel(const char* name);

#ifdef PROFILING
#define PROFILE_FRAME\
Expand Down Expand Up @@ -343,7 +349,11 @@ extern int32 fps;
#define FIXED_SHIFT 14

#define SND_MAX_DIST (8 * 1024)
#define SND_CHANNELS 6

#ifndef SND_CHANNELS
#define SND_CHANNELS 6
#endif

#define SND_FIXED_SHIFT 8
#define SND_VOL_SHIFT 6
#define SND_PITCH_SHIFT 7
Expand All @@ -362,14 +372,8 @@ extern int32 fps;
#define SND_SAMPLE_FREQ 22050
#define SND_ENCODE(x) (x)
#define SND_DECODE(x) ((x) - 128)

#ifdef USE_9BIT_SOUND
#define SND_MIN -255
#define SND_MAX 254
#else
#define SND_MIN -128
#define SND_MAX 127
#endif
#define SND_MIN -128
#define SND_MAX 127
#elif defined(__DOS__)
#define SND_SAMPLES 1024
#define SND_OUTPUT_FREQ 11025
Expand Down Expand Up @@ -580,10 +584,12 @@ struct Matrix
};

struct Quad {
#ifdef __3DO__
Index indices[4];
uint32 flags;
#else
Index indices[4];
uint16 flags;
#ifdef __3DO__
uint16 _unused;
#endif
};

Expand Down Expand Up @@ -1689,6 +1695,12 @@ enum EffectType
FX_TR1_FLICKER = 16
};

enum SoundMode {
UNIQUE,
REPLAY,
LOOP
};

enum SoundID
{
SND_NO = 2,
Expand Down Expand Up @@ -1866,6 +1878,8 @@ struct Level
uint16 itemsCount;
uint16 camerasCount;
uint16 cameraFramesCount;
uint16 soundOffsetsCount;
uint16 _reserved;

const uint16* palette;
const uint8* lightmap;
Expand Down Expand Up @@ -1991,10 +2005,6 @@ extern ItemObj items[MAX_ITEMS];
extern bool enableClipping;
extern bool enableMaxSort;

#ifdef __3DO__
extern uint8* VRAM_TEX;
#endif

template <class T>
X_INLINE void swap(T &a, T &b) {
T tmp = a;
Expand Down Expand Up @@ -2162,10 +2172,17 @@ bool useSwitch(ItemObj* item, int32 timer);
bool useKey(ItemObj* item, ItemObj* lara);
bool usePickup(ItemObj* item);

void musicPlay(int32 track);
void musicStop();
int32 doTutorial(ItemObj* lara, int32 track);

void sndInit();
void sndInitSamples();
void sndFill(uint8* buffer, int32 count);
void* sndPlaySample(int32 index, int32 volume, int32 pitch, int32 mode);
void sndPlayTrack(int32 track);
void sndStopTrack();
void sndStopSample(int32 index);
void sndStop();

X_INLINE void dmaFill(void *dst, uint8 value, uint32 count)
{
ASSERT((count & 3) == 0);
Expand Down
2 changes: 1 addition & 1 deletion src/fixed/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int32 getTextWidth(const char* text)
int32 w = 0;

char c;
while (c = *text++)
while ((c = *text++))
{
if (c == ' ') {
w += 6;
Expand Down
6 changes: 2 additions & 4 deletions src/fixed/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define H_GAME

#include "common.h"
#include "sound.h"
#include "room.h"
#include "camera.h"
#include "item.h"
Expand Down Expand Up @@ -31,9 +30,8 @@ struct Game
animTexFrame = 0;
dynSectorsCount = 0;

osLoadLevel(name);

loadLevel(levelData);
void* data = osLoadLevel(name);
loadLevel(data);
}

void loadLevel(const void* data)
Expand Down
54 changes: 3 additions & 51 deletions src/fixed/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define H_ITEM

#include "common.h"
#include "sound.h"
#include "camera.h"
#include "room.h"

Expand All @@ -28,11 +27,8 @@ int32 alignOffset(int32 a, int32 b)
return -(a + 1);
}

Mixer::Sample* soundPlay(int16 id, const vec3i &pos)
void* soundPlay(int16 id, const vec3i &pos)
{
#ifdef __3DO__
return NULL;
#endif
// TODO gym
// 0 -> 200
// 4 -> 204
Expand Down Expand Up @@ -76,13 +72,7 @@ Mixer::Sample* soundPlay(int16 id, const vec3i &pos)
index += (rand_draw() * b->flags.count) >> 15;
}

const uint8 *data = level.soundData + level.soundOffsets[index];

int32 size;
memcpy(&size, data + 40, 4); // TODO preprocess and remove wave header
data += 44;

return mixer.playSample(data, size, volume, pitch, b->flags.mode);
return sndPlaySample(index, volume, pitch, b->flags.mode);
}

void soundStop(int16 id)
Expand All @@ -96,46 +86,8 @@ void soundStop(int16 id)

for (int32 i = 0; i < b->flags.count; i++)
{
int32 index = b->index + i;

const uint8 *data = level.soundData + level.soundOffsets[index];

int32 size;
memcpy(&size, data + 40, 4); // TODO preprocess and remove wave header
data += 44;

mixer.stopSample(data);
}
}

void musicPlay(int32 track)
{
#ifdef __3DO__
return;
#endif
if (track == 13) {
gCurTrack = 0;
sndStopSample(b->index + i);
}

if (track == gCurTrack)
return;

gCurTrack = track;

struct TrackInfo {
int32 offset;
int32 size;
} *info = (TrackInfo*)((uint8*)TRACKS_IMA + track * 8);

if (!info->size)
return;

mixer.playMusic((uint8*)TRACKS_IMA + info->offset, info->size);
}

void musicStop()
{
mixer.stopMusic();
}

int32 ItemObj::getFrames(const AnimFrame* &frameA, const AnimFrame* &frameB, int32 &animFrameRate) const
Expand Down
6 changes: 4 additions & 2 deletions src/fixed/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void readLevel_GBA(const uint8* data)
for (int32 i = 0; i < level.modelsCount; i++)
{
const Model* model = level.models + i;
ASSERT(model->type < MAX_MODELS);
models[model->type] = *model;
}
level.models = models;
Expand Down Expand Up @@ -120,9 +121,10 @@ void readLevel_GBA(const uint8* data)
for (int32 i = 0; i < level.texturesCount; i++)
{
Texture* tex = level.textures + i;
tex->data += intptr_t(VRAM_TEX);
tex->plut += intptr_t(VRAM_TEX);
tex->data += intptr_t(RAM_TEX);
tex->plut += intptr_t(RAM_TEX);
}
sndInitSamples();
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions src/fixed/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,9 +1279,9 @@ void checkTrigger(const FloorData* fd, ItemObj* lara)

if (flags.mask == ITEM_FLAGS_MASK_ALL) {
flags.once |= FD_ONCE(data);
musicPlay(track);
sndPlayTrack(track);
} else {
musicStop();
sndStopTrack();
}
break;
}
Expand All @@ -1295,7 +1295,7 @@ void checkTrigger(const FloorData* fd, ItemObj* lara)
if (gSaveGame.secrets & (1 << FD_ARGS(triggerCmd)))
break;
gSaveGame.secrets |= (1 << FD_ARGS(triggerCmd));
musicPlay(13);
sndPlayTrack(13);
break;
}

Expand Down
Loading

0 comments on commit f961161

Please sign in to comment.