--- /dev/null
+/// The AudioDevice class.
+
+#include "drivers.h"
+#include <stdexcept>
+
+namespace FreeDV {
+ AudioDevice::AudioDevice(const char * name, const char * parameters)
+ : IODevice(name, parameters), master_amplitude(1.0)
+ {
+ }
+
+ AudioDevice::~AudioDevice()
+ {
+ }
+
+ float
+ AudioDevice::amplitude()
+ {
+ return master_amplitude;
+ }
+
+ void
+ AudioDevice::amplitude(float value)
+ {
+ if ( value < 0.0 || value > 1.0 )
+ throw std::runtime_error(
+ "Amplitude set to value outside of the range 0.0..1.0");
+ master_amplitude = value;
+ }
+}
--- /dev/null
+/// The general base class for drivers.
+
+#include "drivers.h"
+
+namespace FreeDV {
+ Base::Base(const char * _name, const char * _parameters)
+ : name(_name), parameters(copy_string(_parameters))
+ {
+ }
+
+ Base::~Base()
+ {
+ delete parameters;
+ }
+
+ bool const
+ Base::captive() const
+ {
+ return false;
+ }
+
+ std::ostream &
+ Base::print(std::ostream & stream) const
+ {
+ return stream << name << ':' << parameters;
+ }
+}
}
/// Virtual base class for all drivers that perform non-blocking I/O.
- /// These are AudioInput and AudioOutput, PTTInput, TextInput, and
- /// UserInterface.
- /// Keying is assumed to never need to block.
+ /// These are AudioInput and AudioOutput, PTTInput, TextInput,
+ /// KeyingOutput and UserInterface.
class IODevice : public ::FreeDV::Base {
protected:
+ /// Construct an I/O device.
+ /// \param _name Name of the driver. This is expected to be a single
+ /// constant static string per driver class.
+ /// \param _parameters Driver-specific configuration parameters.
IODevice(const char * name, const char * parameters);
public:
/// Key or un-key the transmitter.
/// \param value If true, key the transmitter. If false, un-key.
virtual void key(bool value) = 0;
+
+ /// Return the amount of bytes ready to write.
+ virtual size_t ready() = 0;
};
/// Softmodem driver.
--- /dev/null
+/// The Interfaces class.
+
+#include "drivers.h"
+
+// Empty string, for convenience in initializing drivers.
+static const char empty[1] = { '\0' };
+
+namespace FreeDV {
+ void
+ Interfaces::fill_in()
+ {
+ if ( !codec )
+ codec = Driver::CodecNoOp(empty);
+
+ if ( !keying_output )
+ keying_output = Driver::KeyingSink(empty);
+
+ if ( !loudspeaker )
+ loudspeaker = Driver::AudioSink(empty);
+
+ if ( !microphone )
+ microphone = Driver::Tone(empty);
+
+ if ( !modem )
+ modem = Driver::ModemNoOp(empty);
+
+ if ( !ptt_input_digital )
+ ptt_input_digital = Driver::PTTConstant(empty);
+
+ if ( !ptt_input_ssb )
+ ptt_input_ssb = Driver::PTTConstant(empty);
+
+ if ( !text_input )
+ text_input = Driver::TextConstant(empty);
+
+ if ( !transmitter )
+ transmitter = Driver::AudioSink(empty);
+
+ if ( !receiver )
+ receiver = Driver::Tone(empty);
+
+ if ( !user_interface )
+ user_interface = Driver::BlankPanel(empty, this);
+ }
+
+ std::ostream &
+ Interfaces::print(std::ostream & stream) const
+ {
+ using namespace std;
+
+ stream << "--codec=" << *codec << endl;
+ stream << "--gui=" << *user_interface << endl;
+ stream << "--keying=" << *keying_output << endl;
+ stream << "--loudspeaker=" << *loudspeaker << endl;
+ stream << "--microphone=" << *microphone << endl;
+ stream << "--modem=" << *modem << endl;
+ stream << "--ptt-digital=" << *ptt_input_digital << endl;
+ stream << "--ptt-ssb=" << *ptt_input_ssb << endl;
+ stream << "--receiver=" << *receiver << endl;
+ stream << "--text=" << *text_input << endl;
+ stream << "--transmitter=" << *transmitter << endl;
+
+ return stream;
+ }
+}
/// KeyingOutput output "sink", doesn't key anything. For testing or use with VOX.
class KeyingSink : public KeyingOutput {
public:
+ /// Instantiate keying sink driver.
+ KeyingSink(const char *);
+ virtual ~KeyingSink();
- /// Instantiate keying sink driver.
- KeyingSink(const char *);
- virtual ~KeyingSink();
+ /// If the value is true, transmit. Otherwise receive.
+ void key(bool value);
- /// If the value is true, transmit. Otherwise receive.
- void key(bool value);
+ /// Return the amount of bytes ready for read. In this case, it always
+ /// returns SIZE_MAX.
+ size_t ready();
};
KeyingSink::KeyingSink(const char * parameters)
std::cerr << "keying: RECEIVE" << std::endl;
}
+ size_t
+ KeyingSink::ready()
+ {
+ return SIZE_MAX;
+ }
+
KeyingOutput *
Driver::KeyingSink(const char * parameter)
{
};
TEST_F(KeyingSinkTest, CanCallKey) {
-
k->key(true);
k->key(false);
}
+
+TEST_F(KeyingSinkTest, AlwaysReady) {
+ EXPECT_EQ(SIZE_MAX, k->ready());
+}
--- /dev/null
+#include "drivers.h"
+#include <string.h>
+
+namespace FreeDV {
+ char *
+ copy_string(const char * s)
+ {
+ const size_t length(strlen(s) + 1);
+ char * copy = new char[length];
+ memcpy(copy, s, length);
+ return copy;
+ }
+}