Add skeleton for codec2 and fdmdv2 drivers.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 26 Apr 2014 04:39:13 +0000 (04:39 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 26 Apr 2014 04:39:13 +0000 (04:39 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1577 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/codec2.cpp [new file with mode: 0644]
freedv-server/source/drivers.h
freedv-server/source/modem_fdmdv2.cpp [new file with mode: 0644]

diff --git a/freedv-server/source/codec2.cpp b/freedv-server/source/codec2.cpp
new file mode 100644 (file)
index 0000000..6977602
--- /dev/null
@@ -0,0 +1,106 @@
+/// \file codec_codec2.cpp
+/// Codec2, for FreeDV, "HT of the Future", and other modes using Codec2.
+///
+/// \copyright Copyright (C) 2013-2014 Algoram. See the LICENSE file.
+///
+
+#include "drivers.h"
+#include <string.h>
+
+namespace FreeDV {
+  /// Codec2.
+  class Codec2 : public Codec {
+  public:
+
+    /// Instantiate the no-op codec.
+                       Codec2(const char *);
+                       ~Codec2();
+
+    /// Decode from data bytes to audio samples.
+    /// \param i The encoded data, in an array of unsigned 8-bit integers.
+    /// \param o The array of audio samples after decoding, in an array
+    /// of signed 16-bit integers.
+    /// \param data_length When called: The number of bytes of data that are
+    /// available to be decoded. On return: the number of bytes of data
+    /// that were consumed.
+    /// \param sample_length The number of audio samples that may be decoded.
+    /// \return The number of audio samples that were actually decoded.
+    virtual std::size_t
+                       decode16(const std::uint8_t * i,
+                        std::int16_t * o,
+                        std::size_t * data_length,
+                        std::size_t sample_length);
+
+    /// Encode from audio samples to data bytes.
+    /// \param i The array of audio samples to be encoded, in an array
+    /// of signed 16-bit integers.
+    /// \param o The encoded data, in an array of unsigned 8-bit integers.
+    /// \param data_length The number of 8-bit data to be encoded.
+    /// \param sample_length On call: The number of 16-bit audio samples to
+    /// be encoded. On return: the number of samples that were consumed.
+    /// \return The number of 8-bit data elements in the encoded array.
+    virtual std::size_t
+                       encode16(
+                        const std::int16_t * i,
+                        std::uint8_t * o, \
+                        std::size_t data_length,
+                        std::size_t *sample_length);
+
+    /// \return The number of samples required to encode a frame in the
+    /// currently-selected mode.
+    virtual std::size_t
+    samples_per_frame() const;
+  };
+
+  Codec2::Codec2(const char * _parameters)
+  : Codec("no-op", _parameters)
+  {
+  }
+
+  Codec2::~Codec2()
+  {
+  }
+
+  std::size_t
+  Codec2::decode16(const std::uint8_t * i, std::int16_t * o, std::size_t * data_length, std::size_t sample_length)
+  {
+    return 0;
+  }
+
+  std::size_t
+  Codec2::encode16(
+   const std::int16_t * i,
+   std::uint8_t * o,
+   std::size_t data_length,
+   std::size_t *sample_length)
+  {
+    return 0;
+  }
+
+  std::size_t
+  Codec2::samples_per_frame() const
+  {
+    return 0;
+  }
+
+  Codec *
+  Driver::Codec2(const char * parameter)
+  {
+    return new ::FreeDV::Codec2(parameter);
+  }
+
+  static std::ostream &
+  Codec2Enumerator(std::ostream & stream)
+  {
+    stream << "codec2:" << std::endl;
+    return stream;
+  }
+
+  static bool
+  initializer()
+  {
+    driver_manager()->register_codec("codec2", Driver::Codec2, Codec2Enumerator);
+    return true;
+  }
+  static const bool UNUSED initialized = initializer();
+}
index 4dd5222db9dd51da94714dd45aec26060f822fa0..36e8d043fcbe14e336a06a9eee909ff258ca799f 100644 (file)
@@ -775,6 +775,13 @@ AudioOutput *      AudioOutALSA(const char * parameter);
 ///
 AudioOutput *  AudioOutDefault();
 
+/// Opens Codec2.
+/// for testing.
+/// \param parameter
+/// \return A pointer to the codec instance.
+///
+Codec *                Codec2(const char * parameter);
+
 /// Opens a no-op codec, which copies its input to its output unmodified,
 /// for testing.
 /// \param parameter Not used.
@@ -795,6 +802,12 @@ Framer *   FramerNoOp(const char * parameter);
 ///
 KeyingOutput * KeyingSink(const char * parameter);
 
+/// Opens the FDMDV2 modem.
+/// \param parameter
+/// \return A pointer to the Modem instance.
+///
+Modem *                ModemFDMDV2(const char * parameter);
+
 /// Opens a no-op modem, which copies its input to its output unmodified,
 /// for testing.
 /// \param parameter Not used.
diff --git a/freedv-server/source/modem_fdmdv2.cpp b/freedv-server/source/modem_fdmdv2.cpp
new file mode 100644 (file)
index 0000000..78dd5c5
--- /dev/null
@@ -0,0 +1,113 @@
+/// \file modem_noop.cpp
+/// The FDMDV2 modem.
+///
+/// \copyright Copyright (C) 2013-2014 Algoram. See the LICENSE file.
+///
+
+#include "drivers.h"
+#include <string.h>
+
+namespace FreeDV {
+  /// Modem "FDMDV2".
+  class ModemFDMDV2 : public Modem {
+  public:
+
+       /// Instantiate the FDMDV2 modem.
+       ///
+                       ModemFDMDV2(const char *);
+
+       virtual         ~ModemFDMDV2();
+
+    /// Return the number of data bytes output in a single modem frame.
+    /// The data buffer provided to demodulate16 must be a multiple of
+    /// this value. The result is invariant.
+    /// \return The number of data bytes necessary to store a modem frame.
+    virtual std::size_t
+                       bytes_per_frame() const;
+
+    /// Demodulate from audio samples to data.
+    /// \param i The array of audio samples to be demodulated, in an array
+    /// of signed 16-bit integers.
+    /// \param o The demodulated data, in an array of unsigned 8-bit integers.
+    /// \param data_length The number of bytes of data that may be demodulated.
+    /// \param sample_length On call: The number of audio samples to be
+    /// demodulated. On return: The number of audio samples consumed.
+    /// \return The number of bytes of data that were actually decoded.
+    virtual std::size_t
+                       demodulate16(
+                        const std::int16_t * i,
+                        std::uint8_t * o,
+                        std::size_t data_length,
+                        std::size_t * sample_length);
+
+    /// Modulate from data to audio samples.
+    /// \param i The data, in an array of unsigned 8-bit integers.
+    /// \param o The array of audio samples after modulation, in an array
+    /// of signed 16-bit integers.
+    /// \param data_length On call: The number of bytes of data to be
+    /// modulated. On return: The number of bytes consumed.
+    /// \return The number of 16-bit audio samples in the modulated array.
+    virtual std::size_t
+                       modulate16(
+                         const std::uint8_t * i,
+                        std::int16_t * o, \
+                        std::size_t *data_length,
+                        std::size_t sample_length);
+  };
+
+  ModemFDMDV2::ModemFDMDV2(const char * _parameters)
+  : Modem("FDMDV2", _parameters)
+  {
+  }
+
+  ModemFDMDV2::~ModemFDMDV2()
+  {
+  }
+
+  std::size_t
+  ModemFDMDV2::bytes_per_frame() const
+  {
+    return 0;
+  }
+
+  std::size_t
+  ModemFDMDV2::demodulate16(
+   const std::int16_t * i,
+   std::uint8_t * o,
+   std::size_t data_length,
+   std::size_t * sample_length)
+  {
+    return 0;
+  }
+
+  std::size_t
+  ModemFDMDV2::modulate16(
+   const std::uint8_t * i,
+   std::int16_t * o,
+   std::size_t *data_length,
+   std::size_t sample_length)
+  {
+    return 0;
+  }
+
+  Modem *
+  Driver::ModemFDMDV2(const char * parameter)
+  {
+    return new ::FreeDV::ModemFDMDV2(parameter);
+  }
+
+  static std::ostream &
+  ModemFDMDV2Enumerator(std::ostream & stream)
+  {
+    stream << "fdmdv2:" << std::endl;
+    return stream;
+  }
+
+  static bool
+  initializer()
+  {
+    driver_manager()->register_modem("fdmdv2", Driver::ModemFDMDV2, ModemFDMDV2Enumerator);
+    return true;
+  }
+  static const bool UNUSED initialized = initializer();
+}