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
fb135c0a
Commit
fb135c0a
authored
Sep 07, 2021
by
Dan Wilcox
Browse files
fixed buffer size issue when using input chan > 1, removed redundant member vars
parent
98174ef5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/ofApp.cpp
View file @
fb135c0a
...
...
@@ -64,17 +64,15 @@ void ofApp::setup() {
ofLogWarning
(
PACKAGE
)
<<
"audio input device does not have enough input channels"
;
inputChannel
=
0
;
}
numInputChannels
=
inputChannel
+
1
;
recordedSamplesPerBuffer
=
bufferSize
*
numInputChannels
;
ofLogNotice
(
PACKAGE
)
<<
"audio input channel: "
<<
inputChannel
;
ofLogNotice
(
PACKAGE
)
<<
"audio input samplerate: "
<<
sampleRate
;
ofLogNotice
(
PACKAGE
)
<<
"audio input buffer size: "
<<
recordedSamplesPerB
uffer
;
ofLogNotice
(
PACKAGE
)
<<
"audio input buffer size: "
<<
b
uffer
Size
;
settings
.
setInDevice
(
device
);
settings
.
setInListener
(
this
);
settings
.
sampleRate
=
sampleRate
;
settings
.
numOutputChannels
=
0
;
settings
.
numInputChannels
=
numI
nputChannel
s
;
settings
.
bufferSize
=
recordedSamplesPerBuffer
;
settings
.
numInputChannels
=
i
nputChannel
+
1
;
settings
.
bufferSize
=
bufferSize
*
(
inputChannel
+
1
)
;
if
(
!
soundStream
.
setup
(
settings
))
{
ofLogError
(
PACKAGE
)
<<
"audio input device "
<<
inputDevice
<<
" setup failed"
;
ofLogError
(
PACKAGE
)
<<
"perhaps try a different device or samplerate?"
;
...
...
@@ -84,6 +82,9 @@ void ofApp::setup() {
if
(
!
listening
)
{
soundStream
.
stop
();
}
if
(
soundStream
.
getSampleRate
()
==
44100
)
{
ofLogWarning
(
PACKAGE
)
<<
"treating sample rate of 44100 as 48000, may or may not affect detection"
;
}
// display
volHistory
.
assign
(
400
,
0.0
);
...
...
@@ -255,11 +256,13 @@ void ofApp::exit() {
//--------------------------------------------------------------
void
ofApp
::
audioIn
(
ofSoundBuffer
&
input
)
{
// beh, ofSoundBuffer::getNumFrames() actually returns the buffer size?
std
::
size_t
numFrames
=
input
.
getNumFrames
()
/
input
.
getNumChannels
();
// copy desired channel out of interleaved stream into mono buffer,
// assume input stream has enough channels...
for
(
std
::
size_t
i
=
0
;
i
<
input
.
getN
umFrames
()
;
i
++
)
{
monoBuffer
[
i
]
=
input
[
i
*
numInput
Channels
+
inputChannel
];
for
(
std
::
size_t
i
=
0
;
i
<
n
umFrames
;
i
++
)
{
monoBuffer
[
i
]
=
input
[
(
i
*
input
.
getNum
Channels
())
+
inputChannel
];
}
// calculate the root mean square which is a rough way to calculate volume
...
...
src/ofApp.h
View file @
fb135c0a
...
...
@@ -67,8 +67,8 @@ class ofApp : public ofBaseApp {
// audio
ofSoundStream
soundStream
;
int
inputDevice
=
-
1
;
// -1 means search for default device
int
inputChannel
=
0
;
// 0
means mono, 1 means stereo
int
inputDevice
=
-
1
;
// -1 means search for default device
int
inputChannel
=
0
;
// 0
- chan 1 (left), 1 - chan 2 (right), 2 - chan 3, etc
bool
listening
=
true
;
// neural network input parameters
...
...
@@ -76,20 +76,17 @@ class ofApp : public ofBaseApp {
// we want to keep the buffersize a multiple of the downsampling factor
// downsamplingFactor = sampleRate / modelSampleRate
// downsampling is required for microphones that do not have 16kHz sampling
std
::
size_t
bufferSize
=
1024
;
std
::
size_t
bufferSize
=
1024
;
//< in this case, number of sample frames
std
::
size_t
sampleRate
=
48000
;
std
::
size_t
downsamplingFactor
=
3
;
std
::
size_t
recordedSamplesPerBuffer
;
std
::
size_t
numInputChannels
;
// since volume detection has some latency we keep a history of buffers
// since volume detection has some latency,d we keep a history of buffers
AudioBufferFifo
previousBuffers
;
std
::
size_t
numPreviousBuffers
=
10
;
// how many buffers to save before trigger happens
// sampleBuffers acts as a buffer for recording (could be fused)
AudioBufferFifo
sampleBuffers
;
std
::
size_t
numBuffers
;
SimpleAudioBuffer
monoBuffer
;
//< mono inputChannel stream buffer
SimpleAudioBuffer
monoBuffer
;
//< mono inputChannel stream buffer
// volume
float
curVol
=
0.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