Hi,
I wrapped the SFXR from Dr.Petter now.
(http://www.glbasic.com/pix/tnsfxr_3_.png) (http://www.glbasic.com/pix/sfxr_3_.png)
The "README.txt"
+++ SFXR port for GLBasic +++
V1.0 - added generator buttons
This file features a quick port of the famous "SFXR" program by DrPetter.
I'm not streaming the data to the sound card, but rather write a temp file and read that.
I included the Flash version of the program (as3sfxr.mht) which you can also find on:
http://www.superflashbros.net/as3sfxr/
It can copy/paste settings strings to the clipboard. You can use these strings in the one any only call:
SFXR(data$, filename$)
to generate a .wav file that you later on can read with LOADSOUND.
The data$ is a comma seperated list of these values, in this order:
waveType% [ 0] Shape of the wave (0:square, 1:saw, 2:sin or 3:noise)
attackTime [ 1] Length of the volume envelope attack (0 to 1)
sustainTime [ 2] Length of the volume envelope sustain (0 to 1)
sustainPunch [ 3] Tilts the sustain envelope for more 'pop' (0 to 1)
decayTime [ 4] Length of the volume envelope decay (yes, I know it's called release) (0 to 1)
startFrequency [ 5] Base note of the sound (0 to 1)
minFrequency [ 6] If sliding, the sound will stop at this frequency, to prevent really low notes (0 to 1)
slide [ 7] Slides the note up or down (-1 to 1)
deltaSlide [ 8] Accelerates the slide (-1 to 1)
vibratoDepth [ 9] Strength of the vibrato effect (0 to 1)
vibratoSpeed [10] Speed of the vibrato effect (i.e. frequency) (0 to 1)
changeAmount [11] Shift in note, either up or down (-1 to 1)
changeSpeed [12] How fast the note shift happens (only happens once) (0 to 1)
squareDuty [13] Controls the ratio between the up and down states of the square wave, changing the tibre (0 to 1)
dutySweep [14] Sweeps the duty up or down (-1 to 1)
repeatSpeed [15] Speed of the note repeating - certain variables are reset each time (0 to 1)
phaserOffset [16] Offsets a second copy of the wave by a small phase, changing the tibre (-1 to 1)
phaserSweep [17] Sweeps the phase up or down (-1 to 1)
lpFilterCutoff [18] Frequency at which the low-pass filter starts attenuating higher frequencies (0 to 1)
lpFilterCutoffSweep[19] Sweeps the low-pass cutoff up or down (-1 to 1)
lpFilterResonance [20] Changes the attenuation rate for the low-pass filter, changing the timbre (0 to 1)
hpFilterCutoff [21] Frequency at which the high-pass filter starts attenuating lower frequencies (0 to 1)
hpFilterCutoffSweep[22] Sweeps the high-pass cutoff up or down (-1 to 1)
Up to you is to write a GUI (DDgui) for that thing now :P
Bye,
-Gernot
26-aug-2010 www.glbasic.com
and the project:
Nice. I see it's gained a GUI since earlier today :)
I've put together some code to open .sfs files that have been saved from SFXR, but I've no idea how to implement a save/load function with the GUI at the moment. So here's the loading code, maybe someone wants to tidy it up and integrate it.
FUNCTION loadSFXR$: filename$
LOCAL data$, data1$, data2$, data3$, data4$, dataAll$
LOCAL version%, waveType%, masterVolume, startFrequency, minFrequency, slide, deltaSlide
LOCAL squareDuty, dutySweep, vibratoDepth, vibratoSpeed, unusedVibratoDelay
LOCAL attackTime, sustainTime, decayTime, sustainPunch, unusedFilterOn%
LOCAL lpFilterResonance, lpFilterCutoff, lpFilterCutoffSweep, hpFilterCutoff, hpFilterCutoffSweep
LOCAL phaserOffset, phaserSweep, repeatSpeed, changeSpeed, changeAmount
OPENFILE(1,filename$,1)
READLONG 1, version%
READLONG 1, waveType%
READSHORTIEEE 1, masterVolume
READSHORTIEEE 1, startFrequency
READSHORTIEEE 1, minFrequency
READSHORTIEEE 1, slide
READSHORTIEEE 1, deltaSlide
READSHORTIEEE 1, squareDuty
READSHORTIEEE 1, dutySweep
READSHORTIEEE 1, vibratoDepth
READSHORTIEEE 1, vibratoSpeed
READSHORTIEEE 1, unusedVibratoDelay
READSHORTIEEE 1, attackTime
READSHORTIEEE 1, sustainTime
READSHORTIEEE 1, decayTime
READSHORTIEEE 1, sustainPunch
READBYTE 1, unusedFilterOn%
READSHORTIEEE 1, lpFilterResonance
READSHORTIEEE 1, lpFilterCutoff
READSHORTIEEE 1, lpFilterCutoffSweep
READSHORTIEEE 1, hpFilterCutoff
READSHORTIEEE 1, hpFilterCutoffSweep
READSHORTIEEE 1, phaserOffset
READSHORTIEEE 1, phaserSweep
READSHORTIEEE 1, repeatSpeed
READSHORTIEEE 1, changeSpeed
READSHORTIEEE 1, changeAmount
CLOSEFILE 1
data$ = waveType% + "," + attackTime + "," + sustainTime + "," + sustainPunch + "," + decayTime
data1$= startFrequency + "," + minFrequency + "," + slide + "," + deltaSlide
data2$= vibratoDepth + "," + vibratoSpeed + "," + changeAmount + "," + changeSpeed + "," + squareDuty
data3$= dutySweep + "," + repeatSpeed + "," + phaserOffset + "," + phaserSweep + "," + lpFilterCutoff
data4$= lpFilterCutoffSweep + "," + lpFilterResonance + "," + hpFilterCutoff + "," + hpFilterCutoffSweep
dataAll$ = data$ + "," + data1$ + "," + data2$ + "," + data3$ + "," + data4$
RETURN dataAll$
ENDFUNCTION
You can put it at the end of SFXR.gbas and call it as follows: LOCAL SFXRdata$ = loadSFXR$("sample.sfs")
After that you can use: SFXR(SFXRdata$, "wavefile.wav")
To generate the WAV file
Maybe needed:
- Extand it to make "savefiles" for a sound, that you can load in! ( so you can tweek it a bit later )
- SaveWavAs! ;)
Can help if you want, i like the idea to make sounds with GLBasic :D <3
Never search the net for cool gamesounds... now i can do it by my own :D :good:
Works very well!
Excellent Bursar!
I've implemented a Load SFS button that gives you a file dialog to open an SFS file. There's no error checking, so if you open something that isn't a valid file, I'm guessing it will all go horribly wrong!
Next step is to add saving of SFS and a dialog for saving WAV files.
However I'm supposed to be 'working' so I don't know if I'll get a chance to do that during the day. If not, I'll carry on with it this evening.
next think i'd like to see added is able to use a function call in progam to to play the sound from inside setting the varuables to generate the soiund live.. as opposed to reading in .wav etc..
eg:
CreatePlaySFX(waveType%, attackTime, sustainTime, sustainPunch, decayTime, startFrequency, minFrequency, slide, deltaSlide, vibratoDepth, vibratoSpeed, changeAmount, changeSpeed, squareDuty, dutySweep, repeatSpeed, phaserOffset, phaserSweep, lpFilterCutoff, lpFilterCutoffSweep, lpFilterResonance, hpFilterCutoff, hpFilterCutoffSweep)
Straight from in my game program
this way i can have sinfle file and also maybe even able to convert some old code from my C64 ;)
Today I started designing a gui that i think is worthy for sfxr, but i see that there is already a ddgui one.
Do you guys think I should finish this one ?
[attachment deleted by admin]
I'd say continue it.. I'd also like to be able to input values directly or use the slider gadgets to change their values (if you add inputing the values please remember to check that they are within the min/max ranges)
Ketil - Looks very C64'ish, and that's a good thing :) I'd also love the ability to play sounds without having to create the WAV file first, but I guess that'll mean some upgrades to GLB in order to create sound files in memory rather than having to read them from disk. You'd also need a way of freeing that memory block afterwards, otherwise you could rapidly use up vast amounts of RAM. Guess that's no different from the current setup where you read the WAV files in though.
But with playing from RAM, you could have DATA statements for each sound effect, removing the need to distribute WAV files.
I know. But playing from RAM is very complicated, especially on iPhone platform. I'll see if I can find a way, though.
The C64 interface looks very nice.
New update will have PLATFORMINFO$("TEMP") for the temp directory at least.
Quote from: Kitty Hello on 2010-Aug-27
I know. But playing from RAM is very complicated, especially on iPhone platform. I'll see if I can find a way, though.
It doesn't have to be an either/or situation. The current system of loading WAV files can remain, you just have an extra set of commands available for creating them direct in RAM. If it created a handle in the same way that loading a WAV does, then the play back code doesn't need to change either.
Quote from: Bursar on 2010-Aug-27
Ketil - Looks very C64'ish, and that's a good thing :)
It is actually made from the original C64 charset, and the sfxr is IFLI font from a demo we made in 1991 (http://noname.c64.org/csdb/release/download.php?id=38642).
The colorscheme is from WinVICE-2.2 (c64 emulator) =D
I am also thinking about adding a box for note-values so it's possible to tune (at least the start of ) the FX to the same note/key/scale as the background music.
I think that will sound better.
If you ported the code for Coin/pickup/Explosion and such, please GIMME! :D
No. I have not ported that code, but I'll look into it.
By a quick look at the original gui, I think the "generator concept" is just locking of some parameters while others are randomized within a predefined range.
This could easily be done without touching the synth-code.
Quote from: ketil on 2010-Aug-27
... is just locking of some parameters ...
=
... is just locking of some parameters to "predefined values" ...
Yes, the code is here:
http://code.google.com/p/as3sfxr/source/browse/trunk/src/SfxrGenerator.as
Quote from: Kitty Hello on 2010-Aug-27
Yes, the code is here:
http://code.google.com/p/as3sfxr/source/browse/trunk/src/SfxrGenerator.as
Thanks :good:
That's where I got the file format for opening the .sfs files. Worth having a browse through :)
:nw: :nw: :nw:
Hi, this is for me great, can make sounds un Glbasic, is a great leap forward.
That´s works fine on Windows CE, I goes to try on Wiz and iPhone.
Best Regards, and thanks again for this great advance.
PS: I think the forum will should any threads for annuncements of some what advertising about the new things on Glbasic, whitout comments, only for when intro in Glbasic web, you know what it´s happens new on Glabsic, just I find this for casuality.
OK, updates:
Fixed a minor bug with the slider ranges for import/export.
Added the generator buttons.
Slightly better GUI - bigger buttons.
Fits a 800x480 screen -> anyone volunteers for Pandora?
The genious about SFXR is, that you can store the sound files for your game now in a simple string. I use that for SEUCK on the iPad. That way I have _one_ file for the whole project.
Watch this to want more SFXR in your projects:
http://vimeo.com/15769163 (http://vimeo.com/15769163)
Where can i find the latest copy of this? top message?
yes.
QuoteHey HK
Love the program , finally got it to work when i added ddgui to the sources!
SFXR(data$, filename$)
Im sorry to bug you about this, but really ive been trying and trying to put this command all over in the program,
and i still cant get anything to save :()
Where do i put this command?
Ok im just answering myself :S
filename$ needs to have ..a name, duurr
Thanks for the port of this, its pretty-dern-cool
Saving to and reading from an external file isn't going to suit me at all, and yet I really would like to use generated sound from SFXR in my game. I really need to be able to write to and play from RAM...
"The genious about SFXR is, that you can store the sound files for your game now in a simple string. I use that for SEUCK on the iPad. That way I have _one_ file for the whole project."
This sounds interesting but still requires that the SXFR engine interprets the string and saves output to a WAVE file which is then read in and played using PLAYSOUND, right?
Ah well if I want it bad enough I guess I'll have to figure out how to do this myself (_if_ I can). :)
Here's my synth using the wrapper.
Hey amazing work Matchy! (and what a heavy british accent :P)
On the virtual keyboars, can there be more octaves then a single 1?
You said the basic tempo is set to 4x4 (16), can that be changed? Maybe someone wants to track a waltz :S
Really great stuff, love the simple interface! Congrats! :good:
Well done, it's already looking a lot of fun. How do you handle timing as there is no interupts in GLB?
Quote from: bigsofty on 2012-Oct-15
Well done, it's already looking a lot of fun. How do you handle timing as there is no interupts in GLB?
You could set up a thread that runs in the background and reads the current timer at the start and at the end pauses for the amount of time left to make it a fixed time (i.e. if timer is at 1000 when you enter and once the thread has run its at 1005 and you want to run it every 100ms you pause for 95ms before running again).
I have used this in a program and it works very well
@Gary: That's quite an unusual approach Gary, one that has definitely got me thinking, thank you. :booze:
Genious. :nw:
I have a slew of sheet music ready for this.
I love music composition, i want a copy!
And as erico mentioned, is there an ability to use all the octaves?
8) =D :good:
http://www.glbasic.com/forum/index.php?topic=8515.msg71988#msg71988
Threading does the trick for timing but is not related to sfxr. Also it just creates short, fixed length wav file using just one sfxr command, then the wav is loaded back in realtime. Not really complex at all although directly driving the output would be better, like the real deal: :rtfm:
http://www.drpetter.se/project_musagi.html
It´s a very nice project... I think putting a more good looking UI, can be very nice... the trouble perhaps it´s in mobile devices, isn´t it?¿, I think when I try the port of gernnot, runs very Slowly for make the sounds in real time...
Nice nice!!! :booze: :booze:
Quote from: matchy on 2012-Oct-18
8) =D :good:
http://www.glbasic.com/forum/index.php?topic=8515.msg71988#msg71988
Threading does the trick for timing but is not related to sfxr. Also it just creates short, fixed length wav file using just one sfxr command, then the wav is loaded back in realtime. Not really complex at all although directly driving the output would be better, like the real deal: :rtfm:
http://www.drpetter.se/project_musagi.html
Wow, Musagi looks great.
What we really need is OpenAL buffers for better creation of the waves in real time without push/pulling off of the HD for real time filtering etc.
This looks like it performs amazingly well though. BTW how many octaves does it support?
HI Bigsofty today I found this... perhaps it´s very easy make a port... of openAL...
I never touch BlitzBasic, but I think a lot of people in the forum knows how works...
http://tools.mirage-lab.com/
The Open Al it´s a free wrapper for BlitzBasic... I don´t know if comes whit the source code.... :blink: ,
perhaps it´s possible make something whit this for GLbasic?¿...
It could be but only for Windows (and possibly Mac)
uhmmm!!! ok Sorry!!!
I think Gernot IIRC may be updating the SDL mixer to be used across all platforms, with buffer support. Even if it has no buffer support, when all the supported platforms are using the same API it's much easier to do this sort of thing via Inline.
Hi!
Any progress or method about SFXR data -> RAM?
I need to generate many sound chiptune style sounds at realtime very fast...
TIA!