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
61
バーチャルテルミンを作る/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
54
Pkl/2024-04-17-llt31
ottijp
0
81
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
150
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
270
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
86
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
100
Other Decks in Programming
See All in Programming
おやつのお供はお決まりですか?@WWDC25 Recap -Japan-\(region).swift
shingangan
0
140
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
190
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
410
PicoRuby on Rails
makicamel
2
140
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
11
6.5k
オンコール⼊⾨〜ページャーが鳴る前に、あなたが備えられること〜 / Before The Pager Rings
yktakaha4
1
560
GPUを計算資源として使おう!
primenumber
1
190
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
590
型で語るカタ
irof
0
350
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
880
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
160
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
710
Featured
See All Featured
Producing Creativity
orderedlist
PRO
346
40k
GraphQLとの向き合い方2022年版
quramy
49
14k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Scaling GitHub
holman
460
140k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.7k
Git: the NoSQL Database
bkeepers
PRO
430
65k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Designing for humans not robots
tammielis
253
25k
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