Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gdpd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IVMI
Gdpd
Commits
30973d86
Commit
30973d86
authored
4 years ago
by
BERTHAUT Florent
Browse files
Options
Downloads
Patches
Plain Diff
Added audio device list and selection
parent
2e1fe16c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gdpd.cpp
+73
-16
73 additions, 16 deletions
src/gdpd.cpp
src/gdpd.hpp
+7
-0
7 additions, 0 deletions
src/gdpd.hpp
with
80 additions
and
16 deletions
src/gdpd.cpp
+
73
−
16
View file @
30973d86
...
...
@@ -3,6 +3,11 @@
using
namespace
godot
;
void
Gdpd
::
_register_methods
()
{
register_method
(
"get_available_input_devices"
,
&
Gdpd
::
get_available_input_devices
);
register_method
(
"get_available_output_devices"
,
&
Gdpd
::
get_available_output_devices
);
register_method
(
"init_devices"
,
&
Gdpd
::
init_devices
);
register_method
(
"init"
,
&
Gdpd
::
init
);
register_method
(
"openfile"
,
&
Gdpd
::
openfile
);
register_method
(
"closefile"
,
&
Gdpd
::
closefile
);
...
...
@@ -35,9 +40,75 @@ void Gdpd::_init() {
Gdpd
::~
Gdpd
()
{
}
Array
Gdpd
::
get_available_input_devices
()
{
Array
gdlist
;
for
(
int
d
=
0
;
d
<
m_audio
.
getDeviceCount
();
d
++
)
{
if
(
m_audio
.
getDeviceInfo
(
d
).
inputChannels
>
0
)
{
gdlist
.
push_back
(
m_audio
.
getDeviceInfo
(
d
).
name
.
c_str
());
}
}
return
gdlist
;
}
Array
Gdpd
::
get_available_output_devices
()
{
Array
gdlist
;
for
(
int
d
=
0
;
d
<
m_audio
.
getDeviceCount
();
d
++
)
{
if
(
m_audio
.
getDeviceInfo
(
d
).
outputChannels
>
0
)
{
gdlist
.
push_back
(
m_audio
.
getDeviceInfo
(
d
).
name
.
c_str
());
}
}
return
gdlist
;
}
int
Gdpd
::
init_devices
(
String
inputDevice
,
String
outputDevice
)
{
std
::
wstring
inpWs
=
inputDevice
.
unicode_str
();
std
::
string
inpStr
(
inpWs
.
begin
(),
inpWs
.
end
());
std
::
wstring
outWs
=
outputDevice
.
unicode_str
();
std
::
string
outStr
(
outWs
.
begin
(),
outWs
.
end
());
for
(
int
d
=
0
;
d
<
m_audio
.
getDeviceCount
();
d
++
)
{
std
::
string
n
=
m_audio
.
getDeviceInfo
(
d
).
name
;
if
(
n
.
compare
(
inpStr
)
==
0
)
{
m_inputDevice
=
d
;
}
if
(
n
.
compare
(
outStr
)
==
0
)
{
m_outputDevice
=
d
;
}
}
RtAudio
::
DeviceInfo
inpInfo
=
m_audio
.
getDeviceInfo
(
m_inputDevice
);
RtAudio
::
DeviceInfo
outInfo
=
m_audio
.
getDeviceInfo
(
m_outputDevice
);
m_nbInputs
=
inpInfo
.
inputChannels
;
m_nbOutputs
=
outInfo
.
outputChannels
;
m_sampleRate
=
outInfo
.
preferredSampleRate
;
m_bufferFrames
=
128
;
return
start
();
}
int
Gdpd
::
init
(
int
nbInputs
,
int
nbOutputs
,
int
sampleRate
,
int
bufferSize
)
{
m_inputDevice
=
m_audio
.
getDefaultInputDevice
();
m_outputDevice
=
m_audio
.
getDefaultOutputDevice
();
RtAudio
::
DeviceInfo
inpInfo
=
m_audio
.
getDeviceInfo
(
m_inputDevice
);
RtAudio
::
DeviceInfo
outInfo
=
m_audio
.
getDeviceInfo
(
m_outputDevice
);
m_nbInputs
=
std
::
min
<
int
>
(
nbInputs
,
inpInfo
.
inputChannels
);
m_nbOutputs
=
std
::
min
<
int
>
(
nbOutputs
,
outInfo
.
outputChannels
);
m_sampleRate
=
sampleRate
;
m_bufferFrames
=
std
::
max
<
int
>
(
64
,
bufferSize
);
return
start
();
}
int
Gdpd
::
start
()
{
RtAudio
::
StreamParameters
outParams
,
inpParams
;
inpParams
.
deviceId
=
m_inputDevice
;
inpParams
.
nChannels
=
m_nbInputs
;
outParams
.
deviceId
=
m_outputDevice
;
outParams
.
nChannels
=
m_nbOutputs
;
print
(
"Output channels = "
+
std
::
to_string
(
outParams
.
nChannels
));
print
(
"Input channels = "
+
std
::
to_string
(
inpParams
.
nChannels
));
if
(
!
m_pd
.
init
(
nbInputs
,
nbOutputs
,
sampleRate
,
true
))
{
if
(
!
m_pd
.
init
(
m_nbInputs
,
m_nbOutputs
,
m_sampleRate
,
true
))
{
Godot
::
print
(
"GDPD : Error starting libpd"
);
return
1
;
}
...
...
@@ -59,20 +130,6 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize) {
Godot
::
print
(
"There are no available sound devices."
);
}
RtAudio
::
StreamParameters
outParams
,
inpParams
;
inpParams
.
deviceId
=
m_audio
.
getDefaultInputDevice
();
outParams
.
deviceId
=
m_audio
.
getDefaultOutputDevice
();
RtAudio
::
DeviceInfo
inpInfo
=
m_audio
.
getDeviceInfo
(
inpParams
.
deviceId
);
RtAudio
::
DeviceInfo
outInfo
=
m_audio
.
getDeviceInfo
(
outParams
.
deviceId
);
unsigned
int
sr
=
outInfo
.
preferredSampleRate
;
inpParams
.
nChannels
=
m_nbInputs
=
std
::
min
<
int
>
(
nbInputs
,
inpInfo
.
inputChannels
);
outParams
.
nChannels
=
m_nbOutputs
=
std
::
min
<
int
>
(
nbOutputs
,
outInfo
.
outputChannels
);
print
(
"Output channels = "
+
std
::
to_string
(
outParams
.
nChannels
));
print
(
"Input channels = "
+
std
::
to_string
(
inpParams
.
nChannels
));
m_bufferFrames
=
std
::
max
<
int
>
(
64
,
bufferSize
);
RtAudio
::
StreamOptions
options
;
...
...
@@ -83,7 +140,7 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize) {
}
try
{
m_audio
.
openStream
(
&
outParams
,
&
inpParams
,
RTAUDIO_FLOAT32
,
sr
,
&
m_bufferFrames
,
&
audioCallback
,
m_sampleRate
,
&
m_bufferFrames
,
&
audioCallback
,
this
,
&
options
);
m_audio
.
startStream
();
}
...
...
This diff is collapsed.
Click to expand it.
src/gdpd.hpp
+
7
−
0
View file @
30973d86
...
...
@@ -28,6 +28,9 @@ private:
float
m_vol
;
int
m_nbInputs
;
int
m_nbOutputs
;
int
m_sampleRate
;
int
m_inputDevice
;
int
m_outputDevice
;
public:
static
void
_register_methods
();
...
...
@@ -38,7 +41,11 @@ public:
void
_init
();
//libpd functions
Array
get_available_input_devices
();
Array
get_available_output_devices
();
int
init_devices
(
String
inputDevice
,
String
outputDevice
);
int
init
(
int
nbInputs
,
int
nbOutputs
,
int
sampleRate
,
int
bufferSize
);
int
start
();
void
openfile
(
String
basename
,
String
dirname
);
void
closefile
();
bool
has_message
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment