comparison pico_pcm.c @ 2432:18816c5c11d4

Fix Pico ADPCM decoding and get relative volume approximately correct
author Michael Pavone <pavone@retrodev.com>
date Wed, 07 Feb 2024 20:03:23 -0800
parents 61c0bfe10887
children 2ee25a487e2b
comparison
equal deleted inserted replaced
2431:61c0bfe10887 2432:18816c5c11d4
76 4, 16, 29, 44, 62, 85, 118, 175, -4, -16, -29, -44, -62, -85, -118, -175, 76 4, 16, 29, 44, 62, 85, 118, 175, -4, -16, -29, -44, -62, -85, -118, -175,
77 6, 20, 36, 54, 76, 104, 144, 214, -6, -20, -36, -54, -76, -104, -144, -214 77 6, 20, 36, 54, 76, 104, 144, 214, -6, -20, -36, -54, -76, -104, -144, -214
78 }; 78 };
79 static const int state_delta[16] = {-1, -1, 0, 0, 1, 2, 2, 3, -1, -1, 0, 0, 1, 2, 2, 3}; 79 static const int state_delta[16] = {-1, -1, 0, 0, 1, 2, 2, 3, -1, -1, 0, 0, 1, 2, 2, 3};
80 int16_t ret = sample_delta[(*state << 4) + sample]; 80 int16_t ret = sample_delta[(*state << 4) + sample];
81 int diff = state_delta[*state]; 81 int diff = state_delta[sample];
82 if (diff >= 0 || *state > 0) { 82 if (diff >= 0 || *state > 0) {
83 *state += diff; 83 *state += diff;
84 if (*state > 15) { 84 if (*state > 15) {
85 *state = 15; 85 *state = 15;
86 } 86 }
95 pcm->cycle += pcm->clock_inc; 95 pcm->cycle += pcm->clock_inc;
96 //TODO: Figure out actual attenuation 96 //TODO: Figure out actual attenuation
97 int16_t shift = pcm->ctrl & PCM_VOLUME; 97 int16_t shift = pcm->ctrl & PCM_VOLUME;
98 #ifndef IS_LIB 98 #ifndef IS_LIB
99 if (pcm->scope) { 99 if (pcm->scope) {
100 scope_add_sample(pcm->scope, pcm->scope_channel, (pcm->output >> shift) * 128, 0); 100 scope_add_sample(pcm->scope, pcm->scope_channel, (pcm->output >> shift) * 32, 0);
101 } 101 }
102 #endif 102 #endif
103 render_put_mono_sample(pcm->audio, (pcm->output >> shift) * 128); 103 render_put_mono_sample(pcm->audio, (pcm->output >> shift) * 32);
104 if (!(pcm->ctrl & PCM_ENABLED)) { 104 if (!(pcm->ctrl & PCM_ENABLED)) {
105 continue; 105 continue;
106 } 106 }
107 if (pcm->counter) { 107 if (pcm->counter) {
108 pcm->counter--; 108 pcm->counter--;