Calculates the total sound pressure level based on multiple source levels
165173
def total_level(source_levels):
    
    sums = 0.0
    for l in source_levels:
        if l is None:
            continue
        if l == 0:
            continue
        sums += pow(10.0, float(l) / 10.0)
    level = 10.0 * math.log10(sums)
    return level
1023693
def getAmbientThreshold(self):
    """"""
    command = '$GO'
    threshold = self.sendCommand(command)
    if threshold[0] == 'NK':
      return 0
    else:
      return float(threshold[1])/10
1320848
function() {
    // Loop through the tiles and setup the audio listeners.
    for (var i=0; i<this.grid.length; i++) {
      if (this.grid[i] === 2) {
        var y = Math.floor(i / this.size);
        var x = i % this.size;
        game.audio.speaker(x, y);
      }
    }
  }
743600
def p_levelsigs(self, p):
        ''
        p[0] = p[1] + (p[3],)
        p.set_lineno(0, p.lineno(1))
915354
def noise(params, amplitude=1, offset=0):
    '''
    
    '''
    amplitude = create_buffer(params, amplitude)
    offset = create_buffer(params, offset)
    output = offset + amplitude * (np.random.random(params.length)*2 - 1)
    return output
944505
def run(self):
        

        eta = self.settings['noise_strength']
        gamma = 2 * np.pi * self.settings['noise_bandwidth']
        dt = 1. / self.settings['update frequency']
        control = self.settings['control']

        self._state = self._output
        while self._stop is False:

            A = -gamma * dt

            noise = np.sqrt(2*gamma*eta)*np.random.randn()
            self._state *= (1. + A)
            self._state += noise + control
            self._output =  self._state

            self.msleep(int(1e3 / self.settings['update frequency']))
30372
def _compute_energy(self, rate_wavsample):
    """"""

    e = bob.ap.Energy(rate_wavsample[0], self.win_length_ms, self.win_shift_ms)
    energy_array = e(rate_wavsample[1])
    labels = self._voice_activity_detection(energy_array)
    # discard isolated speech a number of frames defined in smoothing_window
    labels = utils.smoothing(labels,self.smoothing_window)

    logger.info("After 2 Gaussian Energy-based VAD there are %d frames remaining over %d", numpy.sum(labels), len(labels))
    return labels
393075
def __getBarFC(pressure):
    """"""
    if pressure is None:
        return 0
    press = __to_float1(pressure)
    if press < 974:
        return 1
    if press < 990:
        return 2
    if press < 1002:
        return 3
    if press < 1010:
        return 4
    if press < 1022:
        return 5
    if press < 1035:
        return 6
    return 7
392908
def mono(self):
        
        if self.channels == 1:
            return self
        x = self.sum(axis=1) * 0.5
        y = x * 0.5
        return AudioSamples(y, self.samplerate)
1054072
def main(input_filename, songname, format, counter):
    

    # open the file & convert to wav
    song_data = AudioSegment.from_file(input_filename, format=format)
    song_data = song_data.set_channels(1)  # convert to mono
    wav_tmp = song_data.export(format="wav")  # write to a tmp file buffer
    wav_tmp.seek(0)
    rate, wav_data = wavfile.read(wav_tmp)

    # extract peaks and compute constellation hashes & offsets
    peaks = resound.get_peaks(np.array(wav_data))
    fingerprints = list(resound.hashes(peaks))  # hash, offset pairs

    if not fingerprints:
        raise RuntimeError("No fingerprints detected in source file - check your parameters passed to Resound.")

    # Combine duplicate keys
    for fp, abs_offset in fingerprints:
        counter[fp].append((abs_offset, songname))

    print "    Identified {} keypoints in '{}'.".format(len(counter), songname)

    return counter
1157783
def iter_wave_values(self):
        
        typecode = self.get_typecode(self.samplewidth)

        if log.level >= 5:
            if self.cfg.AVG_COUNT > 1:
                # merge samples -> log output in iter_avg_wave_values
                tlm = None
            else:
                tlm = TextLevelMeter(self.max_value, 79)

        # Use only a read size which is a quare divider of the samplewidth
        # Otherwise array.array will raise: ValueError: string length not a multiple of item size
        divider = int(round(float(WAVE_READ_SIZE) / self.samplewidth))
        read_size = self.samplewidth * divider
        if read_size != WAVE_READ_SIZE:
            log.info("Real use wave read size: %i Bytes" % read_size)

        get_wave_block_func = functools.partial(self.wavefile.readframes, read_size)
        skip_count = 0

        manually_audioop_bias = self.samplewidth == 1 and audioop is None

        for frames in iter(get_wave_block_func, ""):

            if self.samplewidth == 1:
                if audioop is None:
                    log.warning("use audioop.bias() work-a-round for missing audioop.")
                else:
                    # 8 bit samples are unsigned, see:
                    # http://docs.python.org/2/library/audioop.html#audioop.lin2lin
                    frames = audioop.bias(frames, 1, 128)

            try:
                values = array.array(typecode, frames)
            except ValueError, err:
                # e.g.:
                #     ValueError: string length not a multiple of item size
                # Work-a-round: Skip the last frames of this block
                frame_count = len(frames)
                divider = int(math.floor(float(frame_count) / self.samplewidth))
                new_count = self.samplewidth * divider
                frames = frames[:new_count] # skip frames
                log.error(
                    "Can't make array from %s frames: Value error: %s (Skip %i and use %i frames)" % (
                        frame_count, err, frame_count - new_count, len(frames)
                ))
                values = array.array(typecode, frames)

            for value in values:
                self.wave_pos += 1 # Absolute position in the frame stream

                if manually_audioop_bias:
                    # audioop.bias can't be used.
                    # See: http://hg.python.org/cpython/file/482590320549/Modules/audioop.c#l957
                    value = value % 0xff - 128

#                 if abs(value) < self.min_volume:
# #                     log.log(5, "Ignore to lower amplitude")
#                     skip_count += 1
#                     continue

                yield (self.wave_pos, value)

        log.info("Skip %i samples that are lower than %i" % (
            skip_count, self.min_volume
        ))
        log.info("Last readed Frame is: %s" % self.pformat_pos())
303540
def makeAudibleSong(self):
        
        sound0=n.hstack((sy.render(220,d=1.5),
                        sy.render(220*(2**(7/12)),d=2.5),
                        sy.render(220*(2**(-5/12)),d=.5),
                        sy.render(220*(2**(0/12)),d=1.5),
                        ))
        sound1=n.hstack((sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(7/12)),d=.25),
                         sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(7/12)),d=.25),
                         sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(7/12)),d=.25),
                         sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(7/12)),d=.25),
                        ))
        sound2=n.hstack((sy.render(220*(2**(0/12)),d=.75),
                         sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(7/12)),d=.75),
                         sy.render(220*(2**(0/12)),d=.25),
                         sy.render(220*(2**(-1/12)),d=2.0),
                       ))
        sound3=n.hstack((n.zeros(44100),
                         sy.render(220*(2**(-1/12)),d=.5),
                         sy.render(220*(2**(8/12)),d=2.),
                         sy.render(220*(2**(8/12)),d=.25),
                         sy.render(220*(2**(8/12)),d=.25),
                         sy.render(220*(2**(-1/12)),d=1.75),
                         sy.render(220*(2**(-1/12)),d=.25),
                       ))
        sound4=n.hstack((
                         sy.render(220*(2**(0/12)),d=1.),
                         sy.render(220*(2**(7/12)),d=.5),
                         sy.render(220*(2**(11/12)),d=.5),
                         sy.render(220*(2**(12/12)),d=.75),
                         sy.render(220*(2**(11/12)),d=.25),
                         sy.render(220*(2**(12/12)),d=1.),
                         sy.render(220*(2**(8/12)),d=2.),
                         sy.render(220*(2**(7/12)),d=2.),
                         sy.render(220*(2**(-1/12)),d=2.),
                         n.zeros(2*44100)
                       ))

        sound=n.hstack((sound0,sound1,sound2,sound3,sound4))
        UT.write(sound,"sound.wav")
640274
def step(self):
        """"""
        # Assign attributes to local variables for convenience.
        u = self._u
        
        if u is None:
            raise ValueError("the levelset function is not set "
                             "(use set_levelset)")
        
        data = self.data
        
        # Determine c0 and c1.
        inside = (u > 0)
        outside = (u <= 0)
        c0 = data[outside].sum() / float(outside.sum())
        c1 = data[inside].sum() / float(inside.sum())
        
        # Image attachment.
        dres = np.array(np.gradient(u))
        abs_dres = np.abs(dres).sum(0)
        #aux = abs_dres * (c0 - c1) * (c0 + c1 - 2*data)
        aux = abs_dres * (self.lambda1*(data - c1) ** 2 -
                          self.lambda2*(data - c0) ** 2)
        
        res = np.copy(u)
        res[aux < 0] = 1
        res[aux > 0] = 0
        
        # Smoothing.
        for i in range(self.smoothing):
            res = curvop(res)
        
        self._u = res
201447
def echo(params, source, delay, strength):
    '''
    
    '''
    source = create_buffer(params, source)
    delay = create_buffer(params, delay)
    strength = create_buffer(params, strength)
    output = source[:]
    for i in range(params.length):
        d = int(i - delay[i])
        if 0 <= d < params.length:
            output[i] += source[d]*strength[i]
    return output
606780
function LGAudioSource() {
        this.properties = {
            src: "",
            gain: 0.5,
            loop: true,
            autoplay: true,
            playbackRate: 1
        };

        this._loading_audio = false;
        this._audiobuffer = null; //points to AudioBuffer with the audio samples decoded
        this._audionodes = [];
        this._last_sourcenode = null; //the last AudioBufferSourceNode (there could be more if there are several sounds playing)

        this.addOutput("out", "audio");
        this.addInput("gain", "number");

        //init context
        var context = LGAudio.getAudioContext();

        //create gain node to control volume
        this.audionode = context.createGain();
        this.audionode.graphnode = this;
        this.audionode.gain.value = this.properties.gain;

        //debug
        if (this.properties.src) {
            this.loadSound(this.properties.src);
        }
    }
49015
def _volume(shape):
    """"""
    prod = 1
    for start, stop in shape:
        prod *= stop - start
    return prod
258646
def main(input_filename, format):
    

    # open the file & convert to wav
    song_data = AudioSegment.from_file(input_filename, format=format)
    song_data = song_data.set_channels(1)  # convert to mono
    wav_tmp = song_data.export(format="wav")  # write to a tmp file buffer
    wav_tmp.seek(0)
    rate, wav_data = wavfile.read(wav_tmp)

    rows_per_second = (1 + (rate - WIDTH)) // FRAME_STRIDE

    # Calculate a coarser window for matching
    window_size = (rows_per_second // TIME_STRIDE, (WIDTH // 2) // FREQ_STRIDE)
    peaks = resound.get_peaks(np.array(wav_data), window_size=window_size)

    # half width (nyquist freq) & half size (window is +/- around the middle)
    f_width = WIDTH // (2 * FREQ_STRIDE) * 2
    t_gap = 1 * rows_per_second
    t_width = 2 * rows_per_second
    fingerprints = resound.hashes(peaks, f_width=f_width, t_gap=t_gap, t_width=t_width)  # hash, offset pairs

    return fingerprints