diff options
author | Jaroslav Kysela <perex@perex.cz> | 2021-08-24 11:36:30 +0200 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2021-10-28 08:40:20 +0200 |
commit | 5a5c2953ea15ad10027619b0609d8873e4e66bbe (patch) | |
tree | 6f21f1dade76428b0d4453941b75a613d90712c2 /test | |
parent | 42eeb5eca03accb9711698e3991551a22e762543 (diff) | |
download | alsa-lib-5a5c2953ea15ad10027619b0609d8873e4e66bbe.tar.gz |
rawmidi: define more abstract API for the timestamp reads
The frame structure is a bit internal thing for the kernel
data transfer implementation. Introduce snd_rawmidi_tread()
function which is straight for the application usage and hides
the framing data transfers (kernel space API).
The current code implements the read cache and does the merging
of the frame reads with the similar timestamps (opposite
to the kernel data split for big chunks).
If the application wants to use super-duper-lighting-fast reads,
the snd_rawmidi_read() may be used, but the structure must be
defined on it's own, because this mechanism is not preferred
and unsupported.
BugLink: https://github.com/alsa-project/alsa-lib/issues/172
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'test')
-rw-r--r-- | test/rawmidi.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/test/rawmidi.c b/test/rawmidi.c index 1090d44b..357abbe4 100644 --- a/test/rawmidi.c +++ b/test/rawmidi.c @@ -179,27 +179,27 @@ int main(int argc,char** argv) } if (handle_in) { - unsigned char ch; - snd_rawmidi_framing_tstamp_t frame; + unsigned char buf[1024]; + ssize_t ret; while (!stop) { if (clock_type != -1) { - snd_rawmidi_read(handle_in, &frame, sizeof(frame)); - if (verbose) { - int i; - if (frame.frame_type) { - fprintf(stderr, "read unknown frame %d", frame.frame_type); - continue; - } - fprintf(stderr, "read [%lld:%09d]", frame.tv_sec, frame.tv_nsec); - for (i = 0; i < frame.length; i++) - fprintf(stderr, " %02x", frame.data[i]); + struct timespec tstamp; + ret = snd_rawmidi_tread(handle_in, &tstamp, buf, sizeof(buf)); + if (ret < 0) + fprintf(stderr, "read timestamp error: %d - %s\n", (int)ret, snd_strerror(ret)); + if (ret > 0 && verbose) { + fprintf(stderr, "read [%lld:%09lld]", (long long)tstamp.tv_sec, (long long)tstamp.tv_nsec); + for (i = 0; i < ret; i++) + fprintf(stderr, " %02x", buf[i]); fprintf(stderr, "\n"); } - } - else { - snd_rawmidi_read(handle_in,&ch,1); - if (verbose) - fprintf(stderr,"read %02x\n",ch); + } else { + ret = snd_rawmidi_read(handle_in, buf, sizeof(buf)); + if (ret < 0) + fprintf(stderr, "read error: %d - %s\n", (int)ret, snd_strerror(ret)); + if (ret > 0 && verbose) + for (i = 0; i < ret; i++) + fprintf(stderr,"read %02x\n",buf[i]); } } } |