Jump to content

BASS Function Library (Sound and Music Functions)


BrettF
 Share

Recommended Posts

Thank you for the link and for keeping this updated. I'm still learning what this can do and I like it so far. :graduated:

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 months later...

If you want to use a newer dll, you have to set $BASS_STARTUP_VERSIONCHECK (Bass.au3) to FALSE

Update:

; Bass.au3: update to dll version 2.4.8.1
;           BugFix -> _BASS_ChannelGet3DPosition
;           add functions:   _BASS_FXReset
;           add constants:   $BASS_DATA_FFT16384
;                           $BASS_DEVICE_DMIX
;                           $BASS_ATTRIB_NOBUFFER
;                           $BASS_ATTRIB_CPU
;                           $BASS_DATA_FFT_REMOVEDC
;                           $BASS_CONFIG_DEV_BUFFER
;                           $BASS_CONFIG_DEV_DEFAULT
;                           $BASS_CONFIG_NET_READTIMEOUT
;                           $BASS_TAG_APE
;                           $BASS_TAG_MP4
;                           $BASS_TAG_CA_CODEC
;                           $BASS_TAG_MF
;                           $BASS_TAG_WAVEFORMAT
;                           $BASS_TAG_RIFF_BEXT
;                           $BASS_TAG_RIFF_CART
;                           $BASS_TAG_RIFF_DISP
;                           $BASS_TAG_APE_BINARY
;                           $BASS_TAG_MUSIC_ORDERS
;                           $BASS_POS_DECODE
;                           $BASS_POS_DECODETO
;
; BassMix.au3: update to dll version 2.4.6.0
;           add functions:  _BASS_Mixer_ChannelGetPositionEx
;                           _BASS_Split_StreamGetAvailable
;                           _BASS_Split_StreamGetSplits
;                           _BASS_Split_StreamResetEx
;           add constants:   $BASS_MIXER_POSEX
;                           $BASS_MIXER_LIMIT
;                           $BASS_SPLIT_SLAVE
;                           $BASS_SYNC_MIXER_ENVELOPE_NODE
;
; BassCD.au3: BugFix -> _BASS_CD_GetTOC (wrong offset in LBA mode)

http://www.autoit.de/index.php?page=Thread&postID=215291#post215291

http://www.autoit.de/index.php?page=Attachment&attachmentID=14717

Link to comment
Share on other sites

I'm getting "Could not initialize audio" when I run any examples. I'm trying this for the first time and am not having any luck.

I tried the two scripts posted by eukalyptus on page 19, and neither one had any output no matter how I ran them. To make sure, I changed all the "ConsoleWrite"s to "MsgBox"s and each program gave me 2 message boxes with no text in them.

I am using the bass.dll and au3 files from http://www.autoit.de/index.php?page=Thread&postID=215291#post215291

Any ideas?

Link to comment
Share on other sites

What OS are you running? Is it x86 or x64? If x64 are you running the script using the #AutoIt3Wrapper_UseX64 = no directive at the start of the script? The BASS DLLs are x86 (32 bit DLLs).

EDIT: I just realized that there are x64 bit DLLs included with the latest package from the German site eukalyptus mentioned earlier. You would have to make sure you're using the correct DLLs for the architecture you're using it on.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What OS are you running? Is it x86 or x64?

...

You would have to make sure you're using the correct DLLs for the architecture you're using it on.

That was exactly it. Thanks so much. I feel a little dumb for not thinking of it but now I'm excited that I can move forward.

Thanks!

Link to comment
Share on other sites

How to record audio for 5 seconds and then play it ?(without saving it to disk)

That´s exactly what Bass_Ext was designed for :)

#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"

OnAutoItExitRegister("_FreeBass")

HotKeySet("{ESC}", "_Exit")

_BASS_Startup()
_BASS_EXT_STARTUP()

_BASS_Init(0, -1, 44100, 0, "")
_BASS_RecordInit(-1)

$iSize = 5 * 44100 * 2 * 16 / 8 ;sec * freq * chan * bitrate / 8 = bytes
$aBuffer = _BASS_EXT_MemoryBufferCreate($iSize)
$hRecord = _BASS_RecordStart(44100, 2, 0, $BASS_EXT_RecordProc, $aBuffer[0])

$iTimer = TimerInit()
Do
    Sleep(100)
    $iBufSize = _BASS_EXT_MemoryBufferGetSize($aBuffer)
    ToolTip("RECORDING" & @CRLF & Floor(TimerDiff($iTimer) / 1000) & " sec" & @CRLF & $iBufSize & " bytes recorded")
Until $iBufSize >= $iSize
_BASS_ChannelStop($hRecord)

