Skip to content

Commit

Permalink
Updated makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
jocic committed Jul 20, 2023
1 parent 751e63a commit 06e77c0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
assets/unit-tests
CMakeLists.txt.user
CMakeLists.txt.user.*
29 changes: 23 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
GCC=gcc

OUTPUT=./assets/test.exe
OUTPUT=./assets/unit-tests

STD=c89

all:

unit-tests:
gcc -I source -o $(OUTPUT) -std=$(STD)\
source/bin.h \
source/format.h \
source/tones.h \
tests/binary-io.h \
tests/wav-format.h \
tests/functionality.h \
source/bin.c \
source/format.c \
source/tones.c \
tests/binary-io.c \
tests/wav-format.c \
main.c
tests/functionality.c \
main.c

install:
gcc -c -fPIC \
source/bin.c \
source/format.c

ar rcs c89-wav.a \
bin.o \
format.o

rm ./bin.o ./format.o

mv c89-wav.a /usr/lib

mkdir /usr/include/c89-wav

cp source/bin.h /usr/include/c89-wav
cp source/format.h /usr/include/c89-wav
15 changes: 11 additions & 4 deletions source/bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

#define C89_WAV_BIN_H

#define BIN_RD (O_RDONLY | O_BINARY)
#define BIN_WR (O_WRONLY | O_BINARY)
#define BIN_RDWR (O_RDWR | O_BINARY)
#define BIN_NEW (O_RDWR | O_CREAT | O_TRUNC | O_BINARY)
#ifdef _WIN32
#define BIN_RD (O_RDONLY | O_BINARY)
#define BIN_WR (O_WRONLY | O_BINARY)
#define BIN_RDWR (O_RDWR | O_BINARY)
#define BIN_NEW (O_RDWR | O_CREAT | O_TRUNC | O_BINARY)
#else
#define BIN_RD (O_RDONLY)
#define BIN_WR (O_WRONLY)
#define BIN_RDWR (O_RDWR)
#define BIN_NEW (O_RDWR | O_CREAT | O_TRUNC)
#endif

typedef struct {
int fd;
Expand Down
2 changes: 1 addition & 1 deletion source/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define wav_get_sample(wf, n, v) (wav_get_1ch_sample(wf, n, v))
#define wav_set_sample(wf, n, v) (wav_set_1ch_sample(wf, n, v))
#define wav_push_sample(wf, v) (wav_push_1ch_sample(wf, v))
#define wav_next_sample(wf) (wav_next_1ch_sample(wf, v))
#define wav_next_sample(wf, v) (wav_next_1ch_sample(wf, v))
#define wav_set_psample(wf, v) (wav_get_1ch_sample(wf, (*wf).curr - 1, v))
#define wav_set_1ch_psample(wf, v) (wav_get_1ch_sample(wf, (*wf).curr - 1, v))
#define wav_set_2ch_psample(wf, lv, rv) (wav_get_1ch_sample(wf, (*wf).curr - 1, lv, rv))
Expand Down
10 changes: 5 additions & 5 deletions tests/binary-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void test_bin_core() {

printf("TEST: Binary I/O -> Core\n");

// File Management (1 by 1)
/* File Management (1 by 1) */

for (i = 0; i < 5; i++) {

Expand All @@ -36,7 +36,7 @@ void test_bin_core() {
assert(!single.open && "Invalid open flag.");
}

// File Management (Multiple)
/* File Management (Multiple) */

for (i = 0; i < 5; i++) {
multiple[i] = bin_open(files[i], BIN_RDWR);
Expand All @@ -63,18 +63,18 @@ void test_bin_read() {
BIN_FILE file;

struct target rd_targets[26] = {
// 8-Bit Values
/* 8-Bit Values */
{ 0x000, 0x97, 0x1, false }, { 0x001, 0x68, 0x1, false },
{ 0x002, 0xAB, 0x1, false }, { 0x003, 0xD9, 0x1, false },
{ 0x0C6, 0xA0, 0x1, false }, { 0x0C7, 0x3A, 0x1, false },
{ 0x0C8, 0xA9, 0x1, false }, { 0x0C9, 0xDB, 0x1, false },
{ 0x1FF, 0xFE, 0x1, false }, { 0x2FF, 0x00, 0x1, false },
// 16-Bit Values
/* 16-Bit Values */
{ 0x000, 0x6897, 0x2, false }, { 0x002, 0xABD9, 0x2, true },
{ 0x004, 0x295E, 0x2, false }, { 0x006, 0x6768, 0x2, true },
{ 0x126, 0xDA01, 0x2, false }, { 0x1FE, 0xB4FE, 0x2, true },
{ 0x2FF, 0x0000, 0x2, false }, { 0x3FF, 0x0000, 0x2, true },
// 32-Bit Values
/* 32-Bit Values */
{ 0x000, 0xD9AB6897, 0x4, false }, { 0x004, 0x5E296768, 0x4, true },
{ 0x0B5, 0x5A1BE627, 0x4, false }, { 0x0D9, 0x4D4B8679, 0x4, true },
{ 0x1FC, 0xFEB44AC2, 0x4, false }, { 0x1FC, 0xC24AB4FE, 0x4, true },
Expand Down
20 changes: 10 additions & 10 deletions tests/wav-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void test_wav_general() {

printf("[*] TEST: WAV Format -> General\n");

// 1 Channel
/* 1 Channel */

WAV_FILE file_1ch = wav_open("test-files/wav-format/16bit-test.wav", WAV_READ);

Expand All @@ -66,7 +66,7 @@ void test_wav_general() {
assert(wav_close(&file_1ch) && "File couldn't be closed.");
assert(wav_last_error(&file_1ch) == WAV_ERR_NONE && "Error flag set.");

// 2 Channel
/* 2 Channel */

WAV_FILE file_2ch = wav_open("test-files/wav-format/mic-rec.wav", WAV_READ);

Expand Down Expand Up @@ -153,7 +153,7 @@ void test_wav_defaults() {

printf("[*] TEST: WAV Format -> Defaults\n");

// 1 Channel
/* 1 Channel */

WAV_FILE file_1ch = wav_open("test-files/wav-format/1ch-defaults.wav", WAV_NEW);

Expand All @@ -180,7 +180,7 @@ void test_wav_defaults() {
assert(wav_close(&file_1ch) && "File couldn't be closed.");
assert(wav_last_error(&file_1ch) == WAV_ERR_NONE && "Error flag set.");

// 2 Channel
/* 2 Channel */

WAV_FILE file_2ch = wav_open("test-files/wav-format/2ch-defaults.wav", WAV_NEW);

Expand Down Expand Up @@ -234,7 +234,7 @@ void test_wav_get() {

printf("[*] TEST: WAV Format -> Get\n");

// 1 Channel
/* 1 Channel */

WAV_FILE file_1ch = wav_open("test-files/wav-format/16bit-test.wav", WAV_READ);

Expand All @@ -253,7 +253,7 @@ void test_wav_get() {
assert(wav_close(&file_1ch) && "File couldn't be closed.");
assert(wav_last_error(&file_1ch) == WAV_ERR_NONE && "Error flag set.");

// 2 Channel
/* 2 Channel */

WAV_FILE file_2ch = wav_open("test-files/wav-format/mic-rec.wav", WAV_READ);

Expand Down Expand Up @@ -296,7 +296,7 @@ void test_wav_set() {

printf("[*] TEST: WAV Format -> Set\n");

// 1 Channel
/* 1 Channel */

WAV_FILE file_1ch = wav_open("test-files/wav-format/1ch-set-test.wav", WAV_NEW);

Expand All @@ -318,7 +318,7 @@ void test_wav_set() {
assert(wav_close(&file_1ch) && "File couldn't be closed.");
assert(wav_last_error(&file_1ch) == WAV_ERR_NONE && "Error flag set.");

// 2 Channel
/* 2 Channel */

WAV_FILE file_2ch = wav_open("test-files/wav-format/2ch-set-test.wav", WAV_NEW);

Expand Down Expand Up @@ -368,7 +368,7 @@ void test_wav_push() {

printf("[*] TEST: WAV Format -> Push\n");

// 1 Channel
/* 1 Channel */

WAV_FILE file_1ch = wav_open("test-files/wav-format/1ch-push-test.wav", WAV_NEW);

Expand All @@ -389,7 +389,7 @@ void test_wav_push() {
assert(wav_close(&file_1ch) && "File couldn't be closed.");
assert(wav_last_error(&file_1ch) == WAV_ERR_NONE && "Error flag set.");

// 2 Channel
/* 2 Channel */

WAV_FILE file_2ch = wav_open("test-files/wav-format/2ch-push-test.wav", WAV_NEW);

Expand Down

0 comments on commit 06e77c0

Please sign in to comment.