Skip to content

Commit

Permalink
add config file
Browse files Browse the repository at this point in the history
  • Loading branch information
paulh002 committed Jun 27, 2022
1 parent b9de449 commit 0f108e3
Show file tree
Hide file tree
Showing 35 changed files with 1,386 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This file was last opened by PID 33640
This file was last opened by PID 19252
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .visualgdb/CodeDB/SoapyHifiBerry-Release-VisualGDB/tmp00000006.npd
Binary file not shown.
Binary file not shown.
Binary file modified .visualgdb/CodeExplorer/NodeFlags.dat
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion SoapyHifiBerry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "AudioInput.h"
#include "AudioOutput.h"
#include "si5351.h"

#include "configfile.h"

typedef enum hifiberrysdrStreamFormat
{
Expand Down Expand Up @@ -156,8 +156,12 @@ class SoapyHifiBerry : public SoapySDR::Device

unique_ptr<AudioOutput> uptr_audiooutput;
unique_ptr<AudioInput> uptr_audioinput;
unique_ptr<cfg::File> uptr_cfg;

DataBuffer<IQSample> source_buffer_rx;
DataBuffer<IQSample> source_buffer_tx;
unique_ptr<Si5351> pSI5351;

int get_int(string section, string key);
string get_string(string section, string key);
};
6 changes: 6 additions & 0 deletions SoapyHifiBerry.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,26 @@
<ItemGroup>
<ClCompile Include="AudioInput.cpp" />
<ClCompile Include="AudioOutput.cpp" />
<ClCompile Include="configfile.cpp" />
<ClCompile Include="configoption.cpp" />
<ClCompile Include="RtAudio.cpp" />
<ClCompile Include="si5351.cpp" />
<ClCompile Include="SoapyHifiBerry.cpp" />
<ClCompile Include="SoapyHifiBerrySettings.cpp" />
<ClCompile Include="SoapyHifiBerryStreaming.cpp" />
<ClCompile Include="strlib.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Audiodefs.h" />
<ClInclude Include="AudioInput.h" />
<ClInclude Include="AudioOutput.h" />
<ClInclude Include="configfile.h" />
<ClInclude Include="configoption.h" />
<ClInclude Include="DataBuffer.h" />
<ClInclude Include="RtAudio.h" />
<ClInclude Include="si5351.h" />
<ClInclude Include="SoapyHifiBerry.h" />
<ClInclude Include="strlib.h" />
</ItemGroup>
<ItemGroup>
<None Include="SoapyHifiBerry-Debug.vgdbsettings" />
Expand Down
18 changes: 18 additions & 0 deletions SoapyHifiBerry.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
<ClCompile Include="SoapyHifiBerryStreaming.cpp">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="configfile.cpp">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="configoption.cpp">
<Filter>Source files</Filter>
</ClCompile>
<ClCompile Include="strlib.cpp">
<Filter>Source files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SoapyHifiBerry.h">
Expand All @@ -63,6 +72,15 @@
<ClInclude Include="si5351.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="configfile.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="configoption.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="strlib.h">
<Filter>Header files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="SoapyHifiBerry-Debug.vgdbsettings">
Expand Down
40 changes: 37 additions & 3 deletions SoapyHifiBerrySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
/***********************************************************************
* Device interface
**********************************************************************/
const cfg::File::ConfigMap defaultOptions = {
{"si5351", {{"correction", cfg::makeOption("50000")}}},
{"sound", {{"device", cfg::makeOption("snd_rpi_hifiberry_dacplusadcpro")}}}
};

int SoapyHifiBerry::get_int(string section, string key)
{
auto option = uptr_cfg->getSection(section);
auto s = option.find(key);
if (s == option.end())
return 0;
string st = s->second;
return atoi((const char *)st.c_str());
}

string SoapyHifiBerry::get_string(string section, string key)
{
string st;
auto option = uptr_cfg->getSection(section);
auto s = option.find(key);
if (s != option.end())
st = s->second;
return st;
}

SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
{
Expand All @@ -20,6 +44,13 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
SoapySDR_log(SOAPY_SDR_INFO, "SoapyHifiBerry::SoapyHifiBerry constructor called");
no_channels = 1;

uptr_cfg = make_unique<cfg::File>();
if (!uptr_cfg->loadFromFile("hifiberry.cfg"))
{
uptr_cfg->setDefaultOptions(defaultOptions);
uptr_cfg->writeToFile("hifiberry.cfg");
}

uptr_audiooutput = make_unique<AudioOutput>(192000, &source_buffer_tx, RtAudio::LINUX_ALSA);
uptr_audioinput = make_unique<AudioInput>(192000, true, &source_buffer_rx, RtAudio::LINUX_ALSA);

Expand All @@ -32,12 +63,15 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
printf("Audio device %s\n", devices[i].c_str());
}
}
uptr_audiooutput->open("snd_rpi_hifiberry_dacplusadcpro");
int corr = get_int("si5351", "correction");
string dev = get_string("sound", "device");

uptr_audiooutput->open(dev);
uptr_audioinput->open(uptr_audiooutput->get_device());

pSI5351 = make_unique<Si5351>("/dev/i2c-1",SI5351_BUS_BASE_ADDR);
pSI5351->init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
pSI5351->set_correction(-200000L, SI5351_PLL_INPUT_XO);
pSI5351->set_correction((long)corr, SI5351_PLL_INPUT_XO);
pSI5351->drive_strength(CLK_VFO_RX, SI5351_DRIVE_2MA);
pSI5351->drive_strength(CLK_VFO_TX, SI5351_DRIVE_2MA);
pSI5351->output_enable(CLK_VFO_RX, 1);
Expand Down Expand Up @@ -69,7 +103,7 @@ std::string SoapyHifiBerry::getHardwareKey(void) const
}

SoapySDR::Kwargs SoapyHifiBerry::getHardwareInfo(void) const
{
{

SoapySDR_log(SOAPY_SDR_INFO, "SoapyHifiBerry::getHardwareInfo called");

Expand Down
22 changes: 19 additions & 3 deletions SoapyHifiBerryStreaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <queue>

void SoapyHifiBerry::setSampleRate(const int direction, const size_t channel, const double rate)
{
Expand Down Expand Up @@ -127,6 +128,9 @@ void SoapyHifiBerry::closeStream(SoapySDR::Stream *stream)
}
}

std::queue<float> delay_queue;
const int delay = 0;

int SoapyHifiBerry::readStream(
SoapySDR::Stream *handle,
void *const *buffs,
Expand All @@ -147,13 +151,26 @@ int SoapyHifiBerry::readStream(
uptr_audioinput->read(iqsamples);
for (auto con : iqsamples)
{
target_buffer[nr_samples++] = con;
IQSample iq = con;
if (delay > 0)
{
delay_queue.push(iq.real());
iq.real(0.0);
if (delay_queue.size() == delay)
{
iq.real(delay_queue.front());
delay_queue.pop();
}
}
target_buffer[nr_samples++] = iq;
//printf("I %f, Q %f\n", con.real(), con.imag());
}
}
//printf("nr_samples %d sample: %d %d \n", nr_samples, left_sample, right_sample);
//printf("nr_samples %d sample: %d %d \n", nr_samples, left_sample, right_sample);
return (nr_samples); //return the number of IQ samples
}


int SoapyHifiBerry::writeStream(SoapySDR::Stream *handle, const void *const *buffs, const size_t numElems, int &flags, const long long timeNs, const long timeoutUs)
{
size_t ret;
Expand All @@ -168,7 +185,6 @@ int SoapyHifiBerry::writeStream(SoapySDR::Stream *handle, const void *const *buf
{
for (int i = 0; i < numElems; i++)
{
IQSample iq;
iqsamples.push_back(target_buffer[i]);
}
uptr_audiooutput->write(iqsamples);
Expand Down
Loading

0 comments on commit 0f108e3

Please sign in to comment.