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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
c471b336
Commit
c471b336
authored
Apr 11, 2014
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
tone: fix division by zero
Refs #45116
parent
edd3b051
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
daemon/src/audio/sound/tone.cpp
+10
-13
10 additions, 13 deletions
daemon/src/audio/sound/tone.cpp
with
10 additions
and
13 deletions
daemon/src/audio/sound/tone.cpp
+
10
−
13
View file @
c471b336
...
@@ -80,7 +80,7 @@ Tone::genBuffer(const std::string& definition)
...
@@ -80,7 +80,7 @@ Tone::genBuffer(const std::string& definition)
/* begin scope */
/* begin scope */
{
{
// Sample string: "350+440" or "350+440/2000,244+655/2000"
// Sample string: "350+440" or "350+440/2000,244+655/2000"
int
freq1
,
freq2
,
time
;
int
low
,
high
,
time
;
s
=
definition
.
substr
(
posStart
,
posEnd
-
posStart
);
s
=
definition
.
substr
(
posStart
,
posEnd
-
posStart
);
// The 1st frequency is before the first + or the /
// The 1st frequency is before the first + or the /
...
@@ -99,11 +99,11 @@ Tone::genBuffer(const std::string& definition)
...
@@ -99,11 +99,11 @@ Tone::genBuffer(const std::string& definition)
// without a plus = 1 frequency
// without a plus = 1 frequency
if
(
pos_plus
==
std
::
string
::
npos
)
{
if
(
pos_plus
==
std
::
string
::
npos
)
{
freq1
=
atoi
(
s
.
substr
(
0
,
endfrequency
).
c_str
());
low
=
atoi
(
s
.
substr
(
0
,
endfrequency
).
c_str
());
freq2
=
0
;
high
=
0
;
}
else
{
}
else
{
freq1
=
atoi
(
s
.
substr
(
0
,
pos_plus
).
c_str
());
low
=
atoi
(
s
.
substr
(
0
,
pos_plus
).
c_str
());
freq2
=
atoi
(
s
.
substr
(
pos_plus
+
1
,
endfrequency
-
pos_plus
-
1
).
c_str
());
high
=
atoi
(
s
.
substr
(
pos_plus
+
1
,
endfrequency
-
pos_plus
-
1
).
c_str
());
}
}
// If there is time or if it's unlimited
// If there is time or if it's unlimited
...
@@ -114,7 +114,7 @@ Tone::genBuffer(const std::string& definition)
...
@@ -114,7 +114,7 @@ Tone::genBuffer(const std::string& definition)
// Generate SAMPLING_RATE samples of sinus, buffer is the result
// Generate SAMPLING_RATE samples of sinus, buffer is the result
buffer
.
resize
(
size
+
count
);
buffer
.
resize
(
size
+
count
);
genSin
(
&
(
*
(
buffer
.
begin
()
+
bufferPos
)),
freq1
,
freq2
,
count
);
genSin
(
&
(
*
(
buffer
.
begin
()
+
bufferPos
)),
low
,
high
,
count
);
// To concatenate the different buffers for each section.
// To concatenate the different buffers for each section.
size
+=
count
;
size
+=
count
;
...
@@ -153,7 +153,7 @@ Tone::interpolate(double x) const
...
@@ -153,7 +153,7 @@ Tone::interpolate(double x) const
}
}
void
void
Tone
::
genSin
(
SFLAudioSample
*
buffer
,
int
f
requency
1
,
int
f
requency
2
,
int
nb
)
Tone
::
genSin
(
SFLAudioSample
*
buffer
,
int
lowF
requency
,
int
highF
requency
,
int
nb
)
{
{
xhigher_
=
0.0
;
xhigher_
=
0.0
;
xlower_
=
0.0
;
xlower_
=
0.0
;
...
@@ -161,17 +161,14 @@ Tone::genSin(SFLAudioSample* buffer, int frequency1, int frequency2, int nb)
...
@@ -161,17 +161,14 @@ Tone::genSin(SFLAudioSample* buffer, int frequency1, int frequency2, int nb)
const
double
sr
=
(
double
)
buffer_
->
getSampleRate
();
const
double
sr
=
(
double
)
buffer_
->
getSampleRate
();
static
const
double
tableSize
=
TABLE_LENGTH
;
static
const
double
tableSize
=
TABLE_LENGTH
;
double
N_h
=
sr
/
frequency1
;
const
double
dx_h
=
lowFrequency
and
sr
?
tableSize
/
(
sr
/
lowFrequency
)
:
0.0
;
double
N_l
=
sr
/
frequency2
;
const
double
dx_l
=
highFrequency
and
sr
?
tableSize
/
(
sr
/
highFrequency
)
:
0.0
;
double
dx_h
=
tableSize
/
N_h
;
double
dx_l
=
tableSize
/
N_l
;
double
x_h
=
xhigher_
;
double
x_h
=
xhigher_
;
double
x_l
=
xlower_
;
double
x_l
=
xlower_
;
static
const
double
DATA_AMPLITUDE
=
2047
;
static
const
double
DATA_AMPLITUDE
=
2047
;
double
amp
=
DATA_AMPLITUDE
;
const
double
amp
=
DATA_AMPLITUDE
;
for
(
int
t
=
0
;
t
<
nb
;
t
++
)
{
for
(
int
t
=
0
;
t
<
nb
;
t
++
)
{
buffer
[
t
]
=
amp
*
(
interpolate
(
x_h
)
+
interpolate
(
x_l
));
buffer
[
t
]
=
amp
*
(
interpolate
(
x_h
)
+
interpolate
(
x_l
));
...
...
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