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 SMPTE/DIN Intermodulation test signal -----------------
32
33# SMPTE frequencies
34#
35#Flo = 60
36#Fhi = 7000
37#Ratio = 4
38
39# DIN frequencies
40#
41Flo = 250
42Fhi = 8000
43Ratio = 4
44
45# Level in dB (of lower frequency)
46#
47Level = -20.0
48
49# Create a Jacksignal object.
50#
51J = JackSignal("IMtest")
52if J.get_state() < 0:
53    print ("Failed to create JackSignal -- is the server running ?")
54    exit(1)
55
56# Get Jack info.
57#
58name, Fsamp, period = J.get_jack_info()
59
60# Create one output and connect.
61#
62J.create_output (0, "out")
63J.silence()
64J.connect_output (0, "jaaa:in_1")
65
66# Generate test signal. Since we will loop this we need an
67# exactly integer number of cycles in the buffer.
68#
69siglen = int (1.0 * Fsamp + 0.5) # 1 second
70Flo = adjust_freq (Flo, Fsamp, siglen)
71Fhi = adjust_freq (Fhi, Fsamp, siglen)
72# Amplitudes.
73Alo = pow (10.0, Level / 20.0)
74Ahi = Alo / Ratio
75A = (   gen_sinewave (Alo, Flo, Fsamp, siglen)
76      + gen_sinewave (Ahi, Fhi, Fsamp, siglen)).astype (np.float32)
77
78# Output signal, loop 1000 times.
79#
80J.set_output_data (0, A, nloop = 1000)
81J.process()
82J.wait()
83
84# Cleanup
85#
86del A
87del J
88
89