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 / Create sounds - with no media.

Author
Message
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2005 02:08 Edited at: 20th Aug 2005 23:11
<Updated 20/8/05> This project has really come to life with thanks to the DBP community - thanks to Tommy S, Green Gandalf, Xtom, Raven and Lampton Worm who have all contributed to the creation of this project. Here's the latest version:


Remember computers like the Spectrum, Commodor 64, BBC micro, Acorn Electron .....? They all had commands that would generate beeps and sounds with no media files. Now so does Dark Basic - with this 'createsound' function, which uses real time fm-synthesis. There are lots of parameters to change, so the variety of sounds you can make is huge.

The function call is:

createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)

The first five parameters, and the last one, must have non-zero values, the rest can be left at zero. Here's the function, with some example code so you can see how to use the function, and the kind of sounds you can make.



To make life even easier, this program (thanks Xtom et al) will allow you to adjust the different parameters in real time, and save your createsound() effect to use in your code - or you can save your sounds in wav format:

http://forum.thegamecreators.com/xt/xt_apollo_download.php?i=509254

Just save your sound effect, then open it in notepad, and the createsound() function call can be copied and pasted into your code.

Also include in the download is a help file with suggested ranges and values for the parameters.

Enjoy.

Attachments

Login to view attachments
Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 21st Feb 2005 03:26
That's simply awesome dude!


Check out PanzerGames at: http://www.freewebs.com/panzergames
æ ø å
sadsack
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 21st Feb 2005 03:43
I like it
TEH_CODERER
20
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 21st Feb 2005 04:48
You keep coming up with works of genius! Nice one Ric!

[url]andrewneale2004@yahoo.com[/url]
http://www.elbsoftware.tk
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2005 06:37 Edited at: 21st Feb 2005 06:38
Thanks for the comments - by the way, perhaps I should explain what each parameter does incase anyone hasn't come across this kind of stuff before:

name$: Can be any name you like so long as it is different from any other ones you've created. Must be in "quotes".

soundnumber: This is any number which is used when using the 'play sound [soundnumber]' command

frequency#: In Hertz, this gives the notes pitch (try about 600)

length#: In milliseconds - so 1000 will give a note of one second

loudness#: try values up to about 8000

bend#: this will bend the pitch of the note down(+) or up(-). Use small values like 0.01

decay#: This will make the sound fade out - small numbers again like 0.2

vibratospeed#: This will set the speed of the vibrato. This is where a notes pitch wobbles up and down. Values around 0.05

vibratodepth#: This will set how much the vibrato wobbles up and down - try around 0.2

tremelospeed#: Sets the speed of tremelo - this is where the volume wobbles louder and quieter - try around 0.05

tremelodepth#: Sets the amount of tremelo - needs to be large as human ears are very poor at detecting changes in loudness over a small range - try around 1800.

I'm hoping that a small library of sounds will build up here that people can use for no-media code.


Coding Fodder
20
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 21st Feb 2005 10:33
nice ric, I was thinking of making functions like this be one of the coding challenges. Should I ever win...

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Feb 2005 11:10
nifty. why didn't you just right the data like this?



"eureka" - Archimedes
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2005 11:43
Quote: "why didn't you just right the data like this?"




err..........


Mattman
20
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 21st Feb 2005 14:45
Holy cow, this is so sweet. The idea's are flooding my head

Something to doing?
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 21st Feb 2005 18:43 Edited at: 21st Feb 2005 18:44
Wow, this takes me back years !
Nice work!
squirrel 890
19
Years of Service
User Offline
Joined: 18th Jan 2005
Location: aaaaaaaaaaaaaaaaaaaaa i remeber i forgot
Posted: 24th Feb 2005 05:55
this is awsome.....
what to say, what to say
Three Score
19
Years of Service
User Offline
Joined: 18th Jun 2004
Location: behind you
Posted: 27th Feb 2005 14:23
nice job
so this wav thing is finally done
HOORAY i think i may use this in quite a few things

