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
63
バーチャルテルミンを作る/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
61
Pkl/2024-04-17-llt31
ottijp
0
89
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
160
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
280
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
160
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
170
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
150
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
92
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
110
Other Decks in Programming
See All in Programming
チームのテスト力を鍛える
goyoki
2
130
アセットのコンパイルについて
ojun9
0
130
私の後悔をAWS DMSで解決した話
hiramax
4
210
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
230
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
150
プロパティベーステストによるUIテスト: LLMによるプロパティ定義生成でエッジケースを捉える
tetta_pdnt
0
1.7k
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
Updates on MLS on Ruby (and maybe more)
sylph01
1
180
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
旅行プランAIエージェント開発の裏側
ippo012
2
910
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
460
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
320
Featured
See All Featured
Gamification - CAS2011
davidbonilla
81
5.4k
What's in a price? How to price your products and services
michaelherold
246
12k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Visualization
eitanlees
148
16k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
How to train your dragon (web standard)
notwaldorf
96
6.2k
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