• R/O
  • HTTP
  • SSH
  • HTTPS

cinnamon: Commit

Cinnamon audio library


Commit MetaInfo

Revisiondb52de107c3514479ce37abf8976b133b3bdde5f (tree)
Zeit2019-05-28 05:22:54
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Minor refactor, fix missing OpenAL makefiles

Ändern Zusammenfassung

Diff

--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -0,0 +1,17 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+# GNU makefile.
5+
6+include gcc.mk
7+
8+BACKEND?=openal
9+
10+# Only OpenAL can be compiled without C++ currently.
11+ifeq "$(BACKEND)" "openal"
12+LINK?=$(CC)
13+else
14+LINK=$(CXX)
15+endif
16+
17+include unix.mk
--- /dev/null
+++ b/src/cin_format.h
@@ -0,0 +1,32 @@
1+/* Copyright (c) 2018-2019 Alaskan Emily, Transnat Games
2+ *
3+ * This Source Code Form is subject to the terms of the Mozilla Public
4+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+ */
7+
8+#ifndef CIN_FORMAT_H
9+#define CIN_FORMAT_H
10+#pragma once
11+
12+enum Cin_Format{
13+ Cin_eFormatS8,
14+ Cin_eFormatS16,
15+ Cin_eFormatS32,
16+ Cin_eFormatFloat32,
17+ Cin_eFormatFloat64,
18+ Cin_eFormatULaw8,
19+ Cin_eFormatNUM_FORMATS,
20+
21+ Cin_eFormatBEGIN = 0,
22+ Cin_eFormatEND = (Cin_eFormatNUM_FORMATS - 1)
23+};
24+
25+#define CIN_FORMAT_BYTES_PER_SAMPLE(FMT) ( \
26+ ((FMT) == Cin_eFormatS8 || (FMT) == Cin_eFormatULaw8) ? 1 : \
27+ ((FMT) == Cin_eFormatS16) ? 2 : \
28+ ((FMT) == Cin_eFormatS32 || (FMT) == Cin_eFormatFloat32) ? 4 : \
29+ ((FMT) == Cin_eFormatFloat64) ? 8 : 0 \
30+ )
31+
32+#endif /* CIN_FORMAT_H */
--- a/src/cinnamon.h
+++ b/src/cinnamon.h
@@ -10,31 +10,12 @@
1010 #pragma once
1111
1212 #include "cin_export.h"
13+#include "cin_format.h"
1314
1415 #ifdef __cplusplus
1516 extern "C" {
1617 #endif
1718
18-enum Cin_Format{
19- Cin_eFormatS8,
20- Cin_eFormatS16,
21- Cin_eFormatS32,
22- Cin_eFormatFloat32,
23- Cin_eFormatFloat64,
24- Cin_eFormatULaw8,
25- Cin_eFormatNUM_FORMATS,
26-
27- Cin_eFormatBEGIN = 0,
28- Cin_eFormatEND = (Cin_eFormatNUM_FORMATS - 1)
29-};
30-
31-#define CIN_FORMAT_BYTES_PER_SAMPLE(FMT) ( \
32- ((FMT) == Cin_eFormatS8 || (FMT) == Cin_eFormatULaw8) ? 1 : \
33- ((FMT) == Cin_eFormatS16) ? 2 : \
34- ((FMT) == Cin_eFormatS32 || (FMT) == Cin_eFormatFloat32) ? 4 : \
35- ((FMT) == Cin_eFormatFloat64) ? 8 : 0 \
36- )
37-
3819 /**
3920 * @defgroup Driver Functions that create, destroy, and manipulate the Driver.
4021 * @{
--- a/src/common/GNUmakefile
+++ b/src/common/GNUmakefile
@@ -0,0 +1,26 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+common: libcin_common.a
5+mixer: libcin_mixer.a
6+
7+# No need to run ranlib on a single object
8+libcin_common.a: cin_soft_loader.o
9+ ar rc libcin_common.a cin_soft_loader.o
10+
11+cin_soft_loader.o: cin_soft_loader.c cin_soft_loader.h $(ROOTDIR)/cinnamon.h $(ROOTDIR)/cin_export.h
12+ $(CC) $(CFLAGS) -I$(ROOTDIR) -c cin_soft_loader.c -o cin_soft_loader.o
13+
14+MIXER_OBJECTS=cin_mixer_sound.o cin_dsp.o
15+
16+libcin_mixer.a: $(MIXER_OBJECTS)
17+ rm mix_x.a 2> /dev/null || true
18+ $(AR) rc mix_x.a $(MIXER_OBJECTS)
19+ $(RANLIB) mix_x.a
20+ cp mix_x.a libcin_mixer.a
21+
22+cin_mixer_sound.o: cin_mixer_sound.c cin_mixer_sound.h cin_dsp.h $(ROOTDIR)/cin_export.h $(ROOTDIR)/cin_format.h
23+ $(CC) $(CFLAGS) -I"$(ROOTDIR)" -c cin_mixer_sound.c -o cin_mixer_sound.o
24+
25+cin_dsp.o: cin_dsp.cpp cin_dsp.h
26+ $(CXX) $(CXXFLAGS) -c cin_dsp.cpp -o cin_dsp.o
--- a/src/common/cin_soft_loader.c
+++ b/src/common/cin_soft_loader.c
@@ -5,10 +5,14 @@
55 #include <stdlib.h>
66 #include <string.h>
77
8+/*****************************************************************************/
9+
810 unsigned Cin_StructLoaderSize(){
911 return sizeof(struct Cin_Loader);
1012 }
1113
14+/*****************************************************************************/
15+
1216 CIN_PRIVATE(void) Cin_CreateSoftLoader(struct Cin_Loader *out,
1317 unsigned sample_rate,
1418 unsigned channels,
@@ -23,6 +27,8 @@ CIN_PRIVATE(void) Cin_CreateSoftLoader(struct Cin_Loader *out,
2327 out->first = out->last = NULL;
2428 }
2529
30+/*****************************************************************************/
31+
2632 enum Cin_LoaderError Cin_LoaderPut(struct Cin_Loader *ld,
2733 const void *data,
2834 unsigned byte_size){
@@ -50,6 +56,8 @@ enum Cin_LoaderError Cin_LoaderPut(struct Cin_Loader *ld,
5056 return Cin_eLoaderSuccess;
5157 }
5258
59+/*****************************************************************************/
60+
5361 CIN_PRIVATE(void) Cin_LoaderFreeData(struct Cin_LoaderData *data){
5462 if(data == NULL){
5563 return;
@@ -61,6 +69,8 @@ CIN_PRIVATE(void) Cin_LoaderFreeData(struct Cin_LoaderData *data){
6169 }
6270 }
6371
72+/*****************************************************************************/
73+
6474 CIN_PRIVATE(void) Cin_LoaderMemcpy(const struct Cin_LoaderData *data,
6575 unsigned at,
6676 void *dest,
@@ -79,11 +89,11 @@ CIN_PRIVATE(void) Cin_LoaderMemcpy(const struct Cin_LoaderData *data,
7989 const unsigned remaining = len - at;
8090 if(remaining >= count){
8191 /* Copy out the partial area we care about */
82- memcpy(dest, data->data + at, count);
92+ memcpy(dest, CIN_SOFT_LOADER_DATA(data) + at, count);
8393 }
8494 else{
8595 /* Start our copy from the input index. */
86- memcpy(dest, data->data + at, remaining);
96+ memcpy(dest, CIN_SOFT_LOADER_DATA(data) + at, remaining);
8797 if(next)
8898 Cin_LoaderMemcpy(next,
8999 0,
@@ -95,10 +105,10 @@ CIN_PRIVATE(void) Cin_LoaderMemcpy(const struct Cin_LoaderData *data,
95105 /* Copy out the max of our len and the count */
96106 if(len >= count){
97107 /* This data holds the remaining count. */
98- memcpy(dest, data->data, count);
108+ memcpy(dest, CIN_SOFT_LOADER_DATA(data), count);
99109 }
100110 else{
101- memcpy(dest, data->data, len);
111+ memcpy(dest, CIN_SOFT_LOADER_DATA(data), len);
102112 if(next)
103113 Cin_LoaderMemcpy(next, 0, dest_bytes + len, count - len);
104114 }
--- a/src/common/cin_soft_loader.h
+++ b/src/common/cin_soft_loader.h
@@ -10,7 +10,7 @@
1010 #pragma once
1111
1212 #include "cin_export.h"
13-#include "cinnamon.h"
13+#include "cin_format.h"
1414
1515 #ifdef __cplusplus
1616 extern "C" {
@@ -22,6 +22,13 @@ extern "C" {
2222 /* Push the warning about the data[] field */
2323 #pragma warning(push)
2424 #pragma warning(disable: 4200)
25+
26+#define CIN_SOFT_USE_DATA_FIELD
27+
28+#elif ( __STDC_VERSION__ >= 199901L ) || ( __cplusplus >= 201103L )
29+
30+#define CIN_SOFT_USE_DATA_FIELD
31+
2532 #endif
2633
2734 /*****************************************************************************/
@@ -29,7 +36,12 @@ extern "C" {
2936 struct Cin_LoaderData {
3037 struct Cin_LoaderData *next;
3138 unsigned len;
39+#ifdef CIN_SOFT_USE_DATA_FIELD
3240 unsigned char data[];
41+#define CIN_SOFT_LOADER_DATA(LD) ((LD)->data)
42+#else
43+#define CIN_SOFT_LOADER_DATA(LD) ((unsigned char *)((LD)+1))
44+#endif
3345 };
3446
3547 /*****************************************************************************/
--- a/src/common/nmakefile
+++ b/src/common/nmakefile
@@ -1,12 +1,23 @@
11 # Any copyright is dedicated to the Public Domain.
22 # http://creativecommons.org/publicdomain/zero/1.0/
33
4-all: cin_common.lib
4+common: cin_common.lib
5+mixer: cin_mixer.lib
56
6-OBJECTS=cin_soft_loader.obj
7-
8-cin_common.lib: $(OBJECTS)
9- lib $(LIBFLAGS) /OUT:cin_common.lib $(OBJECTS)
7+cin_common.lib: cin_soft_loader.obj
8+ lib $(LIBFLAGS) /OUT:cin_common.lib cin_soft_loader.obj
109
1110 cin_soft_loader.obj: cin_soft_loader.c cin_soft_loader.h
1211 cl $(CLFLAGS) cin_soft_loader.c
12+
13+
14+MIXER_OBJECTS=cin_mixer_sound.obj cin_dsp.obj
15+
16+cin_mixer.lib: $(MIXER_OBJECTS)
17+ lib $(LIBFLAGS) /OUT:cin_mixer.lib $(MIXER_OBJECTS)
18+
19+cin_mixer_sound.obj: cin_mixer_sound.c cin_mixer_sound.h cin_dsp.h ..\cin_export.h ..\cin_format.h
20+ cl $(CLFLAGS) cin_mixer_sound.c
21+
22+cin_dsp.obj: cin_dsp.cpp cin_dsp.h
23+ cl $(CLFLAGS) cin_dsp.cpp
--- /dev/null
+++ b/src/gcc.mk
@@ -0,0 +1,15 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+# GCC optoins for compilation.
5+
6+CIN_FPICFLAGS?= -fPIC
7+CIN_DEBUGFLAGS?= -g
8+CC?=gcc
9+CXX?=g++
10+CCFLAGS?=-Wall -Wextra -pedantic -Wshadow -Wenum-compare -Wno-switch $(CIN_DEBUGFLAGS) $(CIN_FPICFLAGS)
11+CFLAGS?=$(CCFLAGS) -ansi
12+CXXFLAGS?=$(CCFLAGS) -std=c++98 -fno-rtti -fno-exceptions
13+AR?=ar
14+RANLIB?=ranlib
15+LINKFLAGS?=$(CIN_DEBUGFLAGS) $(CIN_FPICFLAGS)
--- /dev/null
+++ b/src/makefile
@@ -0,0 +1,17 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+# BSD makefile
5+
6+.include "gcc.mk"
7+
8+BACKEND?=oss
9+
10+# Only OpenAL can be compiled without C++ currently.
11+.if "${BACKEND}" == "openal"
12+LINK?=$(CC)
13+.else
14+LINK=$(CXX)
15+.endif
16+
17+.include "unix.mk"
--- a/src/nmakefile
+++ b/src/nmakefile
@@ -9,7 +9,10 @@ LIBFLAGS=/NOLOGO
99 all: dsound sine_test.exe aucat.exe
1010
1111 common_lib:
12- cd common && $(MAKE) /nologo /fnmakefile CLFLAGS="$(CLFLAGS)" LIBFLAGS="$(LIBFLAGS)"
12+ cd common && $(MAKE) common /nologo /fnmakefile CLFLAGS="$(CLFLAGS)" LIBFLAGS="$(LIBFLAGS)"
13+
14+mixer_lib:
15+ cd common && $(MAKE) mixer /nologo /fnmakefile CLFLAGS="$(CLFLAGS)" LIBFLAGS="$(LIBFLAGS)"
1316
1417 dsound_lib:
1518 cd dsound && $(MAKE) /nologo /fnmakefile CLFLAGS="$(CLFLAGS)" LIBFLAGS="$(LIBFLAGS)"
--- a/src/openal/GNUmakefile
+++ b/src/openal/GNUmakefile
@@ -0,0 +1,11 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+all: libcin_openal.a
5+
6+# No need to run ranlib on a single object
7+libcin_openal.a: cin_openal.o
8+ $(AR) rc libcin_openal.a cin_openal.o
9+
10+cin_openal.o: cin_openal.c cin_openal.h
11+ $(CC) $(CFLAGS) -I"$(ROOTDIR)" -c cin_openal.c -o cin_openal.o
--- a/src/sine_test.c
+++ b/src/sine_test.c
@@ -5,9 +5,7 @@
55
66 #define _POSIX_C_SOURCE 199309L
77
8-#include "cin_driver.h"
9-#include "cin_loader.h"
10-#include "cin_sound.h"
8+#include "cinnamon.h"
119
1210 #include <assert.h>
1311 #include <stdlib.h>
--- /dev/null
+++ b/src/unix.mk
@@ -0,0 +1,45 @@
1+# Any copyright is dedicated to the Public Domain.
2+# http://creativecommons.org/publicdomain/zero/1.0/
3+
4+all: libcinnamon.a sine_test aucat
5+
6+CIN_BACKEND?=$(BACKEND)
7+
8+common_lib:
9+ $(MAKE) -C common common CC=$(CC) CFLAGS="$(CFLAGS)" AR=$(AR) RANLIB=$(RANLIB) ROOTDIR="$(CURDIR)"
10+
11+mixer_lib:
12+ $(MAKE) -C common mixer CC=$(CC) CFLAGS="$(CFLAGS)" AR=$(AR) RANLIB=$(RANLIB) ROOTDIR="$(CURDIR)"
13+
14+openal_lib:
15+ $(MAKE) -C openal CC=$(CC) CFLAGS="$(CFLAGS)" AR=$(AR) RANLIB=$(RANLIB) ROOTDIR="$(CURDIR)"
16+
17+oss_lib: mixer_lib common_lib
18+ $(MAKE) -C oss CC=$(CC) CFLAGS="$(CFLAGS)" AR=$(AR) RANLIB=$(RANLIB) ROOTDIR="$(CURDIR)"
19+
20+libcinnamon.a: $(CIN_BACKEND)_lib
21+ cp $(CIN_BACKEND)/libcin_$(CIN_BACKEND).a libcinnamon.a
22+
23+sine_test.o: sine_test.c cinnamon.h cin_export.h cin_format.h
24+ $(CC) $(CFLAGS) -c sine_test.c -o sine_test.o
25+
26+aucat.o: aucat.c cinnamon.h cin_export.h cin_format.h
27+ $(CC) $(CFLAGS) -c aucat.c -o aucat.o
28+
29+sine_test: libcinnamon.a sine_test.o
30+ $(LINK) sine_test.o libcinnamon.a -o sine_test
31+
32+aucat: libcinnamon.a aucat.o
33+ $(LINK) aucat.o libcinnamon.a -o aucat
34+
35+clean:
36+ rm *.o 2> /dev/null || true
37+ rm *.a 2> /dev/null || true
38+ rm *.exe 2> /dev/null || true # For cygwin
39+ rm */*.a 2> /dev/null || true
40+ rm */*.o 2> /dev/null || true
41+ rm */*.so 2> /dev/null || true
42+
43+.PHONY: openal_lib oss_lib mixer_lib common_lib clean
44+.SILENT: clean
45+.IGNORE: clean
Show on old repository browser