now you just need a savesound and extras like that

quit hiting the computer; computers can only do what they are told so we must be telling them to do wrong things
Cian Rice
19
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 27th Feb 2005 20:56
Awesome. It reminds me of Captain Cosmo or whatever his names was (Captain Comic???) I don't know...

Have a heart and join my message board.And now my messageboards work again!Woot!
BiggAdd
Retired Moderator
19
Years of Service
User Offline
Joined: 6th Aug 2004
Location: != null
Posted: 27th Feb 2005 21:52
GENIUS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

dj chainz
19
Years of Service
User Offline
Joined: 25th Sep 2004
Location: England
Posted: 4th Mar 2005 02:50
Quote: "now you just need a savesound"


duh... read the code - it saves the wavs itself anyhow!

btw, nice code. a dj could do great things with it... great things

I am the lead programmer at red spark studios
I also have a blog on how to make a game enginehttp://dbgame.blogspot.com
http://www.brazilianhotties.tk
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 4th Mar 2005 12:05 Edited at: 10th Mar 2005 07:25
A few more sounds have been added to the code at the top


Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 14th Mar 2005 07:45
THATS WICKED!!!!!!!!!!!!!!!!!!!!!

AMD Athlon XP 3000+, S3 Deltachrome s8, 512 PC3200 RAM, 160 GB HD
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 16th Mar 2005 09:04
Amazing Ric, damn amazing.


"Lets migrate like bricks" - Me
Physics coder
19
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 20th Mar 2005 12:00
Awesome, here I changed it a bit if you want to simulate dial tones in your programs/games:


-----------------------------------
HP Laptop, P4 3.0Ghz, 1GB RAM, 128MB Geforce dedicated video RAM, 60GB Hard Drive, 17" bright wide screen.
A.K.A "The Uber Computer"
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 20th Mar 2005 12:47 Edited at: 20th Mar 2005 12:48
lmao - that's cool!


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 20th Mar 2005 22:05 Edited at: 21st Mar 2005 09:59
I've changed it so you can play a tune on it using keys 1 to 8. I've modified the actual function as well as a bit of code outside it for playing the sounds.


To play a chord you need to play it slightly arpeggiated though, because keyboards(computer keyboards) don't like 3 keys being pressed at the same time


"Lets migrate like bricks" - Me
Digital Dragon
19
Years of Service
User Offline
Joined: 17th Dec 2004
Location: ...
Posted: 20th Mar 2005 22:50
lol that is wkd

Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Mar 2005 01:49
Nice one Benjamin! You could have used keystate to allow multiple keypresses I guess.

Could be turned into a cute little no-media tracker.


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2005 02:58
Quote: "You could have used keystate to allow multiple keypresses I guess."

I tried that but to no avail... unless I did something wrong.

Quote: "Could be turned into a cute little no-media tracker."

Thats what I'm thinking


"Lets migrate like bricks" - Me
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2005 04:02 Edited at: 21st Mar 2005 05:32
Hey Ric, look what I made!

Make sure you listen to it until it stops..



Also you can replace the createsound function with this function for a heavier tone:




"Lets migrate like bricks" - Me
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Mar 2005 05:56
Excellent! I'm still trying to figure out how you've managed to get something that sounds like a square wave using your 'thing' variable! Also, I'm wondering how easy it would be to get a tune playing with other things going on in a program (like a game), and still make sure the tune keeps the same tempo ...... guess it would need a pretty solid timing routine.


RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 21st Mar 2005 06:05 Edited at: 21st Mar 2005 06:06
Could you combine the note wav files in sequence to create a music wav file somehow (this stuff is beyond me - at least until I take some time to dig in)? Then you could let DBPro handle the timing.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2005 06:14 Edited at: 21st Mar 2005 06:31
The idea for that sound I thought of ages ago, when I just wanted a simple kind of sound to generate with sound memblocks in DBC. Basically, thing# is increased until it gets to a certain amount, then gets put back at 0. It increments by pitch# which as you probably guessed is what controls the pitch. The faster the variable reaches its peak, the higher the pitch is. I'm not entirely sure why it works like it does, I just know it works. I think its actually a saw tooth sound, because this is what it would look like:



