/// Destroy a codec instance.
virtual ~Codec() = 0;
+ /// Decode from an array of the unsigned 8-bit integer type to an
+ /// array of the signed 16-bit integer type.
+ /// \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 length The number of bytes of data to be decoded.
+ /// \return The number of int16_t elements in the decoded array.
+ virtual std::size_t
+ decode16(const uint8_t * i, int16_t * o, \
+ std::size_t length) = 0;
+
/// Encode from an array of the signed 16-bit integer type to an
- /// array of the unsigned 8-bit integer type (this is usually
- /// implemented as unsigned char).
+ /// array of the unsigned 8-bit integer type.
/// \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.
std::size_t length) = 0;
/// Return the size of uint8_t array necessary to encode the given
- /// number of audio samples. Sample rate is 8K samples/second.
+ /// number of audio samples at SampleRate.
/// The result is invariant for a given input.
/// \param sample_count The number of audio samples to encode.
/// Must be a multiple of frame_size().
frame_duration() const = 0;
/// Return the number of audio samples necessary to decode the given
- /// encoded buffer size. Sample rate is 8K samples/second.
+ /// encoded buffer size at SampleRate.
/// \param buffer_size is the size of the encoded buffer. It must
/// encode a multiple of frame_size() audio samples.
/// \return The number of audio samples necessary to decode the given
samples_per_buffer(std::size_t buffer_size) const = 0;
/// Return the number of audio samples expected to create a codec
- /// frame. Samples provided to encode_buffer_size must be a multiple
- /// of this value. Sample rate is 8K samples/second.
+ /// frame at SampleRate. Samples provided to encode_buffer_size
+ /// must be a multiple of this value.
/// The result for a particular input is invariant.
/// \return The number of audio samples expected to create a codec
/// frame.
public:
virtual ~Modem() = 0;
+
+ /// Decode from an array of the signed 16-bit integer type to an
+ /// array of the unsigned 8-bit integer type.
+ /// \param i The array of audio samples to be decoded, in an array
+ /// of signed 16-bit integers.
+ /// \param o The decoded data, in an array of unsigned 8-bit integers.
+ /// \param length The number of audio samples to be decoded.
+ /// \return The number of uint8_t elements in the decoded array.
+ virtual std::size_t
+ decode16(const int16_t * i, uint8_t * o, \
+ std::size_t length) = 0;
+
+ /// Encode from an array of the unsigned 8-bit integer type to an
+ /// array of the signed 16-bit integer type.
+ /// \param i The data, in an array of unsigned 8-bit integers.
+ /// \param o The array of audio samples after encoding, in an array
+ /// of signed 16-bit integers.
+ /// \param length The number of bytes of data to be encoded.
+ /// \return The number of int16_t elements in the encoded array.
+ virtual std::size_t
+ encode16(const uint8_t * i, int16_t * o, \
+ std::size_t length) = 0;
+
+ /// Return the size of uint8_t array necessary to encode the given
+ /// number of audio samples at SampleRate.
+ /// The result is invariant for a given input.
+ /// \param sample_count The number of audio samples to encode.
+ /// Must be a multiple of frame_size().
+ /// \return The size of uint8_t array necessary to encode the given
+ /// number of audio samples.
+ virtual std::size_t const
+ encoded_buffer_size(std::size_t sample_count) const = 0;
+
+ /// Return the duration of a frame in milliseconds.
+ /// \return The duration of a frame in milliseconds.
+ virtual int const
+ frame_duration() const = 0;
+
+ /// Return the number of audio samples necessary to decode the given
+ /// encoded buffer size at SampleRate.
+ /// \param buffer_size is the size of the encoded buffer. It must
+ /// encode a multiple of frame_size() audio samples.
+ /// \return The number of audio samples necessary to decode the given
+ /// encoded buffer size. The result is invariant for a given input.
+ virtual std::size_t const
+ samples_per_buffer(std::size_t buffer_size) const = 0;
+
+ /// Return the number of audio samples expected to create a codec
+ /// frame at SampleRate. Samples provided to encode_buffer_size
+ /// must be a multiple of this value.
+ /// The result for a particular input is invariant.
+ /// \return The number of audio samples expected to create a codec
+ /// frame.
+ virtual std::size_t const
+ samples_per_frame() const = 0;
};
/// Push-to-talk input driver.
#endif
#include "drivers.h"
+static const char insufficient_privilege_message[] =
+"Warning: Insufficient privilege to set real-time priority.\n"
+"This could cause audio to be interrupted as other programs run.\n"
+"To fix: As root, run\n"
+"\n"
+"\tsetcap cap_sys_nice+ep filename\n"
+"\n"
+"where filename is the executable file for this program. That will\n"
+"allow you to use real-time priority while running as any user.\n"
+"Alternatively, you can execute this program as root.\n\n";
+
+static const char old_kernel_message[] =
+"This kernel doesn't seem to have real-time facilities.\n"
+"If audio is sometimes interrupted, try a newer kernel.\n\n";
+
namespace FreeDV {
void
set_scheduler()
p.sched_priority = sched_get_priority_min(policy);
const int result = sched_setscheduler(0, policy, &p);
if ( result < 0 ) {
- if ( errno == EPERM ) {
- std::cerr << "Insufficient privilege to set real-time priority. "
- "Try runing as root." << std::endl;
- }
- else if ( errno == EINVAL ) {
- std::cerr << "This kernel doesn't seem to have real-time facilities. "
- "If audio is sometimes interrupted, try a newer kernel." << std::endl;
- }
+ if ( errno == EPERM )
+ std::cerr << insufficient_privilege_message << std::flush;
+ else if ( errno == EINVAL )
+ std::cerr << old_kernel_message << std::flush;
else {
std::cerr << "sched_setscheduler: " << strerror(errno) << std::endl;
}