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.

AppGameKit Classic Chat / Is there any way to generate sound digitally without a sound file?

Author
Message
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 9th Dec 2017 10:58 Edited at: 9th Dec 2017 22:00
I have AGK2 and want to know if I can generate sounds in my program without the use of sound files. In essence, the sounds would be 'digitally generated' with numbers, or such.

Anyone know how, or have a code example?

Thanks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Dec 2017 13:34 Edited at: 9th Dec 2017 13:37
yes, with memblock commands.
a wave file is just a header with description , then comes the data. and the header have the length of data.
CreateMemblockFromSound ( soundID )
CreateMemblock( memID, size )
CreateSoundFromMemblock ( memID )
https://www.appgamekit.com/documentation/Reference/Memblock/CreateSoundFromMemblock.htm

there exist also a other thread in agk forum where is more description.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 9th Dec 2017 22:06 Edited at: 9th Dec 2017 22:52
Could anyone supply an actual code example?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Dec 2017 01:56
i made you an example of 16 bit stereo sound
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Dec 2017 02:03 Edited at: 10th Dec 2017 02:05
The help says it all, but you have to pick your way through it to assemble the required data.

First, create a memblock using createMemBlock() of the required size then:

The first 2 bytes of the memlbock store the number of channels (1 or 2 supported)

so

SetMemBlockShort(MemID,0,1) // e.g. mono. Use SetMemblockShort cos it needs 2 bytes. This is set at offset 0
SetMemBlockShort(memID,2,16) // next 2 bytes for 16 bit. This is set at offset 2
and next 4 for samples per sec
etc. etc. according to the help.

When you have populated the memblock with the data you want, call CreateSoundFromMemblock( memID )

[edit] markus!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Dec 2017 03:09
btw the memblock wave header in agk is different from original wave file.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Dec 2017 00:11
Do a search on the forum, someone's done this before in both DBP and AppGameKit (I think)

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 16th Dec 2017 11:55
Thanks, very useful example for generating in code sounds.
I guess the same could be used for textures but not sure what the format would be.
puzzler2018
User Banned
Posted: 16th Dec 2017 12:14
Here is my texture creator



to use, just call

textureimage = createtexture(32,32, makecolor(255,255,0) ,255)


D
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 16th Dec 2017 13:25 Edited at: 16th Dec 2017 13:34
Excellent example Marcus! Thanks

If anyone wants to hear what my TV station sounds like, then change line 40 from ...

w=w+(360.0 / 44100.0) * Hz

to

w=w+(random(1,360) / 44100.0) * Hz


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 16th Dec 2017 13:44 Edited at: 16th Dec 2017 13:45
Pretty cool stuff! Thanks for sharing puzzler2018.
Immediately gave it a try. Very flexible and gives quite a nice effect.
(This actually deserves it's own thread, in case someone else is looking).



Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 16th Dec 2017 13:56
Hehehe, static sound- nice one Conjured.
Was giving it the good old C64 treatment already, experimenting with different tone heights and cut offs.
Samples are ok, but I've really missed fiddling with computer generated audio.


puzzler2018
User Banned
Posted: 16th Dec 2017 13:57
Glad you found it useful

D
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Dec 2017 15:03
@Conjured Entertainment
nice, also up and down vary the Hz give good sound effects.
i made wind,motor,heli,random,burner,beeps,brum sounds



AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
puzzler2018
User Banned
Posted: 16th Dec 2017 15:24
Cool

Ill have a dabble to try create a piano keys so can do a piano training sim - maybe

Nice work
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 16th Dec 2017 16:04 Edited at: 16th Dec 2017 16:06
Quote: "I've really missed fiddling with computer generated audio."

I miss the old Commodore days too. (Vic-20)

Quote: "nice, also up and down vary the Hz give good sound effects.
i made wind,motor,heli,random,burner,beeps,brum sounds"

Sweet, generating sounds in AppGameKit is definitely something I will be experimenting with in the near future.

I am still playing with the text to speech at the moment, but I will be seeing if I can combine the two for some nice two way radio communications in game.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
puzzler2018
User Banned
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Dec 2017 15:14 Edited at: 27th Dec 2017 04:29
Here is a link to a site I found that has some very good basic information about sound...

https://www.codeproject.com/articles/15786/fundamentals-of-sound-how-to-make-music-out-of-not

EDIT
Quote: "also up and down vary the Hz give good sound effects"

Okay, so I know I won't be doing any lengthy songs, and I know there are better ways to execute this, but I played with Markus' Example and got a jingle.

I was thinking I would only do sound effects and not music, but I am definitely going to start experimenting with this aspect of AppGameKit .


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 29th Dec 2017 15:55
Both Audio and Texture procedural generation will be useful thanks guys
-EdzUp

Login to post a reply

Server time is: 2024-04-20 17:40:21
Your offset time is: 2024-04-20 17:40:21