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 audiotools.audiofile import AudioFile
25from jacktools.jacksignal import JackSignal
26
27
28# Simple example using Audiofile and Jacksignal.
29# Skip 10 seconds then play 20 seconds of a stereo audio file.
30
31
32F = AudioFile()
33# Replace by your favourite track...
34#
35rv = F.open_read("/audio/audiofiles/tracks/susheela_raman-maya.wav")
36if rv == None:
37    print ("Failed to open audio file.")
38    exit (1)
39
40F.seek (10 * F.sampfreq ())
41nsam = 20 * F.sampfreq ()
42A2 = np.empty ([nsam, 2], dtype = np.float32)
43F.read (A2)
44F.close ()
45
46J = JackSignal ("JackSignal")
47if J.get_state () < 0:
48    print ("Failed to create JackSignal -- is the server running ?")
49    exit (1)
50
51J.create_output (0, "out-1")
52J.create_output (1, "out-2")
53J.silence()
54J.connect_output (0, "system:playback_1")
55J.connect_output (1, "system:playback_2")
56
57# Assign slices to outputs.
58#
59J.set_output_data (0, A2 [:,0])
60J.set_output_data (1, A2 [:,1])
61
62# Set gains.
63#
64J.set_output_gain (0, 0.1)
65J.set_output_gain (1, 0.1)
66
67# Play.
68#
69J.process ()
70J.wait ()
71