-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpuTone.py
47 lines (39 loc) · 1.2 KB
/
cpuTone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import ctypes as ct
import os
from intelHelpers import include_ipp
include_ipp()
os.environ["PATH"] = (
os.environ["PATH"] + os.pathsep +
os.path.dirname(os.path.realpath(__file__))
)
# if os.name == "nt":
# os.add_dll_directory(os.path.join(
# os.environ["IPPROOT"], "redist", "intel64"))
# elif os.name == "posix":
# os.environ["PATH"] = (
# os.environ["PATH"]
# + os.pathsep
# + os.path.join(os.environ["IPPROOT"], "lib", "intel64")
# )
def cpuTone(length: int, freq: float, fs: int, phase: float = 0):
"""
IPP wrapper for ippsTone.
"""
_libmc = np.ctypeslib.load_library(
"cpuToneDll", loader_path=os.path.dirname(os.path.realpath(__file__))
)
array_1d_complexdouble = np.ctypeslib.ndpointer(
dtype=np.complex128, ndim=1, flags="CONTIGUOUS"
)
_libmc.cpuTone.restype = ct.c_int32
_libmc.cpuTone.argtypes = [
ct.c_int32,
ct.c_double,
ct.c_double,
ct.c_double,
array_1d_complexdouble,
]
out = np.empty(int(length), dtype=np.complex128) # make the output
retcode = _libmc.cpuTone(length, freq, float(fs), phase, out)
return out, retcode