Giter Site home page Giter Site logo

kunichiko / ms2109-mono-to-stereo-mac Goto Github PK

View Code? Open in Web Editor NEW
16.0 4.0 2.0 1.33 MB

Convert the MS2109's mono sound input stream to stereo one on the macOS. This project is inspired by ToadKing's mono-to-stereo project ( https://github.com/ToadKing/mono-to-stereo ).

License: MIT License

C 0.23% Swift 99.13% Makefile 0.64%
audio macos coreaudio

ms2109-mono-to-stereo-mac's Introduction

MS2109-mono-to-stereo-mac

日本語版はこちら

About

This program converts MS2109's 96kHz mono sound stream to 48kHz stereo sound stream in real time.

This is realized by a mechanism in which this program receives the input of one voice input interface (microphone, capture device, etc.), returns it, and re-outputs it to another voice output interface (line output, etc.).

It does not mean that "installing this program will automatically turn monaural audio into stereo", so you will need to use it in combination with other tools such as Black Hole to capture the converted stereo audio.

How to Use

If you want to convert a mono sound to stereo and capture by QuickTime Player, you should use 'Black Hole' virtual sound device.

Black Hole is software that functions as a virtual sound device with audio input and output, and from the perspective of macOS and other programs, it seems that new audio input / output interfaces named Black Hole has attached.

Please see here for details. https://github.com/ExistentialAudio/BlackHole

A major feature of Black Hole is that when audio is output to the Black Hole output device as shown below, the audio can be captured from the Black Hole input device.

BlackHole(Out) <== audio out from some app
↓
BlackHole(In)  ==> audio in to some app

By using this behaviour, you can capture stereo sound with QuickTime etc. as follows.

MS2109Device(In) ==> mono2stereo
                       ↓ convert to stereo
BlackHole(Out)   <== Select BlackHole(Out) as output device
↓
BlackHole(In)    ==> Select BlackHole(In) as input device on QuickTime.

Step 0-1. Install Homebrew

This mono2stereo and BlackHole can be installed using Homebrew, so please install Homebrew first. If you already have a Homebre environment, you can skip it.

https://brew.sh/index_ja

Install it by executing the command listed on the above page on the macOS terminal.

Step 0-2. Install Xcode

You need to install Xcode because building may not succeed when using the Command Line Tools that Homebrew automatically installs. After installing Xcode, please execute the following command in the terminal (even if it is already installed, please execute it just to be sure).

> xcode-select -p

If the output is /Library/Developer/CommandLineTools , you should change the active developer directory to Xcode's path, as shown below:

> sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

※ This example assumes Xcode was installed in /Applications/Xcode.app . If it was installed in a different path, please adjust the command accordingly.

Step 1. Install mono2stereo

Install this program (mono2stereo) using Homebrew. To install from my personal repository (tap) instead of the official Homebrew repository, run the command below.

> brew install kunichiko/tap/mono2stereo

In order to install it, you need to compile it from the source code, so you need to install Xcode. We have confirmed the operation with the following combination t.

  • macOS 11.6.4 (Big Sur) + Xcode 12.5.1
  • macOS 12.2.1 (Monterey) + Xcode 13.2.1
  • macOS 13.2.1 (Ventura) + Xcode 14.2

If you have successfully installed it, you should be able to use the command mono2stereo. If you run it from the terminal and get the following output, it's OK.

> mono2stereo
Input Device : 49
Output Device: 85
I: 97792.0, 0.0 : Avg:104.1355kHz,  E:0
O: 64512.0, 0.0 : Avg:47.9934kHz,  E:0
D: 8448.0

I: 196096.0, 0.0 : Avg:99.8913kHz,  E:0
O: 195584.0, 0.0 : Avg:47.9993kHz,  E:0
D: 8448.0

The program can be stopped with Control + C.

If the MS2109 device cannot be found, the following message may appear.

No MS2109 device was found. Please specify audio device id with -i option.
To find MS2109 device manually, please use -l option that lists all audio devices on your Mac.

If the name of the MS2109 device is not FY HD Audio, the automatic detection will fail, so specify the device manually using the method described below.

Step 2. install BlackHole 2ch

> brew install blackhole-2ch

https://github.com/ExistentialAudio/BlackHole

Step 3. Find input/output device id

> mono2stereo -l
Found device:50 hasout=X "USB MICROPHONE", uid=AppleUSBAudioEngine:MICE MICROPHONE:USB MICROPHONE:201308:1
Found device:54 hasout=O "EX-LD4K271D", uid=25E4211B-0000-0000-1C1D-0103803C2278
Found device:69 hasout=O "BlackHole 2ch", uid=BlackHole2ch_UID
Found device:76 hasout=O "Mac mini's speaker", uid=BuiltInSpeakerDevice
Found device:82 hasout=X "FY HD Audio", uid=AppleUSBAudioEngine:MACROSILICON:FY HD Video:1114000:3
Found device:85 hasout=O "EpocCam Microphone", uid=VirtualMicInputOutput:01

Now you can find:

  • input
    • FY HD Audio (MS2109 device) is 82
  • output
    • BlackHole 2ch is 69

Step 4. Start converter

Set the input and output device id by using -i and -o options like below:

> mono2stereo -i 82 -o 69

You can also specify these devices by name like below:

> mono2stereo -i "FY HD Audio" -o "BlackHole 2ch"

Step 5. Open QuickTime Player and record

  • Select File -> New Movie Recording
  • Click the triangle menu put on right side of recording button
  • Select Camera as FY HD Video
  • Select Microphone as BlackHole 2ch
  • Start recording

Tips

List all the options

You can list all the options by passing -h option like below:

> mono2stereo -h
USAGE: mono2stereo [--list-audio-units] [--debug] [--input-device <input-device>] [--output-device <output-device>] [--invert-lr] [--volume <volume>]

OPTIONS:
  -l, --list-audio-units  Show the list of AudioUnits.
  -d, --debug             Enable debug log.
  -i, --input-device <input-device>
                          AudioUnit ID or name for input.
  -o, --output-device <output-device>
                          AudioUnit ID or name for output.
  -I, --invert-lr         Invert L/R signal.
  -V, --volume <volume>   Volume adjust(+6 db 〜 -40 db). "p6" means +6 db, "m6"
                          means -6 db.
  -h, --help              Show help information.

Invert L/R

You can invert L/R channels by using the -I option.

Adjust volume

You can adjust the output volume by using the -V option, as shown below:

# -20 db
> mono2stereo -V m20
# -3 db
> mono2stereo -V p3

Ambiguous device naming

When specifying input/output devices by name, you can use ambiguous device names, as shown below

> mono2stereo -o "BlackHole 2ch"
> mono2stereo -o black
> mono2stereo -o hole

Problems

Buffer underrun / overrun

The input device's clock and output device's clock is not perfectly synchronized. Below is an example of my environment.

I: 2781381689.0, 0.0 : Avg:95.9975kHz,  E:0
O: 2781477888.0, 0.0 : Avg:48.0005kHz,  E:0
D: 1792.0

The input device is MS2109 and the theoretical sampling rate is 96kHz, but measured value was 95.9975kHz. Similarly, the output device's theoretical sampling rate is 48kHz, but measured value was 48.0005kHz.

It means output speed is a bit faster than input speed and it causes buffer underrun. So if you use this program for longer time, some noise will be produced.

This measured values are depend on my environment, so your environment may produces other values. If input speed is faster than output speed in your environment, it causes buffer overrun. In this situation, output sound will be getting delayed and finally it make some noise.

I will try to fix these problems in future version by inserting dummy signal and deleting extra signal.

ms2109-mono-to-stereo-mac's People

Contributors

kunichiko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ms2109-mono-to-stereo-mac's Issues

Segfault

Not workin' for me:

 ~ mono2stereo -i 56 -o 77
Input Device : 56
Output Device: 77
[1]    84712 segmentation fault  mono2stereo -i 56 -o 77

install error

“brew install kunichiko/tap/mono2stereo” ended with error message below.
Could you help to solve it ?

macOS : 13.2
Xcode : 14.2

swift build -c release --disable-sandbox
warning: /Users/xxxxxx/Library/org.swift.swiftpm/configuration is not accessible or not writable, disabling user-level configuration features.
warning: /Users/xxxxxx/Library/org.swift.swiftpm/security is not accessible or not writable, disabling user-level security features.
warning: /Users/xxxxxx/Library/Caches/org.swift.swiftpm is not accessible or not writable, disabling user-level cache features.
warning: 'ms2109-mono-to-stereo-mac-0.9.1': failed loading cached manifest for 'ms2109-mono-to-stereo-mac-0.9.1': Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “manifests” in the folder “org.swift.swiftpm”." UserInfo={NSFilePath=/Users/xxxxxx/Library/Caches/org.swift.swiftpm/manifests, NSUnderlyingError=0x600003559260 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
warning: 'ms2109-mono-to-stereo-mac-0.9.1': failed closing cache: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “manifests” in the folder “org.swift.swiftpm”." UserInfo={NSFilePath=/Users/xxxxxx/Library/Caches/org.swift.swiftpm/manifests, NSUnderlyingError=0x600003553e70 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
error: 'ms2109-mono-to-stereo-mac-0.9.1': Invalid manifest
/private/tmp/mono2stereo-20230210-2273-1dju8dk/MS2109-mono-to-stereo-mac-0.9.1/Package.swift:4:8: error: no such module 'PackageDescription'
import PackageDescription
^
make: *** [build] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.