Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
02fccc09
There was an error fetching the commit references. Please try again later.
Commit
02fccc09
authored
6 years ago
by
bunnei
Browse files
Options
Downloads
Patches
Plain Diff
cubeb_sink: Support variable sample_rate and num_channels.
parent
34b3f834
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/audio_core/cubeb_sink.cpp
+25
-15
25 additions, 15 deletions
src/audio_core/cubeb_sink.cpp
with
25 additions
and
15 deletions
src/audio_core/cubeb_sink.cpp
+
25
−
15
View file @
02fccc09
...
@@ -13,14 +13,24 @@ namespace AudioCore {
...
@@ -13,14 +13,24 @@ namespace AudioCore {
class
SinkStreamImpl
final
:
public
SinkStream
{
class
SinkStreamImpl
final
:
public
SinkStream
{
public:
public:
SinkStreamImpl
(
cubeb
*
ctx
,
cubeb_devid
output_device
,
const
std
::
string
&
name
)
:
ctx
{
ctx
}
{
SinkStreamImpl
(
cubeb
*
ctx
,
u32
sample_rate
,
u32
num_channels_
,
cubeb_devid
output_device
,
cubeb_stream_params
params
;
const
std
::
string
&
name
)
params
.
rate
=
48000
;
:
ctx
{
ctx
},
num_channels
{
num_channels_
}
{
params
.
channels
=
GetNumChannels
();
if
(
num_channels
==
6
)
{
// 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2
// channel for now
is_6_channel
=
true
;
num_channels
=
2
;
}
cubeb_stream_params
params
{};
params
.
rate
=
sample_rate
;
params
.
channels
=
num_channels
;
params
.
format
=
CUBEB_SAMPLE_S16NE
;
params
.
format
=
CUBEB_SAMPLE_S16NE
;
params
.
layout
=
CUBEB_LAYOUT_STEREO
;
params
.
layout
=
num_channels
==
1
?
CUBEB_LAYOUT_MONO
:
CUBEB_LAYOUT_STEREO
;
u32
minimum_latency
=
0
;
u32
minimum_latency
{}
;
if
(
cubeb_get_min_latency
(
ctx
,
&
params
,
&
minimum_latency
)
!=
CUBEB_OK
)
{
if
(
cubeb_get_min_latency
(
ctx
,
&
params
,
&
minimum_latency
)
!=
CUBEB_OK
)
{
LOG_CRITICAL
(
Audio_Sink
,
"Error getting minimum latency"
);
LOG_CRITICAL
(
Audio_Sink
,
"Error getting minimum latency"
);
}
}
...
@@ -58,11 +68,7 @@ public:
...
@@ -58,11 +68,7 @@ public:
queue
.
reserve
(
queue
.
size
()
+
sample_count
*
GetNumChannels
());
queue
.
reserve
(
queue
.
size
()
+
sample_count
*
GetNumChannels
());
if
(
num_channels
==
2
)
{
if
(
is_6_channel
)
{
// Copy as-is
std
::
copy
(
samples
,
samples
+
sample_count
*
GetNumChannels
(),
std
::
back_inserter
(
queue
));
}
else
if
(
num_channels
==
6
)
{
// Downsample 6 channels to 2
// Downsample 6 channels to 2
const
size_t
sample_count_copy_size
=
sample_count
*
num_channels
*
2
;
const
size_t
sample_count_copy_size
=
sample_count
*
num_channels
*
2
;
queue
.
reserve
(
sample_count_copy_size
);
queue
.
reserve
(
sample_count_copy_size
);
...
@@ -71,13 +77,14 @@ public:
...
@@ -71,13 +77,14 @@ public:
queue
.
push_back
(
samples
[
i
+
1
]);
queue
.
push_back
(
samples
[
i
+
1
]);
}
}
}
else
{
}
else
{
ASSERT_MSG
(
false
,
"Unimplemented"
);
// Copy as-is
std
::
copy
(
samples
,
samples
+
sample_count
*
GetNumChannels
(),
std
::
back_inserter
(
queue
));
}
}
}
}
u32
GetNumChannels
()
const
{
u32
GetNumChannels
()
const
{
// Only support 2-channel stereo output for now
return
num_channels
;
return
2
;
}
}
private
:
private
:
...
@@ -85,6 +92,8 @@ private:
...
@@ -85,6 +92,8 @@ private:
cubeb
*
ctx
{};
cubeb
*
ctx
{};
cubeb_stream
*
stream_backend
{};
cubeb_stream
*
stream_backend
{};
u32
num_channels
{};
bool
is_6_channel
{};
std
::
vector
<
s16
>
queue
;
std
::
vector
<
s16
>
queue
;
...
@@ -131,7 +140,8 @@ CubebSink::~CubebSink() {
...
@@ -131,7 +140,8 @@ CubebSink::~CubebSink() {
SinkStream
&
CubebSink
::
AcquireSinkStream
(
u32
sample_rate
,
u32
num_channels
,
SinkStream
&
CubebSink
::
AcquireSinkStream
(
u32
sample_rate
,
u32
num_channels
,
const
std
::
string
&
name
)
{
const
std
::
string
&
name
)
{
sink_streams
.
push_back
(
std
::
make_unique
<
SinkStreamImpl
>
(
ctx
,
output_device
,
name
));
sink_streams
.
push_back
(
std
::
make_unique
<
SinkStreamImpl
>
(
ctx
,
sample_rate
,
num_channels
,
output_device
,
name
));
return
*
sink_streams
.
back
();
return
*
sink_streams
.
back
();
}
}
...
...
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