1#!/usr/bin/python
2
3# ----------------------------------------------------------------------------
4#
5#  Copyright (C) 2008-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 numpy as np
24from math import *
25from time import sleep
26from jacktools.jacksignal import JackSignal
27
28
29# ----------------------- 1 kHz bursts to test jkmeter --------------------------
30#
31# Make sure jkmeter is running.
32
33# Create a JackSignal object with 1 output.
34#
35J = JackSignal("JackSignal")
36if J.get_state() < 0:
37    print ("Failed to create JackSignal -- is Jack running ?")
38    exit(1)
39
40J.create_output (0, "out_1")
41J.silence()
42J.connect_output (0, "jkmeter:in-1")
43
44# Get Jack info.
45#
46name, fsamp, period = J.get_jack_info ()
47
48# Create output buffer.
49#
50size = int (0.5 * fsamp + 0.1)
51A = np.empty ([size,], dtype = np.float32)
52
53# Generate 1 kHz sine wave
54#
55w = 1e3 * 2 * pi / fsamp
56for i in range (size):
57    A [i] = sin (w * i)
58
59# Generate burst of size t in seconds.
60#
61def burst (t):
62    print ("t = %5.3f" % (t,))
63    n = int (t * fsamp + 0.5)
64    if n > size: n = size
65    J.set_output_data (0, A [0:n])
66    J.process()
67    J.wait ()
68
69# Run the test.
70#
71tburst = [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5]
72twait = 5.0 # Let jkmeter fall back.
73for t in tburst:
74    burst (t)
75    sleep (twait)
76