gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

fakeAudioDevice.h (3171B)


      1 #pragma once
      2 
      3 #include "JuceHeader.h"
      4 
      5 class FakeAudioIODevice : public AudioIODevice
      6 {
      7 public:
      8     FakeAudioIODevice()
      9         : AudioIODevice("Fake Audio Device", "Fake Type"),
     10           m_sampleRate(44100.0),
     11           m_bufferSizeSamples(512),
     12           m_isOpenFlag(false),
     13           m_isPlayingFlag(false)
     14     {
     15     }
     16 
     17     StringArray getOutputChannelNames() override { return {"Output"}; }
     18     StringArray getInputChannelNames() override { return {"Input"}; }
     19 
     20     std::optional<BigInteger> getDefaultOutputChannels() const override { return BigInteger(2); }
     21     std::optional<BigInteger> getDefaultInputChannels() const override { return BigInteger(2); }
     22 
     23     Array<double> getAvailableSampleRates() override;
     24     Array<int> getAvailableBufferSizes() override;
     25 
     26     int getDefaultBufferSize() override;
     27 
     28     String open(const uint32_t& _numInputChannels,
     29                 const uint32_t& _numOutputChannels,
     30                 double _sampleRate,
     31                 int _bufferSizeSamples);
     32 
     33 	void start(AudioIODeviceCallback* _callback) override;
     34 
     35 private:
     36     String open(const BigInteger& _inputChannels,
     37                 const BigInteger& _outputChannels,
     38                 double _sampleRate,
     39                 int _bufferSizeSamples) override;
     40 
     41     void close() override { m_isOpenFlag = false; }
     42     bool isOpen() override { return m_isOpenFlag; }
     43 
     44     void stop() override;
     45 
     46     bool isPlaying() override { return m_isPlayingFlag; }
     47     String getLastError() override { return {}; }
     48 
     49     int getCurrentBufferSizeSamples() override { return m_bufferSizeSamples; }
     50     double getCurrentSampleRate() override { return m_sampleRate; }
     51     int getCurrentBitDepth() override { return 32; }
     52 
     53     BigInteger getActiveInputChannels() const override { return m_activeInputChannels; }
     54     BigInteger getActiveOutputChannels() const override { return m_activeOutputChannels; }
     55 
     56     int getOutputLatencyInSamples() override { return 0; }
     57     int getInputLatencyInSamples() override { return 0; }
     58 
     59     bool hasControlPanel() const override { return false; }
     60     bool showControlPanel() override { return false; }
     61     bool setAudioPreprocessingEnabled(bool) override { return false; }
     62     int getXRunCount() const noexcept override { return 0; }
     63 
     64 public:
     65 	void prepareProcess();
     66 
     67     void processAudio()
     68     {
     69 		m_callback->audioDeviceIOCallbackWithContext(m_buffer.getArrayOfReadPointers(),
     70 		                                             m_numInputChannels ? static_cast<int>(m_numInputChannels) : 2,
     71 		                                             m_buffer.getArrayOfWritePointers(),
     72 		                                             static_cast<int>(m_numOutputChannels),
     73 		                                             m_buffer.getNumSamples(),
     74 		                                             AudioIODeviceCallbackContext());
     75     }
     76 
     77 private:
     78     double m_sampleRate;
     79     int m_bufferSizeSamples;
     80     bool m_isOpenFlag;
     81     bool m_isPlayingFlag;
     82     AudioIODeviceCallback* m_callback = nullptr;
     83 	uint32_t m_numInputChannels = 2;
     84 	uint32_t m_numOutputChannels = 2;
     85     BigInteger m_activeInputChannels{0b11};
     86     BigInteger m_activeOutputChannels{0b11};
     87 	AudioBuffer<float> m_buffer;
     88 };