嗨,我正在为我的大学建造一个实验室,我正在尝试使用 Alsa 软件为我在 1 个循环中的中断数量发出声音。存储在 Alsa 缓冲区中的值大多像 0,1,2 偶尔是 4 或 5(我计算循环之间的中断差异)。我找到了一个产生正弦波的程序,并发出连续的哔哔声,我想把那个波转换成中断波,有人能帮忙吗?
在第一个代码中,我试图让 alsa 在中断为 != 0 时发出声音,或者在中断为 == 0 时不发出任何声音。
int playback_callback (snd_pcm_sframes_t nframes)
{
static float t = 0;
int err;
unsigned long long ti = 0, ti1 = 0, diff = 0,secs = 0;
ti = ti1 = num_interrupts();
printf ("playback callback called with %lu frames\n", nframes);
for(int i = 0; i < BUFSIZE; ++i) {
/*num_interrupts: function to calculate interrupts on /proc/interrupts*/
ti = num_interrupts();
diff = ti-ti1;
ti1 = ti;
/*printf("diff%llu\n",diff);*/
if(diff != 0) {
buf[i] = 65535;
} else {
buf[i] = 0;
}
}
if ((err = snd_pcm_writei (playback_handle, buf, nframes)) < 0) {
fprintf (stderr, "write failed (%s)\n", snd_strerror (err));
}
return err;
}