$hStream = _BASS_StreamCreate(44100, 2, 0, $BASS_EXT_StreamProc, $aBuffer[0])
_BASS_ChannelPlay($hStream, True)

$iTimer = TimerInit()
Do
    Sleep(100)
    $iBufSize = _BASS_EXT_MemoryBufferGetSize($aBuffer)
    ToolTip("PLAYING" & @CRLF & Floor(TimerDiff($iTimer) / 1000) & " sec" & @CRLF & $iBufSize & " bytes in buffer")
Until $iBufSize <= 0


Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _FreeBass()
    _BASS_RecordFree()
    _BASS_StreamFree($hStream)
    _BASS_Free()
EndFunc   ;==>_FreeBass
Link to comment
Share on other sites

Thanks for the answer, with little modification to your script I have managed to play in "real time" the recorded data, however the latency is quite high (around 2 secs).

Thus I have tried to do the same using bassasio:

#include "Bass.au3"
#include "BassAsio.au3"
#include "BassFx.au3"
#include "BassExt.au3"
;~ #include "BassMix.au3"
#include <Array.au3>
OnAutoItExitRegister("_Exit")

HotKeySet("{ESC}", "_Exit")
Global $iFreq = 44100
Global $iChans = 2
_BASS_Startup()
_BASS_ASIO_Startup()
_BASS_FX_Startup()
_BASS_EXT_Startup()
;~ _BASS_MIX_Startup()

_BASS_ASIO_Init(0)
$iSampleRate = _BASS_ASIO_GetRate()
_BASS_Init(0, -1, $iSampleRate, 0, "")
$aInfo = _BASS_ASIO_GetInfo()

$aBuffer = _BASS_EXT_MemoryBufferCreate()
_BASS_ASIO_ChannelEnable(True, 0, $BASS_EXT_AsioProc, $aBuffer[0])
_BASS_ASIO_ChannelJoin(True, 1, 0)
_BASS_ASIO_ChannelSetFormat(1, 0, $BASS_ASIO_FORMAT_16BIT)

$hStream = _BASS_StreamCreate($iSampleRate, $iChans, $BASS_STREAM_DECODE, $BASS_EXT_StreamProc, $aBuffer[0])

$hTempo = _BASS_FX_TempoCreate($hStream, 0)
_BASS_ChannelSetAttribute($hStream, $BASS_ATTRIB_TEMPO_PITCH, -7)
$aPipe = _BASS_EXT_StreamPipeCreate($hStream, $BASS_EXT_STREAMPROC_PUSH)

_BASS_ASIO_ChannelEnable(False, 0, $BASS_EXT_AsioProc, $aPipe[0])
_BASS_ASIO_ChannelJoin(False, 1, 0)
_BASS_ASIO_ChannelSetFormat(0, 0, $BASS_ASIO_FORMAT_16BIT)
_BASS_ASIO_Start($aInfo[5])

_BASS_ASIO_ChannelSetVolume(True, 0, 0.2)
_BASS_ASIO_ChannelSetVolume(True, 1, 0.2)
_BASS_ASIO_ChannelSetVolume(False, 0, 1)
_BASS_ASIO_ChannelSetVolume(False, 1, 1)
While 1
Sleep(10)
WEnd

Func _Exit()
_BASS_StreamFree($hStream)
_BASS_ASIO_Free()
_BASS_Free()
Exit
EndFunc

It works fine except for the pitch effect.

(using bassasio only for the input and bass for the output works, however I would like to do this only with bassasio)

Link to comment
Share on other sites

Hmm...

I can´t test this at the moment, but try this:

$aPipeIn = _BASS_EXT_StreamPipeCreate($hStream, $BASS_EXT_STREAMPROC_PUSH)
_BASS_ASIO_ChannelEnable(True, 0, $BASS_EXT_AsioProc, $aPipeIn[0])
$aPipeOut = _BASS_EXT_StreamPipeCreate($hTempo, $BASS_EXT_STREAMPROC_PUSH)
_BASS_ASIO_ChannelEnable(False, 0, $BASS_EXT_AsioProc, $aPipeOut[0])

E

Link to comment
Share on other sites

Unfortunately it doesn't work, I can't hear anything, here is the script:

#include "Bass.au3"
#include "BassAsio.au3"
#include "BassFx.au3"
#include "BassExt.au3"
#include "BassMix.au3"
#include <Array.au3>OnAutoItExitRegister("_Exit")

HotKeySet("{ESC}", "_Exit")Global $iFreq = 44100
Global $iChans = 2
_BASS_Startup()
_BASS_ASIO_Startup()_BASS_FX_Startup()
_BASS_EXT_Startup()
_BASS_MIX_Startup()

