#!/usr/bin/python """Computes an inverse fourier transform, i.e. converts a bitmap into frequency/time. (C) 2002 by Sami Kyöstilä, Joonas Kerttula.""" xres = 64 yres = 64 # must be 64 picture = "in.raw" output = "out.wav" base = 2048 # base frequency, i.e. the bottom of the image on the spectrogram scale = 700 # the size of the image volume = 0.07 invert = 0 # should the picture be inverted? import wave import sys import math import time def sample(amp): return chr(int((amp+1.0)*127)) i = open(picture, "rb") image = [] for y in range(0,yres): row = [] str = "" for x in range(0,xres): p = i.read(1) if not p: raise UserWarning("Kuva on rikki! (%d, %d)" % (x,y)) if invert: row.append(1.0-float(ord(p)/256.0)) else: row.append(float(ord(p)/256.0)) # str+=(chr(ord('A') + (ord(p)/8))) image.append(row) # print str[:70] i.close() f = wave.open(output, "wb") f.setnchannels(1) f.setsampwidth(1) f.setframerate(11025) t = 0 r = range(0,yres) start = time.time() while t1.0: amp=1.0 amp *= 0.3 f.writeframes(sample(amp)) t+=1.0/(11025.0*4) if time.time()>start+1: start=time.time() p = t / (xres/64.0) print "[" + "=" * int(p*40) + ">" + "." * int((1-p)*40) + "] ", print "%.1f%%" % (p*100) f.close() print "Valamis!"