Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: David Henningsson <coding@diwic.se>
To: tiwai@suse.de, alsa-devel@alsa-project.org, perex@perex.cz
Cc: David Henningsson <coding@diwic.se>
Subject: [PATCH v3 2/2] Add test for rawmidi framing API
Date: Tue, 17 Aug 2021 16:21:13 +0200	[thread overview]
Message-ID: <20210817142113.14750-3-coding@diwic.se> (raw)
In-Reply-To: <20210817142113.14750-1-coding@diwic.se>

Adds a "clock type" parameter to the "rawmidi" test program, that when
used and combined with -i (and -v to be useful), activates tstamp type
framing with the specified clock type.

Signed-off-by: David Henningsson <coding@diwic.se>
---
 test/rawmidi.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/test/rawmidi.c b/test/rawmidi.c
index 67f585b0..1090d44b 100644
--- a/test/rawmidi.c
+++ b/test/rawmidi.c
@@ -13,6 +13,7 @@ static void usage(void)
 	fprintf(stderr, "    -o device-id : test ALSA output device\n");
 	fprintf(stderr, "    -I node      : test input node\n");
 	fprintf(stderr, "    -O node      : test output node\n");
+	fprintf(stderr, "    -c clock     : kernel clock type (0=none, 1=realtime, 2=monotonic, 3=monotonic raw)\n");
 	fprintf(stderr, "    -t: test midi thru\n");
 	fprintf(stderr, "  example:\n");
 	fprintf(stderr, "    rawmidi -i hw:0,0 -O /dev/midi1\n");
@@ -37,7 +38,8 @@ int main(int argc,char** argv)
 	char *device_out = NULL;
 	char *node_in = NULL;
 	char *node_out = NULL;
-	
+	int clock_type = -1;
+
 	int fd_in = -1,fd_out = -1;
 	snd_rawmidi_t *handle_in = 0,*handle_out = 0;
 	
@@ -58,6 +60,10 @@ int main(int argc,char** argv)
 				case 't':
 					thru = 1;
 					break;
+				case 'c':
+					if (i + 1 < argc)
+						clock_type = atoi(argv[++i]);
+					break;
 				case 'i':
 					if (i + 1 < argc)
 						device_in = argv[++i];
@@ -133,20 +139,67 @@ int main(int argc,char** argv)
 		}		
 	}
 
-
-
 	if (!thru) {
 		if (handle_in || fd_in!=-1) {
+			if (clock_type != -1) {
+				snd_rawmidi_params_t *params;
+				snd_rawmidi_params_malloc(&params);
+				if (!handle_in) {
+					fprintf(stderr, "-c only usable with -i");
+					clock_type = -1;
+				}
+				if (clock_type != -1) {
+					fprintf(stderr, "Enable kernel clock type %d\n", clock_type);
+					snd_rawmidi_params_current(handle_in, params);
+					err = snd_rawmidi_params_set_framing_type(handle_in, params, 1);
+					if (err) {
+						fprintf(stderr,"snd_rawmidi_params_set_framing_type failed: %d\n", err);
+						clock_type = -1;
+					}
+				}
+				if (clock_type != -1) {
+					err = snd_rawmidi_params_set_clock_type(handle_in, params, clock_type);
+					if (err) {
+						fprintf(stderr, "snd_rawmidi_params_set_clock_type failed: %d\n", err);
+						clock_type = -1;
+					}
+				}
+				if (clock_type != -1) {
+					err = snd_rawmidi_params(handle_in, params);
+					if (err) {
+						fprintf(stderr, "snd_rawmidi_params failed: %d\n", err);
+						clock_type = -1;
+					}
+				}
+				snd_rawmidi_params_free(params);
+			}
+
 			fprintf(stderr,"Read midi in\n");
 			fprintf(stderr,"Press ctrl-c to stop\n");
 		}
 
 		if (handle_in) {
 			unsigned char ch;
+			snd_rawmidi_framing_tstamp_t frame;
 			while (!stop) {
-				snd_rawmidi_read(handle_in,&ch,1);
-				if (verbose) {
-					fprintf(stderr,"read %02x\n",ch);
+				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]);
+						fprintf(stderr, "\n");
+					}
+				}
+				else {
+					snd_rawmidi_read(handle_in,&ch,1);
+					if (verbose)
+						fprintf(stderr,"read %02x\n",ch);
 				}
 			}
 		}
-- 
2.25.1


  parent reply	other threads:[~2021-08-17 14:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 14:21 [PATCH v3 0/2] alsa-lib patches for rawmidi framing David Henningsson
2021-08-17 14:21 ` [PATCH v3 1/2] Add rawmidi framing API David Henningsson
2021-08-17 14:21 ` David Henningsson [this message]
2021-08-20  6:49 ` [PATCH v3 0/2] alsa-lib patches for rawmidi framing Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210817142113.14750-3-coding@diwic.se \
    --to=coding@diwic.se \
    --cc=alsa-devel@alsa-project.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox