Hiya guys.
I've been playing around with Purebasic for close to two years now, tinkering here and there. So, as a 2D-game advocate, remembering with fond memories such awesome games as those that appeared on my trusty old Commodore 64... I have come to this...
I've been looking for, and with no success, a way to recreate sounds like you'd hear from a real C64. No one seems to do a decent sound effects library that I can find. Some support basic wave-forms, but not the ability to shape them a lot, or do the craziest of things with them! So, I'd be forced to look for wav files from the net. I have WAV files! Its really about project size, and I think sound could be a lot less....
What annoys me most, is how quickly a project can get bloated with wav files for sound, and how people seem to go with MP3's for music. Oh no, thats not for me! I can live with good old MOD music from the Amiga days, - but as for sound effects, its been gnawing at me for years, and I mean years now..
To the point then!
I've got some success in creating different basic sound shapes, such as sine, square, and triangular shaped noises (saw tooth). The hard one, is noise! I've got my very own noise generator working now - and so, what was once a simple project where I can create wav files to store these sound effects that will be made from these basic sound shapes - has now turned a possible corner with your help, into something more...
I'm quite happy that my code will generate sound on-the-fly, so to speak, but I'm looking for a way to make this a self contained library, or at least a big include file!
What I want to try and do, is create sound every 60th of a second - I understand about the idea of a sound buffer etc - thats fine. So, what I want, is some help in how I make a sound buffer, or buffers, and use them to create the illusion of one very long, ever lasting sound, as opposed to the idea of creating a huge bank of sound effects when a program starts. (Thats my current idea).
I'd like to take it a step further. In saying all that, do you think its worth the effort? I mean, I'm keeping sound to a really low sample rate (10k a sec!!) - and so, one whole minute of sound effects is only 600k of memory. Thats just a drop in an ocean of so many PC's of today!
Anyway - to give you an idea of what I'm shooting for (and looking to surpass by a long way) look at the "Shoot'Em Up Construction Kit" on the commodore 64. www.c64.com (just the sound editor!!!)
For what I'm aiming more towards, try playing Hunter's Moon (on the Commodore 64). I'm looking to achieve this, and perhaps the flexibility to achieve even more?
Am I crazy? Am I sane? let me know, oh mighty and all powerful PB community!
By the way, for your information, I used to use Blitz Basic, but switched, for a number of reasons. Firstly, that PureBasic allowed me to fix a refresh rate of a game. Blitz didn't. don't know if it does now?
Secondly, it seemed to be a lot more powerful in its ability to mix 2D / 3D. I'd go so far as to say it game better options for the 2D anyway, - PB's way of handing Sprites is a breath of fresh air!
There's more to the story - but not for this post.
PB Rulez! Now, come on guys - help!
Sound's difficult?
Don't get too excited because my opinions are those of a newbie - just a few weeks older than yours!
It is really a question of what your program is. Is it a sound creation program or a game?
Your text suggests it is a game. If it is that concentrate on the game and use one of the many programs (such as Audacity) to create the sound effects you require.
WAVs do take space. On the other hand OGG don't and you are not going to face possible legal issues which you might with MP3. So create your sounds and convert them to OGG using something like dpPowerAmp.
One small problem is that OGG sound under PureBasic is somewhat erratic. However it works very well in the recently launched Beta version. Whether your timescale will allow that version to filter through to a stable version I obviously cannot tell.
If timescale is critical the Audiere library works well but is very convoluted.
If like me a library to you has up to now been something that you add as a single Include at the top of the program, and then arm yourself with a printout of the functions structure, you will find the Audiere heavy going. Ov:Lib is another one which is much simpler to use (Windows platform only).
I think I have rambled on a bit. However my basic suggestion is - concentrate on the job. The data (sound samples in your case) can be prepared without re-inventing thw wheel.
It is really a question of what your program is. Is it a sound creation program or a game?
Your text suggests it is a game. If it is that concentrate on the game and use one of the many programs (such as Audacity) to create the sound effects you require.
WAVs do take space. On the other hand OGG don't and you are not going to face possible legal issues which you might with MP3. So create your sounds and convert them to OGG using something like dpPowerAmp.
One small problem is that OGG sound under PureBasic is somewhat erratic. However it works very well in the recently launched Beta version. Whether your timescale will allow that version to filter through to a stable version I obviously cannot tell.
If timescale is critical the Audiere library works well but is very convoluted.
If like me a library to you has up to now been something that you add as a single Include at the top of the program, and then arm yourself with a printout of the functions structure, you will find the Audiere heavy going. Ov:Lib is another one which is much simpler to use (Windows platform only).
I think I have rambled on a bit. However my basic suggestion is - concentrate on the job. The data (sound samples in your case) can be prepared without re-inventing thw wheel.
Regards,
Ernest
Ernest
You may wanna look/search around for a SID library to use.
And then find a SID tracker/mod program.
You could then simply put all the music (and sound effects)
into a folder, and these SID modules only take a few KB if even that in some cases.
SID was the name of the soundprocessor in the C64,
Various players has been made and is still popular,
one I remember was called PlaySID I think.
It should exist in lib and dll forms too.
No clue what to suggest as far as a SID tracker/editor goes tough.
But there is guaranteed at least one program out there,
cause SID tunes are still being made by oldschool music fans
And then find a SID tracker/mod program.
You could then simply put all the music (and sound effects)
into a folder, and these SID modules only take a few KB if even that in some cases.
SID was the name of the soundprocessor in the C64,
Various players has been made and is still popular,
one I remember was called PlaySID I think.
It should exist in lib and dll forms too.
No clue what to suggest as far as a SID tracker/editor goes tough.
But there is guaranteed at least one program out there,
cause SID tunes are still being made by oldschool music fans

