Ak4951-ALC_base adding WM8731-boost OFF options

This commit is contained in:
Brumi-2021 2022-09-28 22:42:33 +02:00
parent 379ad6dbf0
commit 745574d3c4
11 changed files with 82 additions and 23 deletions

View File

@ -110,6 +110,7 @@ void SoundBoardView::start_tx(const uint32_t id) {
1536000 / 20, // Update vu-meter at 20Hz
transmitter_model.channel_bandwidth(),
0, // Gain is unused
8, // shift_bits_s16, default 8 bits, but also unused
TONES_F2D(tone_key_frequency(tone_key_index), 1536000),
0, //AM
0, //DSB

View File

@ -73,6 +73,7 @@ void MicTXView::configure_baseband() {
sampling_rate / 20, // Update vu-meter at 20Hz
transmitting ? transmitter_model.channel_bandwidth() : 0,
mic_gain,
shift_bits_s16, // to be used in dsp_modulate
TONES_F2D(tone_key_frequency(tone_key_index), sampling_rate),
enable_am,
enable_dsb,
@ -186,7 +187,7 @@ void MicTXView::rxaudio(bool is_on) {
baseband::run_image(portapack::spi_flash::image_tag_mic_tx);
audio::output::stop();
audio::input::start(ak4951_alc_GUI_selected); // set up audio input = mic config of any audio coded AK4951/WM8731, (in WM8731 parameter will be ignored)
audio::input::start(ak_alc_GUI_selected ); // set up audio input = mic config of any audio coded AK4951/WM8731, (in WM8731 parameter will be ignored)
portapack::pin_i2s0_rx_sda.mode(3);
configure_baseband();
}
@ -216,6 +217,7 @@ MicTXView::MicTXView(
&labels_WM8731, // we have audio codec WM8731, same MIC menu as original.
&vumeter,
&options_gain, // MIC GAIN float factor on the GUI.
&options_wm8731_boost_mode,
// &check_va,
&field_va,
&field_va_level,
@ -281,12 +283,39 @@ MicTXView::MicTXView(
configure_baseband();
};
options_gain.set_selected_index(1); // x1.0
ak_alc_GUI_selected = 0; // 0,..11 AK-ALC options,
if (audio::debug::codec_name() =="WM8731") {
options_wm8731_boost_mode.on_change = [this](size_t, int8_t v) {
switch(v) {
case 0: // +00 dBs reference level , (when +20dB's boost ON)
shift_bits_s16 = 8; // same as original conditions fw 1.5.4 , using WM mic boost ON(+20dB's) and shift bits (>>8),
break; // now mic-boost off(+00dBs) shift bits (8) (+20+0dB's)=20 dBs ref => +00dB's
case 1:
shift_bits_s16 = 4; // +04 dBs respect ref level , (when +20dB's boost OFF)
break; // now mic-boost off (+00dBs) shift bits (4) (+0+24dB's)=24 dBs => +04dB's respect ref.
case 2:
shift_bits_s16 = 5; // -02 dBs respect ref level , (when +20dB's boost OFF)
break; // now mic-boost off (+00dBs) shift bits (5) (+0+18dB's)=18 dBs => -02dB's respect ref.
case 3:
shift_bits_s16 = 6; // -08 dBs respect ref level , (when +20dB's boost OFF)
break; // now mic-boost off (+00dBs) shift bits (6) (+0+12dB's)=12 dBs => -08dB's respect ref.
}
configure_baseband(); // sending var-parameters msg , to audio_tx to M4 CPU Proc -
};
options_wm8731_boost_mode.set_selected_index(2); // preset GUI index.
} else {
shift_bits_s16 = 8; // Initialized default fixed >>8 for FM tx mod , shift audio data for AK (using top 8 bits s16 data)
options_ak4951_alc_mode.on_change = [this](size_t, int8_t v) {
ak_alc_GUI_selected = v; // 0,..11 AK-ALC options,
audio::input::start(ak_alc_GUI_selected ); // Set up proper ALC mode in AK4951
configure_baseband(); // sending var-parameters msg , to audiotx to M4-
};
}
options_ak4951_alc_mode.on_change = [this](size_t, int8_t v) {
ak4951_alc_GUI_selected = v;
audio::input::start(ak4951_alc_GUI_selected);
};
// options_ak4951_alc_mode.set_selected_index(0);
// options_ak4951_alc_mode.set_selected_index(0);
tx_frequency = transmitter_model.tuning_frequency();
field_frequency.set_value(transmitter_model.tuning_frequency());
@ -536,9 +565,10 @@ MicTXView::MicTXView(
transmitter_model.set_baseband_bandwidth(1750000);
set_tx(false);
audio::set_rate(audio::Rate::Hz_24000);
audio::input::start(ak4951_alc_GUI_selected); // originally , audio::input::start(); (we added parameter)
audio::set_rate(audio::Rate::Hz_24000);
audio::input::start(ak_alc_GUI_selected ); // originally , audio::input::start(); (we added parameter)
}
MicTXView::~MicTXView() {

View File

@ -83,7 +83,7 @@ private:
bool rx_enabled { false };
uint32_t tone_key_index { };
float mic_gain { 1.0 };
uint8_t ak4951_alc_GUI_selected { 0 };
uint8_t ak_alc_GUI_selected { 0 };
uint32_t audio_level { 0 };
uint32_t va_level { };
uint32_t attack_ms { };
@ -99,6 +99,7 @@ private:
rf::Frequency rx_frequency { 0 };
int32_t focused_ui { 2 };
bool button_touch { false };
uint8_t shift_bits_s16 {4} ; // shift bits factor to the captured ADC S16 audio sample.
//AM TX Stuff
bool enable_am { false };
@ -109,6 +110,7 @@ private:
Labels labels_WM8731 {
{ { 3 * 8, 1 * 8 }, "MIC-GAIN:", Color::light_grey() },
{ { 17 * 8, 1 * 8 }, "Boost", Color::light_grey() },
{ { 3 * 8, 3 * 8 }, "F:", Color::light_grey() },
{ { 15 * 8, 3 * 8 }, "BW: FM kHz", Color::light_grey() },
{ { 3 * 8, 5 * 8 }, "GAIN:", Color::light_grey() },
@ -186,6 +188,17 @@ private:
}
};
OptionsField options_wm8731_boost_mode {
{ 22 * 8, 1 * 8 }, // Coordinates are: int:x (px), int:y (px)
4,
{
{ "ON +00dB", 0 }, // WM8731 Mic Boost ON ,original condition, easy to saturate ADC sat in high voice ,relative G = +00 dB's (ref level) sampling 24Khz
{ "OFF+04dB", 1 }, // WM8731 Mic Boost OFF to avoid ADC sat in high voice ,relative G = +04 dB's (respect ref level) sampling 24Khz
{ "OFF-02dB", 2 }, // WM8731 Mic Boost OFF to avoid ADC sat in high voice ,relative G = -02 dB's (respect ref level)
{ "OFF-08dB", 3 }, // WM8731 Mic Boost OFF to avoid ADC sat in high voice ,relative G = -12 dB's (respect ref level)
}
};
FrequencyField field_frequency {
{ 5 * 8, 3 * 8 },
};

View File

@ -183,12 +183,13 @@ void kill_afsk() {
}
void set_audiotx_config(const uint32_t divider, const float deviation_hz, const float audio_gain,
const uint32_t tone_key_delta, const bool am_enabled, const bool dsb_enabled,
const bool usb_enabled, const bool lsb_enabled) {
uint8_t audio_shift_bits_s16, const uint32_t tone_key_delta, const bool am_enabled,
const bool dsb_enabled, const bool usb_enabled, const bool lsb_enabled) {
const AudioTXConfigMessage message {
divider,
deviation_hz,
audio_gain,
audio_shift_bits_s16,
tone_key_delta,
(float)persistent_memory::tone_mix() / 100.0f,
am_enabled,

View File

@ -61,8 +61,8 @@ void set_tones_config(const uint32_t bw, const uint32_t pre_silence, const uint1
void kill_tone();
void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration);
void set_audiotx_config(const uint32_t divider, const float deviation_hz, const float audio_gain,
const uint32_t tone_key_delta, const bool am_enabled, const bool dsb_enabled,
const bool usb_enabled, const bool lsb_enabled);
uint8_t audio_shift_bits_s16, const uint32_t tone_key_delta, const bool am_enabled,
const bool dsb_enabled, const bool usb_enabled, const bool lsb_enabled);
void set_fifo_data(const int8_t * data);
void set_pitch_rssi(int32_t avg, bool enabled);
void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space,

View File

@ -42,10 +42,16 @@ void Modulator::set_over(uint32_t new_over) {
over = new_over;
}
void Modulator::set_gain_vumeter_beep(float new_audio_gain , bool new_play_beep ) {
audio_gain = new_audio_gain ;
void Modulator::set_gain_shiftbits_vumeter_beep(float new_audio_gain ,uint8_t new_audio_shift_bits_s16, bool new_play_beep ) {
//new_audio_shift_bits_s16 are the direct shift bits (FM mod >>x) , and can be 8 fixed (AK) or 4,5,6 (WM boost OFF) or 8 (WM boost ON)
audio_gain = new_audio_gain ;
audio_shift_bits_s16_FM = new_audio_shift_bits_s16; //FM : >>8(AK) fixed , >>4,5,6 (WM boost OFF)
if (new_audio_shift_bits_s16==8) { //FM : we are in AK codec IC => for AM-SSB-DSB we were using >>2 fixed (wm boost ON) .
audio_shift_bits_s16_AM_DSB_SSB = 2; //AM-DSB-SSB: >>2(AK) fixed , >>0,1,2 (WM boost OFF)
} else {
audio_shift_bits_s16_AM_DSB_SSB = (new_audio_shift_bits_s16-4) ; //AM-DSB-SSB: >>0,1,2 (WM boost OFF)
}
play_beep = new_play_beep;
}
int32_t Modulator::apply_beep(int32_t sample_in, bool& configured_in, uint32_t& new_beep_index, uint32_t& new_beep_timer, TXProgressMessage& new_txprogress_message ) {
@ -85,7 +91,7 @@ void SSB::execute(const buffer_s16_t& audio, const buffer_c8_t& buffer, bool& co
if (counter % 128 == 0) {
float i = 0.0, q = 0.0;
sample = audio.p[counter / over] >> 2;
sample = audio.p[counter / over] >> audio_shift_bits_s16_AM_DSB_SSB; // originally fixed >> 2, now >>2 for AK, 0,1,2,3 for WM (boost off)
sample *= audio_gain; // Apply GAIN Scale factor to the audio TX modulation.
//switch (mode) {
@ -145,7 +151,7 @@ void FM::execute(const buffer_s16_t& audio, const buffer_c8_t& buffer, bool& con
for (size_t counter = 0; counter < buffer.count; counter++) {
sample = audio.p[counter>>6] >> 8; // sample = audio.p[counter / over] >> 8; (not enough efficient running code, over = 1536000/240000= 64 )
sample = audio.p[counter>>6] >> audio_shift_bits_s16_FM ; // Orig. >>8 , sample = audio.p[counter / over] >> 8; (not enough efficient running code, over = 1536000/240000= 64 )
sample *= audio_gain; // Apply GAIN Scale factor to the audio TX modulation.
if (play_beep) {
@ -190,7 +196,7 @@ void AM::execute(const buffer_s16_t& audio, const buffer_c8_t& buffer, bool& con
for (size_t counter = 0; counter < buffer.count; counter++) {
if (counter % 128 == 0) {
sample = audio.p[counter / over] >> 2;
sample = audio.p[counter / over] >> audio_shift_bits_s16_AM_DSB_SSB; // originally fixed >> 2, now >>2 for AK, 0,1,2,3 for WM (boost off)
sample *= audio_gain; // Apply GAIN Scale factor to the audio TX modulation.
}

View File

@ -50,9 +50,11 @@ public:
void set_mode(Mode new_mode);
void set_over(uint32_t new_over);
void set_gain_vumeter_beep(float new_audio_gain , bool new_play_beep );
void set_gain_shiftbits_vumeter_beep(float new_audio_gain ,uint8_t new_audio_shift_bits_s16, bool new_play_beep );
int32_t apply_beep(int32_t sample_in, bool& configured_in, uint32_t& new_beep_index, uint32_t& new_beep_timer, TXProgressMessage& new_txprogress_message );
float audio_gain { };
uint8_t audio_shift_bits_s16_FM { }; // shift bits factor to the captured ADC S16 audio sample.
uint8_t audio_shift_bits_s16_AM_DSB_SSB { };
bool play_beep { false };
uint32_t power_acc_count { 0 }; // this var it is initialized from Proc_mictx.cpp
uint32_t divider { }; // this var it is initialized from Proc_mictx.cpp

View File

@ -35,7 +35,7 @@ void MicTXProcessor::execute(const buffer_c8_t& buffer){
if (!configured) return;
audio_input.read_audio_buffer(audio_buffer);
modulator->set_gain_vumeter_beep(audio_gain, play_beep ) ;
modulator->set_gain_shiftbits_vumeter_beep(audio_gain, audio_shift_bits_s16, play_beep ) ;
modulator->execute(audio_buffer, buffer, configured, beep_index, beep_timer, txprogress_message, level_message, power_acc_count, divider ); // Now "Key Tones & CTCSS" baseband additon inside FM mod. dsp_modulate.cpp"
/* Original fw 1.3.1 good reference, beep and vu-meter
@ -141,6 +141,7 @@ void MicTXProcessor::on_message(const Message* const msg) {
}
audio_gain = config_message.audio_gain;
audio_shift_bits_s16 = config_message.audio_shift_bits_s16;
divider = config_message.divider;
power_acc_count = 0;

View File

@ -61,6 +61,8 @@ private:
uint32_t divider { };
float audio_gain { };
uint8_t audio_shift_bits_s16 { } ; // shift bits factor to the captured ADC S16 audio sample.
uint64_t power_acc { 0 };
uint32_t power_acc_count { 0 };
bool play_beep { false };

View File

@ -868,6 +868,7 @@ public:
const uint32_t divider,
const float deviation_hz,
const float audio_gain,
const uint8_t audio_shift_bits_s16,
const uint32_t tone_key_delta,
const float tone_key_mix_weight,
const bool am_enabled,
@ -878,6 +879,7 @@ public:
divider(divider),
deviation_hz(deviation_hz),
audio_gain(audio_gain),
audio_shift_bits_s16(audio_shift_bits_s16),
tone_key_delta(tone_key_delta),
tone_key_mix_weight(tone_key_mix_weight),
am_enabled(am_enabled),
@ -890,6 +892,7 @@ public:
const uint32_t divider;
const float deviation_hz;
const float audio_gain;
const uint8_t audio_shift_bits_s16;
const uint32_t tone_key_delta;
const float tone_key_mix_weight;
const bool am_enabled;

View File

@ -84,7 +84,7 @@ void WM8731::init() {
});
write(AnalogAudioPathControl {
.micboost = 1, // Enable 20dB boost
.micboost = 0, // Disable 20dB boost by default
.mutemic = 0, // Disable mute (unmute)
.insel = 1, // Microphone input to ADC
.bypass = 0,