summaryrefslogtreecommitdiff
path: root/tools/aif2pcm/main.c
diff options
context:
space:
mode:
authormid-kid <esteve.varela@gmail.com>2021-11-04 21:07:26 +0000
committerGitHub <noreply@github.com>2021-11-04 14:07:26 -0700
commit681ca68ac96e8d39f49eb2c9f42e5c1e1041f5e0 (patch)
tree52a507350ab3fb83d1207b7ccf8266693c2f5a24 /tools/aif2pcm/main.c
parentf1394cbb03aa9fb1c928c6de1648ef459d2bf66b (diff)
Disassemble some more tables and the first graphic (#71)
* Sync tools/ directory with pokeemerald We really ought to have a central repository for this mess * Make incremental builds faster Scientists hate him! He made NODEP disappear with this ONE SIMPLE TRICK!!! Want to know more? -> __click here__ <- * Disassemble some more tables and the first graphic
Diffstat (limited to 'tools/aif2pcm/main.c')
-rw-r--r--tools/aif2pcm/main.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/tools/aif2pcm/main.c b/tools/aif2pcm/main.c
index cd5ac4a..3dad6fc 100644
--- a/tools/aif2pcm/main.c
+++ b/tools/aif2pcm/main.c
@@ -351,6 +351,12 @@ const int gDeltaEncodingTable[] = {
-64, -49, -36, -25, -16, -9, -4, -1,
};
+#define POSITIVE_DELTAS_START 0
+#define POSITIVE_DELTAS_END 8
+
+#define NEGATIVE_DELTAS_START 8
+#define NEGATIVE_DELTAS_END 16
+
struct Bytes *delta_decompress(struct Bytes *delta, unsigned int expected_length)
{
struct Bytes *pcm = malloc(sizeof(struct Bytes));
@@ -418,15 +424,32 @@ struct Bytes *delta_decompress(struct Bytes *delta, unsigned int expected_length
return pcm;
}
+#define U8_TO_S8(value) ((value) < 128 ? (value) : (value) - 256)
+#define ABS(value) ((value) >= 0 ? (value) : -(value))
+
int get_delta_index(uint8_t sample, uint8_t prev_sample)
{
int best_error = INT_MAX;
int best_index = -1;
+ int delta_table_start_index;
+ int delta_table_end_index;
+ int sample_signed = U8_TO_S8(sample);
+ int prev_sample_signed = U8_TO_S8(prev_sample);
+
+ // if we're going up (or equal), only choose positive deltas
+ if (prev_sample_signed <= sample_signed) {
+ delta_table_start_index = POSITIVE_DELTAS_START;
+ delta_table_end_index = POSITIVE_DELTAS_END;
+ } else {
+ delta_table_start_index = NEGATIVE_DELTAS_START;
+ delta_table_end_index = NEGATIVE_DELTAS_END;
+ }
- for (int i = 0; i < 16; i++)
+ for (int i = delta_table_start_index; i < delta_table_end_index; i++)
{
uint8_t new_sample = prev_sample + gDeltaEncodingTable[i];
- int error = sample > new_sample ? sample - new_sample : new_sample - sample;
+ int new_sample_signed = U8_TO_S8(new_sample);
+ int error = ABS(new_sample_signed - sample_signed);
if (error < best_error)
{