<div id="RTEContent"><span style="font-style: italic;">Michael Lange &lt;klappnase@web.de&gt;</span><span style="font-style: italic;"> wrote:</span><br style="font-style: italic;"><span style="font-style: italic;">&gt; Hello list,</span><br style="font-style: italic;"><span style="font-style: italic;">&gt;</span><br style="font-style: italic;"><span style="font-style: italic;">&gt; I am trying to draw a graphical representation of a soundfile </span><br style="font-style: italic;"><span style="font-style: italic;">&gt; (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>&nbsp;&nbsp;&nbsp; t1 = time.time()<br>&nbsp;&nbsp;&nbsp; global
 c<br>&nbsp;&nbsp;&nbsp; # remove the old shapes.<br>&nbsp;&nbsp;&nbsp; for item in c.find_all():<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c.delete(item)<br>&nbsp;&nbsp;&nbsp; # calculate a random amplitude<br>&nbsp;&nbsp;&nbsp; amplitude = random.random() * int(c.winfo_height()) / 2<br>&nbsp;&nbsp;&nbsp; points = []<br>&nbsp;&nbsp;&nbsp; for x in range(0, c.winfo_width()):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = math.sin(x * math.pi / (zoom*180)) * amplitude + int(c.winfo_height()) / 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points.append(x)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; points.append(y)<br>&nbsp;&nbsp;&nbsp; #&nbsp; now points should be of form [x0, y0, x1, y1, ...]<br>&nbsp;&nbsp;&nbsp; # not [(x0, y0), ...]<br>&nbsp;&nbsp;&nbsp; c.create_line(smooth=1, *points)<br>&nbsp;&nbsp;&nbsp; c.update_idletasks() # to draw the shapes immediately.<br>&nbsp;&nbsp;&nbsp; print 'Timing:', time.time() - t1<br>&nbsp;&nbsp;&nbsp; <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.