Many thanks,
from pyo import *
import numpy as np
import math
s = Server().boot()
s.start()
# ----
# Create and play a table with random waveform
snippet_length = 3; # in seconds, no more audio output above appr. 5.25
samples = secToSamps(snippet_length) # corresponding number of samples
cycle_freq = 1.0/snippet_length # Frequency at which random snippet is played
# Create NumPy array with uniform random numbers between 0 and 1
size = samples
monte_carlo_array = np.random.random_sample(size)
# Convert into pyo table object
monte_carlo_table = DataTable(size,
init=monte_carlo_array.tolist())
monte_carlo_table.normalize() # Should normalize to range -1 to 1
monte_carlo_table.view() # But here seems not to do so, see graph
# Loop the snippet using Osc object
output = Osc(table=monte_carlo_table,
freq=1.0/snippet_length,mul=0.5).out()
s.gui(locals())
##########################Hi Olivier,
thank you for the quick response, that were exactly the directions I needed. Very helpful!
In your code I found two minor issues:
1) I needed to add s.start() to make the server work
2) The second part of creating a matrix causes no audio output. It does not produce an error, however. I could narrow it down to the three lines:I simply threw the whole Matrix part out then.
rr2 = np.array([[math.sin(2 * math.pi * j / size + math.sin(i/16.0)) for j in range(size)] for i in range(size)])
m = NewMatrix(size, size, arr2.tolist())
m.view()
2) The .normalize() method does not seem to affect the monte_carlo_table Table. I expected to see random numbers between -1 and 1 after normalization, but they are between 0 and 1 in my graph.
Thank you, and greetings to UdM from the other side of the mountain,
Lennart
svn checkout http://pyo.googlecode.com/svn/trunk/ pyo-read-only
to get the source, then installed it using
sudo python setup.py install --install-layout=deb --use-double
I am on Ubuntu 10.04, if that is of any help...