pax_global_header00006660000000000000000000000064137136206670014525gustar00rootroot0000000000000052 comment=2667033fc0209d26097a231ef5112020f74fbbd8 jack-stdio-1.6/000077500000000000000000000000001371362066700134235ustar00rootroot00000000000000jack-stdio-1.6/.gitignore000066400000000000000000000000351371362066700154110ustar00rootroot00000000000000jack-stdout jack-stdin *.swp jack-stdio-1.6/AUTHORS000066400000000000000000000000401371362066700144650ustar00rootroot00000000000000Robin Gareus jack-stdio-1.6/COPYING000066400000000000000000000432541371362066700144660ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. jack-stdio-1.6/ChangeLog000066400000000000000000000015571371362066700152050ustar00rootroot000000000000002011-06-07 rgareus * clean-up manual page (thanks to Alessio Tregilia) * small PREFIX makefile patch (also by Alessio) * v1.4 2011-04-03 rgareus * fixed jack-stdout write retry/abort * increased default jack-stdin buffer-prefill to 50% * v1.3 2011-04-01 rgareus * fixes for PPC/big-endian architecture * v1.2 2011-03-31 rgareus * removed some warnings that went to stdout * fixed few typos in manual * added jack-stdin * support for 8 and 32 bit integers * added test-cases * v1.1 2011-03-29 rgareus * major rewrite * dynamic channel count * support various formats, encoding * added command-line parameters, help * manual page, debian packaging * v1.0 2008-07-01 rgareus * basic version based on jack capture_client.c example jack-stdio-1.6/Makefile000066400000000000000000000017671371362066700150760ustar00rootroot00000000000000# override e.g. `make install PREFIX=/usr` PREFIX ?= /usr/local CFLAGS ?= -O3 override CFLAGS += -Wall `pkg-config --cflags jack` LIBS=`pkg-config --libs jack` -lpthread -lm #compat w/ NetBSD and GNU Make LDADD=${LIBS} LDLIBS=${LIBS} all: jack-stdout jack-stdin jack-stdout: jack-stdout.c jack-stdin: jack-stdin.c install: all install -d $(DESTDIR)$(PREFIX)/bin install -m 755 jack-stdout $(DESTDIR)$(PREFIX)/bin/ install -m 755 jack-stdin $(DESTDIR)$(PREFIX)/bin/ install -d $(DESTDIR)$(PREFIX)/share/man/man1 install -m 644 jack-stdout.1 $(DESTDIR)$(PREFIX)/share/man/man1/ install -m 644 jack-stdin.1 $(DESTDIR)$(PREFIX)/share/man/man1/ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/jack-stdout rm -f $(DESTDIR)$(PREFIX)/bin/jack-stdin rm -f $(DESTDIR)$(PREFIX)/share/man/man1/jack-stdout.1 rm -f $(DESTDIR)$(PREFIX)/share/man/man1/jack-stdin.1 -rmdir $(DESTDIR)$(PREFIX)/bin -rmdir $(DESTDIR)$(PREFIX)/share/man/man1 clean: /bin/rm -f jack-stdout jack-stdin .PHONY: all install uninstall clean jack-stdio-1.6/build-deb.sh000077500000000000000000000001411371362066700156050ustar00rootroot00000000000000#!/bin/sh git-buildpackage --git-upstream-branch=master --git-debian-branch=master -rfakeroot $@ jack-stdio-1.6/debian/000077500000000000000000000000001371362066700146455ustar00rootroot00000000000000jack-stdio-1.6/debian/changelog000066400000000000000000000013211371362066700165140ustar00rootroot00000000000000jack-stdio (1.4-1) unstable; urgency=low * clean-up man-page * version 1.4 -- Robin Gareus Wed, 08 Jun 2011 02:30:22 +0200 jack-stdio (1.3-2) unstable; urgency=low * fixed jack-stdout write retry/abort * increased default jack-stdin buffer-prefill to 50% * version 1.3 -- Robin Gareus Sun, 03 Apr 2011 16:08:25 +0200 jack-stdio (1.2-1) unstable; urgency=low * fixed PPC/big-endian architecture support * version 1.2 -- Robin Gareus Fri, 01 Apr 2011 21:19:16 +0200 jack-stdio (1.1-2) unstable; urgency=low * renamed from jack-stdout to jack-stdio * version 1.1 -- Robin Gareus Thu, 31 Mar 2011 18:12:16 +0200 jack-stdio-1.6/debian/compat000066400000000000000000000000021371362066700160430ustar00rootroot000000000000007 jack-stdio-1.6/debian/control000066400000000000000000000015171371362066700162540ustar00rootroot00000000000000Source: jack-stdio Section: sound Priority: optional Maintainer: Robin Gareus Build-Depends: debhelper (>= 7.0.50~), libjack-dev | libjack-jackd2-dev Homepage: http://rg42.org/oss/jackstdout/ Standards-Version: 3.9.1 Package: jack-stdio Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Recommends: sox Replaces: jack-stdout Description: program to pipe audio-data from and to JACK Two simple command-line utilities to read and write raw audio-data from JACK from/to standard-io. . jack-stdio supports unlimited number of channel and a variety of raw PCM encodings: signed/unsigned 8/16/24/24 bit integer, floating-point, little/big-endian. . jack-stdout can be used to capture or with additional tools to live-encoding audio from JACK. . jack-stdin pipes data from some external command into JACK. jack-stdio-1.6/debian/copyright000066400000000000000000000022251371362066700166010ustar00rootroot00000000000000Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=142 Name: jack-stdio Maintainer: Robin Gareus Source: git://rg42.org/jack-stdout/ Copyright: 2011 Robin Gareus License: GPL-2+ Files: debian/* Copyright: 2011 Robin Gareus License: GPL-2+ License: GPL-2 This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA X-Comment: On Debian systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-2'. jack-stdio-1.6/debian/rules000077500000000000000000000002341371362066700157240ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ override_dh_auto_build: $(MAKE) override_dh_auto_install: $(MAKE) install DESTDIR=$(CURDIR)/debian/jack-stdio PREFIX=/usr jack-stdio-1.6/jack-stdin.1000066400000000000000000000054361371362066700155440ustar00rootroot00000000000000.\" jack-stdin.1 written by Robin Gareus .TH JACK-STDIN 1 "21 February 2019" .SH NAME jack-stdin \- write JACK audio data to stdin .SH SYNOPSIS .HP .B jack-stdin .RI [ OPTIONS ] .RI port1 .RB [ .RI port2 .RB ...] .SH DESCRIPTION .LP \fBjack-stdin\fR reads raw audio data from standard-input and writes it to a JACK audio port. .P The number of given ports detemine the number of audio channels that are used. If more than one channel is given, the input audio-sample data needs to be interleaved. .SH OPTIONS .TP \fB\-b\fR, \fB\-\-bitdepth \fIBITS\fR .RS Specify the bit-depth of each sample. For integer-encoding this can be 16 or 24. The default is 16. This setting is only used for integer encoding: Floating-point samples will always be 32 bit wide. .RE .TP \fB-d\fR, \fB--duration\fR \fISEC\fR .RS Specify the time for which jack-stdin should run in seconds. A value less than 1 means to run indefinitely. The default is 0 which reads until end-of-file. .RE .TP \fB-e\fR, \fB--encoding\fR \fIFORMAT\fR .RS Set the input format of the data: signed-integer, unsigned-integer, floating-point (default: signed) .RE .TP \fB-n\fR, \fB--name\fR \fICLIENTNAME\fR .RS Set JACK client name (default: jstdin) .RE .TP \fB-f\fR, \fB--file\fR \fIFILENAME\fR .RS Read data from given file instead of standard-input. .RE .TP \fB-h\fR, \fB--help\fR .RS Print a brief usage information .RE .TP \fB-p\fR, \fB--prebuffer\fR \fIPERCENT\fR .RS Pre-fill the buffer before starting audio output to JACK (default 50.0%). NOTE: disable pre-buffering (\-p 0) or use a small buffer size to play back very short samples. .RE .TP \fB-L\fR, \fB--little-endian\fR .RS The input-data is in little-endian byte-order or native-byte-order float (this is the default) .RE .TP \fB-B\fR, \fB--big-endian\fR .RS Interpret input audio data in big-endian byte-order or swap the byte-order of floating-point. .RE .TP \fB-q\fR, \fB--quiet\fR .RS Inhibit usual output. This affects information and buffer-overflow warnings but not setup-errors. .RE .TP \fB-S\fR, \fB--bufsize\fR \fISAMPLES\fR .RS Choose the internal buffer-size in samples. The default size is 65536. The given value will be multiplied by the number of channels and bit-depth to get the size of the ring-buffer. Note: the buffersize must be larger than JACK's period size. .RE .SH EXAMPLES .nf jack-stdout vlc_31994:out_1 vlc_31994:out_2 \\ | sox \-t raw \-r 48k \-e signed \-b 16 \-c 2 \- \\ \-t raw \-r 48k \-e signed \-b 16 \-c 2 \- \\ tremolo 5 100 \\ | ./jack-stdin system:playback_1 system:playback_2 cat /dev/dsp \\ | jack-stdin system:playback_1 system:playback_2 .fi .SH "KNOWN ISSUES" .PP jack-stdin is not suitable to play-back files shorter than twice the jack-period size. .SH AUTHOR Robin Gareus . .SH SEE ALSO http://jackaudio.org/, jack-stdio-1.6/jack-stdin.c000066400000000000000000000370141371362066700156230ustar00rootroot00000000000000/** jack-stdin - write raw audio data from stdin to JACK * * This tool is based on capture_client.c from the jackaudio.org examples * and modified by Robin Gareus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Copyright (C) 2001 Paul Davis * Copyright (C) 2003 Jack O'Quin * Copyright (C) 2008, 2011 Robin Gareus * * compile with * gcc -o jack-stdin jack-stdin.c -ljack -lm -lpthread * */ #include #include #include #include #include #include #include #include #include #include #include #include #include typedef struct _thread_info { pthread_t thread_id; pthread_t mesg_thread_id; jack_nframes_t duration; jack_nframes_t rb_size; jack_client_t *client; unsigned int channels; volatile int can_capture; volatile int can_process; float prebuffer; int readfd; int format; /**format: * bit0,1: 16/24/8/32(float) * bit8: signed/unsiged (0x10) * bit9: int/float (0x20) - dup -- 0x03 * bit10: little/big endian (0x40) */ } jack_thread_info_t; #define IS_FMTFLT ((info->format&0x20)) #define IS_BIGEND (info->format&0x40) #define IS_FMT32B ((info->format&0x23)==3) #define IS_FMT24B ((info->format&3)==1) #define IS_FMT16B ((info->format&3)==0) #define IS_FMT08B ((info->format&3)==2) #define IS_SIGNED (!(info->format&0x10)) #define SAMPLESIZE ((info->format&2)?((info->format&1)?4:1):((info->format&1)?3:2)) #define POWHX ((info->format&2)?((info->format&1)?0:127):((info->format&1)? 8388607:32767)) #define POWHS ((info->format&2)?((info->format&1)?2147483648.0:128.0):((info->format&1)? 8388608.0:32768.0)) #define FMTOFF ((IS_SIGNED)?0.0:POWHX) #define FMTMLT (POWHS) #define BE(i) ( (IS_BIGEND)?(SAMPLESIZE-i-1):i) /* JACK data */ jack_port_t **ports; jack_default_audio_sample_t **out; jack_nframes_t nframes; /* Synchronization between process thread and disk thread. */ jack_ringbuffer_t *rb; pthread_mutex_t io_thread_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t data_ready = PTHREAD_COND_INITIALIZER; /* global options/status */ int want_quiet = 0; volatile int run = 1; long underruns = 0; void * io_thread (void *arg) { jack_thread_info_t *info = (jack_thread_info_t *) arg; jack_nframes_t total_captured = 0; const size_t bytes_per_frame = info->channels * SAMPLESIZE; void *framebuf = malloc (bytes_per_frame); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_mutex_lock(&io_thread_lock); int readerror =0; size_t roff = 0; while (run && !readerror) { /* Read the data one frame at a time. This is * inefficient, but makes things simpler. */ while (info->can_capture && (jack_ringbuffer_write_space (rb) >= bytes_per_frame)) { if (info->duration > 0 && total_captured >= info->duration) { if (!want_quiet) fprintf(stderr, "io thread finished\n"); readerror=1; break; } #if 0 /* wait (indefinitley) for read-ready */ fd_set fd; FD_ZERO(&fd); FD_SET(fileno(info->fd), &fd); select(fileno(info->fd), &fd, NULL, NULL, NULL); #endif int rv = read(info->readfd, framebuf+roff, bytes_per_frame-roff); if (rv < 0) {readerror=1; break;} /* error */ else if (rv == 0) {readerror=1; break;} /* EOF */ else if (rv < bytes_per_frame) {roff=rv; continue;} else roff=0; jack_ringbuffer_write(rb, framebuf, bytes_per_frame); ++total_captured; } if (!readerror && info->prebuffer == 0) pthread_cond_wait(&data_ready, &io_thread_lock); } //fprintf(stderr, "jack-stdin: EOF..\n"); /* DEBUG */ /* wait until all data is processed */ while (run && info->prebuffer == 0 && jack_ringbuffer_read_space(rb) > jack_get_buffer_size(info->client) * bytes_per_frame) { usleep(10000); //fprintf(stderr, "waiting...\n");usleep(200000); /* DEBUG */ } pthread_mutex_unlock(&io_thread_lock); free(framebuf); return 0; } int process (jack_nframes_t nframes, void *arg) { int chn; size_t i; jack_thread_info_t *info = (jack_thread_info_t *) arg; if ((!info->can_process)) return 0; const size_t bytes_per_frame = info->channels * SAMPLESIZE; const jack_nframes_t rbrs = jack_ringbuffer_read_space(rb); /* initial pre-buffer. */ if (rbrs < ceil(info->rb_size * info->prebuffer / 100.0)) { //fprintf(stderr,"pre-buffer (%.1f%%)\n", 100.0 * (float) rbrs / (float)info->rb_size); /* DEBUG */ return 0; } info->prebuffer=0.0; for (chn = 0; chn < info->channels; ++chn) out[chn] = jack_port_get_buffer(ports[chn], nframes); /* Do nothing until we're ready to begin. and only dequeue samples if a whole period is avail. */ if ((!info->can_capture) || (rbrs < bytes_per_frame * nframes)) { /* silence */ for (chn = 0; chn < info->channels; ++chn) { memset(out[chn], 0, nframes * sizeof(jack_default_audio_sample_t)); } /* count underruns */ if (info->can_capture && rbrs < bytes_per_frame * nframes) { underruns++; fprintf(stderr,"underrun..\n"); } return 0; } /* dequeue interleaved samples from a single ringbuffer. */ for (i = 0; i < nframes; i++) { for (chn = 0; chn < info->channels; ++chn) { jack_default_audio_sample_t js; if (IS_FMTFLT) { /* 32 bit float */ float d; jack_ringbuffer_read (rb, (void *) &d, SAMPLESIZE); if (IS_BIGEND) { /* swap float endianess */ char *flin = (char*) & d; char *fout = (char*) & js; fout[0] = flin[3]; fout[1] = flin[2]; fout[2] = flin[1]; fout[3] = flin[0]; } else { js = d; } out[chn][i] = (jack_default_audio_sample_t) js; } else { /* 8/16/24/32 LE/BE signed/unsigned */ char bytes[4]; jack_ringbuffer_read (rb, (void *) &bytes, SAMPLESIZE); int32_t d=0; d|= ( ((int32_t)bytes[BE(0)]&0xff) ); if (IS_FMT16B || IS_FMT24B || IS_FMT32B) d|= ( ((int32_t)bytes[BE(1)]&0xff)<<8 ); if (IS_FMT24B || IS_FMT32B) d|= ( ((int32_t)bytes[BE(2)]&0xff)<<16 ); if (IS_FMT32B) d|= ( ((int32_t)bytes[BE(3)]&0xff)<<24 ); if (IS_FMT32B) { if (!IS_SIGNED) d^=0x80000000; } else if (IS_SIGNED && (bytes[BE((SAMPLESIZE-1))]&0x80)) { const int32_t mask[3] = { 0xffffff00, 0xffff0000, 0xff000000 }; d|= mask[SAMPLESIZE-1]; } out[chn][i] = (jack_default_audio_sample_t) ((float)(d-FMTOFF) / FMTMLT); } } /* end - foreach channel */ } /* end - foreach sample */ /* Tell the io thread there that frames have been dequeued. */ if (pthread_mutex_trylock(&io_thread_lock) == 0) { pthread_cond_signal(&data_ready); pthread_mutex_unlock(&io_thread_lock); } return 0; } void jack_shutdown (void *arg) { fprintf(stderr, "JACK shutdown\n"); abort(); } void setup_ports (int nports, char *source_names[], jack_thread_info_t *info) { unsigned int i; const size_t in_size = nports * sizeof(jack_default_audio_sample_t *); /* Allocate data structures that depend on the number of ports. */ ports = (jack_port_t **) malloc(sizeof(jack_port_t *) * nports); out = (jack_default_audio_sample_t **) malloc(in_size); rb = jack_ringbuffer_create(nports * SAMPLESIZE * info->rb_size); /* When JACK is running realtime, jack_activate() will have * called mlockall() to lock our pages into memory. But, we * still need to touch any newly allocated pages before * process() starts using them. Otherwise, a page fault could * create a delay that would force JACK to shut us down. */ memset(out, 0, in_size); memset(rb->buf, 0, rb->size); for (i = 0; i < nports; i++) { char name[64]; sprintf(name, "input%d", i+1); if ((ports[i] = jack_port_register(info->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) == 0) { fprintf(stderr, "cannot register input port \"%s\"!\n", name); jack_client_close(info->client); exit(1); } } for (i = 0; i < nports; i++) { if (jack_connect(info->client, jack_port_name(ports[i]), source_names[i])) { fprintf(stderr, "cannot connect input port %s to %s\n", jack_port_name(ports[i]), source_names[i]); #if 0 /* not fatal - connect manually */ jack_client_close(info->client); exit(1); #endif } } /* process() can start, now */ info->can_process = 1; } void catchsig (int sig) { #ifndef _WIN32 signal(SIGHUP, catchsig); /* reset signal */ signal(SIGINT, catchsig); /* reset signal */ #endif if (!want_quiet) fprintf(stderr,"\n jack-stdin: CAUGHT SIGNAL - shutting down.\n"); run=0; /* signal reader thread */ pthread_mutex_lock(&io_thread_lock); pthread_cond_signal(&data_ready); pthread_mutex_unlock(&io_thread_lock); } static void usage (const char *name, int status) { fprintf(status?stderr:stdout, "usage: %s [ OPTIONS ] port1 [ port2 ... ]\n", name); fprintf(status?stderr:stdout, "jack-stdin reads raw audio-data from standard-input and writes it to JACK.\n"); fprintf(status?stderr:stdout, "OPTIONS:\n" " -h, --help print this message\n" " -q, --quiet inhibit usual output\n" " -b, --bitdepth {bits} choose integer bit depth: 16, 24 (default: 16)\n" " -d, --duration {sec} terminate after given time, <1: unlimited (default:0)\n" " -e, --encoding {format} set output format: (default: signed)\n" " signed-integer, unsigned-integer, float\n" " -f, --file {filename} read data from file instead of stdin\n" " -n, --name {clientname} set client name in JACK instead of jstdin\n" " -p, --prebuffer {pct} Pre-fill the buffer before starting audio output\n" " to JACK (default 50.0%%).\n" " -L, --little-endian write little-endian integers or\n" " native-byte-order floats (default)\n" " -B, --big-endian write big-endian integers or swapped-order floats\n" " -S, --bufsize {samples} set buffer size (default: 64k)\n" ); exit(status); } int main (int argc, char **argv) { jack_client_t *client; jack_thread_info_t thread_info; jack_thread_info_t *info = &thread_info; jack_status_t jstat; int c; char *infn = NULL; char *client_name = "jstdin"; memset(&thread_info, 0, sizeof(thread_info)); thread_info.rb_size = 16384 * 4; thread_info.channels = 2; thread_info.duration = 0; thread_info.format = 0; thread_info.prebuffer = 50.0; thread_info.readfd = fileno(stdin); const char *optstring = "d:e:b:S:f:p:n:BLhq"; struct option long_options[] = { { "help", 0, 0, 'h' }, { "quiet", 0, 0, 'q' }, { "duration", 1, 0, 'd' }, { "encoding", 1, 0, 'e' }, { "file", 1, 0, 'f' }, { "name", 1, 0, 'n' }, { "prebuffer", 1, 0, 'p' }, { "little-endian", 0, 0, 'L' }, { "big-endian", 0, 0, 'B' }, { "bitdepth", 1, 0, 'b' }, { "bufsize", 1, 0, 'S' }, { 0, 0, 0, 0 } }; while ((c = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (c) { case 'h': usage(argv[0], 0); break; case 'q': want_quiet = 1; break; case 'f': free(infn); infn=strdup(optarg); break; case 'n': client_name = optarg; break; case 'd': thread_info.duration = atoi(optarg); break; case 'p': thread_info.prebuffer = atof(optarg); if (thread_info.prebuffer<1.0) thread_info.prebuffer=0.0; if (thread_info.prebuffer>90.0) thread_info.prebuffer=90.0; break; case 'e': thread_info.format&=~0x30; if (!strncmp(optarg, "floating-point", strlen(optarg))) thread_info.format|=0x23; else if (!strncmp(optarg, "unsigned-integer", strlen(optarg))) thread_info.format|=0x10; else if (!strncmp(optarg, "signed-integer", strlen(optarg))) ; else { fprintf(stderr, "invalid encoding.\n"); usage(argv[0], 1); } break; case 'b': thread_info.format&=~3; if (atoi(optarg) == 24) thread_info.format|=1; else if (atoi(optarg) == 8) thread_info.format|=2; else if (atoi(optarg) == 32) thread_info.format|=3; else if (atoi(optarg) != 16) { fprintf(stderr, "invalid integer bit-depth. valid values: 16,i 24.\n"); usage(argv[0], 1); } break; case 'L': thread_info.format&=~0x40; break; case 'B': thread_info.format|=0x40; break; case 'S': thread_info.rb_size = atoi(optarg); break; default: fprintf(stderr, "invalid argument.\n"); usage(argv[0], 0); break; } } /* set options depending on JACK params, and perform sanity checks */ if (IS_FMTFLT) { /* float is always 32 bit */ thread_info.format|=3; } if (argc <= optind) { fprintf(stderr, "At least one port/audio-channel must be given.\n"); usage(argv[0], 1); } if (infn) { thread_info.readfd = open(infn, O_RDONLY) ; if (thread_info.readfd <0) { fprintf(stderr, "Can not open file.\n"); exit(1); } } /* set up JACK client */ if ((client = jack_client_open(client_name, JackNoStartServer, &jstat)) == 0) { fprintf(stderr, "Can not connect to JACK.\n"); exit(1); } thread_info.client = client; thread_info.can_process = 0; thread_info.channels = argc - optind; if (thread_info.duration > 0) { thread_info.duration *= jack_get_sample_rate(thread_info.client); } /* bail out if buffer is smaller than twice the jack period */ if ((thread_info.rb_size>>1) < jack_get_buffer_size(thread_info.client)) { fprintf(stderr, "Ringbuffer size needs to be at least twice jack period size\n"); jack_client_close(thread_info.client); usage(argv[0], 1); } /* when using small buffers: check if pre-buffer is not too large */ if ( thread_info.rb_size - ceil(thread_info.rb_size * thread_info.prebuffer /100.0) < jack_get_buffer_size(thread_info.client) ) { fprintf(stderr, "Prebuffer ratio is too high. It will never finish.\n"); jack_client_close(thread_info.client); usage(argv[0], 1); } jack_set_process_callback(client, process, &thread_info); jack_on_shutdown(client, jack_shutdown, &thread_info); if (jack_activate(client)) { fprintf(stderr, "cannot activate client"); } setup_ports(thread_info.channels, &argv[optind], &thread_info); /* set up i/o thread */ pthread_create(&thread_info.thread_id, NULL, io_thread, &thread_info); #ifndef _WIN32 signal(SIGHUP, catchsig); signal(SIGINT, catchsig); #endif if (!want_quiet) { fprintf(stderr, "%i channel%s, %s %sbit %s%s %s @%iSPS.\n", thread_info.channels, (thread_info.channels>1)?"s":"", (thread_info.channels>1)?"interleaved":"", (thread_info.format&2)?(thread_info.format&1?"32":"8"):(thread_info.format&1?"24":"16"), (IS_FMTFLT)?"":(IS_SIGNED?"signed-":"unsigned-"), (IS_FMTFLT)?"float":"integer", (IS_FMTFLT)? (IS_BIGEND?"non-native-endian":"native-endian"): (IS_BIGEND?"big-endian":"little-endian"), jack_get_sample_rate(thread_info.client) ); } /* all systems go - run the i/o thread */ thread_info.can_capture = 1; pthread_join(thread_info.thread_id, NULL); /* end - clean up */ if (infn) { /* close readfd if it is not stdin*/ close(thread_info.readfd); free(infn); } if (underruns > 0 && !want_quiet) { fprintf(stderr, "Note: there were %ld buffer underruns.\n", underruns); } jack_client_close(client); jack_ringbuffer_free(rb); return(0); } jack-stdio-1.6/jack-stdout.1000066400000000000000000000046501371362066700157420ustar00rootroot00000000000000.\" jack-stdout.1 written by Robin Gareus .TH JACK-STDOUT 1 "21 February 2019" .SH NAME jack-stdout \- write JACK audio data to stdout .SH SYNOPSIS .HP .B jack-stdout .RI [ OPTIONS ] .RI port1 .RB [ .RI port2 .RB ...] .SH DESCRIPTION .LP \fBjack-stdout\fR captures audio from JACK and writes raw data to standard-output. .P The number of given ports detemine the number of audio channels that are used. If more than one channel is given, the audio-sample data will be interleaved. .SH OPTIONS .TP \fB\-b\fR, \fB\-\-bitdepth \fIBITS\fR .RS Specify the bit-depth of each sample. For integer-encoding this can be 16 or 24. The default is 16. This setting is only used for integer encoding: Floating-point samples will always be 32 bit wide. .RE .TP \fB-d\fR, \fB--duration\fR \fISEC\fR .RS Specify the time for which jack-stdout should run in seconds. A value less than 1 means to run indefinitely. The default is 0. .RE .TP \fB-e\fR, \fB--encoding\fR \fIFORMAT\fR .RS Set the output format of the data: signed-integer, unsigned-integer, floating-point (default: signed) .RE .TP \fB-n\fR, \fB--name\fR \fICLIENTNAME\fR .RS Set JACK client name (default: jstdout) .RE .TP \fB-h\fR, \fB--help\fR .RS Print a brief usage information .RE .TP \fB-L\fR, \fB--little-endian\fR .RS Write little-endian data or native-byte-order float (this is the default) .RE .TP \fB-B\fR, \fB--big-endian\fR .RS Output big-endian data or swap the byte-order of floating-point .RE .TP \fB-q\fR, \fB--quiet\fR .RS Inhibit usual output. This affects information and buffer-overflow warnings but not setup-errors. .RE .TP \fB-S\fR, \fB--bufsize\fR \fISAMPLES\fR .RS Choose the internal buffer-size in samples. The default size is 65536. The given value will be multiplied by the number of channels and bit-depth to get the size of the ring-buffer. .RE .SH EXAMPLES .nf jack-stdout xmms_0:out_1 xmms_0:out_2 \\ | mono ~/Desktop/Downloads/JustePort.exe - 10.0.1.6 0 jack-stdout \-b 24 \-e unsigned \-B system:capture_1 system:capture_2 \\ | sox \-t raw \-r 48k \-e unsigned \-b 24 \-B \-c 2 \- /tmp/recording.wav jack-stdout system:capture_1 system:capture_2 \\ | oggenc \-r \-R 48000 \-B 16 \-C 2 \- \\ > /tmp/recording.ogg jack-stdout system:capture_1 \\ | oggenc \-r \-R 48000 \-B 16 \-C 1 \- \\ | oggfwd \-p \-n "my live stream" localhost 5900 hackme live.ogg .fi .SH AUTHOR Robin Gareus . .SH SEE ALSO http://jackaudio.org/, jack-stdio-1.6/jack-stdout.c000066400000000000000000000342121371362066700160210ustar00rootroot00000000000000/** jack-stdout - write JACK audio data to stdout. * * This tool is based on capture_client.c from the jackaudio.org examples * and modified by Robin Gareus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Copyright (C) 2001 Paul Davis * Copyright (C) 2003 Jack O'Quin * Copyright (C) 2008, 2011 Robin Gareus * * compile with * gcc -o jack-stdout jack-stdout.c -ljack -lm -lpthread * * example use: * jack-stdout xmms_0:out_1 xmms_0:out_2 \ * | mono ~/Desktop/Downloads/JustePort.exe - 10.0.1.6 0 * * jack-stdout system:capture_1 system:capture_2 \ * | oggenc -r -R 48000 -B 16 -C 2 - \ * > /tmp/my.ogg */ #include #include #include #include #include #include #include #include #include #include #include typedef struct _thread_info { pthread_t thread_id; pthread_t mesg_thread_id; jack_nframes_t duration; jack_nframes_t rb_size; jack_client_t *client; unsigned int channels; volatile int can_capture; volatile int can_process; int format; /**format: * bit0,1: 16/24/8/32(float) * bit8: signed/unsiged (0x10) * bit9: int/float (0x20) - dup -- 0x03 * bit10: little/big endian (0x40) */ } jack_thread_info_t; #define IS_FMTFLT ((info->format&0x20)) #define IS_BIGEND (info->format&0x40) #define IS_FMT32B ((info->format&0x23)==3) #define IS_FMT08B ((info->format&3)==2) #define IS_FMT24B ((info->format&3)==1) #define IS_FMT16B ((info->format&3)==0) #define IS_SIGNED (!(info->format&0x10)) #define SAMPLESIZE ((info->format&2)?((info->format&1)?4:1):((info->format&1)?3:2)) #define POWHX ((info->format&2)?((info->format&1)?2147483647:127):((info->format&1)? 8388607:32767)) #define POWHS ((info->format&2)?((info->format&1)?2147483648.0:128.0):((info->format&1)? 8388608.0:32768.0)) #define FMTOFF ((IS_SIGNED)?0.0:POWHX) #define FMTMLT (POWHS) #define BE(i) ( (IS_BIGEND)?(SAMPLESIZE-i-1):i) /* JACK data */ jack_port_t **ports; jack_default_audio_sample_t **in; jack_nframes_t nframes; /* Synchronization between process thread and disk thread. */ jack_ringbuffer_t *rb; pthread_mutex_t io_thread_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t data_ready = PTHREAD_COND_INITIALIZER; /* global options/status */ int want_quiet = 0; volatile int run = 1; long overruns = 0; void * io_thread (void *arg) { jack_thread_info_t *info = (jack_thread_info_t *) arg; jack_nframes_t total_captured = 0; const size_t bytes_per_frame = info->channels * SAMPLESIZE; void *framebuf = malloc (bytes_per_frame); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_mutex_lock(&io_thread_lock); int writerrors =0; while (run) { /* Write the data one frame at a time. This is * inefficient, but makes things simpler. */ while (info->can_capture && (jack_ringbuffer_read_space (rb) >= bytes_per_frame)) { if (info->duration > 0 && total_captured >= info->duration) { if (!want_quiet) fprintf(stderr, "io thread finished\n"); goto done; } #if 0 /* wait (indefinitley) for write-ready * this select() is only needed if fileno(stdout) is non-blocking */ fd_set fd; FD_ZERO(&fd); FD_SET(fileno(stdout), &fd); select(fileno(stdout), &fd, NULL, NULL, NULL); #endif jack_ringbuffer_read(rb, framebuf, bytes_per_frame); size_t woff = 0; ssize_t rv; while ((rv=write(fileno(stdout), framebuf+woff, bytes_per_frame)) != bytes_per_frame) { if (rv<0) { if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { if (!want_quiet) fprintf(stderr, "FATAL: write error: %s\n", strerror(errno)); goto done; } } if (rv>0) woff += rv; if (++writerrors > 16) { writerrors=0; if (!want_quiet) fprintf(stderr, "write error. retrying.\n"); #if 0 /* bail out ?! */ /* flush remaining bytes from ringbuffer */ if (rv>=0) { rv=0; while (bytes_per_frame - woff - rv > 0) { jack_ringbuffer_read(rb, framebuf, 1); ++rv; } } break; #endif } #if 0 /* this thread can just block.. * this select() is only needed if fileno(stdout) is non-blocking */ fd_set fd; struct timeval tv = { 0, 0 }; tv.tv_sec = 0; tv.tv_usec = 1000; // 1ms FD_ZERO(&fd); FD_SET(fileno(stdout), &fd); select(fileno(stdout), &fd, NULL, NULL, &tv); #endif } ++total_captured; } pthread_cond_wait(&data_ready, &io_thread_lock); } done: pthread_mutex_unlock(&io_thread_lock); free(framebuf); return 0; } int process (jack_nframes_t nframes, void *arg) { int chn; size_t i; jack_thread_info_t *info = (jack_thread_info_t *) arg; const size_t bytes_per_frame = info->channels * SAMPLESIZE; /* Do nothing until we're ready to begin. */ if ((!info->can_process) || (!info->can_capture)) return 0; for (chn = 0; chn < info->channels; ++chn) in[chn] = jack_port_get_buffer(ports[chn], nframes); /* queue interleaved samples to a single ringbuffer. */ for (i = 0; i < nframes; i++) { /* only queue samples if a whole frame (all channels) can be stored */ if (jack_ringbuffer_write_space(rb) < bytes_per_frame ) { overruns++; break; } for (chn = 0; chn < info->channels; ++chn) { const jack_default_audio_sample_t js = in[chn][i]; if (IS_FMTFLT) { /* 32 bit float */ float d; if (IS_BIGEND) { /* swap float endianess */ char *flin = (char*) & js; char *fout = (char*) & d; fout[0] = flin[3]; fout[1] = flin[2]; fout[2] = flin[1]; fout[3] = flin[0]; } else { d = js; } jack_ringbuffer_write(rb, (void *) &d, SAMPLESIZE); } else { /* 8/16/24 LE/BE signed/unsigned */ const int32_t d = (int32_t) rintf(js*FMTMLT) + FMTOFF; char bytes[4]; bytes[BE(0)] = (unsigned char) (d&0xff); if (IS_FMT16B || IS_FMT24B || IS_FMT32B) bytes[BE(1)] = (unsigned char) (((d&0xff00)>>8)&0xff); if (IS_FMT24B || IS_FMT32B) bytes[BE(2)] = (unsigned char) (((d&0xff0000)>>16)&0xff); if (IS_FMT32B) bytes[BE(3)] = (unsigned char) (((d&0xff000000)>>24)&0xff); jack_ringbuffer_write (rb, (void *) &bytes, SAMPLESIZE); } } } /* Tell the io thread there is work to do. */ if (pthread_mutex_trylock(&io_thread_lock) == 0) { pthread_cond_signal(&data_ready); pthread_mutex_unlock(&io_thread_lock); } return 0; } void jack_shutdown (void *arg) { fprintf(stderr, "JACK shutdown\n"); abort(); } void setup_ports (int nports, char *source_names[], jack_thread_info_t *info) { unsigned int i; const size_t in_size = nports * sizeof(jack_default_audio_sample_t *); /* Allocate data structures that depend on the number of ports. */ ports = (jack_port_t **) malloc(sizeof(jack_port_t *) * nports); in = (jack_default_audio_sample_t **) malloc(in_size); rb = jack_ringbuffer_create(nports * SAMPLESIZE * info->rb_size); /* When JACK is running realtime, jack_activate() will have * called mlockall() to lock our pages into memory. But, we * still need to touch any newly allocated pages before * process() starts using them. Otherwise, a page fault could * create a delay that would force JACK to shut us down. */ memset(in, 0, in_size); memset(rb->buf, 0, rb->size); for (i = 0; i < nports; i++) { char name[64]; sprintf(name, "input%d", i+1); if ((ports[i] = jack_port_register(info->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == 0) { fprintf(stderr, "cannot register input port \"%s\"!\n", name); jack_client_close(info->client); exit(1); } } for (i = 0; i < nports; i++) { if (jack_connect(info->client, source_names[i], jack_port_name(ports[i]))) { fprintf(stderr, "cannot connect input port %s to %s\n", jack_port_name(ports[i]), source_names[i]); #if 0 /* not fatal - connect manually */ jack_client_close(info->client); exit(1); #endif } } /* process() can start, now */ info->can_process = 1; } void catchsig (int sig) { #ifndef _WIN32 signal(SIGHUP, catchsig); /* reset signal */ #endif if (!want_quiet) fprintf(stderr,"\n CAUGHT SIGNAL - shutting down.\n"); run=0; /* signal writer thread */ pthread_mutex_lock(&io_thread_lock); pthread_cond_signal(&data_ready); pthread_mutex_unlock(&io_thread_lock); } static void usage (const char *name, int status) { fprintf(status?stderr:stdout, "usage: %s [ OPTIONS ] port1 [ port2 ... ]\n", name); fprintf(status?stderr:stdout, "jack-stdout captures audio-data from JACK and writes it to standard-output.\n"); fprintf(status?stderr:stdout, "OPTIONS:\n" " -h, --help print this message\n" " -q, --quiet inhibit usual output\n" " -b, --bitdepth {bits} choose integer bit depth: 16, 24 (default: 16)\n" " -d, --duration {sec} terminate after given time, <1: unlimited (default:0)\n" " -e, --encoding {format} set output format: (default: signed)\n" " signed-integer, unsigned-integer, float\n" " -n, --name {clientname} set client name in JACK instead of jstdout\n" " -L, --little-endian write little-endian integers or\n" " native-byte-order floats (default)\n" " -B, --big-endian write big-endian integers or swapped-order floats\n" " -S, --bufsize {samples} set buffer size (default: 64k)\n" ); exit(status); } int main (int argc, char **argv) { jack_client_t *client; jack_thread_info_t thread_info; jack_status_t jstat; int c; char *client_name = "jstdout"; memset(&thread_info, 0, sizeof(thread_info)); thread_info.rb_size = 16384 * 4; thread_info.channels = 2; thread_info.duration = 0; thread_info.format = 0; const char *optstring = "d:e:b:S:n:BLhq"; struct option long_options[] = { { "help", 0, 0, 'h' }, { "quiet", 0, 0, 'q' }, { "duration", 1, 0, 'd' }, { "encoding", 1, 0, 'e' }, { "name", 1, 0, 'n' }, { "little-endian", 0, 0, 'L' }, { "big-endian", 0, 0, 'B' }, { "bitdepth", 1, 0, 'b' }, { "bufsize", 1, 0, 'S' }, { 0, 0, 0, 0 } }; while ((c = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (c) { case 'h': usage(argv[0], 0); break; case 'q': want_quiet = 1; break; case 'n': client_name = optarg; break; case 'd': thread_info.duration = atoi(optarg); break; case 'e': thread_info.format&=~0x30; if (!strncmp(optarg, "floating-point", strlen(optarg))) thread_info.format|=0x23; else if (!strncmp(optarg, "unsigned-integer", strlen(optarg))) thread_info.format|=0x10; else if (!strncmp(optarg, "signed-integer", strlen(optarg))) ; else { fprintf(stderr, "invalid encoding.\n"); usage(argv[0], 1); } break; case 'b': thread_info.format&=~3; if (atoi(optarg) == 24) thread_info.format|=1; else if (atoi(optarg) == 8) thread_info.format|=2; else if (atoi(optarg) == 32) thread_info.format|=3; else if (atoi(optarg) != 16) { fprintf(stderr, "invalid integer bit-depth. valid values: 8, 16, 24, 32.\n"); usage(argv[0], 1); } break; case 'L': thread_info.format&=~0x40; break; case 'B': thread_info.format|=0x40; break; case 'S': thread_info.rb_size = atoi(optarg); break; default: fprintf(stderr, "invalid argument.\n"); usage(argv[0], 0); break; } } /* set options depending on JACK params, and perform sanity checks */ if (thread_info.format & 0x20) { /* float is always 32 bit */ thread_info.format|=3; } if (argc <= optind) { fprintf(stderr, "At least one port/audio-channel must be given.\n"); usage(argv[0], 1); } /* set up JACK client */ if ((client = jack_client_open(client_name, JackNoStartServer, &jstat)) == 0) { fprintf(stderr, "Can not connect to JACK.\n"); exit(1); } thread_info.client = client; thread_info.can_process = 0; thread_info.channels = argc - optind; if (thread_info.duration > 0) { thread_info.duration *= jack_get_sample_rate(thread_info.client); } /* bail out if buffer is smaller than twice the jack period */ if ((thread_info.rb_size>>1) < jack_get_buffer_size(thread_info.client)) { fprintf(stderr, "Ringbuffer size needs to be at least twice jack period size\n"); jack_client_close(thread_info.client); usage(argv[0], 1); } jack_set_process_callback(client, process, &thread_info); jack_on_shutdown(client, jack_shutdown, &thread_info); if (jack_activate(client)) { fprintf(stderr, "cannot activate client"); } setup_ports(thread_info.channels, &argv[optind], &thread_info); /* set up i/o thread */ pthread_create(&thread_info.thread_id, NULL, io_thread, &thread_info); #ifndef _WIN32 signal (SIGHUP, catchsig); #endif if (!want_quiet) { fprintf(stderr, "%i channel%s, %s %sbit %s%s %s @%iSPS.\n", thread_info.channels, (thread_info.channels>1)?"s":"", (thread_info.channels>1)?"interleaved":"", (thread_info.format&2)?(thread_info.format&1?"32":"8"):(thread_info.format&1?"24":"16"), (thread_info.format&0x20)?"":(thread_info.format&0x10?"unsigned-":"signed-"), (thread_info.format&0x20)?"float":"integer", (thread_info.format&0x20)? (thread_info.format&0x40?"non-native-endian":"native-endian"): (thread_info.format&0x40?"big-endian":"little-endian"), jack_get_sample_rate(thread_info.client) ); } /* all systems go - run the i/o thread */ thread_info.can_capture = 1; pthread_join(thread_info.thread_id, NULL); /* end - clean up */ if (overruns > 0 && !want_quiet) { fprintf(stderr, "Note: there were %ld buffer overruns.\n", overruns); } jack_client_close(client); jack_ringbuffer_free(rb); return(0); } jack-stdio-1.6/tests.sh000066400000000000000000000076361371362066700151350ustar00rootroot00000000000000#!/bin/sh WAV=${1:-/tmp/you_wont_be_satisfied.wav} RM="" INPORTS="system:capture_1 system:capture_2" OUTPORTS="system:playback_1 system:playback_2" if [ ! -f $WAV ]; then echo "# wav file missing - generating $WAV" sox -n $WAV synth 3 sine 300-3300 gain -5 RM=true fi if true; then echo "testing formats: sox | ./jack-stdin" sox $WAV -t raw -r 48k -e signed -b 8 -c 2 - | ./jack-stdin -e signed -b 8 $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 8 -c 2 -B - | ./jack-stdin -e signed -b 8 -B $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 8 -c 2 - | ./jack-stdin -e unsigned -b 8 $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 8 -c 2 -B - | ./jack-stdin -e unsigned -b 8 -B $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 16 -c 2 - | ./jack-stdin $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 16 -c 2 -B - | ./jack-stdin -B $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 16 -c 2 - | ./jack-stdin -e unsigned -b 16 $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 16 -c 2 -B - | ./jack-stdin -e unsigned -b 16 -B $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 24 -c 2 - | ./jack-stdin -e signed -b 24 $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 24 -c 2 -B - | ./jack-stdin -e signed -b 24 -B $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 24 -c 2 - | ./jack-stdin -e unsigned -b 24 $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 24 -c 2 -B - | ./jack-stdin -e unsigned -b 24 -B $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 32 -c 2 - | ./jack-stdin -e signed -b 32 $OUTPORTS sox $WAV -t raw -r 48k -e signed -b 32 -c 2 -B - | ./jack-stdin -e signed -b 32 -B $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 32 -c 2 - | ./jack-stdin -e unsigned -b 32 $OUTPORTS sox $WAV -t raw -r 48k -e unsigned -b 32 -c 2 -B - | ./jack-stdin -e unsigned -b 32 -B $OUTPORTS sox $WAV -t raw -r 48k -e float -b 32 -c 2 - | ./jack-stdin -e float -b 32 $OUTPORTS sox $WAV -t raw -r 48k -e float -b 32 -c 2 -B - | ./jack-stdin -e float -b 32 -B $OUTPORTS fi if true; then echo "testing ./jack-stdout | ./jack-stdin" ./jack-stdout -d 3 -e signed -b 8 $INPORTS | ./jack-stdin -e signed -b 8 $OUTPORTS ./jack-stdout -d 3 -e signed -b 8 -B $INPORTS | ./jack-stdin -e signed -b 8 -B $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 8 $INPORTS | ./jack-stdin -e unsigned -b 8 $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 8 -B $INPORTS | ./jack-stdin -e unsigned -b 8 -B $OUTPORTS ./jack-stdout -d 3 -e signed -b 16 $INPORTS | ./jack-stdin -e signed -b 16 $OUTPORTS ./jack-stdout -d 3 -e signed -b 16 -B $INPORTS | ./jack-stdin -e signed -b 16 -B $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 16 $INPORTS | ./jack-stdin -e unsigned -b 16 $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 16 -B $INPORTS | ./jack-stdin -e unsigned -b 16 -B $OUTPORTS ./jack-stdout -d 3 -e signed -b 24 $INPORTS | ./jack-stdin -e signed -b 24 $OUTPORTS ./jack-stdout -d 3 -e signed -b 24 -B $INPORTS | ./jack-stdin -e signed -b 24 -B $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 24 $INPORTS | ./jack-stdin -e unsigned -b 24 $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 24 -B $INPORTS | ./jack-stdin -e unsigned -b 24 -B $OUTPORTS ./jack-stdout -d 3 -e signed -b 32 $INPORTS | ./jack-stdin -e signed -b 32 $OUTPORTS ./jack-stdout -d 3 -e signed -b 32 -B $INPORTS | ./jack-stdin -e signed -b 32 -B $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 32 $INPORTS | ./jack-stdin -e unsigned -b 32 $OUTPORTS ./jack-stdout -d 3 -e unsigned -b 32 -B $INPORTS | ./jack-stdin -e unsigned -b 32 -B $OUTPORTS ./jack-stdout -d 3 -e float -b 32 $INPORTS | ./jack-stdin -e float -b 32 $OUTPORTS ./jack-stdout -d 3 -e float -b 32 -B $INPORTS | ./jack-stdin -e float -b 32 -B $OUTPORTS fi test -n "$RM" && rm $WAV