@@ -300,26 +300,47 @@ struct ResampleConfig : public AudioBaseInfo {
300
300
};
301
301
302
302
/* *
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.
304
305
* @author Phil Schatzmann
305
306
* @copyright GPLv3
306
307
* @tparam T data type of audio data
307
308
*/
308
309
template <typename T>
309
310
class ResampleStream : public AudioStreamX , AudioBaseInfoDependent {
310
311
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
+ */
311
319
ResampleStream (Print &out, ResamplePrecision precision = Medium){
312
320
this ->precision = precision;
313
321
up.setOut (down); // we upsample first
314
322
down.setOut (out); // so that we can downsample to the requested rate
315
323
}
316
324
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
+ */
317
332
ResampleStream (Stream &in, ResamplePrecision precision = Medium){
318
333
this ->precision = precision;
319
334
up.seIn (down); // we upsample first
320
335
down.setIn (in); // so that we can downsample to the requested rate
321
336
}
322
337
338
+ // / Returns an empty configuration object
339
+ ResampleConfig defaultConfig () {
340
+ ResampleConfig cfg;
341
+ return cfg;
342
+ }
343
+
323
344
// Recalculates the up and downsamplers
324
345
bool begin () {
325
346
if (channels==0 ){
@@ -348,25 +369,21 @@ class ResampleStream : public AudioStreamX, AudioBaseInfoDependent {
348
369
return begin ();
349
370
}
350
371
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!
352
381
void setAudioInfo (AudioBaseInfo info) override {
353
382
from_rate = info.sample_rate ;
354
383
channels = info.channels ;
355
384
begin ();
356
385
}
357
386
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
-
370
387
// / Determines the number of bytes which are available for write
371
388
int availableForWrite () override { return up.availableForWrite (); }
372
389
0 commit comments