ALSA音序器:避免高速MIDI导致输入缓冲区溢出 [英] ALSA sequencer: Avoid input buffer overrun with High-Speed MIDI

查看:110
本文介绍了ALSA音序器:避免高速MIDI导致输入缓冲区溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过ALSA定序器发送大型SysEx消息(可能是几兆字节):目前,我将它们分为几个ALSA事件,并按如下所示循环发送它们:

I want to send large SysEx messages (which can be several Megabytes) through the ALSA sequencer: Currently I split them into several ALSA events and send each of them in a loop like that:

    while (1) {
      result = snd_seq_event_output_direct( seq, const_cast<snd_seq_event_t*>(&ev) );
      if (result != -EAGAIN && result != -EWOULDBLOCK)
        break;
      snd_seq_sync_output_queue( seq );
      //std::this_thread::sleep_for(sleeptime);
    }

此循环确保所有事件都从发送客户端/端口发送.但是,只要snd_seq_event_output_direct返回-EAGAIN,接收客户端的输入池就会被清空,无条件地抛出约70个事件,而不仅仅是被拒绝的数据包.由于发送客户端没有有关已发送到接收客户端的事件的信息,因此它无法知道丢失了多少个数据包并重新传输.

This loop ensures that all events get sent from the sending client/port. But as soon as snd_seq_event_output_direct returns -EAGAIN, the input pool of the receiving client gets emptied, throwing unconditionally about 70 events away, not only the rejected packet. As the sending client has no information about the events that got sent to the receiving client, it can't know how many packets got lost and retransmit.

有人建议将传输速率限制为MIDI 1.0硬件规范定义的31.25 kbit/s.但这不一定是一个好主意,因为MIDI协议和传输速度实际上已被以太网,蓝牙和USB硬件层的支持所分割,而后者的速度要快得多.MIDI 2.0规范明确地与传输速率无关,并建议开发/使用具有更高传输速率的硬件层.

Some people suggest to limit the transmission rate to 31.25 kbit/s defined by the MIDI 1.0 hardware specification. But this is not necessarily a good idea as the MIDI protocol and the transmission speed have practically been split by the support of Ethernet, Bluetooth and USB hardware layers, which are much faster. The MIDI 2.0 specification is explicitly independent of the transmission rate, and suggests to develop/use hardware layers with higher transmission rates.

所以我的问题是:如何可靠地将大量MIDI数据至少可靠地传递给软件客户端,而又不人为地限制传输?

So my question is: How can I reliably deliver large amounts of MIDI data at least to software clients without artificially throttling the transmission?

我想偷看接收客户端的输入池,但是我不知道该怎么做.到目前为止,我可以找到有关接收端口的输入队列的信息,但是我不知道如何处理.

I thought of peeking at the input pool of the receiving client, but I don't know how to do that. So far I can find information about the input queue of the receiving port, but I don't know how to deal with it.

推荐答案

ALSA定序器旨在实时发送消息.无法根据接收器的缓冲区状态来限制传输.

The ALSA sequencer was designed for sending messages in real time. It is not possible to throttle transmissions based on the receiver's buffer state.

如果您不想将速度限制为MIDI 1.0,那么您唯一的选择是改为使用ALSA RawMIDI界面.

If you do not want to limit the speed to that of MIDI 1.0, then your only choice is to use the ALSA RawMIDI interface instead.

这篇关于ALSA音序器:避免高速MIDI导致输入缓冲区溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