Я работаю с WAVE-файлом, воспроизводя его с помощью интерфейса ALSA PCM в Linux, и услышал шум при быстром и частичном воспроизведении файла.
Вот моя функция воспроизведения. >
static int playback_function(uint8_t *pcm_buf, int pcm_frames)
{
int rc;
uint8_t *buf;
int frame_size, sent;
int periodsize;
int left;
frame_size = chan * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
periodsize = sys_periodsize; // 320 in my system
buf = pcm_buf;
left = pcm_frames;
sent = 0;
while (left > 0) {
sent = (left > periodsize) ? periodsize : left;
rc = snd_pcm_writei(pcm_handle, buf, sent);
printf("rc: %d, sent: %d\n", rc, sent);
if (rc == -EAGAIN || (rc >= 0 && (size_t)rc < sent)) {
snd_pcm_wait(pcm_handle, 10);
} else if (rc == -EPIPE) {
snd_pcm_recover(pcm_handle, rc, 0);
} else if (rc < 0) {
break;
}
if (rc > 0) {
left -= rc;
buf += rc * frame_size;
}
}
return rc;
}
Pcm_buf и pcm_frames получены из swr_convert() в libswresample, в моем случае pcm_frames равно 1187.
Добавив printf("rc: %d, send: %d\n", rc, send);, я получил следующие журналы.
Я работаю с WAVE-файлом, воспроизводя его с помощью интерфейса ALSA PCM в Linux, и услышал шум при быстром и частичном воспроизведении файла. Вот моя функция воспроизведения. > [code]static int playback_function(uint8_t *pcm_buf, int pcm_frames) { int rc; uint8_t *buf; int frame_size, sent; int periodsize; int left;
frame_size = chan * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16); periodsize = sys_periodsize; // 320 in my system buf = pcm_buf; left = pcm_frames; sent = 0;
Итак, как я могу улучшить ВОЛНА играет без шума?? Я изменил вышеуказанную функцию, заполнив 0 до конца буфера данных (чтобы обеспечить тишину). [code]static int playback_test(uint8_t *pcm_buf, int pcm_frames) { uint8_t *buf; int trd; int rc; int left; int frame_size, sent; int periodsize; int aligned = 0;
frame_size = chan * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16); periodsize = sys_periodsize; // 320 in my system
buf = pcm_buf; left = pcm_frames; aligned = (left/periodsize + 1) * periodsize; memset(buf + left * frame_size, 0, (aligned - left) * frame_size); sent = 0; ///left = periodsize; // 0) { sent = (left > periodsize) ? periodsize : left; rc = snd_pcm_writei(pcm_handle, buf, sent); printf("rc: %d, sent: %d\n", rc, sent); if (rc == -EAGAIN || (rc >= 0 && (size_t)rc < sent)) { snd_pcm_wait(pcm_handle, 10); } else if (rc == -EPIPE) { snd_pcm_recover(pcm_handle, rc, 0); } else if (rc < 0) { break; } if (rc > 0) { left -= rc; buf += rc * frame_size; } } return rc; } [/code] По шуму НИКАКОГО улучшения нет.