Codesnippets > Inline / 3rd party

SFXR - pure GLBasic code

(1/8) > >>

Kitty Hello:
Hi,

I wrapped the SFXR from Dr.Petter now.



The "README.txt"

--- Code: (glbasic) ---+++ 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

--- End code ---

and the project:


[attachment deleted by admin]

Bursar:
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.


--- Code: (glbasic) ---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
--- End code ---

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

Schranz0r:
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:

MrTAToad:
Works very well!

Kitty Hello:
Excellent Bursar!

Navigation

[0] Message Index

[#] Next page

Go to full version