View Full Version : Playing sound/music in TB besides TBASS
Hi there, is there any other audio library available for TB besides TBASS that can play sound files(wav, or ogg)?
As much as I like TBASS, I don't agree with it's license.
Unless if it's different from the real BASS library.
winmm is one option that I found on this message boards however.. does it support multiple channels like TBASS?
ErosOlmi
04-07-2011, 08:06
Hi poceduo and welcome to thinBasic community.
TBASS module is a wrapper of original BASS library. I have authorization from Ian Luck (un4seen) to use BASS library as far as scripts created with thinBasic using TBASS are non commercial.
You can use TBASS as far as you create free scripts. If you create commercial scripts you need to buy a BASS licence. See thinBasic help at http://www.thinbasic.com/public/products/thinBasic/help/html/tbass.htm
I do not know if winmm is an option for multiple channels, also considering it is an old API.
Maybe someone else can suggest something on this matter.
If there are other libraries we can consider, we can think about it.
Ciao
Eros
Michael Clease
04-07-2011, 09:43
OpenAL is a cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.
The library models a collection of audio sources moving in a 3D space that are heard by a single listener somewhere in that space. The basic OpenAL objects are a Listener, a Source, and a Buffer. There can be a large number of Buffers, which contain audio data. Each buffer can be attached to one or more Sources, which represent points in 3D space which are emitting audio. There is always one Listener object (per audio context), which represents the position where the sources are heard -- rendering is done from the perspective of the Listener.
I dont have time at the moment but this could be another option.
Petr Schreiber
04-07-2011, 10:34
It depends what level of functionality you need.
If you need 3D sound, I guess the OpenAL recommended by Mike could be an option. As ThinBASIC can access functions from DLLs, you would just create DECLARE statements and then you can use it.
If you need just to play some (even multiple) sounds, manipulate their volume and do other basic (non-3D) stuff, you can try MCI commands:
#MINVERSION 1.8.8.0
String mySoundFile = APP_SourcePath + "prodigy.wav"
' -- To be able to use mciSendString, we need to decalre it first
Declare Function mciSendString Lib "WINMM.DLL" Alias "mciSendStringA" ( ByRef lpstrCommand As Asciiz,
ByRef lpstrReturnString As Asciiz,
ByVal uReturnLength As DWord ,
ByVal hwndCallback As DWord ) As DWord
' -- Open file (WAV, MP3) and give it alias for easier manipulation
mciSendString("open "+mySoundFile+" alias mySound", "", 0, 0)
' -- Start playing the file
mciSendString("play mySound" , "", 0, 0)
' -- Give it second to play
Sleep 1000
' -- Release the file
mciSendString("close mySound" , "", 0, 0)
Documentation of syntax for Open (http://msdn.microsoft.com/en-us/library/dd743638%28v=vs.85%29.aspx)
Documentation of syntax for Play (http://msdn.microsoft.com/en-us/library/dd743667%28v=vs.85%29.aspx)
Petr
Ive been looking in thinBasic documentation and forum for ability to play simple sounds.
The above mentioned solutions (BASS, OpenAL, MCI) seem to be focussed on sound files.
That is not what I want.
Some old BASIC's (GW, BBC, PET) used to have a simple native function like this:-
SOUND (frequency,duration).
With this we can compose a simple melody by issuing a series of SOUND commands.
This is what I seek.
Has progress of technology killed such simple capability?
(vorsprung durch technik I suppose :comp12:
http://www.thinbasic.com/community/images/smilies/_1_smiley-computer012.gif ).
Petr Schreiber
07-03-2012, 13:05
Hi Steve,
I remember this functionality from DOS BASIC dialects. The problem is that not every PC now has the PC Speaker, which was used to generate the sound itself.
The Windows API contains the function to play on speaker, here minimal test in ThinBASIC, but as my PC does not have PC Speaker device, I cannot verify if it works:
' -- Win32 API function to play on speaker
Declare Function WinBeep Lib "KERNEL32.DLL" Alias "Beep" ( ByVal dwFreq As DWord, ByVal dwDuration As DWord ) As Long ' BOOL
' -- Call the function, 750Hz, 300ms
WinBeep( 750, 300 )
Also, as the documentation (http://msdn.microsoft.com/en-us/library/ms679277%28VS.85%29.aspx) says:
Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.
I think the solution could be to generate WAV file programatically, and play it via soundcard device.
Petr
Thanks Petr
WinBeep does the job for me on my ancient rig (Pentium 4, WinXP/sp0)
It is a pity WinBeep is not available in newer Windows.