-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
I made something similar some time ago, but stopped the project.
It should become a very extended version of old QB's Play-command inclusive organ and other instruments, all calculated via maths.
There is quite a good result to listen to here:
http://www.2mal2mal.de/public/purebasic ... sAgoEx.mp3
This song fits into less than 3kB Text (uncompressed) and creates 1:38 minutes fine music
But the compile-time of this song tooks a lot time, because in the middle-part I used an organ with 1sec-sustain, which is calculated and mixed sample by sample for each tone - but sounds nice. So you shouldn't use such a long sustain for realtime-calculation.
Here's the source, perhaps you want to have a look. The Organ is simply made by some sine-wave-octaves:
http://www.2mal2mal.de/public/purebasic/libs/
(QBPlay...)
[edit]
Here's another nice (but very short) song by bobobo for QBPlay: just copy&paste&run if you have QBPlay installed.
[/edit]
It should become a very extended version of old QB's Play-command inclusive organ and other instruments, all calculated via maths.
There is quite a good result to listen to here:
http://www.2mal2mal.de/public/purebasic ... sAgoEx.mp3
This song fits into less than 3kB Text (uncompressed) and creates 1:38 minutes fine music

But the compile-time of this song tooks a lot time, because in the middle-part I used an organ with 1sec-sustain, which is calculated and mixed sample by sample for each tone - but sounds nice. So you shouldn't use such a long sustain for realtime-calculation.
Here's the source, perhaps you want to have a look. The Organ is simply made by some sine-wave-octaves:
http://www.2mal2mal.de/public/purebasic/libs/
(QBPlay...)
[edit]
Here's another nice (but very short) song by bobobo for QBPlay: just copy&paste&run if you have QBPlay installed.
Code: Select all
InitSound()
;/ example by bobobo
*q1.QBSong = QBPlay("o3 ML l16 ccp ccp ccp ccp cgp ggp gcp ccp ccp ccp ccp ccp cgp ggp gce T80 g<cp8", 2, 100, 0, #QBPlay_Tone_Sin,10, 10)
*q2.QBSong = QBPlay("o4 ML l16 cep gep cep gep gfg fdp fef ecp cep gep cep gep gfg fde dce T80 g<cp8", 2, 100, 0, #QBPlay_Tone_Sin, 10, 10)
*q3.QBSong = QBPlay("o1 ML l16 c<c>c c<c>c c<c>c c<c>c c<g>g g<g>g g<g>g c<c>c c<c>c c<c>c c<c>c c<c>c c<g>g g<g>g g<c>c T80 c<c4", 2, 100, 0, #QBPlay_Tone_Tan, 10, 10)
*q4.QBSong = QBPlay("o2 ML l16 c>c>c o2 c>c>c o2 c>c>c o2 c>c>c o2 c>g<g o2 g>g>g o2 g>g>g o2 c>c>c o2 c>c>c o2 c>c>c o2 c>c>c o2 c>c>g o2 c>g>g o2 g>g>g o2 g>c>c o2 T80 MLc", 2, 100, 0, #QBPlay_Tone_Organ, 10, 10)
QBPlay_Mix(*q1, *q2, 0)
QBPlay_Mix(*q1, *q3, 0)
QBPlay_Mix(*q1, *q4, 0)
QBPlay_Start(*q1, 0)
Delay(*q1\lengthMs)
filename.s = SaveFileRequester("Save it (or cancel)", "C:\QBPLAY_SuO.wav", "*.wav|*.wav", 0)
If filename
If QBPlay_WriteToFile(*q1, filename) = 0
MessageRequester("", "Couldn't save file to disc.", 0)
EndIf
EndIf
QBPlay_Free(*q1)
%1>>1+1*1/1-1!1|1&1<<$1=1
Re: Sound's difficult?
How about running the audio stuff in a second thread and have a fifo for audio commands that you feed from the main program. That way the second thread can keep the accurate timing and the first thread can just jam commands into the fifo whenever it feels like. Have a couple fifos perhaps, one (or more) for background music, and one for sound effects. (so the effects can happen right away instead of waiting for the background music). The audio thread could just mix the stuff together and play away.bumblebee wrote:What I want to try and do, is create sound every 60th of a second - I understand about the idea of a sound buffer etc - thats fine. So, what I want, is some help in how I make a sound buffer, or buffers, and use them to create the illusion of one very long, ever lasting sound, as opposed to the idea of creating a huge bank of sound effects when a program starts. (Thats my current idea).
Froggerprogger : that tune kicks butt.
In reply to all your help.
Wow! Thanks for the pointers to QBPlay, I could learn something from that, I think.
I'm just amazed you went as far as you did with QBPlay, without a noise generator. Thats what my efforts have focussed around - for things like drum sounds, or explosions in a game, a decent noise generator is needed!
As for the idea of having a C64 SID emulator playing my Sound effects - thats a great idea! really, I love the idea! But its not what I want to achieve.
My motivation is filesize. You know, the demos I've seen written in Purebasic are truly awesome examples of how 2D should be done! Problem is, they want you to download a couple of MP3's etc as part of the demo - and that kills filesize. Instead of using a mod tune, and making the filesize much more downloadable - especially for the poor modem users!
This piece of code, when compiled, is only 8k! - and for it to generate 44k of sound, is pretty awesome if you ask me. All I need, is to figure out the best way to take it forwards to make a program that generates all your sound effects for your next best game - as its being loaded. QBplay might help me ? Thanks again for that!
Anyway -
As for the Threading idea - that sounds great, and ideally what I'd like to do if not too difficult??? I've no idea how - and still, I'd have to generate some sound, or a partial of it, every 60th of a second, and play that - which in my mind means I need 2 buffers to write to -- one to play a current sound, and another to switch to at the right time to carry on playing the next. I believe the best way to do this, is to take one long piece of memory, say 1 second of sound - generate it up to say, 1 second ahead (way more than I need) - and have the sound loop. So, as long as I stay say half a second ahead of whats playing, and I loop too, writing to the beginning of the sound, as its playing the end of the sound - means I can make a small piece of memory play a continuously changing sound.
See where I'm coming from?
Any help on this idea would be fantastic!
Once I upload my code somewhere, I'll share it with you guys, so you can see what I'm doing!
I'm just amazed you went as far as you did with QBPlay, without a noise generator. Thats what my efforts have focussed around - for things like drum sounds, or explosions in a game, a decent noise generator is needed!
As for the idea of having a C64 SID emulator playing my Sound effects - thats a great idea! really, I love the idea! But its not what I want to achieve.
My motivation is filesize. You know, the demos I've seen written in Purebasic are truly awesome examples of how 2D should be done! Problem is, they want you to download a couple of MP3's etc as part of the demo - and that kills filesize. Instead of using a mod tune, and making the filesize much more downloadable - especially for the poor modem users!
This piece of code, when compiled, is only 8k! - and for it to generate 44k of sound, is pretty awesome if you ask me. All I need, is to figure out the best way to take it forwards to make a program that generates all your sound effects for your next best game - as its being loaded. QBplay might help me ? Thanks again for that!
Anyway -
As for the Threading idea - that sounds great, and ideally what I'd like to do if not too difficult??? I've no idea how - and still, I'd have to generate some sound, or a partial of it, every 60th of a second, and play that - which in my mind means I need 2 buffers to write to -- one to play a current sound, and another to switch to at the right time to carry on playing the next. I believe the best way to do this, is to take one long piece of memory, say 1 second of sound - generate it up to say, 1 second ahead (way more than I need) - and have the sound loop. So, as long as I stay say half a second ahead of whats playing, and I loop too, writing to the beginning of the sound, as its playing the end of the sound - means I can make a small piece of memory play a continuously changing sound.
See where I'm coming from?
Any help on this idea would be fantastic!
Once I upload my code somewhere, I'll share it with you guys, so you can see what I'm doing!
Re: In reply to all your help.
Yes, basically a circular buffer.bumblebee wrote: [...]
So, as long as I stay say half a second ahead of whats playing, and I loop too, writing to the beginning of the sound, as its playing the end of the sound - means I can make a small piece of memory play a continuously changing sound.
You may want to do some in-depth research on "audio streaming" because that's
what you're looking for.

If you don't have to have this running on Linux, I'd personally recommend
you DirectSound. The SDK already comes with a basic streaming sample and
the web is full of further information. DirectSound even already provides you
with notification mechanisms, e.g. "Hey, I played the buffer halfway through!
What's next? C'mon, please send me your data!"

Sounds good? It is!

Last edited by traumatic on Fri Feb 25, 2005 8:36 pm, edited 1 time in total.
Good programmers don't comment their code. It was hard to write, should be hard to read.
euh, think so 
it's interesting indeed, but isn't it going to eat up huge amounts of processing power?

it's interesting indeed, but isn't it going to eat up huge amounts of processing power?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Enthusiast
- Posts: 423
- Joined: Fri Apr 25, 2003 5:22 pm
- Contact:
Yes a noise generator would be fine. At least to create some drums.
At that point I stopped QBPlay, but it's on the ToDo-list for this life.
Further a MIDIToQBPlayString-Converter would be fine to make composing more comfortable.
To create your own sounddata, you have more than one possibility:
You could allocate some memory and write a WAV-header and sounddata to it and then use CatchSound().
Or you could use double buffering as you explained, and realtime-fill it, but then you have to choose an audiodriver. DirectSound ? For DirectSound Danilo posted an example for using buffers:
viewtopic.php?t=8786
Or you could use external audioengines, i think most of them will support realtime-audio-buffers. fmod does it via a callback-function, but it is an external dll with ~160kB.
At that point I stopped QBPlay, but it's on the ToDo-list for this life.

Further a MIDIToQBPlayString-Converter would be fine to make composing more comfortable.
To create your own sounddata, you have more than one possibility:
You could allocate some memory and write a WAV-header and sounddata to it and then use CatchSound().
Or you could use double buffering as you explained, and realtime-fill it, but then you have to choose an audiodriver. DirectSound ? For DirectSound Danilo posted an example for using buffers:
viewtopic.php?t=8786
Or you could use external audioengines, i think most of them will support realtime-audio-buffers. fmod does it via a callback-function, but it is an external dll with ~160kB.
%1>>1+1*1/1-1!1|1&1<<$1=1