sounds
This module defines classes to generate different sounds.
These classes are currently implemented: * Tone : a sinuosoidal pure tone * Noise : a burst of white noise * File : read from a file * Speech * Gap
The behavior of this module depends on prefs.get(‘AUDIOSERVER’). * If this is ‘jack’, or True:
Then import jack, define Jack_Sound, and all sounds inherit from that.
- If this is ‘pyo’:
Then import pyo, define PyoSound, and all sounds inherit from that.
- If this is ‘docs’:
Then import both jack and pyo, define both Jack_Sound and PyoSound, and all sounds inherit from object.
- Otherwise:
Then do not import jack or pyo, or define either Jack_Sound or PyoSound, and all sounds inherit from object.
Todo
Implement sound level and filter calibration
Classes:
|
The Humble Sine Wave |
|
Generates a white noise burst with specified parameters |
|
A .wav file. |
|
A silent sound that does not pad its final chunk -- used for creating precise silent gaps in a continuous noise. |
|
Gammatone filtered noise, using |
Data:
These parameters should be given string columns rather than float columns. |
Functions:
|
Convert 16 or 32 bit integer audio to 32 bit float. |
- class Tone(frequency, duration, amplitude=0.01, **kwargs)[source]
Bases:
autopilot.stim.sound.base.Jack_Sound
The Humble Sine Wave
- Parameters
frequency (float) – frequency of sin in Hz
duration (float) – duration of the sin in ms
amplitude (float) – amplitude of the sound as a proportion of 1.
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
list of strings of parameters to be defined
string human readable name of sound
Methods:
Create a sine wave table using pyo or numpy, depending on the server type.
- PARAMS = ['frequency', 'duration', 'amplitude']
list of strings of parameters to be defined
- Type
- class Noise(duration, amplitude=0.01, channel=None, **kwargs)[source]
Bases:
autopilot.stim.sound.base.Jack_Sound
Generates a white noise burst with specified parameters
The type attribute is always “Noise”.
Initialize a new white noise burst with specified parameters.
The sound itself is stored as the attribute self.table. This can be 1-dimensional or 2-dimensional, depending on channel. If it is 2-dimensional, then each channel is a column.
- Parameters
duration (float) – duration of the noise
amplitude (float) – amplitude of the sound as a proportion of 1.
channel (int or None) – which channel should be used If 0, play noise from the first channel If 1, play noise from the second channel If None, send the same information to all channels (“mono”)
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
list of strings of parameters to be defined
string human readable name of sound
Methods:
Defines self.table, the waveform that is played.
Continuously yield frames of audio.
- PARAMS = ['duration', 'amplitude', 'channel']
list of strings of parameters to be defined
- Type
- init_sound()[source]
Defines self.table, the waveform that is played.
The way this is generated depends on self.server_type, because parameters like the sampling rate cannot be known otherwise.
The sound is generated and then it is “chunked” (zero-padded and divided into chunks). Finally self.initialized is set True.
- class File(path, amplitude=0.01, **kwargs)[source]
Bases:
autopilot.stim.sound.base.Jack_Sound
A .wav file.
Todo
Generalize this to other audio types if needed.
- Parameters
path (str) – Path to a .wav file relative to the prefs.get(‘SOUNDDIR’)
amplitude (float) – amplitude of the sound as a proportion of 1.
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
list of strings of parameters to be defined
string human readable name of sound
Methods:
Load the wavfile with
scipy.io.wavfile
, converting int to float as needed.- init_sound()[source]
Load the wavfile with
scipy.io.wavfile
, converting int to float as needed.Create a sound table, resampling sound if needed.
- class Gap(duration, **kwargs)[source]
Bases:
autopilot.stim.sound.base.Jack_Sound
A silent sound that does not pad its final chunk – used for creating precise silent gaps in a continuous noise.
- Parameters
duration (float) – duration of gap in ms
- Variables
gap_zero (bool) – True if duration is zero, effectively do nothing on play.
Attributes:
string human readable name of sound
list of strings of parameters to be defined
Methods:
Create and chunk an array of zeros according to
Gap.duration
chunk
([pad])If gap is not duration == 0, call parent
chunk
.buffer
()Dump chunks into the sound queue.
play
()Play ourselves.
- chunk(pad=False)[source]
If gap is not duration == 0, call parent
chunk
. :Parameters: pad (bool) – unused, passed to parentchunk
- class Gammatone(frequency: float, duration: float, amplitude: float = 0.01, channel: Optional[int] = None, filter_kwargs: Optional[dict] = None, **kwargs)[source]
Bases:
autopilot.stim.sound.sounds.Noise
Gammatone filtered noise, using
timeseries.Gammatone
– see that class for the filter documentation.- Parameters
frequency (float) – Center frequency of filter, in Hz
duration (float) – Duration of sound, in ms
amplitude (float) – Amplitude scaling of sound (absolute value 0-1, default is .01)
filter_kwargs (dict) – passed on to
timeseries.Gammatone
Attributes:
string human readable name of sound
list of strings of parameters to be defined
- STRING_PARAMS = ['path', 'type', 'speaker', 'vowel', 'token', 'consonant']
These parameters should be given string columns rather than float columns.
Bother Jonny to do this better bc it’s really bad.