Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Hertz-Lab
Research
Intelligent Museum
Language Identifier
Commits
f414d8d3
Commit
f414d8d3
authored
Sep 07, 2021
by
pbethge
Browse files
convert muti to mono channel
parent
13e034bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/ofApp.cpp
View file @
f414d8d3
...
...
@@ -64,15 +64,17 @@ void ofApp::setup() {
ofLogWarning
(
PACKAGE
)
<<
"audio input device does not have enough input channels"
;
inputChannel
=
0
;
}
ofLogNotice
(
PACKAGE
)
<<
"audio input channel: "
<<
inputChannel
+
1
;
numInputChannels
=
inputChannel
+
1
;
recordedSamplesPerBuffer
=
bufferSize
*
numInputChannels
;
ofLogNotice
(
PACKAGE
)
<<
"audio input channel: "
<<
numInputChannels
;
ofLogNotice
(
PACKAGE
)
<<
"audio input samplerate: "
<<
sampleRate
;
ofLogNotice
(
PACKAGE
)
<<
"audio input buffer size: "
<<
b
uffer
Size
;
ofLogNotice
(
PACKAGE
)
<<
"audio input buffer size: "
<<
recordedSamplesPerB
uffer
;
settings
.
setInDevice
(
device
);
settings
.
setInListener
(
this
);
settings
.
sampleRate
=
sampleRate
;
settings
.
numOutputChannels
=
0
;
settings
.
numInputChannels
=
i
nputChannel
+
1
;
settings
.
bufferSize
=
bufferSize
;
settings
.
numInputChannels
=
numI
nputChannel
s
;
settings
.
bufferSize
=
bufferSize
*
numInputChannels
;
if
(
!
soundStream
.
setup
(
settings
))
{
ofLogError
(
PACKAGE
)
<<
"audio input device "
<<
inputDevice
<<
" setup failed"
;
ofLogError
(
PACKAGE
)
<<
"perhaps try a different device or samplerate?"
;
...
...
@@ -254,16 +256,14 @@ void ofApp::exit() {
//--------------------------------------------------------------
void
ofApp
::
audioIn
(
ofSoundBuffer
&
input
)
{
// this shouldn't happen... but we don't let it blow up
if
(
input
.
getNumFrames
()
!=
monoBuffer
.
size
())
{
ofLogWarning
(
PACKAGE
)
<<
"resizing mono input buffer to "
<<
input
.
getNumFrames
();
monoBuffer
.
resize
(
input
.
getNumFrames
());
}
// copy desired channel out of interleaved stream into mono buffer,
// assume input stream has enough channels...
for
(
std
::
size_t
i
=
0
;
i
<
input
.
getNumFrames
();
i
++
)
{
monoBuffer
[
i
]
=
input
[
i
+
inputChannel
];
float
sum
=
0
;
for
(
std
::
size_t
j
=
0
;
j
<
numInputChannels
;
j
++
)
{
sum
=
input
[
i
*
numInputChannels
+
j
];
}
monoBuffer
[
i
]
=
sum
/
numInputChannels
;
}
// calculate the root mean square which is a rough way to calculate volume
...
...
src/ofApp.h
View file @
f414d8d3
...
...
@@ -69,7 +69,6 @@ class ofApp : public ofBaseApp {
ofSoundStream
soundStream
;
int
inputDevice
=
-
1
;
// -1 means search for default device
int
inputChannel
=
0
;
// 0 means mono, 1 means stereo
std
::
vector
<
float
>
monoBuffer
;
//< mono inputChannel stream buffer
bool
listening
=
true
;
// neural network input parameters
...
...
@@ -80,8 +79,9 @@ class ofApp : public ofBaseApp {
std
::
size_t
bufferSize
=
1024
;
std
::
size_t
sampleRate
=
48000
;
std
::
size_t
downsamplingFactor
=
3
;
std
::
size_t
recordedSamplesPerBuffer
;
std
::
size_t
numInputChannels
;
static
const
std
::
size_t
modelSampleRate
;
//< sample rate expected by model
// since volume detection has some latency we keep a history of buffers
AudioBufferFifo
previousBuffers
;
...
...
@@ -89,6 +89,7 @@ class ofApp : public ofBaseApp {
// sampleBuffers acts as a buffer for recording (could be fused)
AudioBufferFifo
sampleBuffers
;
std
::
size_t
numBuffers
;
SimpleAudioBuffer
monoBuffer
;
//< mono inputChannel stream buffer
// volume
float
curVol
=
0.0
;
...
...
@@ -104,9 +105,9 @@ class ofApp : public ofBaseApp {
AudioClassifier
model
;
cppflow
::
tensor
output
;
std
::
size_t
inputSeconds
=
5
;
const
std
::
size_t
inputSamplingRate
=
16000
;
// AI was trained on 16kHz
std
::
size_t
inputSize
;
float
minConfidence
=
0.75
;
static
const
std
::
size_t
modelSampleRate
;
//< sample rate expected by model
// neural network control logic
std
::
size_t
recordingCounter
=
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment