Esempio n. 1
0
 def click(duration, peak=None, samplerate=None, nchannels=1):
     '''
     Returns a click of the given duration.
     
     If ``peak`` is not specified, the amplitude will be 1, otherwise
     ``peak`` refers to the peak dB SPL of the click, according to the
     formula ``28e-6*10**(peak/20.)``.
     '''
     samplerate = get_samplerate(samplerate)
     duration = get_duration(duration,samplerate)
     if peak is not None:
         if not isinstance(peak, dB_type):
             raise dB_error('Peak must be given in dB')
         amplitude = 28e-6*10**(float(peak)/20.)
     else:
         amplitude = 1
     x = amplitude*ones((duration,nchannels))
     return Sound(x, samplerate)
Esempio n. 2
0
 def set_level(self, level):
     '''
     Sets level in dB SPL (RMS) assuming array is in Pascals. ``level``
     should be a value in dB, or a tuple of levels, one for each channel.
     '''
     rms_dB = self.get_level()
     if self.nchannels>1:
         level = array(level)
         if level.size==1:
             level = level.repeat(self.nchannels)
         level = reshape(level, (1, self.nchannels))
         rms_dB = reshape(rms_dB, (1, self.nchannels))
     else:
         if not isinstance(level, dB_type):
             raise dB_error('Must specify level in dB')
         rms_dB = float(rms_dB)
         level = float(level)
     gain = 10**((level-rms_dB)/20.)
     self *= gain