Sound functions

Blitz3D Forums/Blitz3D Programming/Sound functions

Doggie(Posted 2011) [#1]
Anybody have any good sound functions for playing wav files?
I need something to play several concurrent wavs and alter their pitch
so a basic wav file becomes an instrument.
I looked in the archives but not exactly what I need.
Any help appreciated. I always thought sound was Blitz weakest area and always wondered why nothing was ever done to improve it.
Thanks


Abrexxes(Posted 2011) [#2]
Use "Channelpitch" but this will load any "instrument" into the ram. Else you must use an engine like (see signature). There you can load a sample (wav) one time into the ram and play it XXX times with pitch in realtime using channels.

bye

Last edited 2011


Doggie(Posted 2011) [#3]
Thanks. I'll check into that engine and see if I can come up with anything
useful.


Axel Wheeler(Posted 2011) [#4]
Actually, I'd stick to trying to use native commands (channelpitch) until and unless you find that you really can't use it to do what you want. Notice that even Abrexxes, who makes Bass Studio, hinted as much. Avoid implementing additional tools and libraries into a project unless you really need them, because the learning curve and all the other issues that come up with these libraries will distract you from your main goal. Just my 2 cents.

As soon as you're done solving the immediate problem, then download Bass Studio and experiment away when you're not under pressure.

As far as ChannelPitch is concerned, keep the following in mind:

An octave is simply double the pitch of the next lower octave. The following code is untested but should give some idea of how to create an array of the fequencies of the keyboard. The equation(s) are based on this WikiPedia article:

http://en.wikipedia.org/wiki/Equal_temperament

Dim pitch(88)

Function SetupPitches()
	;From WikiPedia: the width of a semitone, i.e. the frequency ratio of the interval between two adjacent notes, is the twelfth root of two:
	Local r#=2.0^(1.0/12.0);1.0594630943593 I think?? untested...
	Local note
	
	For note=1 To  88 ; keys of the keyboard
		pitch(note)=440.0*r^(note-49)
	Next
End Function



Now you need to know whch key and position you are working in and be able to convert that into a note number above. For example, in the major scale you have:

if k=the note of a major key

Do - Tonic (1) (n=k)
Re - Supertonic (2) (n=k+2)
Me - Mediant (3) (n=k+4)
Fa - Subdominant (4) (n=k+5)
So - Dominant (5) (n=k+7)
La - Submediant (6) (n=k+9)
Ti - Leading Tone (7) (n=k+11)
Do - Tonic of next octave (n=k+12)

Note that you would have to divide the result by the pitch of the sound file you are loading from disk (alas, there is no CreateSound() command) to get the final value to feed to ChannelPitch.

Also note that none of this is tested and is just my thoughts to help you proceed. Good luck Doggie!


Doggie(Posted 2011) [#5]
Thanks. It's a little intimidating at the moment since there just aren't enough builtin commands to adequately make music apps in B3D. I realize Mark originally made B3D with emphasis on 3D games and all but there's so much more that B3d could be that it just seems a shame it's a done deal.
Most of y'all are programmers and can use blitz max and the new one I forget it's name but for me, it's way too confusing. I think there'd still be somewhat of a market for someone to make language/command addon packs for B3D. Sound,Music,Character Animation, Animated Sprites(even if I tryed to tackle that one myself)

Anyways....


Axel Wheeler(Posted 2011) [#6]
Agreed. I don't know whether Mark realized it but he created in B3D not just a 3D game system but the best traditional Basic language system around. I think the user base became anyone who wanted to use just Basic (not OO) to do whatever they wanted, but with the power to do 3D, 2D, etc. and do it really well.

Now, I have heard that BlitzMax is not really OO in the sense of "Everything is an object", it's just has objects for those who want them. For example, it's possible that much B3D code (non-3d stuff) would still work with minor modifications. If so, I will probably go there too at some point. However, 3D stuff requires choosing an add-on and learning about all it's issues. So you have to worry about how add-on A works with add-on B and so on. I'm sure it's awesome, just a new learning curve I don't really have time to go to just yet.

Also, I can't help but feel that if I'm going to go through the learning curve of BMax, why not just go a bit further and get Visual Basic.net? The Express edition is free (in fact I have it! and the C# one), and there's a potential job (real money!) at the end of that learning curve. I've put some C# under my belt, but it's very steep. I'm tackling C++ right now because I've noticed that most really strong programmers seem to have started with it.

Keep in mind though that B3D is still an awesome engine and there are lots of existing add-ons in the archives and forums.


Axel Wheeler(Posted 2011) [#7]
Hate to bump this (a week old isn't too far down the list anyway these days... :) but does anyone know of good sites for generic instrument "notes" in some common format (wav, mpg, etc.)? Not music per se, but for exampe, a piano middle c, a flute middle c, etc. that can be used to generate procedural music that would actually sound good. Even using the randomizer...?


Rob the Great(Posted 2011) [#8]
Check out this site:

http://theremin.music.uiowa.edu/MIS.html

It gives you .aiff samples for typical orchestral instruments (piano, flute, cello, trumpet, ect.). It provides different notes at different dynamic levels (pp-ff), but you will definately need to break them apart into loopable regions and start-end regions.

They're free for download, so it might be a great starting place.


Axel Wheeler(Posted 2011) [#9]
Awesome. Thanks RtG!