1#!/usr/bin/python
2
3# ----------------------------------------------------------------------------
4#
5#  Copyright (C) 2013-2020 Fons Adriaensen <fons@linuxaudio.org>
6#
7#  This program is free software; you can redistribute it and/or modify
8#  it under the terms of the GNU General Public License as published by
9#  the Free Software Foundation; either version 3 of the License, or
10#  (at your option) any later version.
11#
12#  This program is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU General Public License for more details.
16#
17#  You should have received a copy of the GNU General Public License
18#  along with this program.  If not, see <http:#www.gnu.org/licenses/>.
19#
20# ----------------------------------------------------------------------------
21
22
23import sys
24import numpy as np
25from time import sleep
26from jacktools.jacksignal import JackSignal
27sys.path.append ('..')
28from utils.sinewave import *
29
30
31# -----------Generate IEC Intermodulation test signal -----------------------
32
33Fcent = 3000
34Fdiff = 60
35
36# Level in dB (of both frequencies)
37#
38Level = -10.0
39
40
41# Create a Jacksignal object.
42#
43J = JackSignal("IMtest")
44if J.get_state() < 0:
45    print ("Failed to create JackSignal -- is the server running ?")
46    exit(1)
47
48# Get Jack info.
49#
50name, Fsamp, period = J.get_jack_info()
51
52# Create one output and connect.
53#
54J.create_output (0, "out")
55J.silence()
56J.connect_output (0, "jaaa:in_1")
57
58# Generate test signal. Since we will loop this we need an
59# exactly integer number of cycles in the buffer.
60#
61siglen = int (1.0 * Fsamp + 0.5) # 1 second
62Flo = adjust_freq (Fcent - 0.5 * Fdiff, Fsamp, siglen)
63Fhi = adjust_freq (Fcent + 0.5 * Fdiff, Fsamp, siglen)
64Amp = pow (10.0, Level / 20.0)
65Aout = (  gen_sinewave (Amp, Flo, Fsamp, siglen)
66        + gen_sinewave (Amp, Fhi, Fsamp, siglen)).astype (np.float32)
67
68# Output signal, loop 1000 times.
69#
70J.set_output_data (0, Aout, nloop = 1000)
71J.process()
72J.wait()
73
74# Cleanup
75#
76del A
77del J
78
79