summaryrefslogtreecommitdiff
path: root/tools/aif2pcm
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aif2pcm')
-rw-r--r--tools/aif2pcm/LICENSE40
-rw-r--r--tools/aif2pcm/Makefile10
-rw-r--r--tools/aif2pcm/main.c27
3 files changed, 53 insertions, 24 deletions
diff --git a/tools/aif2pcm/LICENSE b/tools/aif2pcm/LICENSE
index ce51485..966b92b 100644
--- a/tools/aif2pcm/LICENSE
+++ b/tools/aif2pcm/LICENSE
@@ -1,20 +1,20 @@
-Copyright (c) 2016 huderlem
-Copyright (c) 2005, 2006 by Marco Trillo <marcotrillo@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+Copyright (c) 2016 huderlem
+Copyright (c) 2005, 2006 by Marco Trillo <marcotrillo@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/tools/aif2pcm/Makefile b/tools/aif2pcm/Makefile
index 77df291..dd48a87 100644
--- a/tools/aif2pcm/Makefile
+++ b/tools/aif2pcm/Makefile
@@ -6,12 +6,18 @@ LIBS = -lm
SRCS = main.c extended.c
+ifeq ($(OS),Windows_NT)
+EXE := .exe
+else
+EXE :=
+endif
+
.PHONY: all clean
-all: aif2pcm
+all: aif2pcm$(EXE)
@:
-aif2pcm: $(SRCS)
+aif2pcm$(EXE): $(SRCS)
$(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) $(LIBS)
clean:
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)
{