Add gain adjust values

main
Doug McLain 4 years ago
parent efa604935f
commit 8434c8518d

@ -25,6 +25,9 @@
#include "TranscoderPacket.h" #include "TranscoderPacket.h"
#include "Controller.h" #include "Controller.h"
#define AMBE_GAIN 0 //dB I use -6 here
#define AMBE2_GAIN 0 //dB I use 6 here
CController::CController() : keep_running(true) {} CController::CController() : keep_running(true) {}
bool CController::Start() bool CController::Start()
@ -168,10 +171,10 @@ bool CController::InitVocoders()
} }
if (dstar_device && dmrsf_device) if (dstar_device && dmrsf_device)
{ {
if (dstar_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype)) if (dstar_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, AMBE_GAIN))
return true; return true;
deviceset.pop_front(); deviceset.pop_front();
if (dmrsf_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype)) if (dmrsf_device->OpenDevice(deviceset.front().first, deviceset.front().second, dvtype, AMBE2_GAIN))
return true; return true;
deviceset.pop_front(); deviceset.pop_front();
} }

@ -52,7 +52,7 @@ std::shared_ptr<CTranscoderPacket> CDV3000::PopWaitingPacket(unsigned int /* cha
return waiting_packet.pop(); return waiting_packet.pop();
} }
bool CDV3000::SendAudio(const uint8_t /*channel*/, const int16_t *audio) const bool CDV3000::SendAudio(const uint8_t /*channel*/, const int16_t *audio, const int gain) const
{ {
// Create Audio packet based on input int8_ts // Create Audio packet based on input int8_ts
SDV_Packet p; SDV_Packet p;
@ -61,9 +61,18 @@ bool CDV3000::SendAudio(const uint8_t /*channel*/, const int16_t *audio) const
p.header.packet_type = PKT_SPEECH; p.header.packet_type = PKT_SPEECH;
p.field_id = PKT_SPEECHD; p.field_id = PKT_SPEECHD;
p.payload.audio3k.num_samples = 160U; p.payload.audio3k.num_samples = 160U;
for (int i=0; i<160; i++) const uint32_t g = abs(gain);
p.payload.audio3k.samples[i] = htons(audio[i]);
std::cerr << "SendAudio() gain == " << gain << std::endl;
for (int i=0; i<160; i++){
if(gain < 0){
p.payload.audio3k.samples[i] = htons(audio[i] / g);
}
else{
p.payload.audio3k.samples[i] = htons(audio[i] * g);
}
}
// send audio packet to DV3000 // send audio packet to DV3000
const DWORD size = packet_size(p); const DWORD size = packet_size(p);
DWORD written; DWORD written;

@ -29,7 +29,7 @@ protected:
void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet); void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet);
std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel); std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel);
void ProcessPacket(const SDV_Packet &p); void ProcessPacket(const SDV_Packet &p);
bool SendAudio(const uint8_t channel, const int16_t *audio) const; bool SendAudio(const uint8_t channel, const int16_t *audio, const int gain) const;
bool SendData(const uint8_t channel, const uint8_t *data) const; bool SendData(const uint8_t channel, const uint8_t *data) const;
private: private:

@ -52,7 +52,7 @@ std::shared_ptr<CTranscoderPacket> CDV3003::PopWaitingPacket(unsigned int channe
return waiting_packet[channel].pop(); return waiting_packet[channel].pop();
} }
bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio, const int gain) const
{ {
// Create Audio packet based on input int8_ts // Create Audio packet based on input int8_ts
SDV_Packet p; SDV_Packet p;
@ -62,8 +62,16 @@ bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const
p.field_id = channel + PKT_CHANNEL0; p.field_id = channel + PKT_CHANNEL0;
p.payload.audio.speechd = PKT_SPEECHD; p.payload.audio.speechd = PKT_SPEECHD;
p.payload.audio.num_samples = 160U; p.payload.audio.num_samples = 160U;
for (int i=0; i<160; i++) const uint32_t g = abs(gain);
p.payload.audio.samples[i] = htons(audio[i]);
for (int i=0; i<160; i++){
if(gain < 0){
p.payload.audio3k.samples[i] = htons(audio[i]) / g;
}
else{
p.payload.audio3k.samples[i] = htons(audio[i]) * g;
}
}
// send audio packet to DV3000 // send audio packet to DV3000
const DWORD size = packet_size(p); const DWORD size = packet_size(p);

@ -29,7 +29,7 @@ protected:
void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet); void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet);
std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel); std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel);
void ProcessPacket(const SDV_Packet &p); void ProcessPacket(const SDV_Packet &p);
bool SendAudio(const uint8_t channel, const int16_t *audio) const; bool SendAudio(const uint8_t channel, const int16_t *audio, const int gain) const;
bool SendData(const uint8_t channel, const uint8_t *data) const; bool SendData(const uint8_t channel, const uint8_t *data) const;
private: private:

