1#!/usr/bin/python
2
3# ----------------------------------------------------------------------------
4#
5#  Copyright (C) 2008-2014 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# ----------------------- Linear sweep  --------------------------
30#
31# Generate linear sweep and display with jaaa set to peak hold.
32# Try using different sweep speeds and jaaa bandwidths.
33
34
35FMIN = 0
36FMAX = 20e3
37TIME = 15  # seconds
38AMPL = 0.1 # signal amplitude
39
40
41# Generate a linear sweep signal.
42#
43def linsweep (fmin, fmax, amp, time, A, fsamp):
44    n = int (time * fsamp + 0.1)
45    if n > A.shape [0]: n = A.shape [0]
46    a = fmin / fsamp
47    b = (fmax - fmin) / (fsamp * n);
48    p = 0.0
49    for i in range (n):
50        A [i] = amp * sin (2 * pi * p)
51        a += b
52        p += a
53        if p > 1.0: p -= 1.0
54
55
56# Create a JackSignal object and connect.
57#
58J = JackSignal("JackSignal")
59if J.get_state() < 0:
60    print ("Failed to create JackSignal -- is Jack running ?")
61    exit(1)
62J.create_output (0, "out-1")
63J.silence()
64J.connect_output (0, "jaaa:in_1")
65
66# Get Jack info.
67#
68name, fsamp, period = J.get_jack_info ()
69
70# Create output buffer.
71#
72size = int (TIME * fsamp + 0.1)
73A = np.empty ([size,], dtype = np.float32)
74
75# Run the test
76#
77linsweep (FMIN, FMAX, AMPL, TIME, A, fsamp)
78J.set_output_data (0, A)
79J.process()
80J.wait()
81del J
82
83