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

Add PulseAudio support #194

Merged
merged 96 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
80177ff
WIP for refactoring of PortAudio specific code.
tmiw Dec 19, 2021
45d3193
Add callback handlers for events the main code will need to handle.
tmiw Dec 19, 2021
645313d
Add PortAudio device implementation.
tmiw Dec 19, 2021
b77b126
Add support for getting errors back from PortAudio.
tmiw Dec 19, 2021
ab169d9
Add error handling and engine factory.
tmiw Dec 20, 2021
bb543e6
Use new audio API for the audio options dialog.
tmiw Dec 20, 2021
ed2b88d
Move supported sample rate detection to a new method to avoid perform…
tmiw Dec 20, 2021
cd654b4
Switch main audio pipeline to IAudioEngine.
tmiw Dec 21, 2021
be30f01
Use high latency and mutexes for audio devices and FIFOs.
tmiw Dec 21, 2021
b5a71c2
Remove PortAudio specific configuration settings.
tmiw Dec 21, 2021
1f533fd
Rename g_PAstatus->g_AEstatus.
tmiw Dec 21, 2021
624f3da
Remove unnecessary FIFO mutexes.
tmiw Dec 21, 2021
ab0ec85
Fix typo preventing RX.
tmiw Dec 21, 2021
54b4c7c
Add CMake infrastructure to support PulseAudio linkage.
tmiw Dec 22, 2021
fff5593
Initial PulseAudio code files.
tmiw Dec 22, 2021
6453e9b
WIP towards resolving crashes.
tmiw Dec 22, 2021
d52f13d
Resolve buffer overflow with PulseAudio.
tmiw Dec 22, 2021
02b1bd6
Add user friendly descriptions for pavucontrol.
tmiw Dec 22, 2021
3e6fbc6
Fix GitHub automated build.
tmiw Dec 22, 2021
83dceec
fix some warning building on gcc 9.3.0
drowe67 Dec 22, 2021
5be7f35
Resolve issue with sample .wav files playing 2x as fast as expeted wi…
tmiw Dec 22, 2021
d584579
Fix noise and plot weirdness in audio config.
tmiw Dec 23, 2021
4b28f79
Fix timing issue for audio config plots.
tmiw Dec 23, 2021
e04d24c
Resolve PulseAudio related memory leaks.
tmiw Dec 23, 2021
b25ac24
Minor read tweak.
tmiw Dec 24, 2021
cdaa0e2
Prevent adjustments of FreeDV audio settings by third party apps.
tmiw Dec 25, 2021
17d0cb0
Update build_linux script to use PulseAudio.
tmiw Dec 25, 2021
c0df1e8
Add PulseAudio to GitHub workflow.
tmiw Dec 25, 2021
47d5b60
Modify README to include required Linux packages for PulseAudio.
tmiw Dec 25, 2021
d05ca3c
Fix Windows build issues.
tmiw Dec 25, 2021
18b441c
Go back to codec2 master for macOS builds.
tmiw Dec 25, 2021
988ee5c
Back out Windows changes that didn't work.
tmiw Dec 25, 2021
6de7615
Use PulseAudio recommended maxlength.
tmiw Dec 25, 2021
1d16d15
Merge branch 'ms-pulseaudio' of github.com:drowe67/freedv-gui into ms…
tmiw Dec 25, 2021
d3dbf9d
Warning cleanup.
tmiw Dec 25, 2021
ce07637
Move adding of plot samples to the GUI thread.
tmiw Dec 25, 2021
dfdf417
Apply in Audio Options should not stop the audio engine.
tmiw Dec 25, 2021
be43831
Resolve codec2 build issues in MinGW Docker container.
tmiw Dec 25, 2021
a0722fe
Reenable and actually handle when pavucontrol changes devices.
tmiw Dec 25, 2021
daeef19
Fix compile and logic bugs from the previous commit.
tmiw Dec 25, 2021
296933d
CPack packages should depend on PulseAudio if compiled for it.
tmiw Dec 25, 2021
8bd6ece
Fix typo during initialization.
tmiw Dec 26, 2021
2fd647e
Forgot to fix additional typo during initialization.
tmiw Dec 26, 2021
5c4e410
Minor cleanup.
tmiw Dec 26, 2021
8816933
Trim whitespace in sound device names.
tmiw Dec 27, 2021
f77a56a
Remove strict 20ms wait and replace with notification of TX/RX thread…
tmiw Dec 27, 2021
27797b1
Change version number for testing.
tmiw Dec 27, 2021
b38765e
Add logging to see if we time out while waiting for audio.
tmiw Dec 27, 2021
a210b0a
Start/stop sound devices after threads start/stop.
tmiw Dec 27, 2021
9efa837
Create FIFOs for TX only if enabled.
tmiw Dec 28, 2021
d14f6a6
Fragment size should match target size.
tmiw Dec 28, 2021
80c25ae
Prevent segfault if more than one thread executes stopRxStream at the…
tmiw Dec 28, 2021
bc33356
Merge branch 'master' into ms-pulseaudio
tmiw Dec 29, 2021
7d62fdd
Auto-build both PulseAudio and PortAudio variants on PR push.
tmiw Dec 31, 2021
0e1de24
Resolve PortAudio related compiler errors.
tmiw Dec 31, 2021
8b6b72f
Ensure that PulseAudio stream termination is synchronous to avoid ref…
tmiw Dec 31, 2021
ea616b7
Set TX and RX thread pointers to default values.
tmiw Dec 31, 2021
5ecb957
Warning removal inside PulseAudioEngine.
tmiw Dec 31, 2021
8e5981e
Resolve UTF8 encoding issue with audio device names.
tmiw Jan 1, 2022
df63b02
Resolve PulseAudio compiler errors.
tmiw Jan 1, 2022
cb92b39
Stop trimming sound device names.
tmiw Jan 2, 2022
36c6b73
Remove unneeded/interfering wxString/std::string conversions.
tmiw Jan 2, 2022
e7b5ad9
Merge branch 'master' into ms-pulseaudio
tmiw Jan 2, 2022
d297709
Update README to describe PortAudio and PulseAudio variants for Linux.
tmiw Jan 2, 2022
147109b
latest user manual PDF
tmiw Jan 2, 2022
5ee658e
Merge branch 'master' into ms-pulseaudio
tmiw Jan 7, 2022
f7ece75
Bump version to 1.7.0.
tmiw Jan 7, 2022
4f2667a
latest user manual PDF
tmiw Jan 7, 2022
32c4376
Always include patch version in version string.
tmiw Jan 7, 2022
ca8a0d6
Bring over PA_FPB value from previous implementation instead of using 0.
tmiw Jan 12, 2022
d0b6ea7
Suppress spurious timeout messages during start/stop.
tmiw Jan 12, 2022
0e3e18e
Merge branch 'master' into ms-pulseaudio
tmiw Jan 12, 2022
ff88cf1
Create data collection thread so that PulseAudioEngine's behavior is …
tmiw Jan 13, 2022
9d24a41
Additional tuning to make PipeWire work correctly.
tmiw Jan 13, 2022
b396254
Cap pending data to the target latency.
tmiw Jan 13, 2022
7c9c6dd
Auto-adjust based on reported latency.
tmiw Jan 13, 2022
4261636
Ensure that latency never decreases.
tmiw Jan 13, 2022
20e3004
Fix Pulse RX decode issues by not feeding all zeroes if there's no da…
tmiw Jan 13, 2022
36c62fb
Don't start TX audio until after PTT's triggered.
tmiw Jan 13, 2022
dfbffcb
Improve PulseAudio playback quality.
tmiw Jan 14, 2022
cda9762
Revert "Don't start TX audio until after PTT's triggered."
tmiw Jan 14, 2022
fd8a8df
Clear second audio channel's memory if no data available.
tmiw Jan 14, 2022
c293da0
Oops, fix compile error.
tmiw Jan 14, 2022
5140d08
Experiment: see if we can reduce target latency.
tmiw Jan 16, 2022
3da1977
Revert "Experiment: see if we can reduce target latency."
tmiw Jan 16, 2022
1398f27
Replace fixed sleeps with condition variables for PulseAudio audio in…
tmiw Jan 20, 2022
62ddc1b
Revert "Replace fixed sleeps with condition variables for PulseAudio …
tmiw Jan 20, 2022
e1cf4ac
Refactor PulseAudio sample handling logic.
tmiw Jan 21, 2022
4b7244b
Add debugging output to determine how much buffer PulseAudio is askin…
tmiw Jan 21, 2022
3825566
Merge branch 'master' into ms-pulseaudio
tmiw Feb 5, 2022
c2a7117
Warning cleanup.
tmiw Feb 5, 2022
0551fd6
Add release notes to user manual for 1.7.0.
tmiw Feb 5, 2022
9c14527
latest user manual PDF
tmiw Feb 5, 2022
2f1bd87
Resolve merge issue causing segfaults.
tmiw Feb 5, 2022
cb33436
Merge branch 'ms-pulseaudio' of github.com:drowe67/freedv-gui into ms…
tmiw Feb 5, 2022
8f6822f
Disable extra logging of Pulse latency.
tmiw Feb 5, 2022
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
11 changes: 8 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install libspeexdsp-dev libsamplerate0-dev sox git libwxgtk3.0-gtk3-dev portaudio19-dev libhamlib-dev libasound2-dev libao-dev libgsm1-dev libsndfile-dev
sudo apt-get install libpulse-dev libspeexdsp-dev libsamplerate0-dev sox git libwxgtk3.0-gtk3-dev portaudio19-dev libhamlib-dev libasound2-dev libao-dev libgsm1-dev libsndfile-dev

- name: Build freedv-gui
- name: Build freedv-gui using PortAudio
shell: bash
working-directory: ${{github.workspace}}
run: ./build_linux.sh
run: ./build_linux.sh portaudio

- name: Build freedv-gui using PulseAudio
shell: bash
working-directory: ${{github.workspace}}
run: ./build_linux.sh pulseaudio
37 changes: 30 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ message(STATUS "Compilation date = XX${DATE_RESULT}XX")
#
set(FREEDV_VERSION_MAJOR 1)
set(FREEDV_VERSION_MINOR 6)
set(FREEDV_VERSION_PATCH 1)
set(FREEDV_VERSION_SUFFIX "")
set(FREEDV_VERSION_PATCH 2)
set(FREEDV_VERSION_SUFFIX "pulseaudio-devel")
tmiw marked this conversation as resolved.
Show resolved Hide resolved

set(FREEDV_VERSION ${FREEDV_VERSION_MAJOR}.${FREEDV_VERSION_MINOR})
if(FREEDV_VERSION_PATCH)
Expand Down Expand Up @@ -122,6 +122,8 @@ set(USE_STATIC_SPEEXDSP FALSE CACHE BOOL
"Download and build static speex instead of the system library.")
set(BOOTSTRAP_WXWIDGETS FALSE CACHE BOOL
"Download and build static wxWidgets instead of the system library.")
set(USE_PULSEAUDIO FALSE CACHE BOOL
"Use PulseAudio instead of PortAudio for audio I/O.")

if(USE_STATIC_DEPS)
set(USE_STATIC_PORTAUDIO TRUE FORCE)
Expand Down Expand Up @@ -284,9 +286,9 @@ endif(CODEC2_BUILD_DIR)


#
# Find or build portaudio Library
# Find or build portaudio/PulseAudio Library
#
if(NOT USE_STATIC_PORTAUDIO)
if(NOT USE_STATIC_PORTAUDIO AND NOT USE_PULSEAUDIO)
message(STATUS "Looking for portaudio...")
find_package(portaudio-2.0 REQUIRED)
if(PORTAUDIO_FOUND)
Expand All @@ -309,10 +311,26 @@ On Windows it's easiest to use the cmake option: USE_STATIC_PORTAUDIO"
if(NOT ${PORTAUDIO_VERSION} EQUAL 19 AND NOT MINGW)
message(WARNING "Portaudio versions other than 19 are known to have issues. You have been warned!")
endif()
else(NOT USE_STATIC_PORTAUDIO)
elseif(USE_PULSEAUDIO)
message(STATUS "Finding PulseAudio...")
find_package(PulseAudio REQUIRED)
if(PULSEAUDIO_FOUND)
message(STATUS " PulseAudio library: ${PULSEAUDIO_LIBRARY}")
message(STATUS " PulseAudio headers: ${PULSEAUDIO_INCLUDE_DIR}")
list(APPEND FREEDV_LINK_LIBS ${PULSEAUDIO_LIBRARY})
include_directories(${PULSEAUDIO_INCLUDE_DIR})
add_definitions(-DAUDIO_ENGINE_PULSEAUDIO_ENABLE)
else()
message(FATAL_ERROR "PulseAudio library not found.
On Linux systems try installing:
pulseaudio-libs-devel (RPM based systems)
libpulse-dev (DEB based systems)
")
endif()
else()
message(STATUS "Will attempt static build of portaudio.")
include(cmake/Buildportaudio-2.0.cmake)
endif(NOT USE_STATIC_PORTAUDIO)
endif()

#
# Hamlib library
Expand Down Expand Up @@ -563,7 +581,12 @@ elseif(UNIX AND NOT APPLE)
# Linux packaging
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Mooneer Salem <mooneer@gmail.com>") #required
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "codec2 (>= 0.9.2), libspeexdsp1 (>= 1.2~rc1.2-1+b2), libsamplerate0 (>= 0.1.9-2), libwxgtk3.0-gtk3-0v5 (>= 3.0.4+dfsg-3), libportaudio2 (>= 19.6.0-1build1), libhamlib2 (>= 3.3-10build1), libasound2 (>= 1.1.8-1), libao4 (>= 1.2.2+20180113-1), libgsm1 (>= 1.0.18-2), libsndfile1 (>= 1.0.28-6)")
if(USE_PULSEAUDIO)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "codec2 (>= 1.0.0), libspeexdsp1 (>= 1.2~rc1.2-1+b2), libsamplerate0 (>= 0.1.9-2), libwxgtk3.0-gtk3-0v5 (>= 3.0.4+dfsg-3), libpulse0 (>= 14.2-2), libhamlib2 (>= 3.3-10build1), libasound2 (>= 1.1.8-1), libao4 (>= 1.2.2+20180113-1), libgsm1 (>= 1.0.18-2), libsndfile1 (>= 1.0.28-6)")
else(USE_PULSEAUDIO)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "codec2 (>= 1.0.0), libspeexdsp1 (>= 1.2~rc1.2-1+b2), libsamplerate0 (>= 0.1.9-2), libwxgtk3.0-gtk3-0v5 (>= 3.0.4+dfsg-3), libportaudio2 (>= 19.6.0-1build1), libhamlib2 (>= 3.3-10build1), libasound2 (>= 1.1.8-1), libao4 (>= 1.2.2+20180113-1), libgsm1 (>= 1.0.18-2), libsndfile1 (>= 1.0.28-6)")
endif(USE_PULSEAUDIO)

SET(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
include(CPack)

Expand Down
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This document describes how to build the FreeDV GUI program for various operatin
* [FreeDV GUI User Manual](USER_MANUAL.md)
* [Building for Windows using Docker](docker/README_docker.md)

## Building on Ubuntu Linux (16-20)
## Building on Ubuntu Linux (16-20) with PortAudio
```
$ sudo apt install libspeexdsp-dev libsamplerate0-dev sox git \
libwxgtk3.0-gtk3-dev portaudio19-dev libhamlib-dev libasound2-dev libao-dev \
libgsm1-dev libsndfile-dev cmake module-assistant build-essential
$ git clone https://github.com/drowe67/freedv-gui.git
$ cd freedv-gui
$ ./build_linux.sh
$ ./build_linux.sh portaudio
```
(For Ubuntu 20.04 the wxWidgets package is named `libwxgtk3.0-gtk3-dev`.)

Expand All @@ -26,21 +26,54 @@ This document describes how to build the FreeDV GUI program for various operatin

Note this builds all libraries locally, nothing is installed on your machine. ```make install``` is not required.

## Building on Fedora Linux
## Building on Fedora Linux with PortAudio
```
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf install cmake wxGTK3-devel portaudio-devel libsamplerate-devel \
libsndfile-devel speexdsp-devel hamlib-devel alsa-lib-devel libao-devel \
gsm-devel
$ git clone https://github.com/drowe67/freedv-gui.git
$ cd freedv-gui
$ ./build_linux.sh
$ ./build_linux.sh portaudio
```
Then run with:
```
$ ./build_linux/src/freedv
```

## Building on Ubuntu Linux (16-20) with PulseAudio
```
$ sudo apt install libspeexdsp-dev libsamplerate0-dev sox git \
libwxgtk3.0-gtk3-dev libhamlib-dev libasound2-dev libao-dev \
libgsm1-dev libsndfile-dev cmake module-assistant build-essential libpulse-dev
$ git clone https://github.com/drowe67/freedv-gui.git
$ cd freedv-gui
$ ./build_linux.sh pulseaudio
```
(For Ubuntu 20.04 the wxWidgets package is named `libwxgtk3.0-gtk3-dev`.)

Then run with:
```
$ ./build_linux/src/freedv
```

Note this builds all libraries locally, nothing is installed on your machine. ```make install``` is not required.

## Building on Fedora Linux with PulseAudio
```
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf install cmake wxGTK3-devel libsamplerate-devel \
libsndfile-devel speexdsp-devel hamlib-devel alsa-lib-devel libao-devel \
gsm-devel pulseaudio-libs-devel
$ git clone https://github.com/drowe67/freedv-gui.git
$ cd freedv-gui
$ ./build_linux.sh pulseaudio
```
Then run with:
```
$ ./build_linux/src/freedv
```

## Installing on Linux

You need to install the codec2 and lpcnetfreedv shared libraries, and freedv-gui:
Expand Down Expand Up @@ -130,7 +163,7 @@ Testing FreeDV API:
$ play -t .s16 -r 16000 -b 16 out.raw
```

## Building and installing on OSX
## Building and installing on macOS

Please see [README.osx](README.osx).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drowe67, do we still support FreeBSD at all? Should I spin up a VM with it here and do some tests?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gosh I'm not sure. Sure, if you like, give it a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work for decoding .wav files in single sound card mode:

Screen Shot 2022-01-02 at 10 04 18 PM

I didn't try to set up hamlib or a second sound card to test TX, though. Plus LPCNet spit out some errors about /proc/cpuinfo not existing during cmake and incorrectly assumed there was no AVX support.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(BTW, build_linux.sh worked on FreeBSD as well once I installed the needed packages using pkg and from Ports.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's quite impressive! I guess it shows what we have is quite portable ...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the only finishing touch is a BSD version of detecting AVX.

Expand Down
Binary file modified USER_MANUAL.pdf
Binary file not shown.
14 changes: 12 additions & 2 deletions build_linux.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/usr/bin/env bash
# build_ubuntu.sh
# build_linux.sh
#
# Build script for Ubuntu and Fedora Linux, git pulls codec2 and
# lpcnet repos so they are available for parallel development.

# Echo what you are doing, and fail if any of the steps fail:
set -x -e

# Allow building of either PulseAudio or PortAudio variants
FREEDV_VARIANT=${1:-portaudio}
if [[ "$FREEDV_VARIANT" != "portaudio" && "$FREEDV_VARIANT" != "pulseaudio" ]]; then
echo "Usage: build_linux.sh [portaudio|pulseaudio]"
exit -1
fi

export FREEDVGUIDIR=${PWD}
export CODEC2DIR=$FREEDVGUIDIR/codec2
export LPCNETDIR=$FREEDVGUIDIR/LPCNet
Expand Down Expand Up @@ -46,5 +53,8 @@ export LD_LIBRARY_PATH=$LPCNETDIR/build_linux/src
# Finally, build freedv-gui
cd $FREEDVGUIDIR && git pull
mkdir -p build_linux && cd build_linux && rm -Rf *
cmake -DCMAKE_BUILD_TYPE=Debug -DCODEC2_BUILD_DIR=$CODEC2DIR/build_linux -DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux ..
if [[ "$FREEDV_VARIANT" == "pulseaudio" ]]; then
PULSEAUDIO_PARAM="-DUSE_PULSEAUDIO=1"
fi
cmake $PULSEAUDIO_PARAM -DCMAKE_BUILD_TYPE=Debug -DCODEC2_BUILD_DIR=$CODEC2DIR/build_linux -DLPCNET_BUILD_DIR=$LPCNETDIR/build_linux ..
make VERBOSE=1
2 changes: 1 addition & 1 deletion build_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cd $FREEDVGUIDIR
if [ ! -d codec2 ]; then
git clone https://github.com/drowe67/codec2.git
fi
cd codec2 && git checkout ms-reliable-text && git pull
cd codec2 && git checkout master && git pull
mkdir -p build_osx && cd build_osx && rm -Rf * && cmake -DBUILD_OSX_UNIVERSAL=1 .. && make -j4

# OK, build and test LPCNet
Expand Down
2 changes: 1 addition & 1 deletion docker/fdv_win_fedora/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM fedora:${FED_REL}
# tar: bzip2
# arm-none-eabi-gdb: ncurses-compat-libs

RUN dnf -y install --setopt=install_weak_deps=False @development-tools cmake git speexdsp-devel libsamplerate-devel octave octave-signal gnuplot sox python3-numpy automake libtool libusb1-devel wget bc glibc.i686 which bzip2 ncurses-compat-libs && useradd -m build
RUN dnf -y install --setopt=install_weak_deps=False @development-tools cmake git speexdsp-devel libsamplerate-devel octave octave-signal gnuplot sox python3-numpy automake libtool libusb1-devel wget bc glibc.i686 which bzip2 ncurses-compat-libs gcc gcc-c++ && useradd -m build

# specific for windows mingw build
RUN dnf install -y dnf-plugins-core
Expand Down
9 changes: 5 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set(FREEDV_SOURCES
dlg_options.cpp
dlg_ptt.cpp
main.cpp
pa_wrapper.cpp
plot.cpp
plot_scalar.cpp
plot_scatter.cpp
Expand All @@ -21,7 +20,6 @@ set(FREEDV_SOURCES
dlg_ptt.h
defines.h
main.h
pa_wrapper.h
plot.h
plot_scalar.h
plot_scatter.h
Expand Down Expand Up @@ -67,6 +65,9 @@ set(FREEDV_LINK_LIBS_OSX
"-framework AVFoundation"
)

# Compile FreeDV components
add_subdirectory(audio)

# WIN32 is needed for Windows GUI apps and is ignored for UNIX like systems.
# In addition, there are some required OSX-specific code files for platform specific handling.
if(APPLE)
Expand All @@ -90,9 +91,9 @@ endif(APPLE)

# Link imported or build tree targets.
if(APPLE)
target_link_libraries(FreeDV codec2 lpcnetfreedv)
target_link_libraries(FreeDV codec2 lpcnetfreedv fdv_audio)
else(APPLE)
target_link_libraries(freedv codec2 lpcnetfreedv)
target_link_libraries(freedv codec2 lpcnetfreedv fdv_audio)
endif(APPLE)

# Add build dependencies for interally built external libraries.
Expand Down
37 changes: 37 additions & 0 deletions src/audio/AudioDeviceSpecification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//=========================================================================
// Name: AudioDeviceSpecification.cpp
// Purpose: Describes an audio device on the user's system.
//
// Authors: Mooneer Salem
// License:
//
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.1,
// as published by the Free Software Foundation. This program is
// distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//=========================================================================

#include "AudioDeviceSpecification.h"

bool AudioDeviceSpecification::isValid() const
{
return deviceId != -1;
}

AudioDeviceSpecification AudioDeviceSpecification::GetInvalidDevice()
{
AudioDeviceSpecification result = {
.deviceId = -1
};

return result;
}
41 changes: 41 additions & 0 deletions src/audio/AudioDeviceSpecification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//=========================================================================
// Name: AudioDeviceSpecification.h
// Purpose: Describes an audio device on the user's system.
//
// Authors: Mooneer Salem
// License:
//
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.1,
// as published by the Free Software Foundation. This program is
// distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//=========================================================================

#ifndef AUDIO_DEVICE_SPECIFICATION_H
#define AUDIO_DEVICE_SPECIFICATION_H

#include <wx/string.h>
#include <vector>

struct AudioDeviceSpecification
{
int deviceId;
wxString name;
wxString apiName;
int defaultSampleRate;
int maxChannels;

bool isValid() const;
static AudioDeviceSpecification GetInvalidDevice();
};

#endif // AUDIO_DEVICE_SPECIFICATION_H
44 changes: 44 additions & 0 deletions src/audio/AudioEngineFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//=========================================================================
// Name: AudioEngineFactory.cpp
// Purpose: Creates AudioEngines for the current platform.
//
// Authors: Mooneer Salem
// License:
//
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.1,
// as published by the Free Software Foundation. This program is
// distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//=========================================================================

#include "AudioEngineFactory.h"
#if defined(AUDIO_ENGINE_PULSEAUDIO_ENABLE)
#include "PulseAudioEngine.h"
#else
#include "PortAudioEngine.h"
#endif // defined(AUDIO_ENGINE_PULSEAUDIO_ENABLE)

std::shared_ptr<IAudioEngine> AudioEngineFactory::SystemEngine_;

std::shared_ptr<IAudioEngine> AudioEngineFactory::GetAudioEngine()
{
if (!SystemEngine_)
{
#if defined(AUDIO_ENGINE_PULSEAUDIO_ENABLE)
SystemEngine_ = std::shared_ptr<IAudioEngine>(new PulseAudioEngine());
#else
SystemEngine_ = std::shared_ptr<IAudioEngine>(new PortAudioEngine());
#endif // defined(AUDIO_ENGINE_PULSEAUDIO_ENABLE)
}

return SystemEngine_;
}
Loading