-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first pass of framework for resampler * add resample header * convert mono to stereo in ResamplerStreamer * reduce timeout for announcing state * first pass at sending stream info/stereo output * working stereo mp3s * working resampler! * use mp3s for TTS * split most streamers into own files * revert back to using pcm for tts * functioning flac decoder * implement dac volume control * publish state after muting/unmuting * flac decoder pulls directly from ring buffer * update todos * add support for volume up and down commands * tweak some memory allocations * add volume support * define i2c registers as static const * mixing algorithm - consistent announcement loudness * clear specific ring bufers in mixer when stopping * stop announcement on wake word * add some TODOs * avoid high freq loopers to prevent stuttering * apply biquad filters when resampling * clean up code/variable names * integrate synesthesiam's wav header parser * stop active pipeline before starting new stream * uniform I2C function return behavior * simplify announcement flag handling * increase and align buffer sizes * fix edge case of trying to stop a stopping pipeline * initial work for playing local media files * update for release * fix typo
- Loading branch information
Showing
27 changed files
with
3,430 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// **** BIQUAD **** // | ||
// Simple Biquad Filter Library // | ||
// Copyright (c) 2021 - 2022 David Bryant. // | ||
// All Rights Reserved. // | ||
// Distributed under the BSD Software License (see license.txt) // | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
// biquad.c | ||
|
||
#include "biquad.h" | ||
|
||
// Second-order Lowpass | ||
|
||
void biquad_lowpass (BiquadCoefficients *filter, double frequency) | ||
{ | ||
double Q = sqrt (0.5), K = tan (M_PI * frequency); | ||
double norm = 1.0 / (1.0 + K / Q + K * K); | ||
|
||
filter->a0 = K * K * norm; | ||
filter->a1 = 2 * filter->a0; | ||
filter->a2 = filter->a0; | ||
filter->b1 = 2.0 * (K * K - 1.0) * norm; | ||
filter->b2 = (1.0 - K / Q + K * K) * norm; | ||
} | ||
|
||
// Second-order Highpass | ||
|
||
void biquad_highpass (BiquadCoefficients *filter, double frequency) | ||
{ | ||
double Q = sqrt (0.5), K = tan (M_PI * frequency); | ||
double norm = 1.0 / (1.0 + K / Q + K * K); | ||
|
||
filter->a0 = norm; | ||
filter->a1 = -2.0 * norm; | ||
filter->a2 = filter->a0; | ||
filter->b1 = 2.0 * (K * K - 1.0) * norm; | ||
filter->b2 = (1.0 - K / Q + K * K) * norm; | ||
} | ||
|
||
// Initialize the specified biquad filter with the given parameters. Note that the "gain" parameter is supplied here | ||
// to save a multiply every time the filter in applied. | ||
|
||
void biquad_init (Biquad *f, const BiquadCoefficients *coeffs, float gain) | ||
{ | ||
f->coeffs = *coeffs; | ||
f->coeffs.a0 *= gain; | ||
f->coeffs.a1 *= gain; | ||
f->coeffs.a2 *= gain; | ||
f->in_d1 = f->in_d2 = 0.0F; | ||
f->out_d1 = f->out_d2 = 0.0F; | ||
f->first_order = (coeffs->a2 == 0.0F && coeffs->b2 == 0.0F); | ||
} | ||
|
||
// Apply the supplied sample to the specified biquad filter, which must have been initialized with biquad_init(). | ||
|
||
float biquad_apply_sample (Biquad *f, float input) | ||
{ | ||
float sum; | ||
|
||
if (f->first_order) | ||
sum = (input * f->coeffs.a0) + (f->in_d1 * f->coeffs.a1) - (f->coeffs.b1 * f->out_d1); | ||
else | ||
sum = (input * f->coeffs.a0) + (f->in_d1 * f->coeffs.a1) + (f->in_d2 * f->coeffs.a2) - (f->coeffs.b1 * f->out_d1) - (f->coeffs.b2 * f->out_d2); | ||
|
||
f->out_d2 = f->out_d1; | ||
f->out_d1 = sum; | ||
f->in_d2 = f->in_d1; | ||
f->in_d1 = input; | ||
return sum; | ||
} | ||
|
||
// Apply the supplied buffer to the specified biquad filter, which must have been initialized with biquad_init(). | ||
|
||
void biquad_apply_buffer (Biquad *f, float *buffer, int num_samples, int stride) | ||
{ | ||
if (f->first_order) while (num_samples--) { | ||
float sum = (*buffer * f->coeffs.a0) + (f->in_d1 * f->coeffs.a1) - (f->coeffs.b1 * f->out_d1); | ||
f->out_d2 = f->out_d1; | ||
f->in_d2 = f->in_d1; | ||
f->in_d1 = *buffer; | ||
*buffer = f->out_d1 = sum; | ||
buffer += stride; | ||
} | ||
else while (num_samples--) { | ||
float sum = (*buffer * f->coeffs.a0) + (f->in_d1 * f->coeffs.a1) + (f->in_d2 * f->coeffs.a2) - (f->coeffs.b1 * f->out_d1) - (f->coeffs.b2 * f->out_d2); | ||
f->out_d2 = f->out_d1; | ||
f->in_d2 = f->in_d1; | ||
f->in_d1 = *buffer; | ||
*buffer = f->out_d1 = sum; | ||
buffer += stride; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// **** BIQUAD **** // | ||
// Simple Biquad Filter Library // | ||
// Copyright (c) 2021 - 2022 David Bryant. // | ||
// All Rights Reserved. // | ||
// Distributed under the BSD Software License (see license.txt) // | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
// biquad.h | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
typedef struct { | ||
float a0, a1, a2, b1, b2; | ||
} BiquadCoefficients; | ||
|
||
typedef struct { | ||
BiquadCoefficients coeffs; // coefficients | ||
float in_d1, in_d2; // delayed input | ||
float out_d1, out_d2; // delayed output | ||
int first_order; // optimization | ||
} Biquad; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void biquad_init (Biquad *f, const BiquadCoefficients *coeffs, float gain); | ||
|
||
void biquad_lowpass (BiquadCoefficients *filter, double frequency); | ||
void biquad_highpass (BiquadCoefficients *filter, double frequency); | ||
|
||
void biquad_apply_buffer (Biquad *f, float *buffer, int num_samples, int stride); | ||
float biquad_apply_sample (Biquad *f, float input); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.