Skip to content

Instantly share code, notes, and snippets.

@nperony
Last active January 22, 2020 08:45
Show Gist options
  • Save nperony/d89f0167ce8663a45befce17f76e0d6f to your computer and use it in GitHub Desktop.
Save nperony/d89f0167ce8663a45befce17f76e0d6f to your computer and use it in GitHub Desktop.
Recording simultaneous bi-directional raw audio streams (e.g. calls) on OS X

Recording simultaneous bi-directional raw audio streams (e.g. calls) on OS X


Steps

  1. Install kernel module to mirror speaker/headphones audio onto input interface
  2. Create a virtual "multi-output" device to pipe audio output simultaneously to speakers/headphones and input interface
  3. Create a virtual "aggregate" device to multiplex output/input audio channels
  4. Record audio file
  5. Blend channels, normalise audio, export stereo file.

1. Install kernel module to loop back speaker/headphones audio onto input interface

Install the Soundflower kernel extension; this signed disk image of the latest release will come in handy. Since it is just a kernel module to mirror the audio output to an input interface, you won't see anything new in your applications folder. Enabling the interface will disable sound to your speakers (since it is piped to this "virtual microphone"), hence the need for step 2.


2. Create a virtual "multi-output" device to pipe audio output simultaneously to speakers/headphones and input interface

  • Open Audio MIDI Setup: (found in /Applications/Utilities)
  • Click the '+' button in the bottom left corner and select "Create Multi Output Device" in the the panel that appears on the right. Select "Built-in Output" AND "Soundflower (2ch)", then click on the gear icon at the bottom left and select "use this device for sound output". You should now be hearing output audio normally (but it will also be cloned onto the virtual mic).


3. Create a virtual "aggregate" device to multiplex output/input audio channels

Repeat the procedure above but this time create an aggregate device (mixing input and output into a single interface) combining your microphone and the newly created output device.


4. Record audio file

  • Plug in your headset (to avoid cross-contamination between audio streams)
  • In sound settings (System Preferences -> Sound), make sure that your output interface is the multi-output device you created, and your input comes from your microphone.
  • Record audio. Audacity is a powerful free tool to manipulate audio files and streams. Use it (or similar software) to record a call with your aggregate device as input. The recorded stream will effectively have 4 channels: 2 carrying stereo output from your speakers, and 2 carrying stereo input from your microphone.


5. Blend channels, normalise audio, export stereo file.

  • If you use Audacity, select (Shift+click) pairs of channels and mix them into a single track for input and another one for output with the Mix & Render transform in the "Tracks" menu.

  • Normalise track volume (so input and output have the same amplitude) with the "Normalize" effect (Effects -> Normalize). Make sure that "Normalize stereo channels independently" is ticked.

  • To keep both tracks from being merged into a single one during export, assign one (say input) to the left channel and one (output) to the right channel, by clicking on the arrow pointing downwards next to "Mix" in the track properties.

  • To keep both tracks from being merged into a single one during export, assign one (say input) to the left channel and one (output) to the right channel, by clicking on the arrow pointing downwards next to "Mix" in the track properties.

  • Play back your file to make sure that both channels are indeed assigned to two different ears (assuming you're still wearing your headset), and then export (File -> Export audio) your stereo recording as a 16-bit PCM (uncompressed) WAV file.

If you're done, switch back your audio interface to output interface to headphones/speakers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment