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
60
バーチャルテルミンを作る/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
52
Pkl/2024-04-17-llt31
ottijp
0
79
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
150
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
260
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
150
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
160
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
140
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
84
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
100
Other Decks in Programming
See All in Programming
Java on Azure で LangGraph!
kohei3110
0
160
GoのWebAssembly活用パターン紹介
syumai
3
10k
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
150
CursorはMCPを使った方が良いぞ
taigakono
0
150
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
120
関数型まつり2025登壇資料「関数プログラミングと再帰」
taisontsukada
2
840
エラーって何種類あるの?
kajitack
5
280
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
3
310
Bytecode Manipulation 으로 생산성 높이기
bigstark
2
360
WindowInsetsだってテストしたい
ryunen344
1
190
Perplexity Slack Botを作ってAI活用を進めた話 / AI Engineering Summit プレイベント
n3xem
0
670
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
290
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Balancing Empowerment & Direction
lara
1
340
The Invisible Side of Design
smashingmag
299
51k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
4 Signs Your Business is Dying
shpigford
184
22k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Typedesign – Prime Four
hannesfritz
42
2.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
41
7.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Why Our Code Smells
bkeepers
PRO
337
57k
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