Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
バーチャルテルミンを作る/2019-08-05-llt10
Search
Satoshi SAKAO
August 05, 2019
Programming
1
58
バーチャルテルミンを作る/2019-08-05-llt10
社内のLTイベント「えるLT Vol.10」で発表した資料です
Satoshi SAKAO
August 05, 2019
Tweet
Share
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Testcontainers/2024-11-20-llt32
ottijp
0
28
Pkl/2024-04-17-llt31
ottijp
0
64
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
130
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
210
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
130
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
140
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
130
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
73
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
87
Other Decks in Programming
See All in Programming
SRE、開発、QAが協業して挑んだリリースプロセス改革@SRE Kaigi 2025
nealle
3
4.1k
時計仕掛けのCompose
mkeeda
1
280
負債になりにくいCSSをデザイナとつくるには?
fsubal
9
2.3k
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
230
Formの複雑さに立ち向かう
bmthd
1
720
Grafana Cloudとソラカメ
devoc
0
140
Immutable ActiveRecord
megane42
0
130
Conform を推す - Advocating for Conform
mizoguchicoji
3
680
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
360
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
最近のVS Codeで気になるニュース 2025/01
74th
1
250
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
The Invisible Side of Design
smashingmag
299
50k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
We Have a Design System, Now What?
morganepeng
51
7.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
540
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Being A Developer After 40
akosma
89
590k
A Tale of Four Properties
chriscoyier
158
23k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Become a Pro
speakerdeck
PRO
26
5.1k
Transcript
バーチャルテルミンを作る Satoshi SAKAO えるLT Vol.10 2019/08/05 (Mon) H1
話すひと H2 インフォコム株式会社 品質マネジメント推進室 " ソフトウェアエンジニア JS (ES6) / Node.js
/ GCP / IoT / iOS (Swift) シュタゲ(コミックス) Satoshi SAKAO @ottijp
話すこと • iOS の Core Audio と Audio Unit •
Audio Unit を使ったバーチャルテルミン H3
H4 モチベーション
テルミンを使ってみたい H5 https://bit.ly/2ZwpAAi
高い!! H6 https://amzn.to/2KqEjGt
実物はあきらめた • バーチャルテルミンっぽいものをiOSアプリで作る • iOSのCore Audioサービスを使う H7
H8 Core Audio と Audio Unit
Core Audio なんぞ? • iOS/macOSのオーディオ基盤 • アプリがオーディオを取り扱うためのフレームワークを提供 • 主なサービス(iOS) •
オーディオの再生・録音 • 変換・コーデック • Audio Unit • MIDI H9
Audio Unit なんぞ? • オーディオ処理をするプラグイン • 主な種類 • 信号処理(エフェクタ) •
ソフトウェアシンセサイザ(楽器) • プログラムによる信号発生 • フォーマット変換 H10 https://support.apple.com/kb/PH25047? viewlocale=ja_JP&locale=ja_JP
H11 Audio Unitを使ったバーチャルテルミン
Audio Unitの作成手順 • 1. Audio Unitの作成 • 2. Audio Unitのストリーム設定
• 3. Audio Unitのレンダラ設定 H12
1. Audio Unitの作成 • Audio Component • Audio Unitを生成する型のようなもの •
製造者: Apple, タイプ: Outputのものを検索して取得 • AudioComponentFindNext ファンクションを使う • Audio Unit • Audio Componentのインスタンス • AudioComponentInstanceNew ファンクションでインスタンス化 • AudioUnitInitialize ファンクションで初期化 H13
1. Audio Unitの作成 H14 // Apple OuputΦʔσΟίϯϙʔωϯτͷऔಘ acd = AudioComponentDescription()
acd.componentType = kAudioUnitType_Output acd.componentSubType = kAudioUnitSubType_RemoteIO acd.componentManufacturer = kAudioUnitManufacturer_Apple acd.componentFlags = 0 acd.componentFlagsMask = 0 guard let ac = AudioComponentFindNext(nil, &acd) else { fatalError("audio component not found") } // ΦʔσΟίϯϙʔωϯτͷΠϯελϯεԽͱॳظԽʢΦʔσΟΦϢχοτͷੜʣ AudioComponentInstanceNew(ac, &au) AudioUnitInitialize(au)
2. Audio Unitのストリーム設定 • AudioUnitSetProperty ファンクションで設定 • フォーマット: PCM •
サンプルデータのデータ型: Float • サンプルレート: 44,100Hz • チャネル数: 2 • フレーム中チャネル数: 1 • パケット中フレーム数: 1 • パケットサイズ: 4 bytes • フレームサイズ: 4 bytes • チャネルサイズ: 32 bits H15
2. Audio Unitのストリーム設定 H16 // PCMετϦʔϜϑΥʔϚοτͷઃఆ var asbd = AudioStreamBasicDescription()
asbd.mSampleRate = sampleRate asbd.mFormatID = kAudioFormatLinearPCM asbd.mFormatFlags = kAudioFormatFlagIsFloat asbd.mChannelsPerFrame = 1 asbd.mFramesPerPacket = 1 asbd.mBytesPerPacket = UInt32(MemoryLayout<Float32>.size) asbd.mBytesPerFrame = UInt32(MemoryLayout<Float32>.size) asbd.mBitsPerChannel = UInt32(8 * MemoryLayout<Float32>.size) asbd.mReserved = 0 AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &asbd, UInt32(MemoryLayout<AudioStreamBasicDescription>.size))
3. Audio Unitのレンダラ設定 • 信号生成するコールバックファンクションを作成 • 設定周波数に従って正弦波のデータサンプルを作成 • 作成したコールバックファンクションをオーディオユニットに設定 •
AudioUnitSetProperty ファンクション H17
3. Audio Unitのレンダラ設定 H18 let renderer: AURenderCallback = { (inRef:
UnsafeMutableRawPointer, inActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>, inTimeStamp: UnsafePointer<AudioTimeStamp>, inBusNumber: UInt32, inNumberFrames: UInt32, ioData: UnsafeMutablePointer<AudioBufferList>?) -> OSStatus in let sampler = inRef.bindMemory(to: SineSampler.self, capacity: 1).pointee let out = ioData?[0].mBuffers.mData for i in 0..<inNumberFrames { let sv = Float32(sin(sampler.phase)) out?.storeBytes(of: sv, toByteOffset: Int(i) * MemoryLayout<Float32>.size, as: Float32.self) sampler.phase = sampler.phase + sampler.phaseDelta } return noErr }
3. Audio Unitのレンダラ設定 H19 // ΦʔσΟΦϢχοτʹϨϯμʔίʔϧόοΫΛઃఆ var callback = AURenderCallbackStruct()
callback.inputProc = renderer let selfPt = UnsafeMutablePointer<SineSampler>.allocate(capacity: 1) let a = UnsafeMutableRawPointer(selfPt) a.storeBytes(of: self, toByteOffset: 0, as: SineSampler.self) callback.inputProcRefCon = a AudioUnitSetProperty(au, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback, UInt32(MemoryLayout<AURenderCallbackStruct>.size))
H20 Demo
H21
話したこと • iOS の Core Audio と Audio Unit •
Audio Unit を使ったバーチャルテルミン H22
$ exit H23
H24 Appendix
参考 • What Is Core Audio? • https://developer.apple.com/library/archive/documentation/ MusicAudio/Conceptual/CoreAudioOverview/ WhatisCoreAudio/WhatisCoreAudio.html
• iOSでサイン波を鳴らす (Swift4 × AudioUnit) • https://qiita.com/fooka/items/e89b6e7e45302f7236f2 • Swift3のポインタの基礎知識 · M.Ike • https://mike-neko.github.io/blog/swift-pointer/ H25
iOSのCore Audioアーキテクチャ H26 https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/ CoreAudioOverview/WhatisCoreAudio/WhatisCoreAudio.html