Distribute pyjack with freewheel-related functionality
[jack_freewheel_button.git] / pyjack-0.5.2 / demos / testtone.py
blob5b61858f2963014b0ae1fb6207e2870ca293bea7
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Plays a 440.0 Hz test tone for 3 seconds to alsa_pcm:playback_1.
5 # Copyright 2003, Andrew W. Schmeder
6 # This source code is released under the terms of the GNU Public License.
7 # See LICENSE for the full text of these terms.
9 import numpy
10 import jack
12 jack.attach("testtone")
13 jack.register_port("in_1", jack.IsInput)
14 jack.register_port("out_1", jack.IsOutput)
15 jack.activate()
16 jack.connect("testtone:out_1", "alsa_pcm:playback_1")
18 N = jack.get_buffer_size()
19 Sr = float(jack.get_sample_rate())
20 print "Buffer Size:", N, "Sample Rate:", Sr
21 sec = 3.0
23 input = numpy.zeros((1,N), 'f')
24 output = numpy.reshape(
25 numpy.sin(
26 2*numpy.pi*440.0 * (numpy.arange(0, sec, 1.0/(Sr), 'f')[0:int(Sr*sec)])
27 ), (1, Sr*sec)).astype('f')
29 i = 0
30 while i < output.shape[1] - N:
31 try:
32 jack.process(output[:,i:i+N], input)
33 i += N
34 except jack.InputSyncError:
35 pass
36 except jack.OutputSyncError:
37 pass
39 jack.deactivate()
41 jack.detach()