Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
ec9d2ea1
Commit
ec9d2ea1
authored
12 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Allow specifying a frequency of zero for silence.
parent
8afd241b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/xpbeep.c
+63
-56
63 additions, 56 deletions
src/xpdev/xpbeep.c
with
63 additions
and
56 deletions
src/xpdev/xpbeep.c
+
63
−
56
View file @
ec9d2ea1
...
...
@@ -190,60 +190,65 @@ void makewave(double freq, unsigned char *wave, int samples, enum WAVE_SHAPE sha
double
pos
;
BOOL
endhigh
;
midpoint
=
samples
/
2
;
inc
=
8
.
0
*
atan
(
1
.
0
);
inc
*=
((
double
)
freq
/
(
double
)
S_RATE
);
for
(
i
=
0
;
i
<
samples
;
i
++
)
{
pos
=
(
inc
*
(
double
)
i
);
pos
-=
(
int
)(
pos
/
WAVE_TPI
)
*
WAVE_TPI
;
switch
(
shape
)
{
case
WAVE_SHAPE_SINE
:
wave
[
i
]
=
(
sin
(
pos
))
*
127
+
128
;
break
;
case
WAVE_SHAPE_SINE_HARM
:
wave
[
i
]
=
(
sin
(
pos
))
*
64
+
128
;
wave
[
i
]
=
(
sin
((
inc
*
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
=
(
sin
((
inc
*
3
)
*
(
double
)
i
))
*
16
;
break
;
case
WAVE_SHAPE_SAWTOOTH
:
wave
[
i
]
=
(
WAVE_TPI
-
pos
)
*
40
.
5
;
break
;
case
WAVE_SHAPE_SQUARE
:
wave
[
i
]
=
(
pos
<
WAVE_PI
)
?
255
:
0
;
break
;
case
WAVE_SHAPE_SINE_SAW
:
wave
[
i
]
=
(((
sin
(
pos
))
*
127
+
128
)
+
((
WAVE_TPI
-
pos
)
*
40
.
5
))
/
2
;
break
;
case
WAVE_SHAPE_SINE_SAW_CHORD
:
wave
[
i
]
=
(((
sin
(
pos
))
*
64
+
128
)
+
((
WAVE_TPI
-
pos
)
*
6
.
2
))
/
2
;
wave
[
i
]
+=
(
sin
((
inc
/
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
+=
(
sin
((
inc
/
3
)
*
(
double
)
i
))
*
16
;
break
;
case
WAVE_SHAPE_SINE_SAW_HARM
:
wave
[
i
]
=
(((
sin
(
pos
))
*
64
+
128
)
+
((
WAVE_TPI
-
pos
)
*
6
.
2
))
/
2
;
wave
[
i
]
+=
(
sin
((
inc
*
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
+=
(
sin
((
inc
*
3
)
*
(
double
)
i
))
*
16
;
break
;
}
if
(
freq
==
0
)
{
memset
(
wave
,
128
,
samples
);
}
else
{
midpoint
=
samples
/
2
;
inc
=
8
.
0
*
atan
(
1
.
0
);
inc
*=
((
double
)
freq
/
(
double
)
S_RATE
);
for
(
i
=
0
;
i
<
samples
;
i
++
)
{
pos
=
(
inc
*
(
double
)
i
);
pos
-=
(
int
)(
pos
/
WAVE_TPI
)
*
WAVE_TPI
;
switch
(
shape
)
{
case
WAVE_SHAPE_SINE
:
wave
[
i
]
=
(
sin
(
pos
))
*
127
+
128
;
break
;
case
WAVE_SHAPE_SINE_HARM
:
wave
[
i
]
=
(
sin
(
pos
))
*
64
+
128
;
wave
[
i
]
=
(
sin
((
inc
*
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
=
(
sin
((
inc
*
3
)
*
(
double
)
i
))
*
16
;
break
;
case
WAVE_SHAPE_SAWTOOTH
:
wave
[
i
]
=
(
WAVE_TPI
-
pos
)
*
40
.
5
;
break
;
case
WAVE_SHAPE_SQUARE
:
wave
[
i
]
=
(
pos
<
WAVE_PI
)
?
255
:
0
;
break
;
case
WAVE_SHAPE_SINE_SAW
:
wave
[
i
]
=
(((
sin
(
pos
))
*
127
+
128
)
+
((
WAVE_TPI
-
pos
)
*
40
.
5
))
/
2
;
break
;
case
WAVE_SHAPE_SINE_SAW_CHORD
:
wave
[
i
]
=
(((
sin
(
pos
))
*
64
+
128
)
+
((
WAVE_TPI
-
pos
)
*
6
.
2
))
/
2
;
wave
[
i
]
+=
(
sin
((
inc
/
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
+=
(
sin
((
inc
/
3
)
*
(
double
)
i
))
*
16
;
break
;
case
WAVE_SHAPE_SINE_SAW_HARM
:
wave
[
i
]
=
(((
sin
(
pos
))
*
64
+
128
)
+
((
WAVE_TPI
-
pos
)
*
6
.
2
))
/
2
;
wave
[
i
]
+=
(
sin
((
inc
*
2
)
*
(
double
)
i
))
*
24
;
wave
[
i
]
+=
(
sin
((
inc
*
3
)
*
(
double
)
i
))
*
16
;
break
;
}
}
/* Now we have a "perfect" wave...
* we must clean it up now to avoid click/pop
*/
if
(
wave
[
samples
-
1
]
>
128
)
endhigh
=
TRUE
;
else
endhigh
=
FALSE
;
/* Completely remove the last wave fragment */
i
=
samples
-
1
;
if
(
wave
[
i
]
!=
128
)
{
for
(;
i
>
midpoint
;
i
--
)
{
if
(
endhigh
&&
wave
[
i
]
<
128
)
break
;
if
(
!
endhigh
&&
wave
[
i
]
>
128
)
break
;
wave
[
i
]
=
128
;
/* Now we have a "perfect" wave...
* we must clean it up now to avoid click/pop
*/
if
(
wave
[
samples
-
1
]
>
128
)
endhigh
=
TRUE
;
else
endhigh
=
FALSE
;
/* Completely remove the last wave fragment */
i
=
samples
-
1
;
if
(
wave
[
i
]
!=
128
)
{
for
(;
i
>
midpoint
;
i
--
)
{
if
(
endhigh
&&
wave
[
i
]
<
128
)
break
;
if
(
!
endhigh
&&
wave
[
i
]
>
128
)
break
;
wave
[
i
]
=
128
;
}
}
}
}
...
...
@@ -842,12 +847,14 @@ BOOL DLLCALL xptone(double freq, DWORD duration, enum WAVE_SHAPE shape)
unsigned
char
wave
[
S_RATE
*
15
/
2
+
1
];
int
samples
;
if
(
freq
<
17
)
if
(
freq
<
17
&&
freq
!=
0
)
freq
=
17
;
samples
=
S_RATE
*
duration
/
1000
;
if
(
samples
<=
S_RATE
/
freq
*
2
)
samples
=
S_RATE
/
freq
*
2
;
if
(
samples
>
S_RATE
/
freq
*
2
)
{
if
(
freq
)
{
if
(
samples
<=
S_RATE
/
freq
*
2
)
samples
=
S_RATE
/
freq
*
2
;
}
if
(
freq
==
0
||
samples
>
S_RATE
/
freq
*
2
)
{
int
sample_len
;
makewave
(
freq
,
wave
,
S_RATE
*
15
/
2
,
shape
);
...
...
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