Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
savoirfairelinux
jami-daemon
Commits
dbba9e62
Commit
dbba9e62
authored
1 year ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tone: generate requested length
Change-Id: Ifc8e85cad40def55606591c4267a81b0a3d90951
parent
0f032559
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/media/audio/sound/dtmfgenerator.cpp
+2
-2
2 additions, 2 deletions
src/media/audio/sound/dtmfgenerator.cpp
src/media/audio/sound/tone.cpp
+5
-7
5 additions, 7 deletions
src/media/audio/sound/tone.cpp
src/media/audio/sound/tone.h
+1
-1
1 addition, 1 deletion
src/media/audio/sound/tone.h
with
8 additions
and
10 deletions
src/media/audio/sound/dtmfgenerator.cpp
+
2
−
2
View file @
dbba9e62
...
@@ -116,9 +116,9 @@ DTMFGenerator::fillToneBuffer(int index)
...
@@ -116,9 +116,9 @@ DTMFGenerator::fillToneBuffer(int index)
ptr
->
format
=
tone_
.
getFormat
().
sampleFormat
;
ptr
->
format
=
tone_
.
getFormat
().
sampleFormat
;
ptr
->
sample_rate
=
sampleRate_
;
ptr
->
sample_rate
=
sampleRate_
;
ptr
->
channel_layout
=
AV_CH_LAYOUT_MONO
;
ptr
->
channel_layout
=
AV_CH_LAYOUT_MONO
;
av_channel_layout_from_mask
(
&
ptr
->
ch_layout
,
AV_CH_LAYOUT_MONO
);
av_channel_layout_from_mask
(
&
ptr
->
ch_layout
,
AV_CH_LAYOUT_MONO
);
av_frame_get_buffer
(
ptr
.
get
(),
0
);
av_frame_get_buffer
(
ptr
.
get
(),
0
);
tone_
.
genSin
(
ptr
.
get
(),
0
,
tones_
[
index
].
higher
,
tones_
[
index
].
lower
);
tone_
.
genSin
(
ptr
.
get
(),
0
,
ptr
->
nb_samples
,
tones_
[
index
].
higher
,
tones_
[
index
].
lower
);
return
ptr
;
return
ptr
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/media/audio/sound/tone.cpp
+
5
−
7
View file @
dbba9e62
...
@@ -97,8 +97,7 @@ Tone::genBuffer(std::string_view definition)
...
@@ -97,8 +97,7 @@ Tone::genBuffer(std::string_view definition)
if
(
definition
.
empty
())
if
(
definition
.
empty
())
return
;
return
;
auto
[
total_samples
,
frequencies
]
=
parseDefinition
(
definition
,
buffer_
->
sample_rate
);
auto
[
total_samples
,
frequencies
]
=
parseDefinition
(
definition
,
format_
.
sample_rate
);
buffer_
->
nb_samples
=
total_samples
;
buffer_
->
nb_samples
=
total_samples
;
buffer_
->
format
=
format_
.
sampleFormat
;
buffer_
->
format
=
format_
.
sampleFormat
;
buffer_
->
sample_rate
=
format_
.
sample_rate
;
buffer_
->
sample_rate
=
format_
.
sample_rate
;
...
@@ -107,13 +106,13 @@ Tone::genBuffer(std::string_view definition)
...
@@ -107,13 +106,13 @@ Tone::genBuffer(std::string_view definition)
size_t
outPos
=
0
;
size_t
outPos
=
0
;
for
(
auto
&
[
low
,
high
,
count
]
:
frequencies
)
{
for
(
auto
&
[
low
,
high
,
count
]
:
frequencies
)
{
genSin
(
buffer_
.
get
(),
outPos
,
low
,
high
);
genSin
(
buffer_
.
get
(),
outPos
,
count
,
low
,
high
);
outPos
+=
count
;
outPos
+=
count
;
}
}
}
}
void
void
Tone
::
genSin
(
AVFrame
*
buffer
,
unsigned
outPo
s
,
unsigned
lowFrequency
,
unsigned
highFrequency
)
Tone
::
genSin
(
AVFrame
*
buffer
,
size_t
outPos
,
unsigned
nb_sample
s
,
unsigned
lowFrequency
,
unsigned
highFrequency
)
{
{
static
constexpr
auto
PI_2
=
3.141592653589793238462643383279502884
L
*
2.0
L
;
static
constexpr
auto
PI_2
=
3.141592653589793238462643383279502884
L
*
2.0
L
;
const
double
sr
=
(
double
)
buffer
->
sample_rate
;
const
double
sr
=
(
double
)
buffer
->
sample_rate
;
...
@@ -121,16 +120,15 @@ Tone::genSin(AVFrame* buffer, unsigned outPos, unsigned lowFrequency, unsigned h
...
@@ -121,16 +120,15 @@ Tone::genSin(AVFrame* buffer, unsigned outPos, unsigned lowFrequency, unsigned h
const
double
dx_l
=
sr
?
PI_2
*
highFrequency
/
sr
:
0.0
;
const
double
dx_l
=
sr
?
PI_2
*
highFrequency
/
sr
:
0.0
;
static
constexpr
double
DATA_AMPLITUDE_S16
=
2048
;
static
constexpr
double
DATA_AMPLITUDE_S16
=
2048
;
static
constexpr
double
DATA_AMPLITUDE_FLT
=
0.0625
;
static
constexpr
double
DATA_AMPLITUDE_FLT
=
0.0625
;
size_t
nb
=
buffer
->
nb_samples
;
if
(
buffer
->
format
==
AV_SAMPLE_FMT_S16
||
buffer
->
format
==
AV_SAMPLE_FMT_S16P
)
{
if
(
buffer
->
format
==
AV_SAMPLE_FMT_S16
||
buffer
->
format
==
AV_SAMPLE_FMT_S16P
)
{
int16_t
*
ptr
=
((
int16_t
*
)
buffer
->
data
[
0
])
+
outPos
;
int16_t
*
ptr
=
((
int16_t
*
)
buffer
->
data
[
0
])
+
outPos
;
for
(
size_t
t
=
0
;
t
<
nb
;
t
++
)
{
for
(
size_t
t
=
0
;
t
<
nb
_samples
;
t
++
)
{
ptr
[
t
]
=
DATA_AMPLITUDE_S16
*
(
sin
(
t
*
dx_h
)
+
sin
(
t
*
dx_l
));
ptr
[
t
]
=
DATA_AMPLITUDE_S16
*
(
sin
(
t
*
dx_h
)
+
sin
(
t
*
dx_l
));
}
}
}
else
if
(
buffer
->
format
==
AV_SAMPLE_FMT_FLT
||
buffer
->
format
==
AV_SAMPLE_FMT_FLTP
)
{
}
else
if
(
buffer
->
format
==
AV_SAMPLE_FMT_FLT
||
buffer
->
format
==
AV_SAMPLE_FMT_FLTP
)
{
float
*
ptr
=
((
float
*
)
buffer
->
data
[
0
])
+
outPos
;
float
*
ptr
=
((
float
*
)
buffer
->
data
[
0
])
+
outPos
;
for
(
size_t
t
=
0
;
t
<
nb
;
t
++
)
{
for
(
size_t
t
=
0
;
t
<
nb
_samples
;
t
++
)
{
ptr
[
t
]
=
(
sin
(
t
*
dx_h
)
+
sin
(
t
*
dx_l
))
*
DATA_AMPLITUDE_FLT
;
ptr
[
t
]
=
(
sin
(
t
*
dx_h
)
+
sin
(
t
*
dx_l
))
*
DATA_AMPLITUDE_FLT
;
}
}
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/media/audio/sound/tone.h
+
1
−
1
View file @
dbba9e62
...
@@ -53,7 +53,7 @@ public:
...
@@ -53,7 +53,7 @@ public:
* @param frequency2 The second frequency
* @param frequency2 The second frequency
* @param nb the number of samples to generate
* @param nb the number of samples to generate
*/
*/
static
void
genSin
(
AVFrame
*
buffer
,
unsigned
outPo
s
,
unsigned
frequency1
,
unsigned
frequency2
);
static
void
genSin
(
AVFrame
*
buffer
,
size_t
outPos
,
unsigned
nb_sample
s
,
unsigned
frequency1
,
unsigned
frequency2
);
private
:
private
:
/**
/**
...
...
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