Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _enter(self):
super(SoundFile, self)._enter()
global _got_pyo
default_init_audio_server()
self._sound_start_time = None
self._sound_stop_time = None
self.__snd = None
if _got_pyo:
# init the sound table (two steps to get mono in both speakers)
sndtab = pyo.SndTable(initchnls=_pyo_server.getNchnls())
sndtab.setSound(path=self._filename, start=self._start,
stop=self._stop)
# set the end time
if not self._loop:
self.cancel(self._start_time + sndtab.getDur())
# read in sound info
self.__snd = pyo.TableRead(sndtab, freq=sndtab.getRate(),
loop=self._loop,
mul=self._volume)
if self.__snd is None:
raise RuntimeError("Could not load sound file: %r" %
self._filename)
# schedule playing the sound
def load_file(self):
# load file to sound table
print(self.path)
sys.stdout.flush()
self.snd_table = pyo.SndTable(self.path, chnl=2)
self.table = pyo.TableRead(self.snd_table, freq=self.snd_table.getRate(),
loop=False, mul=self.amplitude)
envelope = pyo.Sine(freq=soundParams['modFrequency'],
mul=halfAmp,
add=halfAmp,phase=0.75)
soundObj = pyo.Fader(fadein=self.risetime, fadeout=self.falltime,
dur=soundParams['duration'], mul=envelope)
soundwaveObj = pyo.Noise(mul=soundObj).out()
return(soundObj,[envelope,soundwaveObj])
'''
soundObj = pyo.Fader(fadein=self.risetime, fadeout=self.falltime,
dur=soundParams['duration'], mul=soundAmp)
envelope = pyo.Sine(freq=soundParams['modFrequency'],mul=soundObj,add=soundAmp,phase=0)
soundwaveObj = pyo.Noise(mul=envelope).out()
return(soundObj,[envelope,soundwaveObj])
'''
elif soundParams['type']=='fromfile':
tableObj = pyo.SndTable(soundParams['filename'])
samplingFreq = tableObj.getRate()
if soundParams.get('duration'):
duration = soundParams['duration']
else:
duration = tableObj.getDur()
if soundParams.get('channel')=='left':
fs = [samplingFreq,0]
elif soundParams.get('channel')=='right':
fs = [0,samplingFreq]
else:
fs = 2*[samplingFreq]
soundObj = pyo.Fader(fadein=self.risetime, fadeout=self.falltime,
dur=duration, mul=soundAmp)
print duration
print fs
soundwaveObj = pyo.Osc(table=tableObj, freq=fs, mul=soundObj).out()
def _setSndFromFile(self, fileName):
# want mono sound file played to both speakers, not just left / 0
self.fileName = fileName
self._sndTable = pyo.SndTable(initchnls=self.channels)
# in case a tone with inf loops had been used before
self.loops = self.requestedLoops
# mono file loaded to all chnls:
try:
self._sndTable.setSound(self.fileName,
start=self.startTime, stop=self.stopTime)
except Exception:
msg = (u'Could not open sound file `%s` using pyo; not found '
'or format not supported.')
logging.error(msg % fileName)
raise TypeError(msg % fileName)
self._updateSnd()
self.duration = self._sndTable.getDur()
def _setSndFromFile(self, fileName):
# want mono sound file played to both speakers, not just left / 0
self.fileName = fileName
self._sndTable = pyo.SndTable(initchnls=self.channels)
# in case a tone with inf loops had been used before
self.loops = self.requestedLoops
# mono file loaded to all chnls:
try:
self._sndTable.setSound(self.fileName,
start=self.startTime, stop=self.stopTime)
except Exception:
msg = ('Could not open sound file `%s` using pyo; not found '
'or format not supported.')
logging.error(msg % fileName)
raise TypeError(msg % fileName)
self._updateSnd()
self.duration = self._sndTable.getDur()