From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nicolas Graner Newsgroups: gmane.emacs.help Subject: Re: sending data to an asynchronous process Date: Fri, 02 Apr 2021 20:35:54 +0200 Message-ID: <86im548rg5.fsf@graner.name> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40779"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 02 20:37:35 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lSOfn-000AV5-09 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 02 Apr 2021 20:37:35 +0200 Original-Received: from localhost ([::1]:57886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSOfm-0000MB-2J for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 02 Apr 2021 14:37:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSOeJ-0000Jp-Jn for help-gnu-emacs@gnu.org; Fri, 02 Apr 2021 14:36:03 -0400 Original-Received: from smtp26.services.sfr.fr ([93.17.128.208]:10057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSOeE-0002DJ-Io for help-gnu-emacs@gnu.org; Fri, 02 Apr 2021 14:36:01 -0400 Original-Received: from hypra-graner (1.124.67.86.rev.sfr.net [86.67.124.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by msfrf2630.sfr.fr (SMTP Server) with ESMTPS id 7E9D71C002410 for ; Fri, 2 Apr 2021 20:35:55 +0200 (CEST) X-mail-filterd: 1.0.0 X-sfr-mailing: LEGIT X-sfr-spamrating: 40 X-sfr-spam: not-spam DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=graner.name; s=202006; t=1617388555; h=From:To:Subject:In-Reply-To:Date; bh=alml8P32mKAHY/LZvAeUGO6 ljQH9VuLdt4o2EzjD1gc=; b=L4+zH1cDVp8bl1PxBPX3vn+Z7Y88WkdchFvk+F0n8kqZodDGgYA PHIzpddXEDsgwoZK0OPLnrbHsxpQq45HJ4rPDp/ZuwTnBzFu3Zrrf2ru6WQIOlDgeRi0VqegfYLj ZKa/CP9D3SEPdTCL/tP7AlAbEVkBPkkgrsVcDUsECAWzVdiZv8HSvsMsEAm4zc16bpIRqk3jNgtS YRqntrzA3W+jLPshaGyrmBlki9DgQdPLvw5vC9C+oZISv22awYWxAlUjJ2RSgFTBw0XOf8refNGa IvMiLkV21+m4AWi5n22fnOMzkoH8xpCpE58c9PLYjwVVyHjKn1p/fLNUySstUxA==; Original-Received: from hypra-graner (1.124.67.86.rev.sfr.net [86.67.124.1]) by msfrf2630.sfr.fr (SMTP Server) with ESMTP id 643531C002408 for ; Fri, 2 Apr 2021 20:35:55 +0200 (CEST) Original-Received: from hypra-graner (1.124.67.86.rev.sfr.net [86.67.124.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by msfrf2630.sfr.fr (SMTP Server) with ESMTPS for ; Fri, 2 Apr 2021 20:35:55 +0200 (CEST) In-Reply-To: (message from Jean Louis on Fri, 2 Apr 2021 20:18:54 +0300) Received-SPF: pass client-ip=93.17.128.208; envelope-from=nicolas.graner@sfr.fr; helo=smtp26.services.sfr.fr X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128817 Archived-At: Jean Louis wrote on 2021-04-02 20:18: > * Nicolas Graner [2021-04-02 13:21]: >> I am writing a program that creates audio samples in an emacs >> buffer, then sends them to an external program (sox) to play in >> the background while I continue working with emacs. Part of the >> code is roughly as follows: >>=20 > (setq process > (let ((process-connection-type nil)) > (start-process "my-process" nil > "sox" "-r" rate "-c" channels "-b" bits "-e" encoding "-q" "-d")= )) > (process-send-region process start end) > (process-send-eof process) > > For process-send-region, it says: > > If PROCESS is a non-blocking network process that hasn=E2=80=99t been ful= ly > set up yet, this function will block until socket setup has completed. > > Maybe that applies. No. No network involved whatsoever. Just running /usr/bin/sox which is a regular file. > It would be nice to show all the function you use there. No other function is needed. If you want to reproduce the problem, just fill a buffer with 1 MB of random binary data and evaluate this slightly modified version of the above code: (setq process (let ((process-connection-type nil)) (start-process "my-process" nil "/usr/bin/sox" "-r" "44100" "-c" "2" "-b" "32" "-e" "signed-integer" "-t" "raw" "-" "-q" "-d"))) (process-send-region process (point-min) (point-max)) (process-send-eof process) If you have sox installed, be prepared to hear some horrible random noise :) You will notice that the first expression above returns immediately as expected, but the second (process-send-region ...) does not. That's the problem I'm trying to solve. > I would like to know if you play files or you feed data to sox to > play files, where does that come from? Is it maybe an elevator > music from an UDP port? The data originally came from files that I read into a buffer and did some processing on. At the time of calling the above code, all the data is sitting quietly in an emacs buffer. No network, disk access or anything else involved. Just sending the contents of a buffer through a pipe to a program that was started as an asynchronous process. Nicolas