Audio library for FreeBasic - Features

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
NorbyDroid
Posts: 93
Joined: May 21, 2016 22:55

Re: Audio library for FreeBasic - Features

Post by NorbyDroid »

Is it possible to do Sound(Duration, Frequency, Volume) using this sfx? I am tryin to add a sound command to a project I am workin on.

I tried to run buildlinux.sh and it cannot find ../bin/fbc:
norby@norby-xps:~/Projects/TI_System/sfx$ bash ./buildlinux.sh
build cpu layer
./buildlinux.sh: line 3: ../bin/fbc: No such file or directory
norby@norby-xps:~/Projects/TI_System/sfx$
angros47
Posts: 2409
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

The directory "sfx" is supposed to be inside the FreeBasic directory when you run the building script, otherwise you have to modify the script itself for it to work.

And it is possible to implement a sound command like you want, you need to also include the waveform (likely you want to use a PulseWave, if you plan to simulate the sound produced by pc speaker).
SMC
Posts: 33
Joined: Feb 22, 2012 4:05

Re: Audio library for FreeBasic - Features

Post by SMC »

I'm getting an error 'GLIBC_2.33' and 'GLIBC_2.34' not found. Any idea how I can fix this? Thanks. I'm using linux Mint 20 with an Ubuntu 20 base.
angros47
Posts: 2409
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

I tried to compile it on Ubuntu 24, I didn't encounter that issue, so I can't help.

Also, I noticed another issue: the soft synthesis for Midi doesn't work, with FreeBasic 1.10.1, unless in the file amidi.bas I either modify the line :

Code: Select all

		if thread_handle=0 then thread_handle = threadcreate( @_FMSoundThread)
to

Code: Select all

		if thread_handle=0 then thread_handle = threadcreate( @_FMSoundThread,0,1000000)
or replace:

Code: Select all

sub _FMSoundThread(ByVal userdata As Any Ptr )
	dim as short Buffer(4096*8)
with:

Code: Select all

dim shared as short Buffer(4096*8)
sub _FMSoundThread(ByVal userdata As Any Ptr )
Basically, the stack space in threads by default is insufficient. But, according to documentation ( https://www.freebasic.net/wiki/KeyPgThreadcreate ), it shouldn't happen:
On some systems (Linux), the stack automatically grows beyond stack_size if more space is needed; on others (Win32), this is the fixed maximum allowed. Behavior is undefined when more stack is used than the reserved size on systems where stacks are not able to grow.
Why does it happen?
adeyblue
Posts: 356
Joined: Nov 07, 2019 20:08

Re: Audio library for FreeBasic - Features

Post by adeyblue »

Why does it happen?
Someone misread or misunderstood the man page for pthread_attr_setstacksize. That's been on the wiki page since the dawn of time so who knows what the man page said then, but now it says:
A thread's stack size is fixed at the time of thread creation.
Only the main thread can dynamically grow its stack.
Using 8MB as an example, what 'dynamically grow its stack' seems to mean is 'uses guard pages to allocate it on demand a page at a time' whereas, by default, those created with pthread_create allocate the entire 8MB as read-write up front. It doesn't mean 'has an infinitely-large stack' and as it says, wouldn't apply to threadcreated threads if it did.

Godbolt/compiler explorer lets you run apps not just look at the disassembly, so here's something based on sample code in the man page that dumps the memory map and causes stack overflows (click the Executor tab at the top to see the output)
https://godbolt.org/#z:OYLghAFBqRAWIDGB ... QSQNg4gQAA
SMC
Posts: 33
Joined: Feb 22, 2012 4:05

Re: Audio library for FreeBasic - Features

Post by SMC »

I guess my distro is just too old, and needs an update. Thanks.
SMC
Posts: 33
Joined: Feb 22, 2012 4:05

Re: Audio library for FreeBasic - Features

Post by SMC »

I got things working after updating to the latest version of linux mint. I can't play midi's or use play, however, without getting a coredump and segfault error. Both of these examples, from the documentation wiki, fail.

Code: Select all

#include "sfx.bi"
#inclib "fbsfx"

SoundmidiSet ()
PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2"

Code: Select all

#include "sfx.bi"
#inclib "fbsfx"

SoundmidiSet ()
Dim As Any Ptr Midi=LoadMidi("music.mid")
PlayMidi(Midi, 1)
Sleep
The "Example Sound", and "LoadWave, PlayWave" examples work perfectly. The only compiler switches I'm using are -p and -mt.
fbc -mt -p ~/Documents/code/freebasic/fbsfx/sfx file.bas
Roland Chastain
Posts: 1022
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Audio library for FreeBasic - Features

Post by Roland Chastain »

SMC wrote: Feb 15, 2025 3:20I can't play midi's or use play, however, without getting a coredump and segfault error.
Same for me on Linux Mageia.
angros47
Posts: 2409
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

Should be fixed in the last version
SMC
Posts: 33
Joined: Feb 22, 2012 4:05

Re: Audio library for FreeBasic - Features

Post by SMC »

angros47 wrote: Jun 03, 2025 8:21 Should be fixed in the last version
Awesome, thanks. Everything seems to be working right now. Just one question, is there a limit on midi files? I tried loading a 20KB file and it still core dumped on me. Other, shorter midis, worked great.

Here is the midi I tried to download and play: https://freemidis.net/John_Denver/Annies_Song/

Also, how are you building the Dos library? Are you doing it from windows, or are you using a Dos with extended filenames?
RetardedAndProud
Posts: 35
Joined: Jun 09, 2024 18:26

Re: Audio library for FreeBasic - Features

Post by RetardedAndProud »

Hi,

I'm no expert whatsoever especially MIDI or sound related but I think the problem is not the size, but the "Roland Drums" track in that particular file and possibly in general.
I'm sure I read somewhere that Roland Drums doesn't always stick to the MIDI GM standard.

I tested my theory by excluding the loading of track 17 in the "Annie's Song" MIDI file i.e. the Roland Drums, and it didn't crash and it played.

Ignore my stup1d1ty as I say I'm no expert.
angros47
Posts: 2409
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

I made some tests: that specific file uses 17 tracks, while normally MIDI files are expected to have no more than 16 tracks (since the channels are 16). The issue can be solved by changing, in the file "sequencer.bi", the first line

Code: Select all

const MaxTracks=16
setting the value to 17, and rebuilding the library. It's the first time I encounter this issue

About building for DOS, both solutions work (I recall having built it using dosemu, or the dos prompt under windows XP). It does not build under DosBox, unless you edit all the file to use short file names.
SMC
Posts: 33
Joined: Feb 22, 2012 4:05

Re: Audio library for FreeBasic - Features

Post by SMC »

I guess it was a case of a non standard file. For the library, I'll give building it on freedos a try. Also, in case I haven't said it, thanks for all your hard work on this.
Post Reply