Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Load the wavfile with :mod:`scipy.io.wavfile` ,
converting int to float as needed.
Create a sound table, resampling sound if needed.
"""
fs, audio = wavfile.read(self.path)
if audio.dtype in ['int16', 'int32']:
audio = int_to_float(audio)
# load file to sound table
if self.server_type == 'pyo':
self.dtable = pyo.DataTable(size=audio.shape[0], chnls=prefs.NCHANNELS, init=audio.tolist())
# get server to determine sampling rate modification and duration
server_fs = self.dtable.getServer().getSamplingRate()
self.duration = float(self.dtable.getSize()) / float(fs)
self.table = pyo.TableRead(table=self.dtable, freq=float(fs) / server_fs,
loop=False, mul=self.amplitude)
elif self.server_type == 'jack':
# attenuate amplitude
audio = audio*self.amplitude
self.duration = float(audio.shape[0]) / fs
# resample to match our audio server's sampling rate
if fs != self.fs:
new_samples = self.duration*self.fs
audio = resample(audio, new_samples)
def _setSndFromArray(self, thisArray):
self._sndTable = pyo.DataTable(size=len(thisArray),
init=thisArray.T.tolist(),
chnls=self.channels)
self._updateSnd()
# a DataTable has no .getDur() method, so just store the duration:
self.duration = float(len(thisArray)) / self.sampleRate
def _setSndFromArray(self, thisArray):
self._sndTable = pyo.DataTable(size=len(thisArray),
init=thisArray.T.tolist(),
chnls=self.channels)
self._updateSnd()
# a DataTable has no .getDur() method, so just store the duration:
self.duration = float(len(thisArray)) / self.sampleRate
def init_sound(self):
"""
"""
fs, audio = wavfile.read(self.path)
if audio.dtype in ['int16', 'int32']:
audio = int_to_float(audio)
# load file to sound table
if self.server_type == 'pyo':
self.dtable = pyo.DataTable(size=audio.shape[0], chnls=prefs.NCHANNELS, init=audio.tolist())
# get server to determine sampling rate modification and duration
server_fs = self.dtable.getServer().getSamplingRate()
self.duration = float(self.dtable.getSize()) / float(fs)
self.table = pyo.TableRead(table=self.dtable, freq=float(fs) / server_fs,
loop=False, mul=self.amplitude)
elif self.server_type == 'jack':
self.duration = float(audio.shape[0]) / fs
# resample to match our audio server's sampling rate
if fs != self.fs:
new_samples = self.duration*self.fs
audio = resample(audio, new_samples)
self.table = audio
def init_sound(self):
fs, audio = wavfile.read(self.path)
if audio.dtype in ['int16', 'int32']:
audio = int_to_float(audio)
# load file to sound table
if self.server_type == 'pyo':
self.dtable = pyo.DataTable(size=audio.shape[0], chnls=prefs.NCHANNELS, init=audio.tolist())
# get server to determine sampling rate modification and duration
server_fs = self.dtable.getServer().getSamplingRate()
self.duration = float(self.dtable.getSize()) / float(fs)
self.table = pyo.TableRead(table=self.dtable, freq=float(fs) / server_fs,
loop=False, mul=self.amplitude)
elif self.server_type == 'jack':
self.duration = float(audio.shape[0]) / fs
# resample to match our audio server's sampling rate
if fs != self.fs:
new_samples = self.duration*self.fs
audio = resample(audio, new_samples)
self.table = audio
def load_file(self):
# load file to sound table
#
fs, audio = wavfile.read(self.path)
if audio.dtype in ['int16', 'int32']:
audio = int_to_float(audio)
self.dtable = pyo.DataTable(size=audio.shape[0], chnls=2, init=audio.tolist())
# get server to determine sampling rate modification and duration
server_fs = self.dtable.getServer().getSamplingRate()
self.duration = float(self.dtable.getSize())/float(fs)
self.table = pyo.TableRead(table=self.dtable, freq=float(fs)/server_fs,
loop=False, mul=self.amplitude)