Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Switch to PortAudio #76

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[submodule "cnfa"]
path = cnfa
url = https://github.com/cntools/cnfa
shallow = true
[submodule "mini-gdbstub"]
path = mini-gdbstub
url = https://github.com/RinHizakura/mini-gdbstub
shallow = true
[submodule "portaudio"]
path = portaudio
url = https://github.com/PortAudio/portaudio
shallow = true
58 changes: 41 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ OBJS_EXTRA :=
# command line option
OPTS :=

LDFLAGS := -lm
LDFLAGS :=

# virtio-blk
ENABLE_VIRTIOBLK ?= 1
Expand Down Expand Up @@ -55,37 +55,61 @@ endif

# virtio-snd
ENABLE_VIRTIOSND ?= 1
ifneq ($(UNAME_S),$(filter $(UNAME_S),Linux))
ifneq ($(UNAME_S),$(filter $(UNAME_S),Linux Darwin))
ENABLE_VIRTIOSND := 0
endif

# Check ALSA installation
ifeq ($(UNAME_S),Linux)
# Check ALSA installation
ifeq (0, $(call check-alsa))
$(warning No libasound installed. Check libasound in advance.)
ENABLE_VIRTIOSND := 0
endif
endif
ifeq ($(UNAME_S),Darwin)
ifeq (0, $(call check-ca))
$(warning No CoreAudio installed Check AudioToolbox in advance.)
ENABLE_VIRTIOSND := 0
endif
endif
$(call set-feature, VIRTIOSND)
ifeq ($(call has, VIRTIOSND), 1)
OBJS_EXTRA += virtio-snd.o

LDFLAGS += -lasound -lpthread
CFLAGS += -Icnfa
PORTAUDIOLIB := portaudio/lib/.libs/libportaudio.a
LDFLAGS += $(PORTAUDIOLIB)

cnfa/Makefile:
git submodule update --init cnfa
cnfa/os_generic: cnfa/Makefile
$(MAKE) -C $(dir $<) os_generic.h
CNFA_LIB := cnfa/CNFA_sf.h
$(CNFA_LIB): cnfa/Makefile cnfa/os_generic
$(MAKE) -C $(dir $<) CNFA_sf.h
main.o: $(CNFA_LIB)

# suppress warning when compiling CNFA
virtio-snd.o: CFLAGS += -Wno-unused-parameter -Wno-sign-compare
ifeq ($(UNAME_S),Linux)
LDFLAGS += -lasound -lrt
# Check PulseAudio installation
ifeq (1, $(call check-pa))
LDFLAGS += -lpulse
endif
endif
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -framework CoreServices -framework CoreFoundation -framework AudioUnit -framework AudioToolbox -framework CoreAudio
endif

CFLAGS += -Iportaudio/include
# PortAudio requires libm, yet we set -lm in the end of LDFLAGS
# so that the other libraries will be benefited for no need to set
# -lm separately.
LDFLAGS += -lpthread

portaudio/Makefile:
git submodule update --init portaudio
$(PORTAUDIOLIB): portaudio/Makefile
@cd $(dir $<) && ./configure
@cd $(dir $<) && $(MAKE)
main.o: $(PORTAUDIOLIB)

# suppress warning when compiling PortAudio
virtio-snd.o: CFLAGS += -Wno-unused-parameter
endif

# Set libm as the last dependency so that no need to set -lm seperately.
LDFLAGS += -lm

# .DEFAULT_GOAL should be set to all since the very first target is not all
# after git submodule.
.DEFAULT_GOAL := all
Expand Down Expand Up @@ -115,7 +139,7 @@ $(OBJS): $(GDBSTUB_LIB)

$(BIN): $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
$(CC) -o $@ $^ $(LDFLAGS)

%.o: %.c
$(VECHO) " CC\t$@\n"
Expand Down
1 change: 0 additions & 1 deletion cnfa
Submodule cnfa deleted from 60bcdd
35 changes: 35 additions & 0 deletions mk/check-libs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,43 @@ int main(){\n\
}\n'
endef

# Create a mininal PulseAudio program
define create-pa-prog
echo '\
#include <pulse/pulseaudio.h>\n\
int main(){\n\
pa_mainloop *m = NULL;\n\
pa_mainloop_free(m);\n\
return 0;\n\
}\n'
endef

# Create a mininal CoreAudio program
define create-ca-prog
echo '\
#include <CoreAudio/CoreAudio.h>\n\
#include <AudioToolbox/AudioQueue.h>
int main(){\n\
AudioQueueRef queue;\n\
AudioQueueDispose(queue, TRUE);\n\
return 0;\n\
}\n'
endef

# Check ALSA installation
define check-alsa
$(shell $(call create-alsa-prog) | $(CC) -x c -lasound -o /dev/null > /dev/null 2> /dev/null -
&& echo $$?)
endef

# Check PulseAudio installation
define check-pa
$(shell $(call create-pa-prog) | $(CC) -x c -lpulse -o /dev/null > /dev/null 2> /dev/null -
&& echo 0 || echo 1)
endef

# Check CoreAudio installation
define check-ca
$(shell $(call create-ca-prog) | $(CC) -x c -framework AudioToolbox -o /dev/null > /dev/null 2> /dev/null -
&& echo $$?)
endef
1 change: 1 addition & 0 deletions portaudio
Submodule portaudio added at e97eff
Loading
Loading