<div id="RTEContent"><span style="font-style: italic;">Michael Lange <klappnase@web.de></span><span style="font-style: italic;"> wrote:</span><br style="font-style: italic;"><span style="font-style: italic;">> Hello list,</span><br style="font-style: italic;"><span style="font-style: italic;">></span><br style="font-style: italic;"><span style="font-style: italic;">> I am trying to draw a graphical representation of a soundfile </span><br style="font-style: italic;"><span style="font-style: italic;">> (a.k.a. waveform) onto a Canvas,<br></span><br>You have two problems<br>1. Reading a sound file<br>2. drawing the waveform<br><br>I solved the 2nd problem only. This is a code that draws a random waveform.<br>---------------------------------------------------------------------------------<br>from Tkinter import *<br>import random<br>import math<br>import time<br><br>def fun(zoom=.1):<br> t1 = time.time()<br> global
c<br> # remove the old shapes.<br> for item in c.find_all():<br> c.delete(item)<br> # calculate a random amplitude<br> amplitude = random.random() * int(c.winfo_height()) / 2<br> points = []<br> for x in range(0, c.winfo_width()):<br> y = math.sin(x * math.pi / (zoom*180)) * amplitude + int(c.winfo_height()) / 2<br> points.append(x)<br> points.append(y)<br> # now points should be of form [x0, y0, x1, y1, ...]<br> # not [(x0, y0), ...]<br> c.create_line(smooth=1, *points)<br> c.update_idletasks() # to draw the shapes immediately.<br> print 'Timing:', time.time() - t1<br> <br>root = Tk()<br>c =
Canvas(root, bg='beige')<br>c.pack(expand=1, fill=BOTH)<br>Button(root, text='Do waveform', command=fun).pack()<br>mainloop()<br>---------------------------------------------------------------------------------<br>It took 0.0310001373291 second to execute fun() in full-screen mode. <br>I don't think customizing this will be a problem, but you know you can always ask.<br><br><span style="font-style: italic;"></span><br></div><p>
        
                <hr size=1>Yahoo! Photos<br>
Got holiday prints? <a href="http://us.rd.yahoo.com/mail_us/taglines/holidayprints/*http://pa.yahoo.com/*http://us.rd.yahoo.com/mail_us/taglines/photos/evt=38089/*http://pg.photos.yahoo.com/ph//print_splash">See all the ways</a> to get quality prints in your hands ASAP.