def playAudioCoordinates(x, y, screenWidth, screenHeight, screenMinPos, detectBrightness=True,blurFactor=0): """ play audio coordinates: - left to right adjusting the volume between left and right speakers - top to bottom adjusts the pitch of the sound - brightness adjusts the volume of the sound Coordinates (x, y) are absolute, and can be negative. """ # make relative to (0,0) and positive x = x - screenMinPos.x y = y - screenMinPos.y minPitch=config.conf['mouse']['audioCoordinates_minPitch'] maxPitch=config.conf['mouse']['audioCoordinates_maxPitch'] curPitch=minPitch+((maxPitch-minPitch)*((screenHeight-y)/float(screenHeight))) if detectBrightness: startX=min(max(x-blurFactor,0),screenWidth)+screenMinPos.x startY=min(max(y-blurFactor,0),screenHeight)+screenMinPos.y width=min(blurFactor+1,screenWidth) height=min(blurFactor+1,screenHeight) grey=screenBitmap.rgbPixelBrightness(scrBmpObj.captureImage( startX, startY, width, height)[0][0]) brightness=grey/255.0 minBrightness=config.conf['mouse']['audioCoordinates_minVolume'] maxBrightness=config.conf['mouse']['audioCoordinates_maxVolume'] brightness=(brightness*(maxBrightness-minBrightness))+minBrightness else: brightness=config.conf['mouse']['audioCoordinates_maxVolume'] leftVolume=int((85*((screenWidth-float(x))/screenWidth))*brightness) rightVolume=int((85*(float(x)/screenWidth))*brightness) tones.beep(curPitch,40,left=leftVolume,right=rightVolume)
def playAudioCoordinates(x, y, screenWidth, screenHeight, detectBrightness=True, blurFactor=0): minPitch = config.conf['mouse']['audioCoordinates_minPitch'] maxPitch = config.conf['mouse']['audioCoordinates_maxPitch'] curPitch = minPitch + ((maxPitch - minPitch) * ((screenHeight - y) / float(screenHeight))) if detectBrightness: startX = min(max(x - blurFactor, 0), screenWidth) width = min((x + blurFactor + 1) - startX, screenWidth) startY = min(max(y - blurFactor, 0), screenHeight) height = min((y + blurFactor + 1) - startY, screenHeight) grey = screenBitmap.rgbPixelBrightness( scrBmpObj.captureImage(startX, startY, width, height)[0][0]) brightness = grey / 255.0 minBrightness = config.conf['mouse']['audioCoordinates_minVolume'] maxBrightness = config.conf['mouse']['audioCoordinates_maxVolume'] brightness = (brightness * (maxBrightness - minBrightness)) + minBrightness else: brightness = config.conf['mouse']['audioCoordinates_maxVolume'] leftVolume = int( (85 * ((screenWidth - float(x)) / screenWidth)) * brightness) rightVolume = int((85 * (float(x) / screenWidth)) * brightness) tones.beep(curPitch, 40, left=leftVolume, right=rightVolume)
def _playWholeImage(self, imageData): self.lavPanner.azimuth.value = self.lavPanner.azimuth.value self.lavPanner.azimuth.linear_ramp_to_value(fadeLength, 0) self.lavPanner.mul.value = self.lavPanner.mul.value self.lavPanner.mul.linear_ramp_to_value(fadeLength, 0) totalVolume = 0 for y in xrange(self.height): index = -1 - y lavWave, lavPanner = self.lavWaves[index] left = 0 right = 0 brightest = 0 for x in xrange(self.width): rRatio = x / self.width lRatio = 1 - rRatio px = rgbPixelBrightness(imageData[y][x]) if self.reverseBrightness: px = maxBrightness - px brightest = max(brightest, px) left += px * lRatio right += px * rRatio volume = brightest / maxBrightness lavWave.mul.value = lavWave.mul.value lavWave.mul.linear_ramp_to_value(fadeLength, volume) totalVolume += volume waveAngle = ((right - left) / max(left, right)) * 90 if ( left or right) else 0 lavPanner.azimuth.value = lavPanner.azimuth.value lavPanner.azimuth.linear_ramp_to_value(fadeLength, waveAngle) volumeRatio = 0.075 if totalVolume <= 1.0 else 0.075 / totalVolume for y in xrange(self.height): lavWave, lavPanner = self.lavWaves[y] lavPanner.mul.value = lavPanner.mul.value lavPanner.mul.linear_ramp_to_value(fadeLength, volumeRatio)
def _sweepImage(self, imageData, delay, duration, count): self.lavPanner.mul.value = self.lavPanner.mul.value self.lavPanner.mul.set(delay, 1) self.lavPanner.azimuth.value = self.lavPanner.azimuth.value self.lavPanner.azimuth.set(delay, -90) offset = delay for c in xrange(count): self.lavPanner.azimuth.set(offset, -90) offset += sweepGap self.lavPanner.azimuth.envelope(time=offset, duration=duration, values=list(xrange(-90, 91))) offset += duration for y in xrange(self.height): index = -1 - y lavWave, lavPanner = self.lavWaves[index] lavPanner.mul.value = lavPanner.mul.value lavPanner.mul.set(delay, 0) envelopeValues = [0] for x in xrange(self.width): px = rgbPixelBrightness(imageData[y][x]) / maxBrightness if self.reverseBrightness: px = 1 - px envelopeValues.append(px * 0.075) envelopeValues.append(0) lavWave.mul.value = lavWave.mul.value lavWave.mul.set(delay, 0) offset = delay for c in xrange(count): lavWave.mul.set(offset, 0) offset += sweepGap lavWave.mul.envelope(time=offset, duration=duration, values=envelopeValues) offset += duration
def _playWholeImage(self, imageData): self.lavPanner.azimuth.value = 0 self.lavPanner.mul.value = 0 for y in xrange(self.height): index = -1 - y lavWave, lavPanner = self.lavWaves[index] lavPanner.mul.value = 1 left = 0 right = 0 brightest = 0 for x in xrange(self.width): rRatio = x / self.width lRatio = 1 - rRatio px = rgbPixelBrightness(imageData[y][x]) if self.reverseBrightness: px = maxBrightness - px brightest = max(brightest, px) left += px * lRatio right += px * rRatio lavWave.mul.value = lavWave.mul.value lavWave.mul.value = (brightest / maxBrightness) / self.height if left or right: lavPanner.azimuth.value = ((right - left) / max(left, right)) * 90 else: lavPanner.azimuth.value = 0
def _playWholeImage(self, imageData): self.lavPanner.azimuth.value = 0 self.lavPanner.mul.value = 0 for y in xrange(self.height): index = -1 - y lavWave, lavPanner = self.lavWaves[index] lavPanner.mul.value = 1 left = 0 right = 0 brightest = 0 for x in xrange(self.width): rRatio = x / self.width lRatio = 1 - rRatio px = rgbPixelBrightness(imageData[y][x]) if self.reverseBrightness: px = maxBrightness - px brightest = max(brightest, px) left += px * lRatio right += px * rRatio lavWave.mul.value = lavWave.mul.value lavWave.mul.value = (brightest / maxBrightness) / self.height if left or right: lavPanner.azimuth.value = ( (right - left) / max(left, right)) * 90 else: lavPanner.azimuth.value = 0
def playAudioCoordinates(x, y, screenWidth, screenHeight, detectBrightness=True,blurFactor=0): minPitch=config.conf['mouse']['audioCoordinates_minPitch'] maxPitch=config.conf['mouse']['audioCoordinates_maxPitch'] curPitch=minPitch+((maxPitch-minPitch)*((screenHeight-y)/float(screenHeight))) if detectBrightness: startX=min(max(x-blurFactor,0),screenWidth) width=min((x+blurFactor+1)-startX,screenWidth) startY=min(max(y-blurFactor,0),screenHeight) height=min((y+blurFactor+1)-startY,screenHeight) grey=screenBitmap.rgbPixelBrightness(scrBmpObj.captureImage(startX,startY,width,height)[0][0]) brightness=grey/255.0 minBrightness=config.conf['mouse']['audioCoordinates_minVolume'] maxBrightness=config.conf['mouse']['audioCoordinates_maxVolume'] brightness=(brightness*(maxBrightness-minBrightness))+minBrightness else: brightness=config.conf['mouse']['audioCoordinates_maxVolume'] leftVolume=int((85*((screenWidth-float(x))/screenWidth))*brightness) rightVolume=int((85*(float(x)/screenWidth))*brightness) tones.beep(curPitch,40,left=leftVolume,right=rightVolume)
def _sweepImage(self, imageData, duration, count): offset = 0 totalVolumes = [0] * self.width for y in xrange(self.height): index = -1 - y lavWave, lavPanner = self.lavWaves[index] lavPanner.mul = 0 lavWave.mul = 0 envelopeValues = [0] for x in xrange(self.width): px = rgbPixelBrightness(imageData[y][x]) if self.reverseBrightness: px = maxBrightness - px volume = px / maxBrightness envelopeValues.append(volume) envelopeValues.append(0) totalVolumes[x] += volume offset = 0 for c in xrange(count): lavWave.mul.set(offset, 0) offset += sweepGap lavWave.mul.envelope(time=offset, duration=duration, values=envelopeValues) offset += duration for index, totalVolume in enumerate(totalVolumes): totalVolumes[ index] = 0.075 if totalVolume <= 1.0 else 0.075 / totalVolume self.lavPanner.azimuth = -90 self.lavPanner.mul = 0 offset = 0 for c in xrange(count): self.lavPanner.azimuth.set(offset, -90) self.lavPanner.mul.set(offset, 0) offset += sweepGap self.lavPanner.azimuth.envelope(time=offset, duration=duration, values=list(xrange(-90, 91))) self.lavPanner.mul.envelope(time=offset, duration=duration, values=totalVolumes) offset += duration