From patchwork Tue Aug 17 14:21:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Henningsson X-Patchwork-Id: 498148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3AB8C4338F for ; Tue, 17 Aug 2021 14:23:19 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DEC1B60F5C for ; Tue, 17 Aug 2021 14:23:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DEC1B60F5C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=diwic.se Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 28897167F; Tue, 17 Aug 2021 16:22:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 28897167F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629210195; bh=93H/Bl3tvzo2/7LaIskWg0eB/fEr0vRwbw2h76IUyWs=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IUlvReuv3z2ONCmLNww3yHdUgJtXYyGhFpQpl37s3ekD1XJg3lHISKlgpO/vIo9ld 5zSsRE+5dTVIAUiaedh0kvpn8phKGNrWgbi6dLPrbk/Vk1lGZDCRD0jqbYlIJk1mPX Bs0St8pv0952MVNzCbwhQhx2JKa4kUbQZlRC/uVI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A6BD2F8026D; Tue, 17 Aug 2021 16:21:35 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 19ABEF804B0; Tue, 17 Aug 2021 16:21:34 +0200 (CEST) Received: from ns4.inleed.net (mailout4.inleed.net [IPv6:2a0b:dc80:cafe:104::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 749BFF8026D for ; Tue, 17 Aug 2021 16:21:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 749BFF8026D Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=diwic.se header.i=@diwic.se header.b="ErrNzN2y" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=diwic.se; s=x; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rylYG2wCpd7lY70YRMKs49j3We6VXqSIQYSpyRsGnjI=; b=ErrNzN2y6hszVMzFC1WfoltTU0 1L2lktqsnBluSGwgnB9rHFaGX4lfLN3ncgz+mQHkP0mH/bn7ZxI1hepTe2fUzHizh94L57SANKikX DAmKVxCQvy1zupAs3DbQf/8IjA7anyG2WXt1eF3aNx2gSdFGBYOB7dSNiAu3KATS9Vu5qzKLpmhIZ JEcqPYQpEEAZGIL2iQgoBQJoUDxXSS2uIMnBzEc7aLucuWCMhToGqPhYLftH8tEvGv0H8Eso368bl ffJdQilzt6vDomzfRlbhm/VkufHEgc3W1UmoaLF6R6NuY61kCv2edau9u/Oq5Rgjzalljzxf7QSv0 jc2yhHMg==; Received: from c83-254-143-147.bredband.tele2.se ([83.254.143.147] helo=localhost.localdomain) by ns4.inleed.net with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mFzxz-00EDyU-1N; Tue, 17 Aug 2021 16:21:23 +0200 From: David Henningsson To: tiwai@suse.de, alsa-devel@alsa-project.org, perex@perex.cz Subject: [PATCH v3 2/2] Add test for rawmidi framing API Date: Tue, 17 Aug 2021 16:21:13 +0200 Message-Id: <20210817142113.14750-3-coding@diwic.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210817142113.14750-1-coding@diwic.se> References: <20210817142113.14750-1-coding@diwic.se> MIME-Version: 1.0 X-Authenticated-Id: coding@diwic.se Cc: David Henningsson X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 --- 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(¶ms); + 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); } } }