Skip to content

Commit

Permalink
Merge pull request #483 from db4ple/active-devel
Browse files Browse the repository at this point in the history
Changed all uses for audio generation to be based on the softdds functions.
  • Loading branch information
df8oe authored Aug 1, 2016
2 parents 62f897f + 03e6539 commit 74c81d1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 58 deletions.
8 changes: 4 additions & 4 deletions mchf-eclipse/drivers/audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,16 +2331,16 @@ static void audio_rx_processor(int16_t *src, int16_t *dst, int16_t size)
while(i < size/2) // transfer to DMA buffer and do conversion to INT
{
// TODO: move to softdds ...
if((ts.beep_active) && (ads.beep_word)) // is beep active?
if((ts.beep_active) && (ads.beep.step)) // is beep active?
{
// Yes - Calculate next sample
beep_accum += ads.beep_word; // generate tone using frequency word, calculating next sample
beep_idx = (beep_accum >> DDS_ACC_SHIFT)%DDS_TBL_SIZE; // shift accumulator to index sine table

beep_idx = softdds_step(&ads.beep); // shift accumulator to index sine table
ads.b_buffer[i] += (float32_t)(DDS_TABLE[beep_idx] * ads.beep_loudness_factor); // load indexed sine wave value, adding it to audio, scaling the amplitude and putting it on "b" - speaker (ONLY)
}
else // beep not active - force reset of accumulator to start at zero to minimize "click" caused by an abrupt voltage transition at startup
{
beep_accum = 0;
ads.beep.acc = 0;
}
//
*dst++ = (int16_t)ads.b_buffer[i]; // Speaker channel (variable level)
Expand Down
4 changes: 3 additions & 1 deletion mchf-eclipse/drivers/audio/audio_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define __AUDIO_DRIVER_H

#include "arm_math.h"
#include "softdds.h"

// 16 or 24 bits from Codec
//
//#define USE_24_BITS
Expand Down Expand Up @@ -127,7 +129,7 @@ typedef struct AudioDriverState
float fm_subaudible_tone_det_freq; // frequency, in Hz, of currently-selected subaudible tone for detection
bool fm_subaudible_tone_detected; // TRUE if subaudible tone has been detected
//
ulong beep_word; // this is the actively-used DDS tone word for the radio's beep generator
SoftDds beep; // this is the actively-used DDS tone word for the radio's beep generator
float beep_loudness_factor; // this is used to set the beep loudness
//
// The following are pre-calculated terms for the Goertzel functions used for subaudible tone detection
Expand Down
17 changes: 3 additions & 14 deletions mchf-eclipse/drivers/audio/audio_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ void AudioManagement_LoadBeepFreq(void)

if(ts.flags2 & FLAGS2_KEY_BEEP_ENABLE) // is beep enabled?
{
ads.beep_word = softdds_stepForSampleRate(ts.beep_frequency,48000);
softdds_setfreq(&ads.beep, ts.beep_frequency,ts.samp_rate,false);
}
else
{
ads.beep_word = 0; // not enabled - zero out frequency word
softdds_setfreq(&ads.beep, 0,ts.samp_rate,true); // not enabled - zero out frequency word
}
//
calc = (float)ts.beep_loudness; // range 0-20
Expand Down Expand Up @@ -406,16 +406,5 @@ void AudioManagement_SetSidetoneForDemodMode(uint16_t dmod_mode, bool tune_mode)
}
}

if (tonefreq[1] != 0.0)
{
softdds_setfreq_dbl(tonefreq,ts.samp_rate,0);
softdds_setfreq(0.0,ts.samp_rate,0);
}
else
{
softdds_setfreq(tonefreq[0],ts.samp_rate,0);

tonefreq[0] = 0.0;
softdds_setfreq_dbl(tonefreq,ts.samp_rate,0);
}
softdds_setfreq_dbl(tonefreq,ts.samp_rate,0);
}
46 changes: 10 additions & 36 deletions mchf-eclipse/drivers/audio/softdds/softdds.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@
#include "softdds.h"


// Soft DDS public structure
typedef struct
{
// DDS accumulator
ulong acc;

// DDS step - not working if part of the structure
ulong step;

} SoftDds;




// Software DDS public
Expand All @@ -51,43 +39,29 @@ uint32_t softdds_stepForSampleRate(float freq,ulong samp_rate)
/**
* Initialize softdds for given frequency and sample rate
*/
void softdds_setfreq(float freq,ulong samp_rate,uchar smooth)
void softdds_setfreq(__IO SoftDds* softdds_p, float freq,ulong samp_rate,uchar smooth)
{
// Reset accumulator, if need smooth tone
// transition, do not reset it (e.g. wspr)
if(!smooth)
{
softdds.acc = 0;
softdds_p->acc = 0;
}
// Calculate new step
softdds.step = softdds_stepForSampleRate(freq,samp_rate);
softdds_p->step = softdds_stepForSampleRate(freq,samp_rate);
}

void softdds_setfreq_dbl(float freq[2],ulong samp_rate,uchar smooth)
{
// Reset accumulator, if need smooth tone
// transition, do not reset it (e.g. wspr)
if(!smooth)
{
dbldds[0].acc = 0;
dbldds[1].acc = 0;
}
// Calculate new step
dbldds[0].step = softdds_stepForSampleRate(freq[0],samp_rate);
dbldds[1].step = softdds_stepForSampleRate(freq[1],samp_rate);
}

/**
* Execute a single step in the sinus generation
* Initialize softdds for given frequency and sample rate
*/
static inline uint32_t softdds_step(__IO SoftDds* dds)

void softdds_setfreq_dbl(float freq[2],ulong samp_rate,uchar smooth)
{
dds->acc += dds->step;
softdds_setfreq(&dbldds[0],freq[0],samp_rate,smooth);
softdds_setfreq(&dbldds[1],freq[1],samp_rate,smooth);
}

// now scale down precision and make sure that
// index wraps around properly
return (dds->acc >> DDS_ACC_SHIFT)%DDS_TBL_SIZE;
}

/*
* Get the index which represents a -90 degree shift compared to
Expand Down Expand Up @@ -120,7 +94,7 @@ void softdds_runf(float *i_buff,float *q_buff,ushort size)
for(i = 0; i < size; i++)
{
// Calculate next sample
k = softdds_step(&softdds);
k = softdds_step(&dbldds[0]);

// Load I value (sin)
*i_buff = DDS_TABLE[k];
Expand Down
31 changes: 30 additions & 1 deletion mchf-eclipse/drivers/audio/softdds/softdds.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,39 @@
#ifndef __SOFTDDS_H
#define __SOFTDDS_H

#include "dds_table.h"

uint32_t softdds_stepForSampleRate(float freq,ulong samp_rate);

void softdds_setfreq(float freq, ulong samp_rate, uchar smooth);

// Soft DDS public structure
typedef struct
{
// DDS accumulator
ulong acc;

// DDS step - not working if part of the structure
ulong step;

} SoftDds;



/**
* Execute a single step in the sinus generation
*/
inline uint32_t softdds_step(__IO SoftDds* dds)
{
dds->acc += dds->step;

// now scale down precision and make sure that
// index wraps around properly
return (dds->acc >> DDS_ACC_SHIFT)%DDS_TBL_SIZE;
}


void softdds_setfreq(__IO SoftDds* dds, float freq, ulong samp_rate, uchar smooth);

void softdds_runf(float32_t *i_buff, float32_t *q_buff, ushort size);


Expand Down
2 changes: 2 additions & 0 deletions mchf-eclipse/drivers/ui/ui_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6089,7 +6089,9 @@ static void UiDriver_PowerDownCleanup(void)
ts.powering_down = 1; // indicate that we should be powering down

if(ts.ser_eeprom_in_use != SER_EEPROM_IN_USE_DONT_SAVE)
{
UiConfiguration_SaveEepromValues(); // save EEPROM values
}


// Actual power-down moved to "UiDriverHandlePowerSupply()" with part of delay
Expand Down
4 changes: 3 additions & 1 deletion mchf-eclipse/drivers/ui/ui_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,9 @@ static void UiDriverUpdateMenuLines(uchar index, uchar mode, int pos)

if(fchange && ts.dmod_mode == DEMOD_CW) // did it change?
{
softdds_setfreq((float)ts.sidetone_freq,ts.samp_rate,0);
float freq[2] = { ts.sidetone_freq, 0.0 };

softdds_setfreq_dbl(freq,ts.samp_rate,0);
UiDriver_FrequencyUpdateLOandDisplay(false);
}
snprintf(options,32, " %uHz", (uint)ts.sidetone_freq);
Expand Down
3 changes: 2 additions & 1 deletion mchf-eclipse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ void TransceiverStateInit(void)
void MiscInit(void)
{
// Init Soft DDS
softdds_setfreq(0.0,ts.samp_rate,0);
float freq[2] = { 0.0, 0.0 };
softdds_setfreq_dbl(freq,ts.samp_rate,0);
}

/*
Expand Down

1 comment on commit 74c81d1

@BI3MEK
Copy link

@BI3MEK BI3MEK commented on 74c81d1 Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cc] ..\obj\usb_core.o: In function USB_OTG_DriveVbus': [cc] E:\MCHF\mchf-github-active-devel-20160801\mchf-github-active-devel\mchf-eclipse\usb\otg\src/usb_core.c:735: undefined reference toUSB_OTG_BSP_DriveVBUS'
[cc] ..\obj\usb_core.o: In function USB_OTG_CoreInitHost': [cc] E:\MCHF\mchf-github-active-devel-20160801\mchf-github-active-devel\mchf-eclipse\usb\otg\src/usb_core.c:635: undefined reference toUSB_OTG_BSP_ConfigVBUS'

Please sign in to comment.