Skip to content

Commit

Permalink
[WIP] Switch to PortAudio
Browse files Browse the repository at this point in the history
Switch to PortAudio for cross-platform and cross backend compatibility.
There are two limitations:
1. The last period of sound is lost.
2. You cannot play sound twice or the device will crash thus
whole system crashes.
  • Loading branch information
Cuda-Chen committed Feb 23, 2025
1 parent b42df15 commit fd58de0
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 170 deletions.
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
35 changes: 20 additions & 15 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 @@ -70,22 +70,27 @@ $(call set-feature, VIRTIOSND)
ifeq ($(call has, VIRTIOSND), 1)
OBJS_EXTRA += virtio-snd.o

LDFLAGS += -lasound -lpthread
CFLAGS += -Icnfa

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
PORTAUDIOLIB := portaudio/lib/.libs/libportaudio.a
# 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 += $(PORTAUDIOLIB) -lasound -lpthread -lrt -lpulse
CFLAGS += -Iportaudio/include

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
1 change: 0 additions & 1 deletion cnfa
Submodule cnfa deleted from 60bcdd
1 change: 1 addition & 0 deletions portaudio
Submodule portaudio added at e97eff
Loading

0 comments on commit fd58de0

Please sign in to comment.