Skip to content

Commit 43bee66

Browse files
committed
Dynamic Resampling
1 parent fd14b58 commit 43bee66

File tree

8 files changed

+429
-626
lines changed

8 files changed

+429
-626
lines changed

examples/sandbox/examples-sdr/generator-am_sender-audiokit/generator-am_sender-audiokit.ino

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ void setup() {
4141
modulated_data.resize(num_samples);
4242

4343
// define resample we resample the audio data from 44100 to 13M
44-
auto cfgr = resample.defaultConfig();
45-
cfgr.channels = channels;
46-
cfgr.sample_rate_from = sample_rate;
47-
cfgr.sample_rate = sample_rate_carrier;
48-
resample.begin(cfgr);
44+
resample.begin(sample_rate, sample_rate_carrier);
4945

5046
// setup test tone
5147
auto cfgs = sound.defaultConfig();

examples/tests/test-resample-in/test-resample-in.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ void setup(void) {
1616
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
1717

1818
// define resample
19-
auto cfgr = resample.defaultConfig();
20-
cfgr.channels = channels;
21-
cfgr.sample_rate_from = sample_rate;
22-
cfgr.sample_rate = 22050;
23-
resample.begin(cfgr);
19+
int sample_rate_from = sample_rate;
20+
int to_sample_rate = 22050;
21+
resample.begin(sample_rate_from, to_sample_rate);
2422

2523
// Define CSV Output
2624
auto config = out.defaultConfig();

examples/tests/test-resample-out/test-resample-out.ino

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ void setup(void) {
1616
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
1717

1818
// define resample
19-
auto cfgr = resample.defaultConfig();
20-
cfgr.channels = channels;
21-
cfgr.sample_rate_from = sample_rate;
22-
cfgr.sample_rate = 22050;
23-
resample.begin(cfgr);
19+
int sample_rate_from = sample_rate;
20+
int sample_rate_to = 22050;
21+
resample.begin(sample_rate_from, sample_rate_to);
2422

2523
// Define CSV Output
2624
auto config = out.defaultConfig();

jupyter/JupyterEffects.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
"codemirror_mode": "text/x-c++src",
319319
"file_extension": ".cpp",
320320
"mimetype": "text/x-c++src",
321-
"name": "C++17",
321+
"name": "c++",
322322
"version": "17"
323323
},
324324
"widgets": {

jupyter/TestsResample.ipynb

Lines changed: 211 additions & 0 deletions
Large diffs are not rendered by default.

src/AudioLibs/Jupyter/JupyterAudio.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@ class FilePrint : public Print {
4040
template <typename T>
4141
class ChartT {
4242
public:
43-
void setup(std::string fName, int channels, int channel) {
43+
void setup(std::string fName, int channelCount, int channelNo) {
4444
this->fname = fName;
45-
this->channels = channels;
46-
this->channel = channel;
45+
this->channels = channelCount;
46+
if (this->channels==0){
47+
LOGE("Setting channels to 0");
48+
}
49+
this->channel = channelNo;
50+
}
51+
52+
int getChannels() {
53+
return this->channels;
54+
}
55+
56+
int getChannel() {
57+
return this->channel;
4758
}
4859

4960
/// Provides data as svg polyline
@@ -80,7 +91,7 @@ class ChartT {
8091
std::stringstream str;
8192
std::string fname;
8293
const int wav_header_size = 44;
83-
int channels=1;
94+
int channels=0;
8495
int channel=0;
8596

8697
int transform(int x){

src/AudioTools/AudioPrint.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ namespace audio_tools {
1616
# define FLUSH_OVERRIDE
1717
#endif
1818

19+
#ifndef min
20+
# define min(A,B) A<B?A:B
21+
#endif
22+
1923
/**
2024
* @brief Abstract Audio Ouptut class
2125
* @author Phil Schatzmann
@@ -723,5 +727,44 @@ class MemoryPrint : public AudioPrint {
723727

724728
};
725729

730+
/**
731+
* @brief The Print API which writes the data to a byte array
732+
*/
733+
class AdapterPrintToArray : public Print {
734+
public:
735+
void begin(uint8_t* array, int len){
736+
p_array = array;
737+
size = len;
738+
pos = 0;
739+
}
740+
741+
virtual size_t write(const uint8_t *buffer, size_t bytes) override {
742+
int size_eff = min((int)bytes, availableForWrite());
743+
memcpy(p_array+pos, buffer, size_eff);
744+
pos+=size_eff;
745+
return size_eff;
746+
}
747+
748+
749+
virtual size_t write(uint8_t ch) override {
750+
LOGE("Not Supported")
751+
return 0;
752+
}
753+
754+
virtual int availableForWrite() override {
755+
return size-pos;
756+
}
757+
758+
virtual int available() {
759+
return pos;
760+
}
761+
762+
protected:
763+
uint8_t* p_array = nullptr;
764+
int size = 0;
765+
int pos;
766+
767+
};
768+
726769

727770
} //n namespace

0 commit comments

Comments
 (0)