From patchwork Tue Aug 8 22:05:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Baluta X-Patchwork-Id: 9889143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D225A603FA for ; Tue, 8 Aug 2017 22:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF74328A31 for ; Tue, 8 Aug 2017 22:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2CB528A29; Tue, 8 Aug 2017 22:07:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD2ED28A31 for ; Tue, 8 Aug 2017 22:07:23 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E32AE266E2D; Wed, 9 Aug 2017 00:06:21 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5F0B9266E17; Wed, 9 Aug 2017 00:06:19 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by alsa0.perex.cz (Postfix) with ESMTP id 6C928266AA9 for ; Wed, 9 Aug 2017 00:06:17 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id o33so3338185wrb.1 for ; Tue, 08 Aug 2017 15:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GeZudfBn90/GPfZ9ymM8ZDk6VUmj+IrPMMo/eN67AMs=; b=GMjwzRUL7KNkAIsDddCq8joteMQrWMEe9RLqRqXhIZyygP3FwOtRkLICbfHNiv8Pqi FTXYj9oBqEfKBBavoS7E3z3iaOWlCItgzTrLZTEGJOPX45BGxY1QeUoY2jaaa/SKD+/i as0msJ4lLJGji7NUMsr48jJJApfNhzHsrMAuEf3ZMwFp7l56Atbz1/hMltMTk5dJJTFS 1HT2XVanfdx8XUnA7PJAPDJhwnKh4pQMqKrCvPHEz2twvn1LqG0FoDuOEki2BtiV1KKv SJBgl58a924WQJoc+n9XCsskD2bW+2R0643ERmAxeyNgh2KqN3Tp50RWZGIolHZGFM0E 8mCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GeZudfBn90/GPfZ9ymM8ZDk6VUmj+IrPMMo/eN67AMs=; b=bzYmdunND87ZZDHUWAIbT83Fx5MDxI91XwMRUoyt2TROK4FiZpUbtZqjXzpuJS4sGr m66ADYwMJW3PGrIen1Yrt73XTINYKRuRVVmkQ7JlOZfxsLIr4/k8T+C+JHTCROKNZwdp qilQD3GbXYnvLX1rDVTSB5LXXUZdET0MmeoLEvSwHTdN66XuDjL7tPtjn8lU31xlE+bD CwGupxjV8/69rUHQfxqmj8xj+LjRf4G2XS9eM6T1u/CdgLL3hzQMlasPy1COFqwyHCcC rCtGVHPMAMOzBaIoj2n/QPLKOroOjBXpBgmPZyM6KDNJd13bn3dEMIQ1GLFjkAx56vsB 0ECw== X-Gm-Message-State: AHYfb5gl8ZdjPyFu1vQEXTnqSSEhF3Ox80cbM0txjPXFQDY/76F+Js2m O7kP++ry0QH1Pg== X-Received: by 10.223.139.219 with SMTP id w27mr3882097wra.146.1502229976831; Tue, 08 Aug 2017 15:06:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:2f01:5040:14c8:152d:3d14:674f:951]) by smtp.gmail.com with ESMTPSA id g18sm3592132wrg.69.2017.08.08.15.06.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Aug 2017 15:06:16 -0700 (PDT) From: Daniel Baluta To: tiwai@suse.com, alsa-devel@alsa-project.org Date: Wed, 9 Aug 2017 01:05:58 +0300 Message-Id: <1502229960-8516-2-git-send-email-daniel.baluta@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502229960-8516-1-git-send-email-daniel.baluta@gmail.com> References: <1502229960-8516-1-git-send-email-daniel.baluta@gmail.com> Cc: mihai.serban@nxp.com, shengjiu.wang@nxp.com, Ion-Horia Petrisor , Daniel Baluta , viorel.suman@nxp.com Subject: [alsa-devel] [PATCH 1/3] aplay: Add samples argument for playing/recording a given number of samples X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ion-Horia Petrisor -s --samples allows aplay to be used for playback/capture a given number of samples per channel Signed-off-by: Ion-Horia Petrisor Signed-off-by: Daniel Baluta --- aplay/aplay.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index 89baa9a..fb2909f 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -100,6 +100,7 @@ static struct { unsigned int rate; } hwparams, rhwparams; static int timelimit = 0; +static int sampleslimit = 0; static int quiet_mode = 0; static int file_type = FORMAT_DEFAULT; static int open_mode = 0; @@ -212,6 +213,7 @@ _("Usage: %s [OPTION]... [FILE]...\n" "-f, --format=FORMAT sample format (case insensitive)\n" "-r, --rate=# sample rate\n" "-d, --duration=# interrupt after # seconds\n" +"-s, --samples=# interrupt after # samples per channel\n" "-M, --mmap mmap stream\n" "-N, --nonblock nonblocking mode\n" "-F, --period-time=# distance between interrupts is # microseconds\n" @@ -466,8 +468,9 @@ static long parse_long(const char *str, int *err) int main(int argc, char *argv[]) { + int duration_or_sample = 0; int option_index; - static const char short_options[] = "hnlLD:qt:c:f:r:d:MNF:A:R:T:B:vV:IPCi" + static const char short_options[] = "hnlLD:qt:c:f:r:d:s:MNF:A:R:T:B:vV:IPCi" #ifdef CONFIG_SUPPORT_CHMAP "m:" #endif @@ -485,6 +488,7 @@ int main(int argc, char *argv[]) {"format", 1, 0, 'f'}, {"rate", 1, 0, 'r'}, {"duration", 1, 0 ,'d'}, + {"samples", 1, 0, 's'}, {"mmap", 0, 0, 'M'}, {"nonblock", 0, 0, 'N'}, {"period-time", 1, 0, 'F'}, @@ -640,11 +644,28 @@ int main(int argc, char *argv[]) } break; case 'd': + if (duration_or_sample) { + error(_("duration and samples arguments cannot be used together")); + return 1; + } timelimit = parse_long(optarg, &err); if (err < 0) { error(_("invalid duration argument '%s'"), optarg); return 1; } + duration_or_sample = 1; + break; + case 's': + if (duration_or_sample) { + error(_("samples and duration arguments cannot be used together")); + return 1; + } + sampleslimit = parse_long(optarg, &err); + if (err < 0) { + error(_("invalid samples argument '%s'"), optarg); + return 1; + } + duration_or_sample = 1; break; case 'N': nonblock = 1; @@ -2477,9 +2498,12 @@ static off64_t calc_count(void) { off64_t count; - if (timelimit == 0) { - count = pbrec_count; - } else { + if (timelimit == 0) + if (sampleslimit == 0) + count = pbrec_count; + else + count = snd_pcm_format_size(hwparams.format, sampleslimit * hwparams.channels); + else { count = snd_pcm_format_size(hwparams.format, hwparams.rate * hwparams.channels); count *= (off64_t)timelimit; } @@ -3125,7 +3149,7 @@ static void capture(char *orig_name) /* repeat the loop when format is raw without timelimit or * requested counts of data are recorded */ - } while ((file_type == FORMAT_RAW && !timelimit) || count > 0); + } while ((file_type == FORMAT_RAW && !timelimit && !sampleslimit) || count > 0); } static void playbackv_go(int* fds, unsigned int channels, size_t loaded, off64_t count, int rtype, char **names)