1111#define UPSCALE_C2 -8191
1212
1313#if 1
14- #define UPSAMPLE_FUNC (NAME, EMIT ) \
15- void NAME (int16_t sample) { \
16- upsample_buf_##NAME##_a_ = upsample_buf_##NAME##_b_; \
17- upsample_buf_##NAME##_b_ = upsample_buf_##NAME##_c_; \
18- upsample_buf_##NAME##_c_ = upsample_buf_##NAME##_d_; \
19- upsample_buf_##NAME##_d_ = sample; \
20- EMIT (clamptoi16 ((upsample_buf_##NAME##_a_ * UPSCALE_C2 + \
21- upsample_buf_##NAME##_b_ * UPSCALE_C1 + \
22- upsample_buf_##NAME##_c_ * UPSCALE_C1 + \
23- upsample_buf_##NAME##_d_ * UPSCALE_C2) >> 15 )); \
24- EMIT (upsample_buf_##NAME##_c_); \
25- } \
26- void clear_##NAME() { \
27- upsample_buf_##NAME##_a_ = 0 ; \
28- upsample_buf_##NAME##_b_ = 0 ; \
29- upsample_buf_##NAME##_c_ = 0 ; \
30- upsample_buf_##NAME##_d_ = 0 ; \
31- } \
32- int16_t upsample_buf_##NAME##_a_ = 0 ; \
33- int16_t upsample_buf_##NAME##_b_ = 0 ; \
34- int16_t upsample_buf_##NAME##_c_ = 0 ; \
14+ #define UPSAMPLE_FUNC (NAME, EMIT ) \
15+ void NAME (int16_t sample) { \
16+ upsample_buf_##NAME##_a_ = upsample_buf_##NAME##_b_; \
17+ upsample_buf_##NAME##_b_ = upsample_buf_##NAME##_c_; \
18+ upsample_buf_##NAME##_c_ = upsample_buf_##NAME##_d_; \
19+ upsample_buf_##NAME##_d_ = sample; \
20+ EMIT (clamptoi16 ((upsample_buf_##NAME##_a_ * UPSCALE_C2 + \
21+ upsample_buf_##NAME##_b_ * UPSCALE_C1 + \
22+ upsample_buf_##NAME##_c_ * UPSCALE_C1 + \
23+ upsample_buf_##NAME##_d_ * UPSCALE_C2) >> 15 )); \
24+ EMIT (upsample_buf_##NAME##_c_); \
25+ } \
26+ void clear_##NAME() { \
27+ upsample_buf_##NAME##_a_ = 0 ; \
28+ upsample_buf_##NAME##_b_ = 0 ; \
29+ upsample_buf_##NAME##_c_ = 0 ; \
30+ upsample_buf_##NAME##_d_ = 0 ; \
31+ } \
32+ int16_t upsample_buf_##NAME##_a_ = 0 ; \
33+ int16_t upsample_buf_##NAME##_b_ = 0 ; \
34+ int16_t upsample_buf_##NAME##_c_ = 0 ; \
3535 int16_t upsample_buf_##NAME##_d_ = 0
3636#else
37- #define UPSAMPLE_FUNC(NAME, EMIT) \
38- void NAME(int16_t sample) { \
39- EMIT(sample); EMIT(sample); \
40- } \
41- void clear_##NAME() { \
37+ #define UPSAMPLE_FUNC(NAME, EMIT) \
38+ void NAME(int16_t sample) { \
39+ EMIT(sample); EMIT(sample); \
40+ } \
41+ void clear_##NAME() { \
4242 }
4343 #endif
4444
45- #define DOWNSAMPLE_FUNC (NAME, EMIT ) \
46- void NAME (int16_t sample) { \
47- if (downsample_flag_##NAME##_) { \
48- EMIT ((downsample_buf_##NAME##_ + sample) >> 1 ); \
49- downsample_flag_##NAME##_ = false ; \
50- } else { \
51- downsample_buf_##NAME##_ = sample; \
52- downsample_flag_##NAME##_ = true ; \
53- } \
54- } \
55- void clear_##NAME() { \
56- downsample_buf_##NAME##_ = 0 ; \
57- downsample_flag_##NAME##_ = false ; \
58- } \
59- int16_t downsample_buf_##NAME##_ = 0 ; \
45+ #define DOWNSAMPLE_FUNC (NAME, EMIT ) \
46+ void NAME (int16_t sample) { \
47+ if (downsample_flag_##NAME##_) { \
48+ EMIT ((downsample_buf_##NAME##_ + sample) >> 1 ); \
49+ downsample_flag_##NAME##_ = false ; \
50+ } else { \
51+ downsample_buf_##NAME##_ = sample; \
52+ downsample_flag_##NAME##_ = true ; \
53+ } \
54+ } \
55+ void clear_##NAME() { \
56+ downsample_buf_##NAME##_ = 0 ; \
57+ downsample_flag_##NAME##_ = false ; \
58+ } \
59+ int16_t downsample_buf_##NAME##_ = 0 ; \
6060 bool downsample_flag_##NAME##_ = false
6161
6262// PlayWav reads a file from serialflash or SD and converts
@@ -89,6 +89,7 @@ class PlayWav : StateMachine, public ProffieOSAudioStream {
8989 }
9090 PlayLoop (file_id.GetEffect ()->GetFollowing ());
9191 }
92+
9293 void PlayLoop (Effect* effect) {
9394 effect_.set (effect);
9495 }
@@ -258,7 +259,7 @@ class PlayWav : StateMachine, public ProffieOSAudioStream {
258259 }
259260 break ;
260261 }
261-
262+
262263 if (16 != ReadFile (16 )) {
263264 default_output->println (" Read failed." );
264265 goto fail;
@@ -285,7 +286,7 @@ class PlayWav : StateMachine, public ProffieOSAudioStream {
285286
286287 ptr_ = buffer + 8 ;
287288 end_ = buffer + 8 ;
288-
289+
289290 while (true ) {
290291 if (wav_) {
291292 if (ReadFile (8 ) != 8 ) break ;
@@ -428,7 +429,7 @@ class PlayWav : StateMachine, public ProffieOSAudioStream {
428429 // Number of samples_ in samples that has been
429430 // sent out already.
430431 int written_ = 0 ;
431-
432+
432433 // Number of samples in samples_
433434 int num_samples_ = 0 ;
434435 int16_t samples_[32 ];
0 commit comments