_BASS_ASIO_Init(0)$iSampleRate = _BASS_ASIO_GetRate()
_BASS_Init(0, -1, $iSampleRate, 0, "")$aInfo = _BASS_ASIO_GetInfo()
$hStream = _BASS_StreamCreate($iSampleRate, $iChans, BitOR($BASS_ASIO_FORMAT_FLOAT, $BASS_STREAM_DECODE), $STREAMPROC_PUSH, 0)
$hTempo = _BASS_FX_TempoCreate($hStream, 0);$BASS_STREAM_DECODE)
;~ _BASS_ChannelPlay($hTempo, 1)
_BASS_ChannelSetAttribute($hTempo, $BASS_ATTRIB_TEMPO_PITCH, -7)
;~ $hMixer = _BASS_Mixer_StreamCreate($iSampleRate, $iChans, BitOR($BASS_STREAM_DECODE, $BASS_SAMPLE_FLOAT))
;~ _BASS_Mixer_StreamAddChannel($hMixer, $hTempo, $BASS_MIXER_MATRIX)
;~ _BASS_Mixer_StreamAddChannel($hMixer, $hStream, $BASS_MIXER_MATRIX)
$aPipeIn = _BASS_EXT_StreamPipeCreate($hStream, $BASS_EXT_STREAMPROC_PUSH)$aPipeOut = _BASS_EXT_StreamPipeCreate($hTempo, $BASS_EXT_STREAMPROC_PUSH)

_BASS_ASIO_ChannelEnable(False, 0, $BASS_EXT_AsioProc, $aPipeIn[0])
_BASS_ASIO_ChannelEnable(True, 0, $BASS_EXT_AsioProc, $aPipeOut[0])
_BASS_ASIO_ChannelJoin(False, 1, 0)
_BASS_ASIO_ChannelJoin(True, 1, 0)
_BASS_ASIO_ChannelSetFormat(0, 0, $BASS_ASIO_FORMAT_FLOAT)
_BASS_ASIO_ChannelSetFormat(1, 0, $BASS_ASIO_FORMAT_FLOAT)

_BASS_ASIO_Start($aInfo[5])

_BASS_ASIO_ChannelSetVolume(True, 0, 0.2)
_BASS_ASIO_ChannelSetVolume(True, 1, 0.2)_BASS_ASIO_ChannelSetVolume(False, 0, 1)
_BASS_ASIO_ChannelSetVolume(False, 1, 1)
While 1
Sleep(10)
WEnd

Func _Exit()_BASS_StreamFree($hStream)
_BASS_ASIO_Free()
_BASS_Free()
Exit
EndFunc

It looks like that the resampled data from Tempo is not copied to the bassasio output buffer

Link to comment
Share on other sites

  • 2 weeks later...

Please help me. I have used all this night trying to find a way to use that BASS stuff. I would just like to try the BASS-example1. Apparently there are no instructions for that addon. So I have managed by myself to copy the au3-files Bass.au3 and BassConstants.au3 to AutoIt3 Include-folder from the package. That is correct right? It helped to move on to the next error, where I'm stuck right now. It's about the dll-file bass.dll. How I should work with that??? Should i drop it to programfiles/system32 folder? Or restart my computer instead of that? Or register that dll with some fancy windows command? Or something else? Usually I'm pretty good with computers, so it makes me wonder why I don't get this now? I really would appreciate if you could help me to get going.

Edited by pekde
Link to comment
Share on other sites

I am trying out BASS WASAPI RC1 from Breff , because I need to run my script on Win7 in exclusive mode instead of using Direct Sound. However, there is no example in the downloaded udf, so I just wrote out some code based on BASSWASAPI C++ sample from U4Seen. My question is how come there is no sound when the _Bass_Wasapi_Start() is returning TRUE? Also I found that the _BASS_Wasapi_GetdeviceInfo() is not working properly in the udf (A correct device index will cause AutoIT to hang) so I just set _Bass_Wasapi_Init() to use default O/P device. Thanks.

#include "Bass.au3"
#include "BassWASAPI.au3"
#include "BassMix.au3"
#Include <Array.au3>
#Include <String.au3>

