Combining audio files in Terminal with cat f1.aif f2.aif >> f3.aif

At our music school we record all rehearsal halls and performance spaces 24/7. To keep file sizes small we split them if they reach an hour. So we are constantly rejoining files when making masters.

There are a number of GUI methods for this (we use Amadeus; Join Files), but I want to script it. Several sites suggest the Unix/Terminal command cat (for mp3s). I did this with aif files and while the resulting file is the expected size, when I open it in Amadeus Pro I only get the first file. I can't get it to work with text files either.

I've tried:

cat file1.aif file2.aif >> file3.aif
cat file1.aif > file3.aif ; cat file2.aif >> file3.aif
and even
cat test1.rtf test2.rtf >> test3.rtf

Likewise, the content of the second text file is missing. However,

ls > file1 ; man cat > file2 ; cat file1 file2 >> file3

does work.

Several sites show examples for mp3 files:
cat f1.mp3 f2.mp3 >> f3.mp3

Similarly, I tried it with mp3s and I only get the first file.

What am I doing wrong?

< Edited by Host >

MacBook Pro, Mac OS X (10.5.8)

Posted on Nov 23, 2010 9:28 PM

Reply
13 replies

Nov 24, 2010 11:48 AM in response to rccharles

Yes, I should have said, Amadeus is non-scriptable. And my intention was to write an Applescript with a shell command. (Select a group of aif, run the script, it joins them and opens in Amadeus.) I'm an Applescript/shortcut fanatic and we use dozens of scripts to rename files by start time and date (calculating the size and format--48k, 44.1k, and aac--to get the start time from the mod date) and moving them to different servers for various faculty (three performances and two rehearsal halls). We even extract the times and dates of all events for all five halls from a published ical database (created at the main office) and sort them based on how they need to be treated (edited and archived, saved for future use, or ignored). I'm working on an Applescript that will pull the aif files based on the calendar, which gives the room and start time. Using sox I can now gather those files together based solely on the calendar.

We also use Quickeys for a lot of operations: two machines (the system is redundant) send me an email once a day with all open apps and the mod dates of the archive folders. If they are older than 24 hours it sends a warning (that possibly one of the recordings have crashed or the DA converters have choked). I combine Quickeys and Applescripts for those.

sox file1.aif file2.aif file3.aif

works great.

Amadeus allows you to join files, but you have to open the dialog and drag the files to the window (or click add etc.). I didn't want to do that in Quickeys (too much room for error--you can't even copy and paste into the dialog); command lines are much cleaner. I've suggest to the author a faster method, but while he's very open and responsive to suggestions, this one hasn't been added.

Nov 24, 2010 1:03 PM in response to David Cottle

Glad it worked.

Totally off-topic, but do you know anything about afplay?

I've been frustrated by iTunes' inability to match/change the sampling frequency without having to close and restart the program (it uses whatever Audio Midi is set to when it opens). So I wrote a shell script hack that essentially allows me to use afplay to play a track at iTunes as the GUI. But I worry about whether afplay is bit-perfect or if it compromises sound quality.

afplay -q 1 yourfile


supposedly gives you maximum quality playback, but maximum with respect to what? (I figured a music unix person might know).

Nov 24, 2010 1:39 PM in response to Bill Scott

Well, I was a Unix person (studied computer music at U of Illinois before the advent of a mouse) and now just work in OS X (and Logic, SuperCollider, Max). So I know just enough Unix to be dangerous (hence my question about cat). But I might lead you to an answer by how I checked sox f1.aif f2.aif both.aif to see if I was losing any quality. I generated a short mono file filled with noise (in Amadeus), then split the file. I joined them using Amadeus' Join dialog and also with sox. I then inverted one of the joined files and mixed them together (paste/mix). Voila; no sound from phase cancellation. So they were combined exactly the same. (I tried diff and cmp in Terminal, but it just said they were different, no specifics.)

Nov 24, 2010 4:46 PM in response to Tony T1

I don't know either of these that well, but I don't think any sort of bit by bit comparison in terminal would work, because they are different. I'm not sure what the difference is (something in the header?), but my question was whether or not the audio had been compromised by some process (such as dithering). Or possibly joining them in Amadeus put tags (such as a marker at the joints) that sox did not. The point is they were different. But does that mean the audio is different? Inverting the phase and summing them shows that the audio is precisely the same regardless of any headers or markers.

Nov 24, 2010 11:39 PM in response to Bill Scott

A followup: I've constructed a script that combines selected files then opens it in Amadeus. But there was one feature in the Join menu of Amadeus that we used; it marked each joint with a marker (named for the file name joined). This is necessary because we want to check the joints to make sure there is no digital error. Most are seamless, but 1 in 50 have some small flaw.

Any way to add markers between the files joined by sox?

Here is the applescript:

tell application "Finder"
activate
set all to ""
set theseItems to selection
set p to folder of item 1 of theseItems as string
set p_p to (get POSIX path of p)
repeat with n from 1 to number of items in theseItems
set fn to name of item n of theseItems
set all to all & " " & p_p & fn
display dialog all
end repeat
set all to "sox " & all & " " & p_p & "newfile.aif"
--display dialog all
do shell script all
end tell
tell application "Amadeus Pro"
open (p_p & "newfile.aif")
end tell

Nov 25, 2010 10:18 AM in response to David Cottle

David Cottle wrote:
I don't know either of these that well, but I don't think any sort of bit by bit comparison in terminal would work, because they are different. ....but my question was whether or not the audio had been compromised by some process (such as dithering).


If you use SoX to split the files, the use Sox (or another program) to re-join the files, then the md5 before split, and after re-join should be the same (and therefore, no audio compromise).

Nov 25, 2010 12:45 PM in response to Tony T1

Since I'm just now learning SoX, I don't know it's capabilities, so I'm not sure if it would work in our operations. But I like command lines so I'll definitely investigate. Now we record and split using Audio Companion. Files are split automatically based on size (max 1 hour) or levels of ambient noise in each hall. (When it falls below -60 db for 40 seconds it shuts off and splits the files.) And though we've tried most DAWs (including Logic and PTs), we prefer to edit in Amadeus for a number of reasons. So the split files and joined files will never be reconciled bit for bit, even less so if I use SoX to join them. So the phase cancellation still is my best guarantee that the audio itself hasn't been compressed or dithered. (My concern is that there is some default option that will modify the files, such as normalization or dithering. Since I don't know SoX yet, this is the fastest way to guarantee precise duplication of the audio.)

The advantage to joining them using Amadeus is that it drops markers on the joints (so we can easily check for a clean join). I don't see any marker options in SoX, so I'm doing them in the Applescript using soxi to get the duration to the thousandth of a second, then generating a marker list that can be imported into Amadeus after the files are joined.

If you know how to drop markers in SoX, this would help.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Combining audio files in Terminal with cat f1.aif f2.aif >> f3.aif

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.