質問編集履歴
2
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,190 +16,190 @@
|
|
16
16
|
|
17
17
|
###該当のソースコード
|
18
18
|
|
19
|
+
```
|
20
|
+
|
19
21
|
import AudioToolbox
|
20
22
|
|
21
23
|
import UIKit
|
22
24
|
|
25
|
+
private func AudioQueueInputCallback(
|
26
|
+
|
27
|
+
_ inUserData: UnsafeMutableRawPointer?,
|
28
|
+
|
29
|
+
inAQ: AudioQueueRef,
|
30
|
+
|
31
|
+
inBuffer: AudioQueueBufferRef,
|
32
|
+
|
33
|
+
inStartTime: UnsafePointer<AudioTimeStamp>,
|
34
|
+
|
35
|
+
inNumberPacketDescriptions: UInt32,
|
36
|
+
|
37
|
+
inPacketDescs: UnsafePointer<AudioStreamPacketDescription>?)
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
/* ここでマイク入力されたデータを扱いたい*/
|
44
|
+
|
45
|
+
print(inBuffer); //???
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
class ViewController: UIViewController {
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
var queue: AudioQueueRef!
|
58
|
+
|
59
|
+
var audioQueue: AudioQueueRef? = nil
|
60
|
+
|
61
|
+
var timer: Timer!
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
override func viewDidLoad() {
|
66
|
+
|
67
|
+
super.viewDidLoad()
|
68
|
+
|
69
|
+
self.startUpdatingVolume()
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
override func viewDidDisappear(_ animated: Bool) {
|
76
|
+
|
77
|
+
super.viewDidDisappear(animated)
|
78
|
+
|
79
|
+
self.stopUpdatingVolume()
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
override func didReceiveMemoryWarning() {
|
86
|
+
|
87
|
+
super.didReceiveMemoryWarning()
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
func startUpdatingVolume() {
|
94
|
+
|
95
|
+
var dataFormat = AudioStreamBasicDescription(
|
96
|
+
|
97
|
+
mSampleRate: 44100.0,
|
98
|
+
|
99
|
+
mFormatID: kAudioFormatLinearPCM,
|
100
|
+
|
101
|
+
mFormatFlags: AudioFormatFlags(kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked),
|
102
|
+
|
103
|
+
mBytesPerPacket: 2,
|
104
|
+
|
105
|
+
mFramesPerPacket: 1,
|
106
|
+
|
107
|
+
mBytesPerFrame: 2,
|
108
|
+
|
109
|
+
mChannelsPerFrame: 1,
|
110
|
+
|
111
|
+
mBitsPerChannel: 16,
|
112
|
+
|
113
|
+
mReserved: 0)
|
114
|
+
|
115
|
+
var error = noErr
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
self.audioQueue = self.queue;
|
120
|
+
|
121
|
+
error = AudioQueueNewInput(
|
122
|
+
|
123
|
+
&dataFormat,
|
124
|
+
|
125
|
+
AudioQueueInputCallback,
|
126
|
+
|
127
|
+
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()),
|
128
|
+
|
129
|
+
.none,
|
130
|
+
|
131
|
+
.none,
|
132
|
+
|
133
|
+
0,
|
134
|
+
|
135
|
+
&self.audioQueue)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
if error == noErr {
|
140
|
+
|
141
|
+
self.queue = audioQueue
|
142
|
+
|
143
|
+
var bu :AudioQueueBufferRef?;
|
144
|
+
|
145
|
+
AudioQueueAllocateBuffer(self.queue, 16000, &bu) //16000は何の値かは不明です
|
146
|
+
|
147
|
+
AudioQueueEnqueueBuffer (self.queue, bu!, 0, nil)
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
AudioQueueStart(self.queue, nil)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
self.timer = Timer.scheduledTimer(timeInterval: 1.0,
|
158
|
+
|
159
|
+
target: self,
|
160
|
+
|
161
|
+
selector: #selector(ViewController.detectVolume(_:)),
|
162
|
+
|
163
|
+
userInfo: nil,
|
164
|
+
|
165
|
+
repeats: true)
|
166
|
+
|
167
|
+
self.timer?.fire()
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
func stopUpdatingVolume()
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
self.timer.invalidate()
|
178
|
+
|
179
|
+
self.timer = nil
|
180
|
+
|
181
|
+
AudioQueueFlush(self.queue)
|
182
|
+
|
183
|
+
AudioQueueStop(self.queue, false)
|
184
|
+
|
185
|
+
AudioQueueDispose(self.queue, true)
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
func detectVolume(_ timer: Timer)
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
}
|
204
|
+
|
23
205
|
```
|
24
|
-
|
25
|
-
private func AudioQueueInputCallback(
|
26
|
-
|
27
|
-
_ inUserData: UnsafeMutableRawPointer?,
|
28
|
-
|
29
|
-
inAQ: AudioQueueRef,
|
30
|
-
|
31
|
-
inBuffer: AudioQueueBufferRef,
|
32
|
-
|
33
|
-
inStartTime: UnsafePointer<AudioTimeStamp>,
|
34
|
-
|
35
|
-
inNumberPacketDescriptions: UInt32,
|
36
|
-
|
37
|
-
inPacketDescs: UnsafePointer<AudioStreamPacketDescription>?)
|
38
|
-
|
39
|
-
{
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
/* ここでマイク入力されたデータを扱いたい*/
|
44
|
-
|
45
|
-
print(inBuffer); //???
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
class ViewController: UIViewController {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
var queue: AudioQueueRef!
|
58
|
-
|
59
|
-
var audioQueue: AudioQueueRef? = nil
|
60
|
-
|
61
|
-
var timer: Timer!
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
override func viewDidLoad() {
|
66
|
-
|
67
|
-
super.viewDidLoad()
|
68
|
-
|
69
|
-
self.startUpdatingVolume()
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
override func viewDidDisappear(_ animated: Bool) {
|
76
|
-
|
77
|
-
super.viewDidDisappear(animated)
|
78
|
-
|
79
|
-
self.stopUpdatingVolume()
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
override func didReceiveMemoryWarning() {
|
86
|
-
|
87
|
-
super.didReceiveMemoryWarning()
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
func startUpdatingVolume() {
|
94
|
-
|
95
|
-
var dataFormat = AudioStreamBasicDescription(
|
96
|
-
|
97
|
-
mSampleRate: 44100.0,
|
98
|
-
|
99
|
-
mFormatID: kAudioFormatLinearPCM,
|
100
|
-
|
101
|
-
mFormatFlags: AudioFormatFlags(kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked),
|
102
|
-
|
103
|
-
mBytesPerPacket: 2,
|
104
|
-
|
105
|
-
mFramesPerPacket: 1,
|
106
|
-
|
107
|
-
mBytesPerFrame: 2,
|
108
|
-
|
109
|
-
mChannelsPerFrame: 1,
|
110
|
-
|
111
|
-
mBitsPerChannel: 16,
|
112
|
-
|
113
|
-
mReserved: 0)
|
114
|
-
|
115
|
-
var error = noErr
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
self.audioQueue = self.queue;
|
120
|
-
|
121
|
-
error = AudioQueueNewInput(
|
122
|
-
|
123
|
-
&dataFormat,
|
124
|
-
|
125
|
-
AudioQueueInputCallback,
|
126
|
-
|
127
|
-
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()),
|
128
|
-
|
129
|
-
.none,
|
130
|
-
|
131
|
-
.none,
|
132
|
-
|
133
|
-
0,
|
134
|
-
|
135
|
-
&self.audioQueue)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
if error == noErr {
|
140
|
-
|
141
|
-
self.queue = audioQueue
|
142
|
-
|
143
|
-
var bu :AudioQueueBufferRef?;
|
144
|
-
|
145
|
-
AudioQueueAllocateBuffer(self.queue, 16000, &bu) //16000は何の値かは不明です
|
146
|
-
|
147
|
-
AudioQueueEnqueueBuffer (self.queue, bu!, 0, nil)
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
AudioQueueStart(self.queue, nil)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
self.timer = Timer.scheduledTimer(timeInterval: 1.0,
|
158
|
-
|
159
|
-
target: self,
|
160
|
-
|
161
|
-
selector: #selector(ViewController.detectVolume(_:)),
|
162
|
-
|
163
|
-
userInfo: nil,
|
164
|
-
|
165
|
-
repeats: true)
|
166
|
-
|
167
|
-
self.timer?.fire()
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
func stopUpdatingVolume()
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
self.timer.invalidate()
|
178
|
-
|
179
|
-
self.timer = nil
|
180
|
-
|
181
|
-
AudioQueueFlush(self.queue)
|
182
|
-
|
183
|
-
AudioQueueStop(self.queue, false)
|
184
|
-
|
185
|
-
AudioQueueDispose(self.queue, true)
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
func detectVolume(_ timer: Timer)
|
192
|
-
|
193
|
-
{
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
```
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
import UIKit
|
22
22
|
|
23
|
-
|
23
|
+
```
|
24
24
|
|
25
25
|
private func AudioQueueInputCallback(
|
26
26
|
|
@@ -201,3 +201,5 @@
|
|
201
201
|
|
202
202
|
|
203
203
|
}
|
204
|
+
|
205
|
+
```
|