; Load Bass Lib
_BASS_Startup("bass.dll")
; Load Bass WASAPI Lib
_BASS_WASAPI_Startup("basswasapi.dll")
; Load Bass Mix Lib
_BASS_MIX_Startup("bassmix.dll")
; Not playing via BASS, so don't need an update thread
_BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 0)
; Init with no sound device, init dev with exclusive access
_BASS_Init(0, 0, 44100, 0, "")
; Decode media file without playing, looping playback, 32-Bit floating sample data
$hchannel = _BASS_StreamCreateFile(False, "test.mp3", 0, 0, BitOR($BASS_SAMPLE_LOOP, $BASS_STREAM_DECODE, $BASS_SAMPLE_FLOAT))
; Get media file info for WASAPI Init
$bInfo = _BASS_ChannelGetInfo($hchannel)
_ArrayDisplay($bInfo, "Media Info")
; Init default WASAPI o/p device, Exclusive Mode, freq and ch according to source file.
_BASS_WASAPI_Init(-1, $bInfo[0], $bInfo[1], BitOR($BASS_WASAPI_EXCLUSIVE, $BASS_WASAPI_AUTOFORMAT, $BASS_WASAPI_BUFFER), 0.5)
; Get WASAPI device info for BassMixer
$wInfo = _BASS_WASAPI_GetInfo()
_ArrayDisplay($wInfo, "WASAPI Playback Info")
; Init Mixer with stream data without playing it.
$hmix = _BASS_Mixer_StreamCreate($wInfo[1], $wInfo[2], BitOR($BASS_SAMPLE_FLOAT, $BASS_STREAM_DECODE))
; Plugs a channel into a mixer. Downmix if src has more channels
_BASS_Mixer_StreamAddChannel($hmix, $hchannel, $BASS_MIXER_DOWNMIX)
; Start WASAPI Device
MsgBox(0, "", _BASS_WASAPI_Start())
; Display Playback Data in realtime
While(_BASS_ChannelIsActive($hmix))
ToolTip("Wasapi Playing...")
Sleep(100)
WEnd
; Free up library
_BASS_WASAPI_Stop(False)
_BASS_WASAPI_Free()
_BASS_Free()
Edited by VAG
Link to comment
Share on other sites

  • 4 months later...

Just an FYI, if _BassStartUp is run on a computer running an x64 version of Windows, and you're using the x86 version of the DLL (or vice versa), the function will return without setting an error code. It still will set the return value to False, but you can't test the success of the call by checking @error after it has been run. You have to test for success or failure by testing the return of the function call, because @error won't help here.

Something like this would be the way to test whether it worked or not.

If _Bass_Startup(@ScriptDir & "Bass.dll") Then
 ; if the return is True, do this
Else
 ; if the return is False, do this
EndIf

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 4 weeks later...

@BrettF congratulations on the excellent work, your UDF solved a big problem of mine

Link to comment
Share on other sites

  • 4 months later...

Thanks for sharing!

I know I'm a bit late to join the party, but I just realized what more there is to this topic than the name BASS implies, so I've come to it in a roundabout way (CDDB.au3). Now I have 20 pages to digest. Anyway, it seems a fine body of work, and deserves a bump at the very least, and perhaps some others will become aware of it's goodies despite the name.

Perhaps it should be called Sound & Music Function Library (Bass, etc) or somesuch, as I'd been put off by the BASS part of the title.

EDIT

After now having had a slightly deeper look at the content of the zip file, I realize a little better, the historical reason for the name, but still wish the title had been more descriptive as to full content.

Amending the above perhaps to - Sound & Music Function Library (Bass.dll & related, etc)

After a quick perusal, the whole package seems pretty comprehensive, and despite the reliance on a third party DLL, is quite an addition to AutoIt.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • 3 months later...

$test = _BASS_GetDevice($bass_dll)
MsgBox(0,"",$test)

it is return 0...

i dont know way....

It should return the audio device that i am using...

how can i get the audio device name that i am using?

Edited by Guest
Link to comment
Share on other sites

You can't get that with that function, it returns an integer.

Also, you're calling it wrong, it doesn't accept parameters in the function call.

EDIT: This function "_BASS_GetDeviceInfo" might be what you're looking for, I haven't ever used it but it seems to fit your need.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can't get that with that function, it returns an integer.

Also, you're calling it wrong, it doesn't accept parameters in the function call.

EDIT: This function "_BASS_GetDeviceInfo" might be what you're looking for, I haven't ever used it but it seems to fit your need.

thanks but i don't know for what the $device part and don't know what to write in this variable..

_BASS_GetDeviceInfo($bass_dll, $device)

i don't supposed to know what is the $device if i am looking for the device

Edited by Guest
Link to comment
Share on other sites

First of all, stop putting the $bass_dll into every function call, none (or almost none) of these functions will accept you passing it this variable.

Second, the device is the number for the audio device that is being used. Usually starts at 1 and goes up from there. This function returns an array just as an FYI.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...