Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
067572c6
Commit
067572c6
authored
Oct 26, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CrossFade: reimplement mixramp_interpolate() without strtok()
Don't require a writable string, and don't modify it.
parent
7f03f68f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
26 deletions
+19
-26
CrossFade.cxx
src/CrossFade.cxx
+15
-25
CrossFade.hxx
src/CrossFade.hxx
+4
-1
No files found.
src/CrossFade.cxx
View file @
067572c6
...
...
@@ -21,6 +21,7 @@
#include "CrossFade.hxx"
#include "MusicChunk.hxx"
#include "AudioFormat.hxx"
#include "util/NumberParser.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
...
...
@@ -32,20 +33,11 @@
static
constexpr
Domain
cross_fade_domain
(
"cross_fade"
);
#ifdef WIN32
static
char
*
strtok_r
(
char
*
str
,
const
char
*
delim
,
gcc_unused
char
**
saveptr
)
gcc_pure
static
float
mixramp_interpolate
(
const
char
*
ramp_list
,
float
required_db
)
{
return
strtok
(
str
,
delim
);
}
#endif
static
float
mixramp_interpolate
(
char
*
ramp_list
,
float
required_db
)
{
float
db
,
secs
,
last_db
=
nan
(
""
),
last_secs
=
0
;
char
*
ramp_str
,
*
save_str
=
nullptr
;
float
last_db
=
nan
(
""
),
last_secs
=
0
;
/* ramp_list is a string of pairs of dBs and seconds that describe the
* volume profile. Delimiters are semi-colons between pairs and spaces
...
...
@@ -53,24 +45,22 @@ static float mixramp_interpolate(char *ramp_list, float required_db)
* The dB values must be monotonically increasing for this to work. */
while
(
1
)
{
/* Parse the dB tokens out of the input string. */
ramp_str
=
strtok_r
(
ramp_list
,
" "
,
&
save_str
);
/* Tell strtok to continue next time round. */
ramp_list
=
nullptr
;
/* Parse the dB value. */
if
(
nullptr
==
ramp_str
)
char
*
endptr
;
const
float
db
=
ParseFloat
(
ramp_list
,
&
endptr
);
if
(
endptr
==
ramp_list
||
*
endptr
!=
' '
)
break
;
db
=
(
float
)
atof
(
ramp_str
)
;
ramp_list
=
endptr
+
1
;
/* Parse the time. */
ramp_str
=
strtok_r
(
nullptr
,
";"
,
&
save_s
tr
);
if
(
nullptr
==
ramp_str
)
float
secs
=
ParseFloat
(
ramp_list
,
&
endp
tr
);
if
(
endptr
==
ramp_list
||
(
*
endptr
!=
';'
&&
*
endptr
!=
0
)
)
break
;
secs
=
(
float
)
atof
(
ramp_str
);
ramp_list
=
endptr
;
if
(
*
ramp_list
==
';'
)
++
ramp_list
;
/* Check for exact match. */
if
(
db
==
required_db
)
{
...
...
@@ -100,7 +90,7 @@ unsigned
cross_fade_calc
(
float
duration
,
float
total_time
,
float
mixramp_db
,
float
mixramp_delay
,
float
replay_gain_db
,
float
replay_gain_prev_db
,
c
har
*
mixramp_start
,
char
*
mixramp_prev_end
,
c
onst
char
*
mixramp_start
,
const
char
*
mixramp_prev_end
,
const
AudioFormat
af
,
const
AudioFormat
old_format
,
unsigned
max_chunks
)
...
...
src/CrossFade.hxx
View file @
067572c6
...
...
@@ -20,6 +20,8 @@
#ifndef MPD_CROSSFADE_HXX
#define MPD_CROSSFADE_HXX
#include "Compiler.h"
struct
AudioFormat
;
struct
music_chunk
;
...
...
@@ -40,11 +42,12 @@ struct music_chunk;
* @return the number of chunks for crossfading, or 0 if cross fading
* should be disabled for this song change
*/
gcc_pure
unsigned
cross_fade_calc
(
float
duration
,
float
total_time
,
float
mixramp_db
,
float
mixramp_delay
,
float
replay_gain_db
,
float
replay_gain_prev_db
,
c
har
*
mixramp_start
,
char
*
mixramp_prev_end
,
c
onst
char
*
mixramp_start
,
const
char
*
mixramp_prev_end
,
AudioFormat
af
,
AudioFormat
old_format
,
unsigned
max_chunks
);
...
...
Write
Preview
Markdown
is supported
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