Sound (description)

For other topics related to the FreeBASIC project or its community.
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Sound (description)

Postby VANYA » Feb 05, 2021 11:39

This topic is more of an appeal / request to fxm. Maybe on the eve of the release of the new version of the compiler, you fxm will have the opportunity to write an article in WIKI about the simplest library from Angros47? After all, there are mostly QUICKBASIC teams with minor differences. This might prompt CoderJeff to add this library to the compiler's "INCLUDE" directory. For those new to FB, this would be great. But what can I say, it would also be convenient for me to use right out of the box.

P.S. I will not be offended , if you refuse for any reason

Possible description:

Library is cross-platform and comes for Windows, Linux, Dos
Author: angros47
Download link: https://sourceforge.net/projects/freeba ... ary/files/

Compile Library:
all the necessary scripts are in the archive, you just need to substitute the correct path to the compiler in them

Description:
Description of all functions is in the file readme.txt (in archive)

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. It can only play one note at a time. (for more information see command QBASICs play).
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

example Play

Code: Select all

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

SoundmidiSet ()
PLAY "a4e4g4a4g4e4c2f4f4f2d4d4d2"


example Play wih thread

Code: Select all

#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

Code: Select all

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

SoundmidiSet ()
dim as any ptr Midi=CreateMidi()
PLAY Midi,"a4e4g4a4g4e4c2f4f4f2d4d4d2"
SaveMidi "music.mid", Midi


Example LoadMidi , PlayMidi

Code: Select all

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

SoundmidiSet ()
dim as any ptr Midi=LoadMidi("music.mid")
PlayMidi(Midi, 1)
sleep


Example Sound

Code: Select all

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

SoundSet (44100,1,16)
sound SineWave(2000), 1 ' sine 2 kHz
sound NoiseWave(), 1 ' noise
sleep



Example LoadWave , PlayWave

Code: Select all

#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
Last edited by VANYA on Feb 06, 2021 7:43, edited 4 times in total.
fxm
Moderator
Posts: 10357
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Sound (description)

Postby fxm » Feb 05, 2021 12:12

I have never used any Sound library.
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Sound (description)

Postby VANYA » Feb 05, 2021 13:05

I understood , sorry for obsession.
SARG
Posts: 1260
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Sound (description)

Postby SARG » Feb 05, 2021 17:54

I agree with VANYA a light library for sounds would be nice.
I gueess that the readme.txt of the angros47's sfx with some examples for the most current uses will be enough.
So if angros47 could do that fxm has just to create a new page in the Wiki based on the txt file.
And it will remain to add the lib files in every package.
Doesn't seem impossible.
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Sound (description)

Postby badidea » Feb 05, 2021 20:49

SARG wrote:I agree with VANYA a light library for sounds would be nice.

I agree too.
SARG wrote:I guess that the readme.txt of the angros47's sfx with some examples for the most current uses will be enough.
So if angros47 could do that fxm has just to create a new page in the Wiki based on the txt file.

fxm or someone else with an wiki account :-)
I don't think that documentation is the problem. If the sound library is included in the builds, the documentation will be there soon as well.
SARG
Posts: 1260
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Sound (description)

Postby SARG » Feb 05, 2021 22:38

badidea wrote:I don't think that documentation is the problem. If the sound library is included in the builds, the documentation will be there soon as well.
If it's in the help file beginners (or others) will find easily that feature. At least a hint where find the sound library and its possibilities.
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Sound (description)

Postby badidea » Feb 06, 2021 0:02

SARG wrote:
badidea wrote:I don't think that documentation is the problem. If the sound library is included in the builds, the documentation will be there soon as well.
If it's in the help file beginners (or others) will find easily that feature. At least a hint where find the sound library and its possibilities.

Not sure that I understand what you mean. As long as the sound library (of angros47) is not integrated with freebasic, we cannot really integrate it in the wiki. It will be very confusing if certain freebasic (sound) statements are only possible when the user also has to install the sound library separately. The best thing that can be done on the wiki now, is adding a link with example on https://www.freebasic.net/wiki/ExtLibTOC, but then it will be in the "Music/Sound, Audio/Video" section with 12 other entries which may or may not work (depending on OS and bitness).
Without a package manager (like pip for python and cargo for rust), 3rd party libraries will always be complicated, is my opinion.
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Sound (description)

Postby VANYA » Feb 06, 2021 7:14

I added a short description to the first post. I'm not a musician either, but everything is simple here. Who has access to WIKI, please add mine or if you want your own description.

Adding a library to the official distribution ensures that if someone uses the library in their code, then there will be no questions:

1) Nothing compiles, no fbsfx library
2) Where can I get the library?

And adding to WIKI will increase the number of people using the library

P.S. There is also no mention of Joshy's FBSOUND library in WIKI. This is generally strange.
grindstone
Posts: 797
Joined: May 05, 2015 5:35
Location: Germany

Re: Sound (description)

Postby grindstone » Feb 06, 2021 15:57

Analogue to the fbgfx.bi, I would consider a sound library a good idea.
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Sound (description)

Postby badidea » Feb 07, 2021 0:35

grindstone wrote:Analogue to the fbgfx.bi, I would consider a sound library a good idea.

C wrote 13 Mar 2006:
"I'm looking for a real easy to use sound library. I'm not planning to code my own mixer or anything I would just like something that can load and play sound files for games and sfx. Something simple. Also is there any chance that FB will get a standard sound library in the future? It would go great with gfxlib :-)"
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Sound (description)

Postby badidea » Feb 07, 2021 1:20

VANYA wrote:I added a short description to the first post. I'm not a musician either, but everything is simple here. Who has access to WIKI, please add mine or if you want your own description. ... And adding to WIKI will increase the number of people using the library

https://freebasic.net/wiki/ExtLibsfx (linked form here: https://freebasic.net/wiki/ExtLibTOC)

VANYA wrote:P.S. There is also no mention of Joshy's FBSOUND library in WIKI. This is generally strange.

Maybe tomorrow. Freebasic itself is well documented on the wiki. It seems to me that there was a lot of enthusiasm in the beginning of freebasic and multiple people created on the wiki links to code snippets and links to libraries and got basic examples included with the freebasic download. Now, there is 15 years to code on the forum and collecting nice code snippets (that still work) is not much fun. Similar for keeping these library links and examples up to date does not interest many.
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Sound (description)

Postby VANYA » Feb 07, 2021 7:11

badidea wrote:https://freebasic.net/wiki/ExtLibsfx (linked form here: https://freebasic.net/wiki/ExtLibTOC)


Thanks!

Let's hope that coderJeff will complement the FBC 1.08 distribution: library and headers FBSFX.
angros47
Posts: 1870
Joined: Jun 21, 2005 19:04

Re: Sound (description)

Postby angros47 » Feb 07, 2021 22:33

Correction: 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
badidea
Posts: 2328
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Sound (description)

Postby badidea » Feb 07, 2021 22:45

The wiki page updated.
robert
Posts: 148
Joined: Aug 06, 2019 18:45

Re: Sound (description)

Postby robert » Feb 08, 2021 7:04

Code: Select all


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

DIM AS String Instrument
DIM AS String Mario

Mario = "t230o3l8g>ceg>cel4g.e.o3l8g+>c+e+g+>c+e+l4g+.e+.o3l8b->dfb->dfl4b-.l8b-b-b->l2c."

Print "Press q to quit"
SoundmidiSet ()
Do
Instrument = "i" & STR(Int(Rnd * 127) + 1)
PLAY Instrument
PLAY Mario
Loop Until Inkey = "q"


Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests