Skip to content

πŸŽ› πŸ”Š A Python library for audio.

More Ubuntu carve-outs.

Peter Sobot0211aaf32c9c
diff --git a/pedalboard/io/AudioStream.h b/pedalboard/io/AudioStream.h
index 1a91718..6e5baaf 100644
--- a/pedalboard/io/AudioStream.h
+++ b/pedalboard/io/AudioStream.h
@@ -34,15 +34,22 @@ namespace py = pybind11;
namespace Pedalboard {
+class AudioStream : public std::enable_shared_from_this<AudioStream>
#ifdef JUCE_MODULE_AVAILABLE_juce_audio_devices
-class AudioStream : public std::enable_shared_from_this<AudioStream>,
- public juce::AudioIODeviceCallback {
+ ,
+ public juce::AudioIODeviceCallback
+#endif
+{
public:
AudioStream(std::string inputDeviceName, std::string outputDeviceName,
double sampleRate, int bufferSize)
+#ifdef JUCE_MODULE_AVAILABLE_juce_audio_devices
: pedalboard(
std::make_shared<Chain>(std::vector<std::shared_ptr<Plugin>>())),
- livePedalboard(std::vector<std::shared_ptr<Plugin>>()) {
+ livePedalboard(std::vector<std::shared_ptr<Plugin>>())
+#endif
+ {
+#ifdef JUCE_MODULE_AVAILABLE_juce_audio_devices
juce::AudioDeviceManager::AudioDeviceSetup setup;
setup.inputDeviceName = inputDeviceName;
setup.outputDeviceName = outputDeviceName;
@@ -55,8 +62,12 @@ public:
if (!error.isEmpty()) {
throw std::domain_error(error.toStdString());
}
+#else
+ throw std::runtime_error("AudioStream is not supported on this platform.");
+#endif
}
+#ifdef JUCE_MODULE_AVAILABLE_juce_audio_devices
~AudioStream() {
stop();
close();
@@ -199,21 +210,25 @@ private:
// happen in Python) and copies those changes over to data
// structures used by the audio thread.
std::thread changeObserverThread;
+#endif
};
inline void init_audio_stream(py::module &m) {
- py::class_<AudioStream, std::shared_ptr<AudioStream>>(
- m, "AudioStream",
- "A class that pipes audio from an input device to an output device, "
- "passing it through a Pedalboard to add effects.")
- .def(
- py::init([](std::string inputDeviceName, std::string outputDeviceName,
- double sampleRate, int bufferSize) {
- return std::make_shared<AudioStream>(
- inputDeviceName, outputDeviceName, sampleRate, bufferSize);
- }),
- py::arg("input_device_name"), py::arg("output_device_name"),
- py::arg("sample_rate") = 44100, py::arg("buffer_size") = 512)
+ auto audioStream =
+ py::class_<AudioStream, std::shared_ptr<AudioStream>>(
+ m, "AudioStream",
+ "A class that pipes audio from an input device to an output device, "
+ "passing it through a Pedalboard to add effects.")
+ .def(py::init([](std::string inputDeviceName,
+ std::string outputDeviceName, double sampleRate,
+ int bufferSize) {
+ return std::make_shared<AudioStream>(
+ inputDeviceName, outputDeviceName, sampleRate, bufferSize);
+ }),
+ py::arg("input_device_name"), py::arg("output_device_name"),
+ py::arg("sample_rate") = 44100, py::arg("buffer_size") = 512);
+#ifdef JUCE_MODULE_AVAILABLE_juce_audio_devices
+ audioStream
.def("stream", &AudioStream::stream,
"Stream audio from input to output, through the `plugins` on this "
"AudioStream object, until a KeyboardInterrupt is received.")
@@ -255,21 +270,6 @@ inline void init_audio_stream(py::module &m) {
"output_device_names",
[](py::object *obj) { return AudioStream::getDeviceNames(false); },
"The currently-available output device names.");
-}
-#else
-inline void init_audio_stream(py::module &m) {
- py::class_<AudioStream, std::shared_ptr<AudioStream>>(
- m, "AudioStream",
- "A class that pipes audio from an input device to an output device, "
- "passing it through a Pedalboard to add effects.")
- .def(
- py::init([](std::string inputDeviceName, std::string outputDeviceName,
- double sampleRate, int bufferSize) {
- throw std::runtime_error(
- "AudioStream is not yet supported on this operating system.");
- }),
- py::arg("input_device_name"), py::arg("output_device_name"),
- py::arg("sample_rate") = 44100, py::arg("buffer_size") = 512);
-}
#endif
+}
} // namespace Pedalboard
\ No newline at end of file