Browse Source

update

master
zhaohe 2 years ago
parent
commit
5c9bf1f410
  1. 33
      spisound.c

33
spisound.c

@ -52,14 +52,12 @@ typedef struct {
static audio_t multiplierX2(int32_t *voice, int32_t size) {
static int32_t voicebuf[MAX_ONE_FRAME_VOICE_SIZE * 2]; // 50ms
if (size > MAX_ONE_FRAME_VOICE_SIZE) {
size = MAX_ONE_FRAME_VOICE_SIZE;
}
for (size_t i = 0; i < size; i++) {
voicebuf[i * 2] = voice[i];
if (i + 1 < size) {
voicebuf[i * 2 + 1] = (voice[i] + voice[i + 1]) / 2;
} else {
voicebuf[i * 2 + 1] = voice[i] + (voice[i] - voice[i - 1]);
}
}
audio_t ret;
@ -78,6 +76,8 @@ static audio_t multiplierX2_2(int32_t *voice, int32_t size) {
voicebuf[i * 2] = voice[i];
if (i + 1 < size) {
voicebuf[i * 2 + 1] = (voice[i] + voice[i + 1]) / 2;
} else {
voicebuf[i * 2 + 1] = voice[i] + (voice[i] - voice[i - 1]);
}
}
audio_t ret;
@ -115,18 +115,33 @@ static int32_t filter(int32_t input, int32_t v1, int32_t v2, int32_t v3, int32_t
}
static bool filterVoice(int32_t *voice, int32_t size) {
#if 0
#if 1
static int32_t vbuf[MAX_ONE_FRAME_VOICE_SIZE * 3]; // 50ms
static int32_t vbufnum = 0;
vbufnum++;
memmove(vbuf, vbuf + size, 2 * size * sizeof(int32_t));
memcpy(vbuf + 2 * size, voice, size * sizeof(int32_t));
// printf("size:%d\n", size);
if (vbufnum < 3) {
return false;
}
int32_t *cachebegin = &vbuf[size];
for (int i = 0; i < size; i++) {
voice[i] = filter(*(cachebegin + i), //
*(cachebegin + i - 1), //
*(cachebegin + i - 2), //
*(cachebegin + i - 3), //
*(cachebegin + i + 1), //
*(cachebegin + i + 2), //
*(cachebegin + i + 3));
// voice[i] = *(cachebegin + i);
}
return true;
#endif
#if 0
static int32_t vbuf[MAX_ONE_FRAME_VOICE_SIZE]; // 50ms
memcpy(vbuf, voice, size * sizeof(int32_t));
@ -137,6 +152,7 @@ static bool filterVoice(int32_t *voice, int32_t size) {
*(cachebegin + i + 3));
// voice[i] = cachebegin[i];
}
#endif
return true;
}
@ -232,12 +248,19 @@ static void readvoice() {
ret = read(m_fd, voicebuf, rxdatabytesize);
gpio_set_value(1);
static int count = 0;
count++;
if (count < 10) {
return;
}
int32_t voiceframesize = 0;
bool ready = filterVoice(voicebuf, rxdatabytesize / 4);
if (ready) {
audio_t v1 = multiplierX2(voicebuf, rxdatabytesize / 4);
audio_t v2 = multiplierX2_2(v1.voice, v1.size);
if (m_callback) m_callback(v2.voice, v2.size);
// if (m_callback) m_callback(voicebuf, rxdatabytesize / 4);
}
return;

Loading…
Cancel
Save