sfx
Freebasic sfx library is cross-platform and comes for Windows, Linux, Dos
Author: angros47
Download link: https://sourceforge.net/projects/freebasic-sfx-library/files/
Forum link: https://freebasic.net/forum/viewtopic.php?f=17&t=26256
Compile Library: all the necessary scripts are in the archive, you just need to substitute the correct path to the compiler in them
A brief description of the main (not all) functions:
1) SoundmidiSet - setting mode midi (needed for function PLAY)
2) SoundSet - setting mode PCM sound (needed for functions SOUND , PlayWave)
1) PLAY - command is for playing musical notes, octave *.
2) SOUND - command produces sound of a specific frequency for a specific duration
3) LoadMidi - load midi from file, returns a pointer MidiSequence ptr
4) PlayMidi - play midi, in parameters you need to pass pointer MidiSequence ptr
5) CreateMidi - creates MidiSequence ptr, then you can use the pointer using PLAY to write data , and then save in the file
6) SaveMidi - save data MidiSequence ptr in file, in format .mid
7) LoadWave - loads a file into memory WAV (supported only WAVE_FORMAT_PCM), returns a pointer WaveHeaderType ptr
8) PlayWave - play wav , in parameters you need to pass pointer WaveHeaderType ptr
* 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.
Description of all functions is in the file readme.txt (in archive)
Example
Example Play`
#include "sfx.bi"
#inclib "fbsfx"
SoundmidiSet ()
PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2"
`
Example Play wih thread`
#include "sfx.bi"
#inclib "fbsfx"
Dim Shared As Any Ptr mutex
mutex = MutexCreate
Dim Shared As Long iMusicExit
Dim As Double dTimer
Sub procThread(p As Any Ptr)
SoundmidiSet ()
PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2"
MutexLock(mutex)
iMusicExit = 1
MutexUnlock(mutex)
End Sub
dTimer = Timer
ThreadCreate(@procThread)
Do
? Timer - dTimer
MutexLock(mutex)
If iMusicExit Then
Exit Do
EndIf
MutexUnlock(mutex)
Loop
`
Example CreateMidi, SaveMidi
`
#include "sfx.bi"
#inclib "fbsfx"
SoundmidiSet ()
Dim As Any Ptr Midi=CreateMidi()
PLAY Midi,"a4e4g4a4g4e4c2f4f4f2d4d4d2"
SaveMidi "music.mid", Midi
`
Example LoadMidi, PlayMidi
`
#include "sfx.bi"
#inclib "fbsfx"
SoundmidiSet ()
Dim As Any Ptr Midi=LoadMidi("music.mid")
PlayMidi(Midi, 1)
Sleep
`
Example Sound
`
#include "sfx.bi"
#inclib "fbsfx"
SoundSet (44100,1,16)
sound SineWave(2000), 1 ' sine 2 kHz
sound NoiseWave(), 1 ' noise
Sleep
`
Example LoadWave, PlayWave
`
#include "sfx.bi"
#inclib "fbsfx"
Dim As WaveHeaderType Ptr pWave
SoundSet (44100,2,16)
pWave = LoadWave("1.wav")
If pWave = 0 Then
Print "pWave = 0" : End
End If
PlayWave(pWave)
Sleep
`