@ -36,6 +36,17 @@
#include "configure.h" #include "configure.h"
#include "Controller.h" #include "Controller.h"
int16_t calcGainVal(float db)
{
float ratio = powf(10.0, (db/10.0));
if(db < 0){
ratio = (1/ratio) * (-1);
}
return (int16_t)roundf(ratio);
}
extern CController Controller; extern CController Controller;
CDVDevice::CDVDevice(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true) CDVDevice::CDVDevice(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true)
@ -140,7 +151,7 @@ bool CDVDevice::checkResponse(SDV_Packet &p, uint8_t response) const
return false; return false;
} }
bool CDVDevice::OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype) bool CDVDevice::OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype, float dbgain)
{ {
auto status = FT_OpenEx((PVOID)serialno.c_str(), FT_OPEN_BY_SERIAL_NUMBER, &ftHandle); auto status = FT_OpenEx((PVOID)serialno.c_str(), FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
if (FT_OK != status) if (FT_OK != status)
@ -149,6 +160,7 @@ bool CDVDevice::OpenDevice(const std::string &serialno, const std::string &desc,
return true; return true;
} }
gain = calcGainVal(dbgain);
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX ); FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX );
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
@ -593,7 +605,8 @@ void CDVDevice::FeedDevice()
} }
else else
{ {
SendAudio(index, packet->GetAudioSamples()); //SendAudio(index, packet->GetAudioSamples(), (Encoding::dstar==type) ? 4 : -4);
SendAudio(index, packet->GetAudioSamples(), gain);
} }
buffer_depth++; buffer_depth++;
} }

@ -32,7 +32,7 @@ public:
CDVDevice(Encoding t); CDVDevice(Encoding t);
virtual ~CDVDevice(); virtual ~CDVDevice();
bool OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype); bool OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype, float dbgain);
void Start(); void Start();
void CloseDevice(); void CloseDevice();
void AddPacket(const std::shared_ptr<CTranscoderPacket> packet); void AddPacket(const std::shared_ptr<CTranscoderPacket> packet);
@ -46,6 +46,7 @@ protected:
CPacketQueue input_queue; CPacketQueue input_queue;
std::future<void> feedFuture, readFuture; std::future<void> feedFuture, readFuture;
std::string description, productid; std::string description, productid;
int16_t gain;
bool DiscoverFtdiDevices(); bool DiscoverFtdiDevices();
bool ConfigureVocoder(uint8_t pkt_ch, Encoding type); bool ConfigureVocoder(uint8_t pkt_ch, Encoding type);
@ -61,6 +62,6 @@ protected:
virtual void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet) = 0; virtual void PushWaitingPacket(unsigned int channel, std::shared_ptr<CTranscoderPacket> packet) = 0;
virtual std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel) = 0; virtual std::shared_ptr<CTranscoderPacket> PopWaitingPacket(unsigned int channel) = 0;
virtual void ProcessPacket(const SDV_Packet &p) = 0; virtual void ProcessPacket(const SDV_Packet &p) = 0;
virtual bool SendAudio(const uint8_t channel, const int16_t *audio) const = 0; virtual bool SendAudio(const uint8_t channel, const int16_t *audio, const int gain) const = 0;
virtual bool SendData(const uint8_t channel, const uint8_t *data) const = 0; virtual bool SendData(const uint8_t channel, const uint8_t *data) const = 0;
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.