Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Drawing a Sound From a Memblock

Author
Message
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 12th Mar 2003 01:33
Not sure if this is usefull to anyone, but here is a function that will draw a wav sound from an existing memblock.

It's only the mono version for now, I'm having a little problem with reading stereo sample data.
Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 12th Mar 2003 01:33


Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 12th Mar 2003 03:08
Thanks for making this.

One thing, though -- it seems like the waveforms display closer to the middle when they should be more distant from the middle and vise versa. See pic:



If you can fix that, this will be truly excellent.

Surrealist writing toy -- http://www.iconpoet.com
klukk
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Iceland
Posted: 12th Mar 2003 03:48
@Steverino: The code works correcly, at least for me. If you look at the code, you see that it can only display wave files that are mono, and have =>8 bits<= per sample.

Actually the code flips the sound around the x axis, but it'a no problem to rectify that problem

- If nothing sticks to teflon, then how do they make teflon stick to the pan???
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 12th Mar 2003 03:56
Don't worry I'm getting there. I'm working on a function that will show both mono or stereo

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 12th Mar 2003 04:09
You're right -- with an 8-bit sample, it looks more the way it ought to:



Brilliant job, Easily Confused!

Surrealist writing toy -- http://www.iconpoet.com
klukk
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Iceland
Posted: 12th Mar 2003 04:25
Erm, how will you determine if the soundfile in the memblock is mono or stereo? As far as I can see, then there is no info in the memblock that you can use to determine that.

Detecting the bits per sample of the sound is however easy. Just paste this in a good place in your code:



- If nothing sticks to teflon, then how do they make teflon stick to the pan???
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 12th Mar 2003 04:38
I thought something on the lines of:

bitspersec = memblock dword(block,0)
frequency = memblock dword(block,4)
if bitspersec/8 = frequency then mono = 1 else mono = 0

I'm not totaly sure if this is the correct method.

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
klukk
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Iceland
Posted: 12th Mar 2003 04:44
Hmmm, won't work. It will tell you if the sample is 8 bit or 16 bit (or 24,32 bit etc), but has nothing to do with the sample being mono/stereo.

- If nothing sticks to teflon, then how do they make teflon stick to the pan???
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 12th Mar 2003 05:20
Dang! Also when sending a stereo sound into a memblock you can't Make Sound From Memblock to another sound because when you play it, it sounds lousy. All that stereo data is turned into mono data. Double Dang!

So your right, there's no way for DBPro to tell if a loaded sound is mono or stereo.

erm.... when is patch 7 comming out hehe

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 12th Mar 2003 14:31
Yeah, what a drag..

xxxpetratxxx
B. R. W
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 13th Mar 2003 00:05
I can't get the waveform to draw correctly when it's a 16-bit sample. Has anyone got that figured out?

Surrealist writing toy -- http://www.iconpoet.com
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 03:28
I think this will do it:



I hope

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 03:30
Oh! Remove those commented yscale# lines in the middle, I forgot to take those out.

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 03:32
Scratch that! Use this one.



Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 04:06
Hmmm, a minor scaling problem when viewing 16 bit samples.

Change:

v = v / 128

to:

v = v / 256

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 13th Mar 2003 04:08
Man, I would never have figured that out. I do get part of the waveform falling outside the box, though:



I tried adding
if y < top then y = top
if y > bottom then y = bottom
after the line where y is defined, but it just looked clipped.

I think the numbers 32678 should really be 32768, but that doesn't change the look at all. The 8-bit samples display entirely within the box.

Surrealist writing toy -- http://www.iconpoet.com
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 04:16
Whoops! Your right, got my 6's and 7's the wrong way around



Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 13th Mar 2003 04:17
...which you solved while I was describing the problem.

My apologies for being all needy, but I have a hard time getting my brain around memblocks.

Thanks again.

Surrealist writing toy -- http://www.iconpoet.com
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 13th Mar 2003 04:19
hehe Your welcome

Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 22nd Mar 2003 17:42
Update: I was getting a crash from certain 16-bit samples on the line

v = 0x8000 - memblock word(block, startpos)

It cleared up when I changed the line

if startpos > endpos then exitfunction

to

if startpos => endpos
line lastx,lasty,right,centerline
exitfunction
endif

There's probably a better way to do this, but that's what worked for my not-terribly-critical application. Without the "line lastx,lasty,right,centerline", the sample stops before it hits the end of its box.

____________________________________________
Surrealist writing toy -- http://www.iconpoet.com
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Mar 2003 22:03
I use some useful code Van-B used in VSD tracker, it's really easy

You are the th person to view this signature.
Programmers don't die, they just Gosub without return....
PiratSS
22
Years of Service
User Offline
Joined: 18th Oct 2002
Location:
Posted: 23rd Mar 2003 21:50
That's really good!

Keep up the good work,

maby you can do some effects in 2D/3D, that would be nice to see.

Cheers.

1PH J00 C4|\| U|\|dER$T@|\||) +|-|I$, j00 |-|@\/3 4lR3Ady w0|\|! - p1r@T$$
Easily Confused
22
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 29th Mar 2003 00:11
Ok, I've updated the function. The coding is a bit more efficent in places and also should be a little more stable than before (fingers crossed). I think the samples now draw the right way up, not that is critical.

Also I've added an extra draw mode, bar, which draws the sound more complete than lines or dots, well, I think it looks better




...and a small demo showing the new draw mode.



Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.
Steverino
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United States
Posted: 29th Mar 2003 06:06
Excellent -- the samples that were giving it a problem earlier are now loading without complaint. And they are right way up.

I like the new bar draw mode, but I'm staying with line mode for Lip Sync Lab just because I'm used to it.

____________________________________________
Surrealist writing toy -- http://www.iconpoet.com
rockfistus
21
Years of Service
User Offline
Joined: 31st Mar 2003
Location:
Posted: 4th Apr 2003 07:34
Stereo Samples have two waveforms(one for each channel) so maybe there's a way to check for that?

Login to post a reply

Server time is: 2024-11-24 04:27:07
Your offset time is: 2024-11-24 04:27:07