Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
####################################################################
############## 1st test: play some tones ###########################
####################################################################
# Length of audio vector - 1 secs of playback:
n_samples = 1 * Fs
# Build sinewave:
a = np.sin(np.linspace(0, 2 * pi * f * n_samples / Fs))
# Replicated into two rows - One row for each stereo-channel, ie.
# m'th row == m'th channel, n'th column = n'th sample frame:
stereowav = [a, a]
audio.verbosity(5)
# Open audio device: Default audio device, default opmode (playback), default
# latency/timing-precision (low-latency, high precision), sample rate Fs,
# stereo (2) channel output:
stream = audio.Stream(freq=Fs, channels=2)
stream.volume = 0.5 # PsychPortAudio('Volume', pahandle, 0.5)
if True:
# Fill in audio matrix for playback: columns = audio channels, rows = samples
# Do it step-by-step for performance testing:
stereowav = np.array(stereowav, order='f')
# print('Type', type(stereowav), 'Shape', stereowav.shape, 'Datatype',
# stereowav.dtype, 'Order', stereowav.flags);
stereowav = np.transpose(stereowav)
# float32 is a tad faster than the default float64:
stereowav = stereowav.astype('float32')
defaultOutput = audioDevice
travisCI = bool(str(os.environ.get('TRAVIS')).lower() == 'true')
logging.info("Loaded psychtoolbox audio version {}"
.format(audio.get_version_info()['version']))
# ask PTB to align verbosity with our current logging level at console
_verbosities = ((logging.DEBUG, 5),
(logging.INFO, 4),
(logging.EXP, 3),
(logging.WARNING, 2),
(logging.ERROR, 1))
for _logLevel, _verbos in _verbosities:
if logging.console.level <= _logLevel:
audio.verbosity(_verbos)
break
def init(rate=48000, stereo=True, buffer=128):
pass # for compatibility with other backends
def getDevices(kind=None):
"""Returns a dict of dict of audio devices of specified `kind`
The dict keys are names and items are dicts of properties
"""
devs = {}
if travisCI: # travis-CI testing does not have a sound device
return devs
else:
allDevs = audio.get_devices(kind)