Skip to content

Commit

Permalink
miniaudio: Further integration; retire old audio hardware layers
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Oct 21, 2024
1 parent f6f827f commit 6ac2efa
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 658 deletions.
10 changes: 6 additions & 4 deletions source/include/signalflow/node/io/input/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

namespace signalflow
{

class AudioIn_Abstract : public Node
{
public:
AudioIn_Abstract();

virtual int init() = 0;
virtual int start() = 0;
virtual int stop() = 0;
virtual int destroy() = 0;
virtual void init() = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual void destroy() = 0;

virtual void process(Buffer &out, int num_samples) = 0;
};

}
17 changes: 7 additions & 10 deletions source/include/signalflow/node/io/input/miniaudio.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#define AudioIn AudioIn_MiniAudio

#include <soundio/soundio.h>
#include <vector>

#include "abstract.h"
Expand All @@ -13,15 +10,15 @@
namespace signalflow
{

class AudioIn_MiniAudio : public AudioIn_Abstract
class AudioIn : public AudioIn_Abstract
{
public:
AudioIn_MiniAudio(unsigned int num_channels = 1);
virtual ~AudioIn_MiniAudio() override;
virtual int init() override;
virtual int start() override;
virtual int stop() override;
virtual int destroy() override;
AudioIn(unsigned int num_channels = 1);
virtual ~AudioIn() override;
virtual void init() override;
virtual void start() override;
virtual void stop() override;
virtual void destroy() override;
virtual void process(Buffer &out, int num_samples) override;

private:
Expand Down
40 changes: 0 additions & 40 deletions source/include/signalflow/node/io/input/soundio.h

This file was deleted.

8 changes: 4 additions & 4 deletions source/include/signalflow/node/io/output/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class AudioOut_Abstract : public Node
AudioOut_Abstract();
virtual void process(Buffer &out, int num_samples);

virtual int init() = 0;
virtual int start() = 0;
virtual int stop() = 0;
virtual int destroy() = 0;
virtual void init() = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual void destroy() = 0;

virtual void add_input(NodeRef node);
virtual void remove_input(NodeRef node);
Expand Down
8 changes: 4 additions & 4 deletions source/include/signalflow/node/io/output/dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class AudioOut_Dummy : public AudioOut_Abstract
public:
AudioOut_Dummy(int num_channels = 2, int buffer_size = 256);

virtual int init() { return 0; }
virtual int start() { return 0; }
virtual int stop() { return 0; }
virtual int destroy() { return 0; }
virtual void init() {}
virtual void start() {}
virtual void stop() {}
virtual void destroy() {}
};

REGISTER(AudioOut_Dummy, "audioout-dummy")
Expand Down
33 changes: 0 additions & 33 deletions source/include/signalflow/node/io/output/ios.h

This file was deleted.

26 changes: 14 additions & 12 deletions source/include/signalflow/node/io/output/miniaudio.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#define AudioOut AudioOut_MiniAudio

#include <soundio/soundio.h>
#include <vector>

Expand All @@ -14,24 +12,28 @@
namespace signalflow
{

class AudioOut_MiniAudio : public AudioOut_Abstract
class AudioOut : public AudioOut_Abstract
{
public:
AudioOut_MiniAudio(const std::string &backend_name = "",
const std::string &device_name = "",
unsigned int sample_rate = 0,
unsigned int buffer_size = 0);
AudioOut(const std::string &backend_name = "",
const std::string &device_name = "",
unsigned int sample_rate = 0,
unsigned int buffer_size = 0);

virtual int init() override;
virtual int start() override;
virtual int stop() override;
virtual int destroy() override;
virtual void init() override;
virtual void start() override;
virtual void stop() override;
virtual void destroy() override;

std::list<std::string> get_output_device_names();
std::list<std::string> get_output_backend_names();
int get_default_output_device_index();

private:
/*--------------------------------------------------------------------------------
* Initialise a new miniaudio context, using the specified backend name if
* present, or the default backend otherwise.
*-------------------------------------------------------------------------------*/
void init_context(ma_context *context);

std::string backend_name;
Expand All @@ -40,6 +42,6 @@ class AudioOut_MiniAudio : public AudioOut_Abstract
ma_device device;
};

REGISTER(AudioOut_MiniAudio, "audioout-miniaudio")
REGISTER(AudioOut, "audioout")

} // namespace signalflow
48 changes: 0 additions & 48 deletions source/include/signalflow/node/io/output/soundio.h

This file was deleted.

1 change: 0 additions & 1 deletion source/include/signalflow/signalflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#include <signalflow/node/io/input/miniaudio.h>
#include <signalflow/node/io/output/abstract.h>
#include <signalflow/node/io/output/dummy.h>
#include <signalflow/node/io/output/ios.h>
#include <signalflow/node/io/output/miniaudio.h>

/*------------------------------------------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions source/src/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "signalflow/core/graph.h"
#include "signalflow/node/io/output/abstract.h"
#include "signalflow/node/io/output/dummy.h"
#include "signalflow/node/io/output/ios.h"
#include "signalflow/node/io/output/miniaudio.h"
#include "signalflow/node/node.h"
#include "signalflow/node/oscillators/constant.h"
Expand Down Expand Up @@ -49,7 +48,7 @@ AudioGraph::AudioGraph(AudioGraphConfig *config, std::string output_device, bool
this->config = *config;
}

if (output_device == "dummy")
if (output_device == "dummy" || this->config.get_output_device_name() == "dummy")
{
this->output = new AudioOut_Dummy();
}
Expand Down Expand Up @@ -590,13 +589,13 @@ std::list<NodeRef> AudioGraph::get_outputs()

std::list<std::string> AudioGraph::get_output_device_names()
{
AudioOut_MiniAudio *output = (AudioOut_MiniAudio *) (this->output.get());
AudioOut *output = (AudioOut *) (this->output.get());
return output->get_output_device_names();
}

std::list<std::string> AudioGraph::get_output_backend_names()
{
AudioOut_MiniAudio *output = (AudioOut_MiniAudio *) (this->output.get());
AudioOut *output = (AudioOut *) (this->output.get());
return output->get_output_backend_names();
}

Expand Down
6 changes: 0 additions & 6 deletions source/src/node/io/input/abstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

namespace signalflow
{
AudioIn_Abstract *shared_in = nullptr;

AudioIn_Abstract::AudioIn_Abstract()
{
if (shared_in)
throw std::runtime_error("Multiple AudioIn nodes are not yet supported.");

shared_in = this;

this->name = "audioin";
this->set_channels(0, 1);
}
Expand Down
Loading

0 comments on commit 6ac2efa

Please sign in to comment.