Skip to content

Commit 822f335

Browse files
committed
ResampleStream
1 parent 3b85fb6 commit 822f335

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

src/AudioTools/Resample.h

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,26 +300,47 @@ struct ResampleConfig : public AudioBaseInfo {
300300
};
301301

302302
/**
303-
* @brief Stream class which can be used to resample between different sample rates.
303+
* @brief Flexible Stream class which can be used to resample audio data between
304+
* different sample rates.
304305
* @author Phil Schatzmann
305306
* @copyright GPLv3
306307
* @tparam T data type of audio data
307308
*/
308309
template<typename T>
309310
class ResampleStream : public AudioStreamX, AudioBaseInfoDependent {
310311
public:
312+
/**
313+
* @brief Construct a new Resample Stream object which supports resampling
314+
* on it's write operations
315+
*
316+
* @param out
317+
* @param precision
318+
*/
311319
ResampleStream(Print &out, ResamplePrecision precision = Medium){
312320
this->precision = precision;
313321
up.setOut(down); // we upsample first
314322
down.setOut(out); // so that we can downsample to the requested rate
315323
}
316324

325+
/**
326+
* @brief Construct a new Resample Stream object which supports resampling
327+
* both on read and write.
328+
*
329+
* @param out
330+
* @param precision
331+
*/
317332
ResampleStream(Stream &in, ResamplePrecision precision = Medium){
318333
this->precision = precision;
319334
up.seIn(down); // we upsample first
320335
down.setIn(in); // so that we can downsample to the requested rate
321336
}
322337

338+
/// Returns an empty configuration object
339+
ResampleConfig defaultConfig() {
340+
ResampleConfig cfg;
341+
return cfg;
342+
}
343+
323344
// Recalculates the up and downsamplers
324345
bool begin() {
325346
if (channels==0){
@@ -348,25 +369,21 @@ class ResampleStream : public AudioStreamX, AudioBaseInfoDependent {
348369
return begin();
349370
}
350371

351-
/// Handle Change of audio rate or channels
372+
/// Defines the channels and sample rates from the AudioBaseInfo. Please call setFromInfo() or setFromSampleRate() before
373+
bool begin(ResampleConfig info){
374+
channels = info.channels;
375+
from_rate = info.sample_rate_from;
376+
to_rate = info.sample_rate;
377+
return begin();
378+
}
379+
380+
/// Handle Change of the source sampling rate - and channels!
352381
void setAudioInfo(AudioBaseInfo info) override {
353382
from_rate = info.sample_rate;
354383
channels = info.channels;
355384
begin();
356385
}
357386

358-
/// Returns an empty configuration object
359-
ResampleConfig defaultConfig() {
360-
ResampleConfig cfg;
361-
return cfg;
362-
}
363-
364-
/// Defines the channels and sample rates from the AudioBaseInfo. Please call setFromInfo() or setFromSampleRate() before
365-
void begin(ResampleConfig info){
366-
from_rate = info.sample_rate_from;
367-
setAudioInfo(info);
368-
}
369-
370387
/// Determines the number of bytes which are available for write
371388
int availableForWrite() override { return up.availableForWrite(); }
372389

0 commit comments

Comments
 (0)