1.\" $OpenBSD: aucat.1,v 1.116 2020/04/22 05:37:00 jmc Exp $ 2.\" 3.\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: April 22 2020 $ 18.Dt AUCAT 1 19.Os 20.Sh NAME 21.Nm aucat 22.Nd audio files manipulation tool 23.Sh SYNOPSIS 24.Nm aucat 25.Op Fl dn 26.Op Fl b Ar size 27.Op Fl c Ar min : Ns Ar max 28.Op Fl e Ar enc 29.Op Fl f Ar device 30.Op Fl g Ar position 31.Op Fl h Ar fmt 32.Op Fl i Ar file 33.Op Fl j Ar flag 34.Op Fl o Ar file 35.Op Fl p Ar position 36.Op Fl q Ar port 37.Op Fl r Ar rate 38.Op Fl v Ar volume 39.Sh DESCRIPTION 40The 41.Nm 42utility can play, record, mix, and process audio files 43on the fly. 44During playback, 45.Nm 46reads audio data concurrently from all played files, 47mixes it and plays the result on the device. 48Similarly, it stores audio data recorded 49from the device into corresponding files. 50An 51.Em off-line 52mode could be used to process audio files without 53involving audio hardware. 54Processing includes: 55.Pp 56.Bl -bullet -offset indent -compact 57.It 58Change the sound encoding. 59.It 60Route the sound from one channel to another. 61.It 62Control the per-file playback volume. 63.El 64.Pp 65Finally, 66.Nm 67can accept MIDI messages usable for: 68.Pp 69.Bl -bullet -offset indent -compact 70.It 71Volume control. 72.It 73Start, stop and relocate playback and recording. 74.El 75.Pp 76The options are as follows: 77.Bl -tag -width Ds 78.It Fl b Ar size 79The buffer size of the audio device in frames. 80Default is 7680. 81.It Fl c Ar min : Ns Ar max 82The range of audio file channel numbers. 83The default is 84.Cm 0:1 , 85i.e. stereo. 86.It Fl d 87Increase log verbosity. 88.It Fl e Ar enc 89Encoding of the audio file. 90The default is 91.Va s16 . 92Encoding names use the following scheme: signedness 93.Po 94.Va s 95or 96.Va u 97.Pc 98followed 99by the precision in bits, the byte-order 100.Po 101.Va le 102or 103.Va be 104.Pc , 105the number of 106bytes per sample, and the alignment 107.Po 108.Va msb 109or 110.Va lsb 111.Pc . 112Only the signedness and the precision are mandatory. 113Examples: 114.Va u8 , s16le , s24le3 , s24le4lsb . 115.It Fl f Ar device 116Use this 117.Xr sndio 7 118audio device. 119Device mode and parameters are determined from audio files. 120Default is 121.Pa default . 122.It Fl g Ar position 123Go to the given time position and start playback or recording there. 124This option is equivalent to an incoming MMC relocate message 125with the same position. 126The position is expressed as the number of samples (at device sample rate). 127.It Fl h Ar fmt 128Audio file type. 129The following file types are supported: 130.Pp 131.Bl -tag -width auto -compact 132.It Cm raw 133Headerless file. 134.It Cm wav 135Microsoft WAV file format. 136.It Cm aiff 137Apple's audio interchange file format. 138.It Cm au 139Sun/NeXT audio file format. 140.It Cm auto 141Try to guess, depending on the file name. 142This is the default. 143.El 144.It Fl i Ar file 145Play this audio file. 146If the option argument is 147.Sq - 148then standard input will be used. 149.It Fl j Ar flag 150Control whether source channels are joined or expanded if 151they don't match the destination number of channels. 152If the flag is 153.Cm off , 154then each source channel is routed to a single destination channel, 155possibly discarding channels. 156If the flag is 157.Cm on , 158then a single source may be sent to multiple destinations 159and multiple sources may be mixed into a single destination. 160For instance, this feature could be used to convert 161a stereo file into a mono file mixing left and right channels together. 162The default is 163.Cm off . 164.It Fl n 165Off-line mode. 166Read input files and store the result in the output files, 167processing them on the fly. 168This mode is useful to mix, demultiplex, resample or re-encode 169audio files off-line. 170It requires at least one input 171.Pq Fl i 172and one output 173.Pq Fl o . 174.It Fl o Ar file 175Record into this audio file. 176If the option argument is 177.Sq - 178then standard output will be used. 179.It Fl p Ar position 180Time offset where the beginning of the file belongs. 181The first sample of the file will be played or recorded when the device 182reaches the given position. 183The position is expressed as the number of samples (at device sample rate). 184.It Fl q Ar port 185Control audio device properties through this MIDI port. 186This includes per-stream volumes and the ability to 187synchronously start, stop and relocate audio files. 188.It Fl r Ar rate 189Sample rate in Hertz of the audio file. 190The default is 191.Cm 48000 . 192.It Fl v Ar volume 193Software volume attenuation of the file to play. 194The value must be between 1 and 127, 195corresponding to \-42dB and \-0dB attenuation in 1/3dB steps. 196The default is 127, i.e. no attenuation. 197.El 198.Pp 199On the command line, 200per-file parameters 201.Pq Fl cehjrv 202must precede the file definition 203.Pq Fl io . 204.Pp 205If 206.Nm 207is sent 208.Dv SIGHUP , 209.Dv SIGINT 210or 211.Dv SIGTERM , 212it terminates recording to files. 213.Sh MIDI CONTROL 214.Nm 215can be controlled through MIDI 216.Pq Fl q 217as follows: 218a MIDI channel is assigned to each stream, and the volume 219is changed using the standard volume controller (number 7). 220.Pp 221The master volume can be changed using the standard master volume 222system exclusive message. 223.Pp 224All audio files are controlled by the following MMC messages: 225.Bl -tag -width relocate -offset indent 226.It relocate 227All files are relocated to the requested time position. 228If it is beyond the end of a file, the file is temporarily 229disabled until a valid position is requested. 230.It start 231Playback and/or recording is started. 232.It stop 233Playback and/or recording is stopped and all files are rewound 234back to the starting position. 235.El 236.Pp 237MIDI control is intended to be used together with 238.Xr sndiod 8 . 239For instance, the following command will create two devices: 240the default 241.Va snd/0 242and a MMC-controlled one 243.Va snd/0.mmc : 244.Bd -literal -offset indent 245$ sndiod -r 48000 -z 480 -s default -t slave -s mmc 246.Ed 247.Pp 248Programs using 249.Va snd/0 250behave normally, while programs using 251.Va snd/0.mmc 252wait for the MMC start signal and start synchronously. 253Then, the following command will play a file on the 254.Va snd/0.mmc 255audio device, giving full control to MIDI software or hardware 256connected to the 257.Va midithru/0 258MIDI port: 259.Bd -literal -offset indent 260$ aucat -f snd/0.mmc -q midithru/0 -i file.wav 261.Ed 262.Pp 263At this stage, 264.Nm 265will start, stop and relocate automatically following all user 266actions in the MIDI sequencer, assuming it's configured to 267transmit MMC on 268.Va midithru/0 . 269Furthermore, the MIDI sequencer could be configured to use the 270.Va snd/0 271port as MTC clock source, assured to be synchronous to playback of 272.Pa file.wav . 273.Sh EXAMPLES 274Mix and play two files while recording a third file: 275.Bd -literal -offset indent 276$ aucat -i file1.wav -i file2.wav -o file3.wav 277.Ed 278.Pp 279Record channels 2 and 3 into one stereo file and 280channels 6 and 7 into another stereo file using a 44.1kHz sampling 281rate for both: 282.Bd -literal -offset indent 283$ aucat -r 44100 -c 2:3 -o file1.wav -c 6:7 -o file2.wav 284.Ed 285.Pp 286Split a stereo file into two mono files: 287.Bd -literal -offset indent 288$ aucat -n -i stereo.wav -c 0:0 -o left.wav \e 289 -c 1:1 -o right.wav 290.Ed 291.Sh SEE ALSO 292.Xr cdio 1 , 293.Xr audio 4 , 294.Xr sndio 7 , 295.Xr audioctl 8 , 296.Xr mixerctl 8 , 297.Xr sndiod 8 298.Sh BUGS 299Resampling is low quality. 300.Pp 301There are limitations inherent to the 302.Ar wav , 303.Ar aiff , 304and 305.Ar au 306file formats: not all encodings are supported, 307file sizes are limited to 2GB, and the files must support the 308.Xr lseek 2 309operation (e.g. pipes do not support it). 310