|
| 1 | +{{fbdoc item="title" value="sfx"}}---- |
| 2 | +Freebasic sfx library is cross-platform and comes for Windows, Linux, Dos |
| 3 | +Author: angros47 |
| 4 | +Download link: https://sourceforge.net/projects/freebasic-sfx-library/files/ |
| 5 | +Forum link: https://freebasic.net/forum/viewtopic.php?f=17&t=26256 |
| 6 | + |
| 7 | +Compile Library: all the necessary scripts are in the archive, you just need to substitute the correct path to the compiler in them |
| 8 | + |
| 9 | +A brief description of the main (not all) functions: |
| 10 | + |
| 11 | +1) ""SoundmidiSet"" - setting mode midi (needed for function PLAY) |
| 12 | +2) ""SoundSet"" - setting mode PCM sound (needed for functions SOUND , ""PlayWave"") |
| 13 | +1) PLAY - command is for playing musical notes, octave *. |
| 14 | +2) SOUND - command produces sound of a specific frequency for a specific duration |
| 15 | +3) ""LoadMidi"" - load midi from file, returns a pointer ""MidiSequence"" ptr |
| 16 | +4) ""PlayMidi"" - play midi, in parameters you need to pass pointer ""MidiSequence"" ptr |
| 17 | +5) ""CreateMidi"" - creates ""MidiSequence"" ptr, then you can use the pointer using PLAY to write data , and then save in the file |
| 18 | +6) ""SaveMidi"" - save data ""MidiSequence"" ptr in file, in format .mid |
| 19 | +7) ""LoadWave"" - loads a file into memory WAV (supported only WAVE_FORMAT_PCM), returns a pointer ""WaveHeaderType"" ptr |
| 20 | +8) ""PlayWave"" - play wav , in parameters you need to pass pointer ""WaveHeaderType"" ptr |
| 21 | + |
| 22 | +* The command PLAY can play more than one note at time: it supports chords, by grouping notes inside curly brackets, and it allows to play up to 16 channels at the same time. For more information see also command QBASICs play. |
| 23 | + |
| 24 | +Description of all functions is in the file readme.txt (in archive) |
| 25 | + |
| 26 | +{{fbdoc item="ex"}} |
| 27 | + |
| 28 | +Example Play%%(freebasic) |
| 29 | +#include "sfx.bi" |
| 30 | +#inclib "fbsfx" |
| 31 | + |
| 32 | +SoundmidiSet () |
| 33 | +PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2" |
| 34 | +%% |
| 35 | +Example Play wih thread%%(freebasic) |
| 36 | +#include "sfx.bi" |
| 37 | +#inclib "fbsfx" |
| 38 | + |
| 39 | +dim shared as any ptr mutex |
| 40 | +mutex = MutexCreate |
| 41 | + |
| 42 | +dim shared as Long iMusicExit |
| 43 | +dim as Double dTimer |
| 44 | + |
| 45 | +sub procThread(p as any ptr) |
| 46 | + SoundmidiSet () |
| 47 | + PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2" |
| 48 | + MutexLock(mutex) |
| 49 | + iMusicExit = 1 |
| 50 | + MutexUnLock(mutex) |
| 51 | +End Sub |
| 52 | + |
| 53 | +dTimer = timer |
| 54 | +threadcreate(@procThread) |
| 55 | + |
| 56 | +do |
| 57 | + ? timer - dTimer |
| 58 | + MutexLock(mutex) |
| 59 | + if iMusicExit then |
| 60 | + exit do |
| 61 | + EndIf |
| 62 | + MutexUnLock(mutex) |
| 63 | +Loop |
| 64 | +%% |
| 65 | +Example ""CreateMidi"", ""SaveMidi"" |
| 66 | +%%(freebasic) |
| 67 | +#include "sfx.bi" |
| 68 | +#inclib "fbsfx" |
| 69 | + |
| 70 | +SoundmidiSet () |
| 71 | +dim as any ptr Midi=CreateMidi() |
| 72 | +PLAY Midi,"a4e4g4a4g4e4c2f4f4f2d4d4d2" |
| 73 | +SaveMidi "music.mid", Midi |
| 74 | +%% |
| 75 | +Example ""LoadMidi"", ""PlayMidi"" |
| 76 | +%%(freebasic) |
| 77 | +#include "sfx.bi" |
| 78 | +#inclib "fbsfx" |
| 79 | + |
| 80 | +SoundmidiSet () |
| 81 | +dim as any ptr Midi=LoadMidi("music.mid") |
| 82 | +PlayMidi(Midi, 1) |
| 83 | +sleep |
| 84 | +%% |
| 85 | +Example Sound |
| 86 | +%%(freebasic) |
| 87 | +#include "sfx.bi" |
| 88 | +#inclib "fbsfx" |
| 89 | + |
| 90 | +SoundSet (44100,1,16) |
| 91 | +sound SineWave(2000), 1 ' sine 2 kHz |
| 92 | +sound NoiseWave(), 1 ' noise |
| 93 | +sleep |
| 94 | +%% |
| 95 | +Example ""LoadWave"", ""PlayWave"" |
| 96 | +%%(freebasic) |
| 97 | +#include "sfx.bi" |
| 98 | +#inclib "fbsfx" |
| 99 | + |
| 100 | +dim as WaveHeaderType ptr pWave |
| 101 | +SoundSet (44100,2,16) |
| 102 | +pWave = LoadWave("1.wav") |
| 103 | +if pWave = 0 then |
| 104 | + print "pWave = 0" : end |
| 105 | +end if |
| 106 | +PlayWave(pWave) |
| 107 | +sleep |
| 108 | +%% |
| 109 | + |
| 110 | +{{fbdoc item="back" value="ExtLibTOC|External Library Table of Contents"}} |
0 commit comments