I have created a sort of triangle wave sound, but for some reason I'm getting wierd blips and I'm not sure why:



Quote: "Could you combine the note wav files in sequence to create a music wav file somehow (this stuff is beyond me - at least until I take some time to dig in)? Then you could let DBPro handle the timing."

Yes its possible, although personally I have no idea how you would go about combining the notes


"Lets migrate like bricks" - Me

Attachments

Login to view attachments
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Mar 2005 08:33
Quote: "I think its actually a saw tooth sound"


Ah - that makes sense.

Quote: "Could you combine the note wav files in sequence to create a music wav file "


Tommy S, who's code mine was based on, tried something like that, but it was horribly slow creating the wav file, and kind of defeats the point of instant, no media music. I think Van B wrote a tracker in DB - I wonder what his timing routine was like.


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2005 09:08
If I just knew the technique needed to combine two sounds then I would be able to make my own routine..


"Lets migrate like bricks" - Me
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Mar 2005 09:42
Why do you need to combine sounds? You mean as a single wav?


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2005 09:44
Yeah I was thinking from the rendering point of view. I do have an idea, although I think it would be pretty tricky.


"Lets migrate like bricks" - Me
Tallun
19
Years of Service
User Offline
Joined: 30th Oct 2004
Location: Existence
Posted: 1st Apr 2005 01:37
Awesome! This could be very useful! I've made four sounds that're in the code box.

On a stormy night, a long-forgotten secret is uncovered, and the ancient deities are rediscovered... The Dark Jewel (Work in Progress)
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 1st Apr 2005 05:03
Quote: "I've made four sounds that're in the code box"


Just blown up my speakers, eardrums and brain.




Tallun
19
Years of Service
User Offline
Joined: 30th Oct 2004
Location: Existence
Posted: 1st Apr 2005 09:06
Maybe I should've put a warning. Ah well.

On a stormy night, a long-forgotten secret is uncovered, and the ancient deities are rediscovered... The Dark Jewel (Work in Progress)
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 16th Apr 2005 23:28
Handy for police/firetruck/ambulance sirens...or any sirens for that matter.

NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 18th Apr 2005 09:14 Edited at: 2nd May 2005 12:02
Pretty neat, for trumpet like sounds, use triangle wave form.
For flute like sounds, try sinewaves
For synth like sounds, try square waves
Of course, do not make the wave forms all that exact. Now I wish I could get you to work on getting the midi dll working with dark basic pro. (update it's now working)
Almost all soundcards have 128 general midi instruments on board, and they will sound as good as your sounds. What I am thinking is you might be able to layer your sounds with midi sounds, and get something even more interesting, plus its a bit more easy to get real musical instrument sounds from midi. Also your sounds would make a good drum kit. For no media midi output, you just need to get the midiOutShortMsg command in the dll winmm.dll to work. You will find
that dll is in your windows system folder (c:windows/system or if you have xp its in windows/system32
To get a note to play, send a midi out short message of channel 1,note,velocity. Channel=144 for channel 1 note=60 for middle c
velocity=127 max usually 64 is more typical setting. To pick what instrument will play send 192 decimal, followed by decimal number of instrument. 1=piano on most keyboards/soundcards, but yours might start numbering at 0 for piano. Then wait length of note. To play chords, start a note on one channel playing, then start a note on another channel playing, wait lenght of chord.
To shut off notes, just send came command you used to play the note, but set velocity to 0. (not the standard way to do it, but is used freguenctly, and all sequencers and midi files support this method.)
Documentation for the dll is at www.mircsoft.com use search window and do search for winmm.dll or midiOutShortMsg.
The dll has a lot more commands in it.
For a good tutorial, do a web search on midi tutorial, and pick the borg/~glatt site from the list.
NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 19th Apr 2005 05:10
Here is a keyboard note frequency chart that will help users of createsound get musical note frequencys set correct for keyboards.
http://www.phys.unsw.edu.au/~jw/notes.html
NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 30th Apr 2005 07:14 Edited at: 2nd May 2005 11:47
Ric,
I would like you to tell us the recommended range of each varible in your program. I re-wrote it several ways that set the varibles at random, but I have no idea of what the max range I should allow them to be?
The way I would like to see this done is have it create the 17 or so button playable sounds at random, allow the user to play them, and maybe click a button for each one they liked, then it would write the list of ones they liked into a text file. Maybe you could set up a web page for that text file to be posted at.
That way sounds would be collected as people play with it, Then after so many times, a message pops up asking them to email the list to you, so you can post the best ones.

Sometimes some of the sounds did not play at all, guess the combination of variables was not good.
lol, you should of seen the pile of sound files on my drive when I let my name it program create the file names. That got to be too much a problem,and i had to delete them. Need to save these sounds as text settings to keep them more compact, and allow easy cut and paste appending to the collection.
Baggers
19
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 30th Apr 2005 21:29
Though all your posting is valuable and interesting please use the edit button !

Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 1st May 2005 20:29
@NoteJam: Thanks for the info. The code is presented for you to tweak as you desire - so if you have ideas about how to develop it, then please do. You probably know more about the midi dll than I do. Suitable values for variables are given further up this page, but if you want more precise ranges then you'll have to do some more testing.

NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 2nd May 2005 04:29
Baggers,
I would be happy to use the edit key, if I had one for old messages, but no edit button appears for old messages with the aol browser.
Guess I need to hit return more frequently, and not put blank
lines between my text. I appoligize for how my posts appear.
I do not understand what is the cause of it, or how to correct
any old posts. Maybe if someone notified the forum programmer,
that aol browser does not get an edit button, I would end up with
a button some day?
NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 2nd May 2005 04:56
How when I have no edit button with aol browser? Please notify programmer of forum that aol browser has no edit button.
I would do it, but I do not who it is.
All I get is a type in box at end of messages, and I see code buttons, and other buttons by users messages, but no edit button.
Kohaku
19
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 2nd May 2005 09:13 Edited at: 2nd May 2005 12:59
As shameful as saying this may be, I can see an edit button with the AOL browser. You are looking under your avatar right? Just beside where it says 'back to top'.

You are not alone.
NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 2nd May 2005 12:06
Ok, have managed to edit message a bit. I can not see very well, I was looking for a button, not a word, sorry guys. That blue line of text is a bit of a blur for me. Thanks to those that pointed out where it was at fro me.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 3rd May 2005 03:07
it doesnt work for me...is it for dbpro?

"Well, if he dies, it'll teach him not to do it again." - Me
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 3rd May 2005 06:12
It is for dbpro. What are you using?

DBAlex
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: United Kingdom
Posted: 3rd May 2005 06:13
Doesnt work for me either...Im on AC97 Sound...Should that matter?




AMD 64 3000 + 512mb RAM + 80GB HD + Radeon 9600se 128mb
NoteJam
19
Years of Service
User Offline
Joined: 11th Apr 2005
Location:
Posted: 3rd May 2005 08:57
Everyone, if it did not work for you, you probably need to adjust your mixer. To do that, in xp click blue button at bottom right of screen on tool bar, to show more icons. Then find your volume icon.
Think left click it but experiment. Then you can adjust wave volume, overall volume, and un mute if it was set to mute.
For windows98 there is a yellow speaker volume icon on tool bar beside your clock, you might have to scroll around a bit or slide the panel back for it to show up. Do the same thing there. It should work with dark basic pro ok.
Oneka
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location: Hampton,VA
Posted: 6th May 2005 02:23
now thats a pretty creative function right there....good job!

Making better games everday!
Oh yeah and just so you know its Oh-nek-a not One-ka!

Login to post a reply

Server time is: 2024-04-26 19:18:25
Your offset time is: 2024-04-26 19:18:25