Skip to content

Instantly share code, notes, and snippets.

@moutend
moutend / main.swift
Created January 9, 2022 04:03
Get suffix number from file name
import Foundation
extension String {
func trimPrefix(_ prefix: String) -> String {
guard self.hasPrefix(prefix) else {
return self
}
return String(self.dropFirst(prefix.count))
}
@moutend
moutend / README.md
Created December 15, 2021 00:21
Print the default sound output device name on macOS 12.0.

Usage

$ swift main.swift
Default output device: MacBook Pro Speakers
import Foundation
import Darwin
class A: NSObject {
var task = Process()
var slaveFile: FileHandle?
var masterFile: FileHandle?
override init() {
@moutend
moutend / README.md
Created March 27, 2021 01:10
[Swift] Equalizing Audio Signal with vDSP.Biquad

[Swift] Equalizing Audio Signal with vDSP.Biquad

This script reads /tmp/input.wav, applies the low-pass filter, and writes the modified signal as /tmp/output.wav.

To run, open Terminal.app and hit the following command:

$ swift main.swift
@moutend
moutend / README.md
Created March 26, 2021 00:58
[Swift] read and write WAV audio file with AVAudioFile

This script reads /tmp/input.wav and writes the copy of input as /tmp/output.wav.

$ swift main.swift
@moutend
moutend / README.md
Created March 23, 2021 22:15
[Swift] Save UInt8 array as a file

Save UInt8 array as a file

$ swift write1.swift
$ xxd /path/to/file
00000000: 1234 5678                                .4Vx

The write1.swift is a most easy way. You can also implement your own write() method like the write2.swift.

@moutend
moutend / read_wav.swift
Created March 13, 2021 00:54
SwiftでWAV形式の音声ファイルをInt16の配列として読み込む
import AVFoundation
func readWavFile(_ path: String) -> [[Int16]]? {
guard let url = URL(string: path) else {
return nil
}
guard let audio = try? AVAudioFile(forReading: url, commonFormat: .pcmFormatInt16, interleaved: false) else {
return nil
}
guard let buffer = AVAudioPCMBuffer(pcmFormat: audio.processingFormat, frameCapacity: AVAudioFrameCount(audio.length)) else {
@moutend
moutend / slow_fft.swift
Last active March 13, 2021 00:24
Swiftで高速フーリエ変換
import Foundation
struct Complex64 {
var real: Float
var imag: Float
init(_ r: Float, _ i: Float) {
self.real = r
self.imag = i
}
@moutend
moutend / zen-go-synergy-core-ja.md
Created February 24, 2021 00:12
視覚に障害がある方のためのZen Go Synergy Coreマニュアル

視覚に障害がある方のためのZen Go Synergy Coreマニュアル

Antelope AudioのUSBオーディオインターフェース、Zen Go Synergy Coreの使い方をまとめました。

注意

これは非公式なマニュアルです。内容の正確さについては保証しません。公式マニュアル(PDF)は以下を参照してください。

Piano Key Frequencies

$ ruby piano_frequency.rb

You got the table of piano key frequencies in TSV format.

NOTE	FREQUENCY