mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
More lowercase struct field names
This commit is contained in:
parent
b0794ef826
commit
0ed3197b09
@ -761,17 +761,17 @@ static ReturnCode Music_PlayOgg(struct Stream* source) {
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
Ogg_MakeStream(&stream, buffer, source);
|
Ogg_MakeStream(&stream, buffer, source);
|
||||||
vorbis.Source = &stream;
|
vorbis.source = &stream;
|
||||||
if ((res = Vorbis_DecodeHeaders(&vorbis))) goto cleanup;
|
if ((res = Vorbis_DecodeHeaders(&vorbis))) goto cleanup;
|
||||||
|
|
||||||
fmt.Channels = vorbis.Channels;
|
fmt.Channels = vorbis.channels;
|
||||||
fmt.SampleRate = vorbis.SampleRate;
|
fmt.SampleRate = vorbis.sampleRate;
|
||||||
fmt.BitsPerSample = 16;
|
fmt.BitsPerSample = 16;
|
||||||
if ((res = Audio_SetFormat(music_out, &fmt))) goto cleanup;
|
if ((res = Audio_SetFormat(music_out, &fmt))) goto cleanup;
|
||||||
|
|
||||||
/* largest possible vorbis frame decodes to blocksize1 * channels samples */
|
/* largest possible vorbis frame decodes to blocksize1 * channels samples */
|
||||||
/* so we may end up decoding slightly over a second of audio */
|
/* so we may end up decoding slightly over a second of audio */
|
||||||
chunkSize = fmt.Channels * (fmt.SampleRate + vorbis.BlockSizes[1]);
|
chunkSize = fmt.Channels * (fmt.SampleRate + vorbis.blockSizes[1]);
|
||||||
samplesPerSecond = fmt.Channels * fmt.SampleRate;
|
samplesPerSecond = fmt.Channels * fmt.SampleRate;
|
||||||
data = (int16_t*)Mem_Alloc(chunkSize * AUDIO_MAX_BUFFERS, 2, "Ogg final output");
|
data = (int16_t*)Mem_Alloc(chunkSize * AUDIO_MAX_BUFFERS, 2, "Ogg final output");
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ void AxisLinesRenderer_Render(double delta) {
|
|||||||
|
|
||||||
Gfx_SetTexturing(false);
|
Gfx_SetTexturing(false);
|
||||||
pos = LocalPlayer_Instance.Base.Position; pos.Y += 0.05f;
|
pos = LocalPlayer_Instance.Base.Position; pos.Y += 0.05f;
|
||||||
count = Camera.Active->IsThirdPerson ? 12 : 8;
|
count = Camera.Active->isThirdPerson ? 12 : 8;
|
||||||
|
|
||||||
Vector3_Add1(&coords[0], &pos, -AXISLINES_LENGTH);
|
Vector3_Add1(&coords[0], &pos, -AXISLINES_LENGTH);
|
||||||
Vector3_Add1(&coords[1], &pos, -AXISLINES_THICKNESS);
|
Vector3_Add1(&coords[1], &pos, -AXISLINES_THICKNESS);
|
||||||
|
@ -80,7 +80,7 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) {
|
|||||||
float headY, headX;
|
float headY, headX;
|
||||||
Vector2 rot = PerspectiveCamera_GetMouseDelta(delta);
|
Vector2 rot = PerspectiveCamera_GetMouseDelta(delta);
|
||||||
|
|
||||||
if (Key_IsAltPressed() && Camera.Active->IsThirdPerson) {
|
if (Key_IsAltPressed() && Camera.Active->isThirdPerson) {
|
||||||
cam_rotOffset.X += rot.X; cam_rotOffset.Y += rot.Y;
|
cam_rotOffset.X += rot.X; cam_rotOffset.Y += rot.Y;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ void Camera_Init(void) {
|
|||||||
void Camera_CycleActive(void) {
|
void Camera_CycleActive(void) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
struct LocalPlayer* p = &LocalPlayer_Instance;
|
||||||
if (Game_ClassicMode) return;
|
if (Game_ClassicMode) return;
|
||||||
Camera.Active = Camera.Active->Next;
|
Camera.Active = Camera.Active->next;
|
||||||
|
|
||||||
if (!p->Hacks.CanUseThirdPersonCamera || !p->Hacks.Enabled) {
|
if (!p->Hacks.CanUseThirdPersonCamera || !p->Hacks.Enabled) {
|
||||||
Camera.Active = &cam_FirstPerson;
|
Camera.Active = &cam_FirstPerson;
|
||||||
@ -268,7 +268,7 @@ static struct Camera* cams_tail;
|
|||||||
void Camera_Register(struct Camera* cam) {
|
void Camera_Register(struct Camera* cam) {
|
||||||
LinkedList_Add(cam, cams_head, cams_tail);
|
LinkedList_Add(cam, cams_head, cams_tail);
|
||||||
/* want a circular linked list */
|
/* want a circular linked list */
|
||||||
cam->Next = cams_head;
|
cam->next = cams_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cam_focussed;
|
static bool cam_focussed;
|
||||||
|
@ -32,7 +32,7 @@ extern struct _CameraData {
|
|||||||
|
|
||||||
struct Camera {
|
struct Camera {
|
||||||
/* Whether this camera is third person. (i.e. not allowed when -thirdperson in MOTD) */
|
/* Whether this camera is third person. (i.e. not allowed when -thirdperson in MOTD) */
|
||||||
bool IsThirdPerson;
|
bool isThirdPerson;
|
||||||
|
|
||||||
/* Calculates the current projection matrix of this camera. */
|
/* Calculates the current projection matrix of this camera. */
|
||||||
void (*GetProjection)(struct Matrix* proj);
|
void (*GetProjection)(struct Matrix* proj);
|
||||||
@ -60,7 +60,7 @@ struct Camera {
|
|||||||
bool (*Zoom)(float amount);
|
bool (*Zoom)(float amount);
|
||||||
|
|
||||||
/* Next camera in linked list of cameras. */
|
/* Next camera in linked list of cameras. */
|
||||||
struct Camera* Next;
|
struct Camera* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialises the default cameras. */
|
/* Initialises the default cameras. */
|
||||||
|
@ -239,7 +239,7 @@ static struct ChatCommand* Commands_GetMatch(const String* cmdName) {
|
|||||||
String name;
|
String name;
|
||||||
struct ChatCommand* match = NULL;
|
struct ChatCommand* match = NULL;
|
||||||
|
|
||||||
for (cmd = cmds_head; cmd; cmd = cmd->Next) {
|
for (cmd = cmds_head; cmd; cmd = cmd->next) {
|
||||||
name = String_FromReadonly(cmd->Name);
|
name = String_FromReadonly(cmd->Name);
|
||||||
if (!String_CaselessStarts(&name, cmdName)) continue;
|
if (!String_CaselessStarts(&name, cmdName)) continue;
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ static void Commands_PrintDefault(void) {
|
|||||||
Chat_AddRaw("&eList of client commands:");
|
Chat_AddRaw("&eList of client commands:");
|
||||||
String_InitArray(str, strBuffer);
|
String_InitArray(str, strBuffer);
|
||||||
|
|
||||||
for (cmd = cmds_head; cmd; cmd = cmd->Next) {
|
for (cmd = cmds_head; cmd; cmd = cmd->next) {
|
||||||
name = String_FromReadonly(cmd->Name);
|
name = String_FromReadonly(cmd->Name);
|
||||||
|
|
||||||
if ((str.length + name.length + 2) > str.capacity) {
|
if ((str.length + name.length + 2) > str.capacity) {
|
||||||
|
@ -40,7 +40,7 @@ struct ChatCommand {
|
|||||||
void (*Execute)(const String* args, int argsCount);
|
void (*Execute)(const String* args, int argsCount);
|
||||||
bool SingleplayerOnly; /* Whether this command is only usable in singleplayer */
|
bool SingleplayerOnly; /* Whether this command is only usable in singleplayer */
|
||||||
const char* Help[5]; /* Messages to show when a player uses /help on this command */
|
const char* Help[5]; /* Messages to show when a player uses /help on this command */
|
||||||
struct ChatCommand* Next; /* Next command in linked-list of client commands */
|
struct ChatCommand* next; /* Next command in linked-list of client commands */
|
||||||
};
|
};
|
||||||
/* Registers a client-side command, allowing it to be used with /client [cmd name] */
|
/* Registers a client-side command, allowing it to be used with /client [cmd name] */
|
||||||
CC_API void Commands_Register(struct ChatCommand* cmd);
|
CC_API void Commands_Register(struct ChatCommand* cmd);
|
||||||
|
@ -873,12 +873,12 @@ static void LocalPlayer_RenderModel(struct Entity* e, double deltaTime, float t)
|
|||||||
AnimatedComp_GetCurrent(e, t);
|
AnimatedComp_GetCurrent(e, t);
|
||||||
TiltComp_GetCurrent(&p->Tilt, t);
|
TiltComp_GetCurrent(&p->Tilt, t);
|
||||||
|
|
||||||
if (!Camera.Active->IsThirdPerson) return;
|
if (!Camera.Active->isThirdPerson) return;
|
||||||
Model_Render(e->Model, e);
|
Model_Render(e->Model, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LocalPlayer_RenderName(struct Entity* e) {
|
static void LocalPlayer_RenderName(struct Entity* e) {
|
||||||
if (!Camera.Active->IsThirdPerson) return;
|
if (!Camera.Active->isThirdPerson) return;
|
||||||
Player_DrawName((struct Player*)e);
|
Player_DrawName((struct Player*)e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,7 +1300,7 @@ static bool SoundComp_ShouldPlay(struct LocalPlayer* p, Vector3 soundPos) {
|
|||||||
if (p->Base.Anim.Swing < 0.999f) return distSq > 1.75f * 1.75f;
|
if (p->Base.Anim.Swing < 0.999f) return distSq > 1.75f * 1.75f;
|
||||||
|
|
||||||
/* have our legs just crossed over the '0' point? */
|
/* have our legs just crossed over the '0' point? */
|
||||||
if (Camera.Active->IsThirdPerson) {
|
if (Camera.Active->isThirdPerson) {
|
||||||
oldLegRot = (float)Math_Cos(p->Base.Anim.WalkTimeO);
|
oldLegRot = (float)Math_Cos(p->Base.Anim.WalkTimeO);
|
||||||
newLegRot = (float)Math_Cos(p->Base.Anim.WalkTimeN);
|
newLegRot = (float)Math_Cos(p->Base.Anim.WalkTimeN);
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,8 +34,8 @@ if (j - left <= right - i) {\
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define LinkedList_Add(item, head, tail)\
|
#define LinkedList_Add(item, head, tail)\
|
||||||
if (!head) { head = item; } else { tail->Next = item; }\
|
if (!head) { head = item; } else { tail->next = item; }\
|
||||||
tail = item;\
|
tail = item;\
|
||||||
item->Next = NULL;
|
item->next = NULL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
10
src/Game.c
10
src/Game.c
@ -196,7 +196,7 @@ void Game_Reset(void) {
|
|||||||
World_TextureUrl.length = 0;
|
World_TextureUrl.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->Reset) comp->Reset();
|
if (comp->Reset) comp->Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,14 +288,14 @@ static void Game_OnResize(void* obj) {
|
|||||||
|
|
||||||
static void Game_OnNewMapCore(void* obj) {
|
static void Game_OnNewMapCore(void* obj) {
|
||||||
struct IGameComponent* comp;
|
struct IGameComponent* comp;
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->OnNewMap) comp->OnNewMap();
|
if (comp->OnNewMap) comp->OnNewMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Game_OnNewMapLoadedCore(void* obj) {
|
static void Game_OnNewMapLoadedCore(void* obj) {
|
||||||
struct IGameComponent* comp;
|
struct IGameComponent* comp;
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->OnNewMapLoaded) comp->OnNewMapLoaded();
|
if (comp->OnNewMapLoaded) comp->OnNewMapLoaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,7 +498,7 @@ static void Game_Load(void) {
|
|||||||
Game_AddComponent(&AxisLinesRenderer_Component);
|
Game_AddComponent(&AxisLinesRenderer_Component);
|
||||||
|
|
||||||
Game_LoadPlugins();
|
Game_LoadPlugins();
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->Init) comp->Init();
|
if (comp->Init) comp->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ void Game_Free(void* obj) {
|
|||||||
Event_UnregisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
|
Event_UnregisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
|
||||||
Event_UnregisterVoid(&WindowEvents.Closing, NULL, Game_Free);
|
Event_UnregisterVoid(&WindowEvents.Closing, NULL, Game_Free);
|
||||||
|
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->Free) comp->Free();
|
if (comp->Free) comp->Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ struct IGameComponent {
|
|||||||
/* Called to update the component's state when the user has finished loading a new map. */
|
/* Called to update the component's state when the user has finished loading a new map. */
|
||||||
void (*OnNewMapLoaded)(void);
|
void (*OnNewMapLoaded)(void);
|
||||||
/* Next component in linked list of components. */
|
/* Next component in linked list of components. */
|
||||||
struct IGameComponent* Next;
|
struct IGameComponent* next;
|
||||||
};
|
};
|
||||||
/* Adds a component to linked list of components. (always at end) */
|
/* Adds a component to linked list of components. (always at end) */
|
||||||
CC_NOINLINE void Game_AddComponent(struct IGameComponent* comp);
|
CC_NOINLINE void Game_AddComponent(struct IGameComponent* comp);
|
||||||
|
@ -223,7 +223,7 @@ void HeldBlockRenderer_Render(double delta) {
|
|||||||
HeldBlockRenderer_ResetHeldState();
|
HeldBlockRenderer_ResetHeldState();
|
||||||
HeldBlockRenderer_DoAnimation(delta, lastSwingY);
|
HeldBlockRenderer_DoAnimation(delta, lastSwingY);
|
||||||
HeldBlockRenderer_SetBaseOffset();
|
HeldBlockRenderer_SetBaseOffset();
|
||||||
if (!Camera.Active->IsThirdPerson) HeldBlockRenderer_RenderModel();
|
if (!Camera.Active->isThirdPerson) HeldBlockRenderer_RenderModel();
|
||||||
|
|
||||||
Gfx.View = view;
|
Gfx.View = view;
|
||||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
|
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
|
||||||
|
@ -392,7 +392,7 @@ static void Model_Make(struct Model* model) {
|
|||||||
struct Model* Model_Get(const String* name) {
|
struct Model* Model_Get(const String* name) {
|
||||||
struct Model* model;
|
struct Model* model;
|
||||||
|
|
||||||
for (model = models_head; model; model = model->Next) {
|
for (model = models_head; model; model = model->next) {
|
||||||
if (!String_CaselessEqualsConst(name, model->Name)) continue;
|
if (!String_CaselessEqualsConst(name, model->Name)) continue;
|
||||||
|
|
||||||
if (!model->initalised) Model_Make(model);
|
if (!model->initalised) Model_Make(model);
|
||||||
@ -404,7 +404,7 @@ struct Model* Model_Get(const String* name) {
|
|||||||
struct ModelTex* Model_GetTexture(const String* name) {
|
struct ModelTex* Model_GetTexture(const String* name) {
|
||||||
struct ModelTex* tex;
|
struct ModelTex* tex;
|
||||||
|
|
||||||
for (tex = textures_head; tex; tex = tex->Next) {
|
for (tex = textures_head; tex; tex = tex->next) {
|
||||||
if (String_CaselessEqualsConst(name, tex->Name)) return tex;
|
if (String_CaselessEqualsConst(name, tex->Name)) return tex;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -421,7 +421,7 @@ void Model_RegisterTexture(struct ModelTex* tex) {
|
|||||||
static void Models_TextureChanged(void* obj, struct Stream* stream, const String* name) {
|
static void Models_TextureChanged(void* obj, struct Stream* stream, const String* name) {
|
||||||
struct ModelTex* tex;
|
struct ModelTex* tex;
|
||||||
|
|
||||||
for (tex = textures_head; tex; tex = tex->Next) {
|
for (tex = textures_head; tex; tex = tex->next) {
|
||||||
if (!String_CaselessEqualsConst(name, tex->Name)) continue;
|
if (!String_CaselessEqualsConst(name, tex->Name)) continue;
|
||||||
|
|
||||||
Game_UpdateTexture(&tex->TexID, stream, name, &tex->SkinType);
|
Game_UpdateTexture(&tex->TexID, stream, name, &tex->SkinType);
|
||||||
@ -1703,7 +1703,7 @@ static void Models_Init(void) {
|
|||||||
static void Models_Free(void) {
|
static void Models_Free(void) {
|
||||||
struct ModelTex* tex;
|
struct ModelTex* tex;
|
||||||
|
|
||||||
for (tex = textures_head; tex; tex = tex->Next) {
|
for (tex = textures_head; tex; tex = tex->next) {
|
||||||
Gfx_DeleteTexture(&tex->TexID);
|
Gfx_DeleteTexture(&tex->TexID);
|
||||||
}
|
}
|
||||||
Models_ContextLost(NULL);
|
Models_ContextLost(NULL);
|
||||||
|
@ -34,7 +34,7 @@ static CC_INLINE void ModelPart_Init(struct ModelPart* part, int offset, int cou
|
|||||||
|
|
||||||
struct ModelTex;
|
struct ModelTex;
|
||||||
/* Contains information about a texture used for models. */
|
/* Contains information about a texture used for models. */
|
||||||
struct ModelTex { const char* Name; uint8_t SkinType; GfxResourceID TexID; struct ModelTex* Next; };
|
struct ModelTex { const char* Name; uint8_t SkinType; GfxResourceID TexID; struct ModelTex* next; };
|
||||||
|
|
||||||
struct Model;
|
struct Model;
|
||||||
/* Contains a set of quads and/or boxes that describe a 3D object as well as
|
/* Contains a set of quads and/or boxes that describe a 3D object as well as
|
||||||
@ -80,7 +80,7 @@ struct Model {
|
|||||||
void (*DrawArm)(struct Entity* entity);
|
void (*DrawArm)(struct Entity* entity);
|
||||||
|
|
||||||
float MaxScale, ShadowScale, NameScale;
|
float MaxScale, ShadowScale, NameScale;
|
||||||
struct Model* Next;
|
struct Model* next;
|
||||||
};
|
};
|
||||||
#if 0
|
#if 0
|
||||||
public CustomModel[] CustomModels = new CustomModel[256];
|
public CustomModel[] CustomModels = new CustomModel[256];
|
||||||
|
@ -49,9 +49,9 @@ void Particle_DoRender(Vector2* size, Vector3* pos, TextureRec* rec, PackedCol c
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Particle_Reset(struct Particle* p, Vector3 pos, Vector3 velocity, float lifetime) {
|
static void Particle_Reset(struct Particle* p, Vector3 pos, Vector3 velocity, float lifetime) {
|
||||||
p->LastPos = pos; p->NextPos = pos;
|
p->lastPos = pos; p->nextPos = pos;
|
||||||
p->Velocity = velocity;
|
p->velocity = velocity;
|
||||||
p->Lifetime = lifetime;
|
p->lifetime = lifetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Particle_CanPass(BlockID block, bool throughLiquids) {
|
static bool Particle_CanPass(BlockID block, bool throughLiquids) {
|
||||||
@ -82,24 +82,24 @@ static bool Particle_TestY(struct Particle* p, int y, bool topFace, bool through
|
|||||||
bool collideVer;
|
bool collideVer;
|
||||||
|
|
||||||
if (y < 0) {
|
if (y < 0) {
|
||||||
p->NextPos.Y = ENTITY_ADJUSTMENT; p->LastPos.Y = ENTITY_ADJUSTMENT;
|
p->nextPos.Y = ENTITY_ADJUSTMENT; p->lastPos.Y = ENTITY_ADJUSTMENT;
|
||||||
p->Velocity = Vector3_Zero();
|
p->velocity = Vector3_Zero();
|
||||||
particle_hitTerrain = true;
|
particle_hitTerrain = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
block = Particle_GetBlock((int)p->NextPos.X, y, (int)p->NextPos.Z);
|
block = Particle_GetBlock((int)p->nextPos.X, y, (int)p->nextPos.Z);
|
||||||
if (Particle_CanPass(block, throughLiquids)) return true;
|
if (Particle_CanPass(block, throughLiquids)) return true;
|
||||||
minBB = Blocks.MinBB[block]; maxBB = Blocks.MaxBB[block];
|
minBB = Blocks.MinBB[block]; maxBB = Blocks.MaxBB[block];
|
||||||
|
|
||||||
collideY = y + (topFace ? maxBB.Y : minBB.Y);
|
collideY = y + (topFace ? maxBB.Y : minBB.Y);
|
||||||
collideVer = topFace ? (p->NextPos.Y < collideY) : (p->NextPos.Y > collideY);
|
collideVer = topFace ? (p->nextPos.Y < collideY) : (p->nextPos.Y > collideY);
|
||||||
|
|
||||||
if (collideVer && Particle_CollideHor(&p->NextPos, block)) {
|
if (collideVer && Particle_CollideHor(&p->nextPos, block)) {
|
||||||
float adjust = topFace ? ENTITY_ADJUSTMENT : -ENTITY_ADJUSTMENT;
|
float adjust = topFace ? ENTITY_ADJUSTMENT : -ENTITY_ADJUSTMENT;
|
||||||
p->LastPos.Y = collideY + adjust;
|
p->lastPos.Y = collideY + adjust;
|
||||||
p->NextPos.Y = p->LastPos.Y;
|
p->nextPos.Y = p->lastPos.Y;
|
||||||
p->Velocity = Vector3_Zero();
|
p->velocity = Vector3_Zero();
|
||||||
particle_hitTerrain = true;
|
particle_hitTerrain = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -112,39 +112,39 @@ static bool Particle_PhysicsTick(struct Particle* p, float gravity, bool through
|
|||||||
Vector3 velocity;
|
Vector3 velocity;
|
||||||
int y, begY, endY;
|
int y, begY, endY;
|
||||||
|
|
||||||
p->LastPos = p->NextPos;
|
p->lastPos = p->nextPos;
|
||||||
cur = Particle_GetBlock((int)p->NextPos.X, (int)p->NextPos.Y, (int)p->NextPos.Z);
|
cur = Particle_GetBlock((int)p->nextPos.X, (int)p->nextPos.Y, (int)p->nextPos.Z);
|
||||||
minY = Math_Floor(p->NextPos.Y) + Blocks.MinBB[cur].Y;
|
minY = Math_Floor(p->nextPos.Y) + Blocks.MinBB[cur].Y;
|
||||||
maxY = Math_Floor(p->NextPos.Y) + Blocks.MaxBB[cur].Y;
|
maxY = Math_Floor(p->nextPos.Y) + Blocks.MaxBB[cur].Y;
|
||||||
|
|
||||||
if (!Particle_CanPass(cur, throughLiquids) && p->NextPos.Y >= minY
|
if (!Particle_CanPass(cur, throughLiquids) && p->nextPos.Y >= minY
|
||||||
&& p->NextPos.Y < maxY && Particle_CollideHor(&p->NextPos, cur)) {
|
&& p->nextPos.Y < maxY && Particle_CollideHor(&p->nextPos, cur)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->Velocity.Y -= gravity * (float)delta;
|
p->velocity.Y -= gravity * (float)delta;
|
||||||
begY = Math_Floor(p->NextPos.Y);
|
begY = Math_Floor(p->nextPos.Y);
|
||||||
|
|
||||||
Vector3_Mul1(&velocity, &p->Velocity, (float)delta * 3.0f);
|
Vector3_Mul1(&velocity, &p->velocity, (float)delta * 3.0f);
|
||||||
Vector3_Add(&p->NextPos, &p->NextPos, &velocity);
|
Vector3_Add(&p->nextPos, &p->nextPos, &velocity);
|
||||||
endY = Math_Floor(p->NextPos.Y);
|
endY = Math_Floor(p->nextPos.Y);
|
||||||
|
|
||||||
if (p->Velocity.Y > 0.0f) {
|
if (p->velocity.Y > 0.0f) {
|
||||||
/* don't test block we are already in */
|
/* don't test block we are already in */
|
||||||
for (y = begY + 1; y <= endY && Particle_TestY(p, y, false, throughLiquids); y++) {}
|
for (y = begY + 1; y <= endY && Particle_TestY(p, y, false, throughLiquids); y++) {}
|
||||||
} else {
|
} else {
|
||||||
for (y = begY; y >= endY && Particle_TestY(p, y, true, throughLiquids); y--) {}
|
for (y = begY; y >= endY && Particle_TestY(p, y, true, throughLiquids); y--) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
p->Lifetime -= (float)delta;
|
p->lifetime -= (float)delta;
|
||||||
return p->Lifetime < 0.0f;
|
return p->lifetime < 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------Rain particle-----------------------------------------------------*
|
*-------------------------------------------------------Rain particle-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct RainParticle { struct Particle Base; };
|
struct RainParticle { struct Particle base; };
|
||||||
|
|
||||||
static struct RainParticle rain_Particles[PARTICLES_MAX];
|
static struct RainParticle rain_Particles[PARTICLES_MAX];
|
||||||
static int rain_count;
|
static int rain_count;
|
||||||
@ -152,7 +152,7 @@ static TextureRec rain_rec = { 2.0f/128.0f, 14.0f/128.0f, 5.0f/128.0f, 16.0f/128
|
|||||||
|
|
||||||
static bool RainParticle_Tick(struct RainParticle* p, double delta) {
|
static bool RainParticle_Tick(struct RainParticle* p, double delta) {
|
||||||
particle_hitTerrain = false;
|
particle_hitTerrain = false;
|
||||||
return Particle_PhysicsTick(&p->Base, 3.5f, false, delta) || particle_hitTerrain;
|
return Particle_PhysicsTick(&p->base, 3.5f, false, delta) || particle_hitTerrain;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RainParticle_Render(struct RainParticle* p, float t, VertexP3fT2fC4b* vertices) {
|
static void RainParticle_Render(struct RainParticle* p, float t, VertexP3fT2fC4b* vertices) {
|
||||||
@ -161,8 +161,8 @@ static void RainParticle_Render(struct RainParticle* p, float t, VertexP3fT2fC4b
|
|||||||
PackedCol col;
|
PackedCol col;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
Vector3_Lerp(&pos, &p->Base.LastPos, &p->Base.NextPos, t);
|
Vector3_Lerp(&pos, &p->base.lastPos, &p->base.nextPos, t);
|
||||||
size.X = (float)p->Base.Size * 0.015625f; size.Y = size.X;
|
size.X = (float)p->base.size * 0.015625f; size.Y = size.X;
|
||||||
|
|
||||||
x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z);
|
x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z);
|
||||||
col = World_Contains(x, y, z) ? Lighting_Col(x, y, z) : Env.SunCol;
|
col = World_Contains(x, y, z) ? Lighting_Col(x, y, z) : Env.SunCol;
|
||||||
@ -210,10 +210,10 @@ static void Rain_Tick(double delta) {
|
|||||||
*------------------------------------------------------Terrain particle---------------------------------------------------*
|
*------------------------------------------------------Terrain particle---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct TerrainParticle {
|
struct TerrainParticle {
|
||||||
struct Particle Base;
|
struct Particle base;
|
||||||
TextureRec Rec;
|
TextureRec rec;
|
||||||
TextureLoc TexLoc;
|
TextureLoc texLoc;
|
||||||
BlockID Block;
|
BlockID block;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct TerrainParticle terrain_particles[PARTICLES_MAX];
|
static struct TerrainParticle terrain_particles[PARTICLES_MAX];
|
||||||
@ -222,7 +222,7 @@ static uint16_t terrain_1DCount[ATLAS1D_MAX_ATLASES];
|
|||||||
static uint16_t terrain_1DIndices[ATLAS1D_MAX_ATLASES];
|
static uint16_t terrain_1DIndices[ATLAS1D_MAX_ATLASES];
|
||||||
|
|
||||||
static bool TerrainParticle_Tick(struct TerrainParticle* p, double delta) {
|
static bool TerrainParticle_Tick(struct TerrainParticle* p, double delta) {
|
||||||
return Particle_PhysicsTick(&p->Base, 5.4f, true, delta);
|
return Particle_PhysicsTick(&p->base, 5.4f, true, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TerrainParticle_Render(struct TerrainParticle* p, float t, VertexP3fT2fC4b* vertices) {
|
static void TerrainParticle_Render(struct TerrainParticle* p, float t, VertexP3fT2fC4b* vertices) {
|
||||||
@ -231,21 +231,21 @@ static void TerrainParticle_Render(struct TerrainParticle* p, float t, VertexP3f
|
|||||||
Vector2 size;
|
Vector2 size;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
Vector3_Lerp(&pos, &p->Base.LastPos, &p->Base.NextPos, t);
|
Vector3_Lerp(&pos, &p->base.lastPos, &p->base.nextPos, t);
|
||||||
size.X = (float)p->Base.Size * 0.015625f; size.Y = size.X;
|
size.X = (float)p->base.size * 0.015625f; size.Y = size.X;
|
||||||
|
|
||||||
if (!Blocks.FullBright[p->Block]) {
|
if (!Blocks.FullBright[p->block]) {
|
||||||
x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z);
|
x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z);
|
||||||
col = World_Contains(x, y, z) ? Lighting_Col_XSide(x, y, z) : Env.SunXSide;
|
col = World_Contains(x, y, z) ? Lighting_Col_XSide(x, y, z) : Env.SunXSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Blocks.Tinted[p->Block]) {
|
if (Blocks.Tinted[p->block]) {
|
||||||
PackedCol tintCol = Blocks.FogCol[p->Block];
|
PackedCol tintCol = Blocks.FogCol[p->block];
|
||||||
col.R = (uint8_t)(col.R * tintCol.R / 255);
|
col.R = (uint8_t)(col.R * tintCol.R / 255);
|
||||||
col.G = (uint8_t)(col.G * tintCol.G / 255);
|
col.G = (uint8_t)(col.G * tintCol.G / 255);
|
||||||
col.B = (uint8_t)(col.B * tintCol.B / 255);
|
col.B = (uint8_t)(col.B * tintCol.B / 255);
|
||||||
}
|
}
|
||||||
Particle_DoRender(&size, &pos, &p->Rec, col, vertices);
|
Particle_DoRender(&size, &pos, &p->rec, col, vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Terrain_Update1DCounts(void) {
|
static void Terrain_Update1DCounts(void) {
|
||||||
@ -256,7 +256,7 @@ static void Terrain_Update1DCounts(void) {
|
|||||||
terrain_1DIndices[i] = 0;
|
terrain_1DIndices[i] = 0;
|
||||||
}
|
}
|
||||||
for (i = 0; i < terrain_count; i++) {
|
for (i = 0; i < terrain_count; i++) {
|
||||||
index = Atlas1D_Index(terrain_particles[i].TexLoc);
|
index = Atlas1D_Index(terrain_particles[i].texLoc);
|
||||||
terrain_1DCount[index] += 4;
|
terrain_1DCount[index] += 4;
|
||||||
}
|
}
|
||||||
for (i = 1; i < Atlas1D.Count; i++) {
|
for (i = 1; i < Atlas1D.Count; i++) {
|
||||||
@ -273,7 +273,7 @@ static void Terrain_Render(float t) {
|
|||||||
|
|
||||||
Terrain_Update1DCounts();
|
Terrain_Update1DCounts();
|
||||||
for (i = 0; i < terrain_count; i++) {
|
for (i = 0; i < terrain_count; i++) {
|
||||||
index = Atlas1D_Index(terrain_particles[i].TexLoc);
|
index = Atlas1D_Index(terrain_particles[i].texLoc);
|
||||||
ptr = &vertices[terrain_1DIndices[index]];
|
ptr = &vertices[terrain_1DIndices[index]];
|
||||||
|
|
||||||
TerrainParticle_Render(&terrain_particles[i], t, ptr);
|
TerrainParticle_Render(&terrain_particles[i], t, ptr);
|
||||||
@ -414,13 +414,13 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID old, BlockID now) {
|
|||||||
|
|
||||||
life = 0.3f + Random_Float(&rnd) * 1.2f;
|
life = 0.3f + Random_Float(&rnd) * 1.2f;
|
||||||
Vector3_Add(&pos, &origin, &cell);
|
Vector3_Add(&pos, &origin, &cell);
|
||||||
Particle_Reset(&p->Base, pos, velocity, life);
|
Particle_Reset(&p->base, pos, velocity, life);
|
||||||
|
|
||||||
p->Rec = rec;
|
p->rec = rec;
|
||||||
p->TexLoc = loc;
|
p->texLoc = loc;
|
||||||
p->Block = old;
|
p->block = old;
|
||||||
type = Random_Range(&rnd, 0, 30);
|
type = Random_Range(&rnd, 0, 30);
|
||||||
p->Base.Size = (uint8_t)(type >= 28 ? 12 : (type >= 25 ? 10 : 8));
|
p->base.size = (uint8_t)(type >= 28 ? 12 : (type >= 25 ? 10 : 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -445,10 +445,10 @@ void Particles_RainSnowEffect(Vector3 pos) {
|
|||||||
p = &rain_Particles[rain_count++];
|
p = &rain_Particles[rain_count++];
|
||||||
|
|
||||||
Vector3_Add(&pos, &origin, &offset);
|
Vector3_Add(&pos, &origin, &offset);
|
||||||
Particle_Reset(&p->Base, pos, velocity, 40.0f);
|
Particle_Reset(&p->base, pos, velocity, 40.0f);
|
||||||
|
|
||||||
type = Random_Range(&rnd, 0, 30);
|
type = Random_Range(&rnd, 0, 30);
|
||||||
p->Base.Size = (uint8_t)(type >= 28 ? 2 : (type >= 25 ? 4 : 3));
|
p->base.size = (uint8_t)(type >= 28 ? 2 : (type >= 25 ? 4 : 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ struct ScheduledTask;
|
|||||||
extern struct IGameComponent Particles_Component;
|
extern struct IGameComponent Particles_Component;
|
||||||
|
|
||||||
struct Particle {
|
struct Particle {
|
||||||
Vector3 Velocity;
|
Vector3 velocity;
|
||||||
float Lifetime;
|
float lifetime;
|
||||||
Vector3 LastPos, NextPos;
|
Vector3 lastPos, nextPos;
|
||||||
uint8_t Size;
|
uint8_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/ */
|
/* http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/ */
|
||||||
|
@ -596,11 +596,11 @@ static void SoundPatcher_FixupHeader(struct Stream* s, struct VorbisState* ctx)
|
|||||||
Stream_SetU32_BE(&header[12], WAV_FourCC('f','m','t',' '));
|
Stream_SetU32_BE(&header[12], WAV_FourCC('f','m','t',' '));
|
||||||
Stream_SetU32_LE(&header[16], 16); /* fmt chunk size */
|
Stream_SetU32_LE(&header[16], 16); /* fmt chunk size */
|
||||||
Stream_SetU16_LE(&header[20], 1); /* PCM audio format */
|
Stream_SetU16_LE(&header[20], 1); /* PCM audio format */
|
||||||
Stream_SetU16_LE(&header[22], ctx->Channels);
|
Stream_SetU16_LE(&header[22], ctx->channels);
|
||||||
Stream_SetU32_LE(&header[24], ctx->SampleRate);
|
Stream_SetU32_LE(&header[24], ctx->sampleRate);
|
||||||
|
|
||||||
Stream_SetU32_LE(&header[28], ctx->SampleRate * ctx->Channels * 2); /* byte rate */
|
Stream_SetU32_LE(&header[28], ctx->sampleRate * ctx->channels * 2); /* byte rate */
|
||||||
Stream_SetU16_LE(&header[32], ctx->Channels * 2); /* block align */
|
Stream_SetU16_LE(&header[32], ctx->channels * 2); /* block align */
|
||||||
Stream_SetU16_LE(&header[34], 16); /* bits per sample */
|
Stream_SetU16_LE(&header[34], 16); /* bits per sample */
|
||||||
Stream_SetU32_BE(&header[36], WAV_FourCC('d','a','t','a'));
|
Stream_SetU32_BE(&header[36], WAV_FourCC('d','a','t','a'));
|
||||||
Stream_SetU32_LE(&header[40], length - sizeof(header));
|
Stream_SetU32_LE(&header[40], length - sizeof(header));
|
||||||
@ -621,7 +621,7 @@ static void SoundPatcher_DecodeAudio(struct Stream* s, struct VorbisState* ctx)
|
|||||||
|
|
||||||
res = Vorbis_DecodeHeaders(ctx);
|
res = Vorbis_DecodeHeaders(ctx);
|
||||||
if (res) { Logger_Warn(res, "decoding .ogg header"); return; }
|
if (res) { Logger_Warn(res, "decoding .ogg header"); return; }
|
||||||
samples = (int16_t*)Mem_Alloc(ctx->BlockSizes[1] * ctx->Channels, 2, ".ogg samples");
|
samples = (int16_t*)Mem_Alloc(ctx->blockSizes[1] * ctx->channels, 2, ".ogg samples");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
res = Vorbis_DecodeFrame(ctx);
|
res = Vorbis_DecodeFrame(ctx);
|
||||||
@ -651,7 +651,7 @@ static void SoundPatcher_Save(struct ResourceSound* sound, struct HttpRequest* r
|
|||||||
if (res) { Logger_Warn(res, "creating .wav file"); return; }
|
if (res) { Logger_Warn(res, "creating .wav file"); return; }
|
||||||
|
|
||||||
Ogg_MakeStream(&ogg, buffer, &src);
|
Ogg_MakeStream(&ogg, buffer, &src);
|
||||||
ctx.Source = &ogg;
|
ctx.source = &ogg;
|
||||||
|
|
||||||
SoundPatcher_DecodeAudio(&dst, &ctx);
|
SoundPatcher_DecodeAudio(&dst, &ctx);
|
||||||
SoundPatcher_FixupHeader(&dst, &ctx);
|
SoundPatcher_FixupHeader(&dst, &ctx);
|
||||||
|
208
src/Vorbis.c
208
src/Vorbis.c
@ -109,7 +109,7 @@ static uint32_t Vorbis_ReadBits(struct VorbisState* ctx, uint32_t bitsCount) {
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
while (ctx->NumBits < bitsCount) {
|
while (ctx->NumBits < bitsCount) {
|
||||||
res = ctx->Source->ReadU8(ctx->Source, &portion);
|
res = ctx->source->ReadU8(ctx->source, &portion);
|
||||||
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
||||||
Vorbis_PushByte(ctx, portion);
|
Vorbis_PushByte(ctx, portion);
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ static ReturnCode Vorbis_TryReadBits(struct VorbisState* ctx, uint32_t bitsCount
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
while (ctx->NumBits < bitsCount) {
|
while (ctx->NumBits < bitsCount) {
|
||||||
res = ctx->Source->ReadU8(ctx->Source, &portion);
|
res = ctx->source->ReadU8(ctx->source, &portion);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
Vorbis_PushByte(ctx, portion);
|
Vorbis_PushByte(ctx, portion);
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ static uint32_t Vorbis_ReadBit(struct VorbisState* ctx) {
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
if (!ctx->NumBits) {
|
if (!ctx->NumBits) {
|
||||||
res = ctx->Source->ReadU8(ctx->Source, &portion);
|
res = ctx->source->ReadU8(ctx->source, &portion);
|
||||||
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
if (res) { Logger_Abort2(res, "Failed to read byte for vorbis"); }
|
||||||
Vorbis_PushByte(ctx, portion);
|
Vorbis_PushByte(ctx, portion);
|
||||||
}
|
}
|
||||||
@ -552,7 +552,7 @@ static bool Floor_DecodeFrame(struct VorbisState* ctx, struct Floor* f, int ch)
|
|||||||
cval = 0;
|
cval = 0;
|
||||||
if (cbits) {
|
if (cbits) {
|
||||||
bookNum = f->ClassMasterbooks[klass];
|
bookNum = f->ClassMasterbooks[klass];
|
||||||
cval = Codebook_DecodeScalar(ctx, &ctx->Codebooks[bookNum]);
|
cval = Codebook_DecodeScalar(ctx, &ctx->codebooks[bookNum]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < cdim; j++) {
|
for (j = 0; j < cdim; j++) {
|
||||||
@ -560,7 +560,7 @@ static bool Floor_DecodeFrame(struct VorbisState* ctx, struct Floor* f, int ch)
|
|||||||
cval >>= cbits;
|
cval >>= cbits;
|
||||||
|
|
||||||
if (bookNum >= 0) {
|
if (bookNum >= 0) {
|
||||||
yList[idx + j] = Codebook_DecodeScalar(ctx, &ctx->Codebooks[bookNum]);
|
yList[idx + j] = Codebook_DecodeScalar(ctx, &ctx->codebooks[bookNum]);
|
||||||
} else {
|
} else {
|
||||||
yList[idx + j] = 0;
|
yList[idx + j] = 0;
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ static void Floor_Synthesis(struct VorbisState* ctx, struct Floor* f, int ch) {
|
|||||||
|
|
||||||
/* amplitude value synthesis */
|
/* amplitude value synthesis */
|
||||||
yList = f->YList[ch];
|
yList = f->YList[ch];
|
||||||
data = ctx->CurOutput[ch];
|
data = ctx->curOutput[ch];
|
||||||
|
|
||||||
Step2[0] = true;
|
Step2[0] = true;
|
||||||
Step2[1] = true;
|
Step2[1] = true;
|
||||||
@ -700,15 +700,15 @@ static void Floor_Synthesis(struct VorbisState* ctx, struct Floor* f, int ch) {
|
|||||||
|
|
||||||
hx = f->XList[i]; hy = YFinal[i] * f->Multiplier;
|
hx = f->XList[i]; hy = YFinal[i] * f->Multiplier;
|
||||||
if (lx < hx) {
|
if (lx < hx) {
|
||||||
Floor_RenderLine(lx, ly, min(hx, ctx->DataSize), hy, data);
|
Floor_RenderLine(lx, ly, min(hx, ctx->dataSize), hy, data);
|
||||||
}
|
}
|
||||||
lx = hx; ly = hy;
|
lx = hx; ly = hy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill remainder of floor with a flat line */
|
/* fill remainder of floor with a flat line */
|
||||||
/* TODO: Is this right? should hy be 0, if Step2 is false for all */
|
/* TODO: Is this right? should hy be 0, if Step2 is false for all */
|
||||||
if (hx >= ctx->DataSize) return;
|
if (hx >= ctx->dataSize) return;
|
||||||
lx = hx; hx = ctx->DataSize;
|
lx = hx; hx = ctx->dataSize;
|
||||||
|
|
||||||
value = floor1_inverse_dB_table[hy];
|
value = floor1_inverse_dB_table[hy];
|
||||||
for (; lx < hx; lx++) { data[lx] *= value; }
|
for (; lx < hx; lx++) { data[lx] *= value; }
|
||||||
@ -778,14 +778,14 @@ static void Residue_DecodeCore(struct VorbisState* ctx, struct Residue* r, uint3
|
|||||||
/* per spec, ensure decoded bounds are actually in size */
|
/* per spec, ensure decoded bounds are actually in size */
|
||||||
residueBeg = min(r->Begin, size);
|
residueBeg = min(r->Begin, size);
|
||||||
residueEnd = min(r->End, size);
|
residueEnd = min(r->End, size);
|
||||||
classbook = &ctx->Codebooks[r->Classbook];
|
classbook = &ctx->codebooks[r->Classbook];
|
||||||
|
|
||||||
classwordsPerCodeword = classbook->Dimensions;
|
classwordsPerCodeword = classbook->Dimensions;
|
||||||
nToRead = residueEnd - residueBeg;
|
nToRead = residueEnd - residueBeg;
|
||||||
partitionsToRead = nToRead / r->PartitionSize;
|
partitionsToRead = nToRead / r->PartitionSize;
|
||||||
|
|
||||||
/* first half of temp array is used by residue type 2 for storing temp interleaved data */
|
/* first half of temp array is used by residue type 2 for storing temp interleaved data */
|
||||||
classifications_raw = ((uint8_t*)ctx->Temp) + (ctx->DataSize * ctx->Channels * 5);
|
classifications_raw = ((uint8_t*)ctx->temp) + (ctx->dataSize * ctx->channels * 5);
|
||||||
for (i = 0; i < ch; i++) {
|
for (i = 0; i < ch; i++) {
|
||||||
/* add a bit of space in case classwordsPerCodeword is > partitionsToRead*/
|
/* add a bit of space in case classwordsPerCodeword is > partitionsToRead*/
|
||||||
classifications[i] = classifications_raw + i * (partitionsToRead + 64);
|
classifications[i] = classifications_raw + i * (partitionsToRead + 64);
|
||||||
@ -819,7 +819,7 @@ static void Residue_DecodeCore(struct VorbisState* ctx, struct Residue* r, uint3
|
|||||||
|
|
||||||
offset = residueBeg + partitionCount * r->PartitionSize;
|
offset = residueBeg + partitionCount * r->PartitionSize;
|
||||||
v = data[j] + offset;
|
v = data[j] + offset;
|
||||||
c = &ctx->Codebooks[book];
|
c = &ctx->codebooks[book];
|
||||||
|
|
||||||
if (r->Type == 0) {
|
if (r->Type == 0) {
|
||||||
int step = r->PartitionSize / c->Dimensions;
|
int step = r->PartitionSize / c->Dimensions;
|
||||||
@ -839,7 +839,7 @@ static void Residue_DecodeCore(struct VorbisState* ctx, struct Residue* r, uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Residue_DecodeFrame(struct VorbisState* ctx, struct Residue* r, int ch, bool* doNotDecode, float** data) {
|
static void Residue_DecodeFrame(struct VorbisState* ctx, struct Residue* r, int ch, bool* doNotDecode, float** data) {
|
||||||
uint32_t size = ctx->DataSize;
|
uint32_t size = ctx->dataSize;
|
||||||
float* interleaved;
|
float* interleaved;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -853,10 +853,10 @@ static void Residue_DecodeFrame(struct VorbisState* ctx, struct Residue* r, int
|
|||||||
if (!decodeAny) return;
|
if (!decodeAny) return;
|
||||||
decodeAny = false; /* because DecodeCore expects this to be 'false' for 'do not decode' */
|
decodeAny = false; /* because DecodeCore expects this to be 'false' for 'do not decode' */
|
||||||
|
|
||||||
interleaved = ctx->Temp;
|
interleaved = ctx->temp;
|
||||||
/* TODO: avoid using ctx->temp and deinterleaving at all */
|
/* TODO: avoid using ctx->temp and deinterleaving at all */
|
||||||
/* TODO: avoid setting memory to 0 here */
|
/* TODO: avoid setting memory to 0 here */
|
||||||
Mem_Set(interleaved, 0, ctx->DataSize * ctx->Channels * sizeof(float));
|
Mem_Set(interleaved, 0, ctx->dataSize * ctx->channels * sizeof(float));
|
||||||
Residue_DecodeCore(ctx, r, size * ch, 1, &decodeAny, &interleaved);
|
Residue_DecodeCore(ctx, r, size * ch, 1, &decodeAny, &interleaved);
|
||||||
|
|
||||||
/* deinterleave type 2 output */
|
/* deinterleave type 2 output */
|
||||||
@ -898,7 +898,7 @@ static ReturnCode Mapping_DecodeSetup(struct VorbisState* ctx, struct Mapping* m
|
|||||||
if (Vorbis_ReadBit(ctx)) {
|
if (Vorbis_ReadBit(ctx)) {
|
||||||
couplingSteps = Vorbis_ReadBits(ctx, 8) + 1;
|
couplingSteps = Vorbis_ReadBits(ctx, 8) + 1;
|
||||||
/* TODO: How big can couplingSteps ever really get in practice? */
|
/* TODO: How big can couplingSteps ever really get in practice? */
|
||||||
couplingBits = iLog(ctx->Channels - 1);
|
couplingBits = iLog(ctx->channels - 1);
|
||||||
|
|
||||||
for (i = 0; i < couplingSteps; i++) {
|
for (i = 0; i < couplingSteps; i++) {
|
||||||
m->Magnitude[i] = Vorbis_ReadBits(ctx, couplingBits);
|
m->Magnitude[i] = Vorbis_ReadBits(ctx, couplingBits);
|
||||||
@ -913,11 +913,11 @@ static ReturnCode Mapping_DecodeSetup(struct VorbisState* ctx, struct Mapping* m
|
|||||||
m->CouplingSteps = couplingSteps;
|
m->CouplingSteps = couplingSteps;
|
||||||
|
|
||||||
if (submaps > 1) {
|
if (submaps > 1) {
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
m->Mux[i] = Vorbis_ReadBits(ctx, 4);
|
m->Mux[i] = Vorbis_ReadBits(ctx, 4);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
m->Mux[i] = 0;
|
m->Mux[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -959,11 +959,11 @@ static uint32_t Vorbis_ReverseBits(uint32_t v) {
|
|||||||
|
|
||||||
void imdct_init(struct imdct_state* state, int n) {
|
void imdct_init(struct imdct_state* state, int n) {
|
||||||
int k, k2, n4 = n >> 2, n8 = n >> 3, log2_n;
|
int k, k2, n4 = n >> 2, n8 = n >> 3, log2_n;
|
||||||
float *A = state->A, *B = state->B, *C = state->C;
|
float *A = state->a, *B = state->b, *C = state->c;
|
||||||
uint32_t* reversed;
|
uint32_t* reversed;
|
||||||
|
|
||||||
log2_n = Math_Log2(n);
|
log2_n = Math_Log2(n);
|
||||||
reversed = state->Reversed;
|
reversed = state->reversed;
|
||||||
state->n = n; state->log2_n = log2_n;
|
state->n = n; state->log2_n = log2_n;
|
||||||
|
|
||||||
/* setup twiddle factors */
|
/* setup twiddle factors */
|
||||||
@ -991,7 +991,7 @@ void imdct_calc(float* in, float* out, struct imdct_state* state) {
|
|||||||
|
|
||||||
/* Optimised algorithm from "The use of multirate filter banks for coding of high quality digital audio" */
|
/* Optimised algorithm from "The use of multirate filter banks for coding of high quality digital audio" */
|
||||||
/* Uses a few fixes for the paper noted at http://www.nothings.org/stb_vorbis/mdct_01.txt */
|
/* Uses a few fixes for the paper noted at http://www.nothings.org/stb_vorbis/mdct_01.txt */
|
||||||
float *A = state->A, *B = state->B, *C = state->C;
|
float *A = state->a, *B = state->b, *C = state->c;
|
||||||
|
|
||||||
float u[VORBIS_MAX_BLOCK_SIZE];
|
float u[VORBIS_MAX_BLOCK_SIZE];
|
||||||
float w[VORBIS_MAX_BLOCK_SIZE];
|
float w[VORBIS_MAX_BLOCK_SIZE];
|
||||||
@ -1043,7 +1043,7 @@ void imdct_calc(float* in, float* out, struct imdct_state* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* step 4, step 5, step 6, step 7, step 8, output */
|
/* step 4, step 5, step 6, step 7, step 8, output */
|
||||||
reversed = state->Reversed;
|
reversed = state->reversed;
|
||||||
for (k = 0, k2 = 0, k8 = 0; k < n8; k++, k2 += 2, k8 += 8) {
|
for (k = 0, k2 = 0, k8 = 0; k < n8; k++, k2 += 2, k8 += 8) {
|
||||||
uint32_t j = reversed[k], j8 = j << 3;
|
uint32_t j = reversed[k], j8 = j << 3;
|
||||||
e_1 = u[n-j8-1]; e_2 = u[n-j8-3];
|
e_1 = u[n-j8-1]; e_2 = u[n-j8-3];
|
||||||
@ -1109,17 +1109,17 @@ static void Vorbis_CalcWindow(struct VorbisWindow* window, int blockSize) {
|
|||||||
|
|
||||||
void Vorbis_Free(struct VorbisState* ctx) {
|
void Vorbis_Free(struct VorbisState* ctx) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ctx->NumCodebooks; i++) {
|
for (i = 0; i < ctx->numCodebooks; i++) {
|
||||||
Codebook_Free(&ctx->Codebooks[i]);
|
Codebook_Free(&ctx->codebooks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mem_Free(ctx->Codebooks);
|
Mem_Free(ctx->codebooks);
|
||||||
Mem_Free(ctx->Floors);
|
Mem_Free(ctx->floors);
|
||||||
Mem_Free(ctx->Residues);
|
Mem_Free(ctx->residues);
|
||||||
Mem_Free(ctx->Mappings);
|
Mem_Free(ctx->mappings);
|
||||||
Mem_Free(ctx->Modes);
|
Mem_Free(ctx->modes);
|
||||||
Mem_Free(ctx->WindowRaw);
|
Mem_Free(ctx->windowRaw);
|
||||||
Mem_Free(ctx->Temp);
|
Mem_Free(ctx->temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Vorbis_ValidBlockSize(uint32_t size) {
|
static bool Vorbis_ValidBlockSize(uint32_t size) {
|
||||||
@ -1131,7 +1131,7 @@ static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, uint8_t type) {
|
|||||||
bool OK;
|
bool OK;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
if ((res = Stream_Read(ctx->source, header, sizeof(header)))) return res;
|
||||||
if (header[0] != type) return VORBIS_ERR_WRONG_HEADER;
|
if (header[0] != type) return VORBIS_ERR_WRONG_HEADER;
|
||||||
|
|
||||||
OK =
|
OK =
|
||||||
@ -1145,21 +1145,21 @@ static ReturnCode Vorbis_DecodeIdentifier(struct VorbisState* ctx) {
|
|||||||
uint32_t version;
|
uint32_t version;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
if ((res = Stream_Read(ctx->source, header, sizeof(header)))) return res;
|
||||||
version = Stream_GetU32_LE(&header[0]);
|
version = Stream_GetU32_LE(&header[0]);
|
||||||
if (version != 0) return VORBIS_ERR_VERSION;
|
if (version != 0) return VORBIS_ERR_VERSION;
|
||||||
|
|
||||||
ctx->Channels = header[4];
|
ctx->channels = header[4];
|
||||||
ctx->SampleRate = Stream_GetU32_LE(&header[5]);
|
ctx->sampleRate = Stream_GetU32_LE(&header[5]);
|
||||||
/* (12) bitrate_maximum, nominal, minimum */
|
/* (12) bitrate_maximum, nominal, minimum */
|
||||||
ctx->BlockSizes[0] = 1 << (header[21] & 0xF);
|
ctx->blockSizes[0] = 1 << (header[21] & 0xF);
|
||||||
ctx->BlockSizes[1] = 1 << (header[21] >> 4);
|
ctx->blockSizes[1] = 1 << (header[21] >> 4);
|
||||||
|
|
||||||
if (!Vorbis_ValidBlockSize(ctx->BlockSizes[0])) return VORBIS_ERR_BLOCKSIZE;
|
if (!Vorbis_ValidBlockSize(ctx->blockSizes[0])) return VORBIS_ERR_BLOCKSIZE;
|
||||||
if (!Vorbis_ValidBlockSize(ctx->BlockSizes[1])) return VORBIS_ERR_BLOCKSIZE;
|
if (!Vorbis_ValidBlockSize(ctx->blockSizes[1])) return VORBIS_ERR_BLOCKSIZE;
|
||||||
if (ctx->BlockSizes[0] > ctx->BlockSizes[1]) return VORBIS_ERR_BLOCKSIZE;
|
if (ctx->blockSizes[0] > ctx->blockSizes[1]) return VORBIS_ERR_BLOCKSIZE;
|
||||||
|
|
||||||
if (ctx->Channels == 0 || ctx->Channels > VORBIS_MAX_CHANS) return VORBIS_ERR_CHANS;
|
if (ctx->channels == 0 || ctx->channels > VORBIS_MAX_CHANS) return VORBIS_ERR_CHANS;
|
||||||
/* check framing flag */
|
/* check framing flag */
|
||||||
return (header[22] & 1) ? 0 : VORBIS_ERR_FRAMING;
|
return (header[22] & 1) ? 0 : VORBIS_ERR_FRAMING;
|
||||||
}
|
}
|
||||||
@ -1168,7 +1168,7 @@ static ReturnCode Vorbis_DecodeComments(struct VorbisState* ctx) {
|
|||||||
uint32_t i, len, comments;
|
uint32_t i, len, comments;
|
||||||
uint8_t flag;
|
uint8_t flag;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
struct Stream* stream = ctx->Source;
|
struct Stream* stream = ctx->source;
|
||||||
|
|
||||||
/* vendor name, followed by comments */
|
/* vendor name, followed by comments */
|
||||||
if ((res = Stream_ReadU32_LE(stream, &len))) return res;
|
if ((res = Stream_ReadU32_LE(stream, &len))) return res;
|
||||||
@ -1192,12 +1192,12 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 8) + 1;
|
count = Vorbis_ReadBits(ctx, 8) + 1;
|
||||||
ctx->Codebooks = (struct Codebook*)Mem_Alloc(count, sizeof(struct Codebook), "vorbis codebooks");
|
ctx->codebooks = (struct Codebook*)Mem_Alloc(count, sizeof(struct Codebook), "vorbis codebooks");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
res = Codebook_DecodeSetup(ctx, &ctx->Codebooks[i]);
|
res = Codebook_DecodeSetup(ctx, &ctx->codebooks[i]);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
ctx->NumCodebooks = count;
|
ctx->numCodebooks = count;
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6) + 1;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
@ -1206,40 +1206,40 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6) + 1;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Floors = (struct Floor*)Mem_Alloc(count, sizeof(struct Floor), "vorbis floors");
|
ctx->floors = (struct Floor*)Mem_Alloc(count, sizeof(struct Floor), "vorbis floors");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int floor = Vorbis_ReadBits(ctx, 16);
|
int floor = Vorbis_ReadBits(ctx, 16);
|
||||||
if (floor != 1) return VORBIS_ERR_FLOOR_TYPE;
|
if (floor != 1) return VORBIS_ERR_FLOOR_TYPE;
|
||||||
res = Floor_DecodeSetup(ctx, &ctx->Floors[i]);
|
res = Floor_DecodeSetup(ctx, &ctx->floors[i]);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6) + 1;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Residues = (struct Residue*)Mem_Alloc(count, sizeof(struct Residue), "vorbis residues");
|
ctx->residues = (struct Residue*)Mem_Alloc(count, sizeof(struct Residue), "vorbis residues");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int residue = Vorbis_ReadBits(ctx, 16);
|
int residue = Vorbis_ReadBits(ctx, 16);
|
||||||
if (residue > 2) return VORBIS_ERR_FLOOR_TYPE;
|
if (residue > 2) return VORBIS_ERR_FLOOR_TYPE;
|
||||||
res = Residue_DecodeSetup(ctx, &ctx->Residues[i], residue);
|
res = Residue_DecodeSetup(ctx, &ctx->residues[i], residue);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6) + 1;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Mappings = (struct Mapping*)Mem_Alloc(count, sizeof(struct Mapping), "vorbis mappings");
|
ctx->mappings = (struct Mapping*)Mem_Alloc(count, sizeof(struct Mapping), "vorbis mappings");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int mapping = Vorbis_ReadBits(ctx, 16);
|
int mapping = Vorbis_ReadBits(ctx, 16);
|
||||||
if (mapping != 0) return VORBIS_ERR_MAPPING_TYPE;
|
if (mapping != 0) return VORBIS_ERR_MAPPING_TYPE;
|
||||||
res = Mapping_DecodeSetup(ctx, &ctx->Mappings[i]);
|
res = Mapping_DecodeSetup(ctx, &ctx->mappings[i]);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6) + 1;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Modes = (struct Mode*)Mem_Alloc(count, sizeof(struct Mode), "vorbis modes");
|
ctx->modes = (struct Mode*)Mem_Alloc(count, sizeof(struct Mode), "vorbis modes");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
res = Mode_DecodeSetup(ctx, &ctx->Modes[i]);
|
res = Mode_DecodeSetup(ctx, &ctx->modes[i]);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->ModeNumBits = iLog(count - 1); /* ilog([vorbis_mode_count]-1) bits */
|
ctx->modeNumBits = iLog(count - 1); /* ilog([vorbis_mode_count]-1) bits */
|
||||||
framing = Vorbis_ReadBit(ctx);
|
framing = Vorbis_ReadBit(ctx);
|
||||||
Vorbis_AlignBits(ctx);
|
Vorbis_AlignBits(ctx);
|
||||||
/* check framing flag */
|
/* check framing flag */
|
||||||
@ -1258,21 +1258,21 @@ ReturnCode Vorbis_DecodeHeaders(struct VorbisState* ctx) {
|
|||||||
if ((res = Vorbis_DecodeSetup(ctx))) return res;
|
if ((res = Vorbis_DecodeSetup(ctx))) return res;
|
||||||
|
|
||||||
/* window calculations can be pre-computed here */
|
/* window calculations can be pre-computed here */
|
||||||
count = ctx->BlockSizes[0] + ctx->BlockSizes[1];
|
count = ctx->blockSizes[0] + ctx->blockSizes[1];
|
||||||
ctx->WindowRaw = (float*)Mem_Alloc(count, sizeof(float), "Vorbis windows");
|
ctx->windowRaw = (float*)Mem_Alloc(count, sizeof(float), "Vorbis windows");
|
||||||
ctx->Windows[0].Prev = ctx->WindowRaw;
|
ctx->windows[0].Prev = ctx->windowRaw;
|
||||||
ctx->Windows[1].Prev = ctx->WindowRaw + ctx->BlockSizes[0];
|
ctx->windows[1].Prev = ctx->windowRaw + ctx->blockSizes[0];
|
||||||
|
|
||||||
Vorbis_CalcWindow(&ctx->Windows[0], ctx->BlockSizes[0]);
|
Vorbis_CalcWindow(&ctx->windows[0], ctx->blockSizes[0]);
|
||||||
Vorbis_CalcWindow(&ctx->Windows[1], ctx->BlockSizes[1]);
|
Vorbis_CalcWindow(&ctx->windows[1], ctx->blockSizes[1]);
|
||||||
|
|
||||||
count = ctx->Channels * ctx->BlockSizes[1];
|
count = ctx->channels * ctx->blockSizes[1];
|
||||||
ctx->Temp = (float*)Mem_AllocCleared(count * 3, sizeof(float), "Vorbis values");
|
ctx->temp = (float*)Mem_AllocCleared(count * 3, sizeof(float), "Vorbis values");
|
||||||
ctx->Values[0] = ctx->Temp + count;
|
ctx->values[0] = ctx->temp + count;
|
||||||
ctx->Values[1] = ctx->Temp + count * 2;
|
ctx->values[1] = ctx->temp + count * 2;
|
||||||
|
|
||||||
imdct_init(&ctx->imdct[0], ctx->BlockSizes[0]);
|
imdct_init(&ctx->imdct[0], ctx->blockSizes[0]);
|
||||||
imdct_init(&ctx->imdct[1], ctx->BlockSizes[1]);
|
imdct_init(&ctx->imdct[1], ctx->blockSizes[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1310,30 +1310,30 @@ ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx) {
|
|||||||
if (res) return res;
|
if (res) return res;
|
||||||
if (packetType) return VORBIS_ERR_FRAME_TYPE;
|
if (packetType) return VORBIS_ERR_FRAME_TYPE;
|
||||||
|
|
||||||
modeIdx = Vorbis_ReadBits(ctx, ctx->ModeNumBits);
|
modeIdx = Vorbis_ReadBits(ctx, ctx->modeNumBits);
|
||||||
mode = &ctx->Modes[modeIdx];
|
mode = &ctx->modes[modeIdx];
|
||||||
mapping = &ctx->Mappings[mode->MappingIdx];
|
mapping = &ctx->mappings[mode->MappingIdx];
|
||||||
|
|
||||||
/* decode window shape */
|
/* decode window shape */
|
||||||
ctx->CurBlockSize = ctx->BlockSizes[mode->BlockSizeFlag];
|
ctx->curBlockSize = ctx->blockSizes[mode->BlockSizeFlag];
|
||||||
ctx->DataSize = ctx->CurBlockSize / 2;
|
ctx->dataSize = ctx->curBlockSize / 2;
|
||||||
/* long window lapping flags - we don't care about them though */
|
/* long window lapping flags - we don't care about them though */
|
||||||
if (mode->BlockSizeFlag) { Vorbis_ReadBits(ctx, 2); } /* TODO: do we just SkipBits here */
|
if (mode->BlockSizeFlag) { Vorbis_ReadBits(ctx, 2); } /* TODO: do we just SkipBits here */
|
||||||
|
|
||||||
/* swap prev and cur outputs around */
|
/* swap prev and cur outputs around */
|
||||||
tmp = ctx->Values[1]; ctx->Values[1] = ctx->Values[0]; ctx->Values[0] = tmp;
|
tmp = ctx->values[1]; ctx->values[1] = ctx->values[0]; ctx->values[0] = tmp;
|
||||||
Mem_Set(ctx->Values[0], 0, ctx->Channels * ctx->CurBlockSize);
|
Mem_Set(ctx->values[0], 0, ctx->channels * ctx->curBlockSize);
|
||||||
|
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
ctx->CurOutput[i] = ctx->Values[0] + i * ctx->CurBlockSize;
|
ctx->curOutput[i] = ctx->values[0] + i * ctx->curBlockSize;
|
||||||
ctx->PrevOutput[i] = ctx->Values[1] + i * ctx->PrevBlockSize;
|
ctx->prevOutput[i] = ctx->values[1] + i * ctx->prevBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode floor */
|
/* decode floor */
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
submap = mapping->Mux[i];
|
submap = mapping->Mux[i];
|
||||||
floorIdx = mapping->FloorIdx[submap];
|
floorIdx = mapping->FloorIdx[submap];
|
||||||
hasFloor[i] = Floor_DecodeFrame(ctx, &ctx->Floors[floorIdx], i);
|
hasFloor[i] = Floor_DecodeFrame(ctx, &ctx->floors[floorIdx], i);
|
||||||
hasResidue[i] = hasFloor[i];
|
hasResidue[i] = hasFloor[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1351,24 +1351,24 @@ ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx) {
|
|||||||
for (i = 0; i < mapping->Submaps; i++) {
|
for (i = 0; i < mapping->Submaps; i++) {
|
||||||
ch = 0;
|
ch = 0;
|
||||||
/* map residue data to actual channel data */
|
/* map residue data to actual channel data */
|
||||||
for (j = 0; j < ctx->Channels; j++) {
|
for (j = 0; j < ctx->channels; j++) {
|
||||||
if (mapping->Mux[j] != i) continue;
|
if (mapping->Mux[j] != i) continue;
|
||||||
|
|
||||||
doNotDecode[ch] = !hasResidue[j];
|
doNotDecode[ch] = !hasResidue[j];
|
||||||
data[ch] = ctx->CurOutput[j];
|
data[ch] = ctx->curOutput[j];
|
||||||
ch++;
|
ch++;
|
||||||
}
|
}
|
||||||
|
|
||||||
residueIdx = mapping->FloorIdx[i];
|
residueIdx = mapping->FloorIdx[i];
|
||||||
Residue_DecodeFrame(ctx, &ctx->Residues[residueIdx], ch, doNotDecode, data);
|
Residue_DecodeFrame(ctx, &ctx->residues[residueIdx], ch, doNotDecode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inverse coupling */
|
/* inverse coupling */
|
||||||
for (i = mapping->CouplingSteps - 1; i >= 0; i--) {
|
for (i = mapping->CouplingSteps - 1; i >= 0; i--) {
|
||||||
magValues = ctx->CurOutput[mapping->Magnitude[i]];
|
magValues = ctx->curOutput[mapping->Magnitude[i]];
|
||||||
angValues = ctx->CurOutput[mapping->Angle[i]];
|
angValues = ctx->curOutput[mapping->Angle[i]];
|
||||||
|
|
||||||
for (j = 0; j < ctx->DataSize; j++) {
|
for (j = 0; j < ctx->dataSize; j++) {
|
||||||
m = magValues[j]; a = angValues[j];
|
m = magValues[j]; a = angValues[j];
|
||||||
|
|
||||||
if (m > 0.0f) {
|
if (m > 0.0f) {
|
||||||
@ -1388,21 +1388,21 @@ ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* compute dot product of floor and residue, producing audio spectrum vector */
|
/* compute dot product of floor and residue, producing audio spectrum vector */
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
if (!hasFloor[i]) continue;
|
if (!hasFloor[i]) continue;
|
||||||
|
|
||||||
submap = mapping->Mux[i];
|
submap = mapping->Mux[i];
|
||||||
floorIdx = mapping->FloorIdx[submap];
|
floorIdx = mapping->FloorIdx[submap];
|
||||||
Floor_Synthesis(ctx, &ctx->Floors[floorIdx], i);
|
Floor_Synthesis(ctx, &ctx->floors[floorIdx], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inverse monolithic transform of audio spectrum vector */
|
/* inverse monolithic transform of audio spectrum vector */
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
tmp = ctx->CurOutput[i];
|
tmp = ctx->curOutput[i];
|
||||||
|
|
||||||
if (!hasFloor[i]) {
|
if (!hasFloor[i]) {
|
||||||
/* TODO: Do we actually need to zero data here (residue type 2 maybe) */
|
/* TODO: Do we actually need to zero data here (residue type 2 maybe) */
|
||||||
Mem_Set(tmp, 0, ctx->CurBlockSize * sizeof(float));
|
Mem_Set(tmp, 0, ctx->curBlockSize * sizeof(float));
|
||||||
} else {
|
} else {
|
||||||
imdct_calc(tmp, tmp, &ctx->imdct[mode->BlockSizeFlag]);
|
imdct_calc(tmp, tmp, &ctx->imdct[mode->BlockSizeFlag]);
|
||||||
/* defer windowing until output */
|
/* defer windowing until output */
|
||||||
@ -1425,15 +1425,15 @@ int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data) {
|
|||||||
int i, ch;
|
int i, ch;
|
||||||
|
|
||||||
/* first frame decoded has no data */
|
/* first frame decoded has no data */
|
||||||
if (ctx->PrevBlockSize == 0) {
|
if (ctx->prevBlockSize == 0) {
|
||||||
ctx->PrevBlockSize = ctx->CurBlockSize;
|
ctx->prevBlockSize = ctx->curBlockSize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* data returned is from centre of previous block to centre of current block */
|
/* data returned is from centre of previous block to centre of current block */
|
||||||
/* data is aligned, such that 3/4 of prev block is aligned to 1/4 of cur block */
|
/* data is aligned, such that 3/4 of prev block is aligned to 1/4 of cur block */
|
||||||
curQrtr = ctx->CurBlockSize / 4;
|
curQrtr = ctx->curBlockSize / 4;
|
||||||
prevQrtr = ctx->PrevBlockSize / 4;
|
prevQrtr = ctx->prevBlockSize / 4;
|
||||||
overlapQtr = min(curQrtr, prevQrtr);
|
overlapQtr = min(curQrtr, prevQrtr);
|
||||||
|
|
||||||
/* So for example, consider a short block overlapping with a long block
|
/* So for example, consider a short block overlapping with a long block
|
||||||
@ -1448,14 +1448,14 @@ int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data) {
|
|||||||
curOffset = curQrtr - overlapQtr;
|
curOffset = curQrtr - overlapQtr;
|
||||||
prevOffset = prevQrtr - overlapQtr;
|
prevOffset = prevQrtr - overlapQtr;
|
||||||
|
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
prev[i] = ctx->PrevOutput[i] + (prevQrtr * 2);
|
prev[i] = ctx->prevOutput[i] + (prevQrtr * 2);
|
||||||
cur[i] = ctx->CurOutput[i];
|
cur[i] = ctx->curOutput[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for long prev and short cur block, there will be non-overlapped data before */
|
/* for long prev and short cur block, there will be non-overlapped data before */
|
||||||
for (i = 0; i < prevOffset; i++) {
|
for (i = 0; i < prevOffset; i++) {
|
||||||
for (ch = 0; ch < ctx->Channels; ch++) {
|
for (ch = 0; ch < ctx->channels; ch++) {
|
||||||
sample = prev[ch][i];
|
sample = prev[ch][i];
|
||||||
Math_Clamp(sample, -1.0f, 1.0f);
|
Math_Clamp(sample, -1.0f, 1.0f);
|
||||||
*data++ = (int16_t)(sample * 32767);
|
*data++ = (int16_t)(sample * 32767);
|
||||||
@ -1463,17 +1463,17 @@ int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* adjust pointers to start at 0 for overlapping */
|
/* adjust pointers to start at 0 for overlapping */
|
||||||
for (i = 0; i < ctx->Channels; i++) {
|
for (i = 0; i < ctx->channels; i++) {
|
||||||
prev[i] += prevOffset; cur[i] += curOffset;
|
prev[i] += prevOffset; cur[i] += curOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
overlapSize = overlapQtr * 2;
|
overlapSize = overlapQtr * 2;
|
||||||
window = ctx->Windows[(overlapQtr * 4) == ctx->BlockSizes[1]];
|
window = ctx->windows[(overlapQtr * 4) == ctx->blockSizes[1]];
|
||||||
|
|
||||||
/* overlap and add data */
|
/* overlap and add data */
|
||||||
/* also perform windowing here */
|
/* also perform windowing here */
|
||||||
for (i = 0; i < overlapSize; i++) {
|
for (i = 0; i < overlapSize; i++) {
|
||||||
for (ch = 0; ch < ctx->Channels; ch++) {
|
for (ch = 0; ch < ctx->channels; ch++) {
|
||||||
sample = prev[ch][i] * window.Prev[i] + cur[ch][i] * window.Cur[i];
|
sample = prev[ch][i] * window.Prev[i] + cur[ch][i] * window.Cur[i];
|
||||||
Math_Clamp(sample, -1.0f, 1.0f);
|
Math_Clamp(sample, -1.0f, 1.0f);
|
||||||
*data++ = (int16_t)(sample * 32767);
|
*data++ = (int16_t)(sample * 32767);
|
||||||
@ -1481,15 +1481,15 @@ int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* for long cur and short prev block, there will be non-overlapped data after */
|
/* for long cur and short prev block, there will be non-overlapped data after */
|
||||||
for (i = 0; i < ctx->Channels; i++) { cur[i] += overlapSize; }
|
for (i = 0; i < ctx->channels; i++) { cur[i] += overlapSize; }
|
||||||
for (i = 0; i < curOffset; i++) {
|
for (i = 0; i < curOffset; i++) {
|
||||||
for (ch = 0; ch < ctx->Channels; ch++) {
|
for (ch = 0; ch < ctx->channels; ch++) {
|
||||||
sample = cur[ch][i];
|
sample = cur[ch][i];
|
||||||
Math_Clamp(sample, -1.0f, 1.0f);
|
Math_Clamp(sample, -1.0f, 1.0f);
|
||||||
*data++ = (int16_t)(sample * 32767);
|
*data++ = (int16_t)(sample * 32767);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->PrevBlockSize = ctx->CurBlockSize;
|
ctx->prevBlockSize = ctx->curBlockSize;
|
||||||
return (prevQrtr + curQrtr) * ctx->Channels;
|
return (prevQrtr + curQrtr) * ctx->channels;
|
||||||
}
|
}
|
||||||
|
38
src/Vorbis.h
38
src/Vorbis.h
@ -15,34 +15,34 @@ struct Codebook; struct Floor; struct Residue; struct Mapping; struct Mode;
|
|||||||
|
|
||||||
struct imdct_state {
|
struct imdct_state {
|
||||||
int n, log2_n;
|
int n, log2_n;
|
||||||
float A[VORBIS_MAX_BLOCK_SIZE / 2];
|
float a[VORBIS_MAX_BLOCK_SIZE / 2];
|
||||||
float B[VORBIS_MAX_BLOCK_SIZE / 2];
|
float b[VORBIS_MAX_BLOCK_SIZE / 2];
|
||||||
float C[VORBIS_MAX_BLOCK_SIZE / 4];
|
float c[VORBIS_MAX_BLOCK_SIZE / 4];
|
||||||
uint32_t Reversed[VORBIS_MAX_BLOCK_SIZE / 8];
|
uint32_t reversed[VORBIS_MAX_BLOCK_SIZE / 8];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VorbisWindow { float* Prev; float* Cur; };
|
struct VorbisWindow { float* Prev; float* Cur; };
|
||||||
struct VorbisState {
|
struct VorbisState {
|
||||||
uint32_t Bits; /* Holds bits across byte boundaries*/
|
uint32_t Bits; /* Holds bits across byte boundaries*/
|
||||||
uint32_t NumBits; /* Number of bits in Bits buffer*/
|
uint32_t NumBits; /* Number of bits in Bits buffer*/
|
||||||
struct Stream* Source; /* Source for filling Input buffer */
|
struct Stream* source; /* Source for filling Input buffer */
|
||||||
|
|
||||||
uint8_t Channels, ModeNumBits;
|
uint8_t channels, modeNumBits;
|
||||||
uint16_t CurBlockSize, PrevBlockSize, DataSize, NumCodebooks;
|
uint16_t curBlockSize, prevBlockSize, dataSize, numCodebooks;
|
||||||
int SampleRate; int BlockSizes[2];
|
int sampleRate; int blockSizes[2];
|
||||||
float* Temp; /* temp array reused in places */
|
float* temp; /* temp array reused in places */
|
||||||
float* Values[2]; /* swapped each frame */
|
float* values[2]; /* swapped each frame */
|
||||||
float* PrevOutput[VORBIS_MAX_CHANS];
|
float* prevOutput[VORBIS_MAX_CHANS];
|
||||||
float* CurOutput[VORBIS_MAX_CHANS];
|
float* curOutput[VORBIS_MAX_CHANS];
|
||||||
|
|
||||||
struct Codebook* Codebooks;
|
struct Codebook* codebooks;
|
||||||
struct Floor* Floors;
|
struct Floor* floors;
|
||||||
struct Residue* Residues;
|
struct Residue* residues;
|
||||||
struct Mapping* Mappings;
|
struct Mapping* mappings;
|
||||||
struct Mode* Modes;
|
struct Mode* modes;
|
||||||
|
|
||||||
float* WindowRaw;
|
float* windowRaw;
|
||||||
struct VorbisWindow Windows[2];
|
struct VorbisWindow windows[2];
|
||||||
struct imdct_state imdct[2];
|
struct imdct_state imdct[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user