Erick I had a look at this site and tried to incorporate it in my project... I tried to increase the sample ranges but this changed the look of the waveform, i.e it just draws a coloured rectangle. Then i revert back to my original example i have posted to you. The code i used seem to work well with AIFF files, but not with *.mp3 and .*wav files...another side effect is that the files with a time duration of +/- 1 min loads forever; some taking as long as minute to load and drawn as a waveform. Pleasse help me...
PS: I wonder if it is possible to e-mail my project to you for review... Thanks PeterLG ----- Original Message ----- From: "E. Tejkowski" <[EMAIL PROTECTED]> To: "REALbasic NUG" <[email protected]> Sent: Saturday, August 12, 2006 8:33 AM Subject: Re: How to dsiplay a waveform in a canvas control > You load the sound data into memory. Then you loop through the data > finding the individual values in it that you care about. (you'll > probably end up skipping over some values as you scan the data for > speed's sake). Then, it depends on what the format of the audio data > is as to how you handle its drawing. For example, if its 8 bit data, > then you may have samples with an amplitude of 0-256 (AIFF). Some 8 > bit formats have values of -128 to 128 (WAVE). 16 bit audio will have > values much larger values for the positive extreme.(0-65536, to be > exact). > > Next, you create a picture object and match up the dimensions of that > picture to the amplitude extremes of the data. So, say you have sound > data that with amplitudes from -128 to 128. Align this with your > midpoint on the picture. If the Canvas is 256 pixels tall, then 128 > is the midpoint vertically. This corresponds to the zero amp value in > the audio data. Because both the picture and the sound data in this > example has a "height" of 256 (ok, I'm fudging by one, but you get > the idea), you can simply add 128 to the audio amplitude and use that > as your y portion of a pixel coordinate. The x axis corresponds to time. > > If the amp range is larger, then you have to squish it so it fits in > the dimensions of your picture. So, if you have a 16 bit sample with > an amplitude of 12345, and you know the midpoint is 32,768 (half of > 65536), then you know that 12345 falls below the midline. You also > know that it falls 18.84% of the way up the y-axis. (12345/65536). > So, multiple the height of the picture by 0.1884 to find the y- > coordinate. The x position will be based on which sample you are > reading in (ie time). Again, you may need to skip over a certain > number of samples each iteration to make the speed reasonable. > (44,100 samples per second is a lot of samples to loop over). For > most waveforms, you won't notice any visual difference when you skip > samples, as long as the step size doesn't get too large. > > hth, > Erick > > On Aug 11, 2006, at 2:54 PM, Ayden wrote: > > Thanks for the reply Greg. I have read the information referred to, > > but I am > > more interrested in the graphical diplay of the waveform data... > > Any ideas > > on drawing it on a canvas control? > _______________________________________________ > Unsubscribe or switch delivery mode: > <http://www.realsoftware.com/support/listmanager/> > > Search the archives of this list here: > <http://support.realsoftware.com/listarchives/lists.html> > > _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives of this list here: <http://support.realsoftware.com/listarchives/lists.html>
