Jump to content

Recommended Posts

Posted

BASS can load a file from memory when you supply a pointer to thze Memory-block and the size. I think it should work like this:

#include<WinAPI.au3>
#include<Memory.au3>
#include<BASS.au3>

Global $ahOGGHandle[2] = [0,0] ; global Variables

$sOGGFile = "C:\test.ogg"
; Load at the beginning:
Local $iSize = FileGetSize($sOGGFile)
If $iSize Then
    Local $ahOGGHandle[0] = _MemGlobalAlloc($iSize, $GPTR)
    $hFile = _WinAPI_CreateFile($sOGGFile, 2, 2)
    Local $iRead
    _WinAPI_ReadFile($hFile, $ahOGGHandle[0], $iSize, $iRead)
    If $iRead < $iSize Then
        _MemGlobalFree($ahOGGHandle[0])
        $ahOGGHandle[0] = 0
    EndIf
    _WinAPI_CloseHandle($hFile)
    ; create Stream:
    If $ahOGGHandle[0] Then $ahOGGHandle[1] = _BASS_StreamCreateFile(True, $ahOGGHandle[0], 0, $iSize, 0)
EndIf

; now play & stop Music, 
_BASS_ChannelPlay($ahOGGHandle[1], 1)
Sleep(1000)
_BASS_ChannelStop($ahOGGHandle[1])

; free on exit
If $ahOGGHandle[1] Then _BASS_StreamFree($ahOGGHandle[1])
If $ahOGGHandle[0] Then _MemGlobalFree($ahOGGHandle[0])

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted (edited)

Here another method:

;coded by UEZ 2010
#include <WinAPI.au3>
#include <BASS.au3>

Do
    $file = FileOpenDialog("Select audio file to load", @ScriptDir, "Audio (*.mp3;*.ogg; *.wma)")
    If @error Then
    $msg = MsgBox(20, "Error", "Please select an audio file!")
    If $msg = 7 Then
    Exit
    Else
    SetError(1)
    EndIf
    EndIf
Until Not @error

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

$file_size = FileGetSize($file)
If $file_size Then
    $tBuffer = DllStructCreate("byte[" & $file_size & "]")
    $pMem = DllStructGetPtr($tBuffer)
    Global $nBytes
    $hFile =_WinAPI_CreateFile($file, 2, 2)
    _WinAPI_SetFilePointer($hFile, 3)
    _WinAPI_ReadFile($hFile, $pMem, $file_size, $nBytes)
    _WinAPI_CloseHandle($hFile)
    $bass_dll = _BASS_Startup(@ScriptDir & "\BASS.dll")
    _BASS_Init($BASS_DEVICE_CPSPEAKERS)
    $hMusic = _BASS_StreamCreateFile(True, $pMem, 0, $file_size, 0)
    $song_length = _BASS_ChannelGetLength($hMusic, $BASS_POS_BYTE)
    _BASS_ChannelPlay($hMusic, 1)
    While 1
        Sleep(250)
        If _BASS_ChannelGetPosition($hMusic, $BASS_POS_BYTE) >= _BASS_ChannelGetLength($hMusic, $BASS_POS_BYTE) Then ExitLoop
    WEnd
    _Close()
EndIf

Func _CLose()
    _BASS_ChannelStop($hMusic)
    _BASS_StreamFree($hMusic)
    DllClose(@ScriptDir & "\BASS.dll")
    Exit
EndFunc

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

Argh. What the hell. BassEnc works, then it just doesn't. Seriously getting annoying now... Moving on.

I'll try work out BassEnc AGAIN now. I've got a funny feeling I mucked up one of the functions in Bass.au3...

Cheers,

Brett

Edited by BrettF
Posted

As I thought. Please update this function in Bass.au3 again.

Func _BASS_RecordGetInputName($inputn)
    Local $BASS_ret_ = DllCall($_ghBassDll, "ptr", "BASS_RecordGetInputName", "int", $inputn)
    If @error Then Return SetError(1,1,0)
    If $BASS_ret_[0] = "" Then Return SetError(_BASS_ErrorGetCode(),0,$BASS_ret_[0])
    $struc = DllStructCreate ("char[255]", $BASS_ret_[0])
    Return DllStructGetData ($struc, 1)
EndFunc ;==>_BASS_RecordGetInputName
Posted

Nope still dosent works, now it jsut closes when i try to start it.

autoit says this:

STARTING TO DEBUG BASS_ENC_EXAMPLE.

OS = WIN_XP (X86) (SERVICE PACK = Service Pack 2) BUILD = 2600

KB Layout = 0000041D

Running AutoIt V3.3.0.0(64 bit native = 0)

GETTING DEVICES FAILED

0 0

INITATING RECORDING FAILED

1 0

GETTING INPUTS FAILED

1 0

BASSCB RECORD START FAILED

0 0

C:\Documents and Settings\record\BassEnc.au3 (210) : ==> Cannot assign values to constants.:

$error = _BASS_ErrorGetCode()

^ ERROR

Posted (edited)

Update your version of AutoIt.

My Output:

STARTING TO DEBUG BASS_ENC_EXAMPLE.

OS = WIN_7 (X64) (SERVICE PACK = ) BUILD = 7100

KB Layout = 00000409

Running AutoIt V3.3.2.0(64 bit native = 0)

GETTING DEVICES FAILED

0 0

INITATING RECORDING FAILED

1 0

GETTING INPUTS FAILED

0 0

BASSCB RECORD START FAILED

0 0

Edited by BrettF
Posted
Posted
Posted

I am currently working on a little library called EasyBass using bass.au3 and sound effects for simple loading and playing of sounds in games. I eventually want to code windows sound recorder plus :D, but that might take a while and I would probably need bassmix for it, since believe it or not I use the windows recorder to mix all the time. Yay for unprofessional audio editing *grin*.

Posted

Issues issues!

bass_fx doesn't seem to be t working properly. The effects don't do anything. I've edited the example to show @error when you press the echo checkbox, it seems as though we'er calling an incorrect effect type or something.

The edited example can be found at

http://mycrap.scrapping.cc/example.rar

Posted

I am currently working on a little library called EasyBass using bass.au3 and sound effects for simple loading and playing of sounds in games. I eventually want to code windows sound recorder plus :D, but that might take a while and I would probably need bassmix for it, since believe it or not I use the windows recorder to mix all the time. Yay for unprofessional audio editing *grin*.

I feel it is fairly simple as it is? If people can't work out what the functions needed are from the examples and the like, then maybe they should think of trying a more basic project first? Its not really that complicated. Feel free to try the recorder and the like.

Issues issues!

bass_fx doesn't seem to be t working properly. The effects don't do anything. I've edited the example to show @error when you press the echo checkbox, it seems as though we'er calling an incorrect effect type or something.

The edited example can be found at

http://mycrap.scrapping.cc/example.rar

I found that too. The last effect worked though. Let me continue to do some testing to see what I can find. I still need to make some examples for BassFX anyways to make sure its working... : At the moment its relatively untested... :huggles: It will take me a few days to get anything solid going, so hang tight.

Cheers,

Brett

Posted

Woo. Got some examples going.

Tempo:

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassFX.au3>
#include <BassFXConstants.au3>

Global $playing_state = -1
;Startup Bass & BassFX.  Also check if loading failed.
_BASS_STARTUP ("BASS.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

_BASS_FX_Startup("bass_fx.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

;Initalize bass.  Required for most functions.
_BASS_Init(0, -1, 44100, 0, "")

;Check if bass iniated.  If not, we cannot continue.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

;Prompt the user to select a MP3 file
$file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

;Create a stream from that file.
$MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)

;Check if we opened the file correctly.
If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf
$tempo = _BASS_FX_TempoCreate ($MusicHandle, 0)

;Iniate playback
_BASS_ChannelPlay($tempo, 1)

;Get the length of the song in bytes.
$song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)

;Create a timer
$timer = TimerInit ()
;So we can set it to something different each time.
$numberchanges = 0
While 1
    ;Test so we can change the tempo after 5 seconds.
    If TimerDiff ($timer) >= 5000 Then
        ;Make it a loop - reseting after we've cycled through the changes
        Switch $numberchanges
            Case 0 ; Tempo is 0%  Set it to 75%
                ToolTip ("Setting Tempo to +75%", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 75)
            Case 1; Tempo is 75%  Set it to 100%
                ToolTip ("Setting Tempo to 100%", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 100)
            Case 2; Tempo is 100%  Set it to 50%
                ToolTip ("Setting Tempo to +50%", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 50)
            Case 3; Tempo is 50%  Set it to -50%
                ToolTip ("Setting Tempo to -50%", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, -50)
            Case 4; Tempo is -50%  Set it to -75%
                ToolTip ("Setting Tempo to -75%", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, -75)
            Case Else
                $numberchanges = 0
        EndSwitch
        $numberchanges += 1
        ;Reset the timer
        $timer = TimerInit ()
        Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
WEnd

Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
EndFunc   ;==>OnAutoItExit

Pitch:

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassFX.au3>
#include <BassFXConstants.au3>

Global $playing_state = -1
;Startup Bass & BassFX.  Also check if loading failed.
_BASS_STARTUP ("BASS.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

_BASS_FX_Startup("bass_fx.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

;Initalize bass.  Required for most functions.
_BASS_Init(0, -1, 44100, 0, "")

;Check if bass iniated.  If not, we cannot continue.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

;Prompt the user to select a MP3 file
$file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

;Create a stream from that file.
$MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)

;Check if we opened the file correctly.
If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf
$tempo = _BASS_FX_TempoCreate ($MusicHandle, 0)

;Iniate playback
_BASS_ChannelPlay($tempo, 1)

;Get the length of the song in bytes.
$song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)

;Create a timer
$timer = TimerInit ()
;So we can set it to something different each time.
$numberchanges = 0
While 1
    ;Test so we can change the tempo after 5 seconds.
    If TimerDiff ($timer) >= 5000 Then
        ;Make it a loop - reseting after we've cycled through the changes
        Switch $numberchanges
            Case 0
                ToolTip ("Setting Tempo to +60", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 60)
            Case 1
                ToolTip ("Setting Tempo to +30", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 30)
            Case 2
                ToolTip ("Setting Tempo to +10", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 10)
            Case 3
                ToolTip ("Setting Tempo to -30", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, -30)
            Case 4
                ToolTip ("Setting Tempo to -60", 0, 0)
                _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, -60)
            Case Else
                $numberchanges = 0
        EndSwitch
        $numberchanges += 1
        ;Reset the timer
        $timer = TimerInit ()
        Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
WEnd

Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
EndFunc   ;==>OnAutoItExit

Reverse:

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassFX.au3>
#include <BassFXConstants.au3>

Global $playing_state = -1
;Startup Bass & BassFX.  Also check if loading failed.
_BASS_STARTUP ("BASS.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

_BASS_FX_Startup("bass_fx.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf

;Initalize bass.  Required for most functions.
_BASS_Init(0, -1, 44100, 0, "")

;Check if bass iniated.  If not, we cannot continue.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

;Prompt the user to select a MP3 file
$file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

;Create a stream from that file.
$MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)

;Check if we opened the file correctly.
If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf

$tempo = _BASS_FX_ReverseCreate ($MusicHandle, 10, 0)
_BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)

;Iniate playback
_BASS_ChannelPlay($tempo, 1)


;Get the length of the song in bytes.
$song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)
$timer = TimerInit ()
$next = 30000; 30seconds into the song so we can try reduce the chance of going backwards....
$state = 1

While 1
    If TimerDiff ($timer) >= $next Then
        If $state = 1 Then
            _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_REVERSE)
            $next = Random (3000, 5000, 1)
            ToolTip ("Reverse for " & $next & "ms", 0,0)
            $state = 0
        Else
            _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
            $next = Random (5000, 10000, 1)
            ToolTip ("Forward for " & $next & "ms", 0,0)
            $state = 1
        EndIf
        $timer = TimerInit ()
        Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
WEnd

Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
EndFunc   ;==>OnAutoItExit

Please tell me what you think. The reverse was an interesting one as I initially thought it was going to play the whole thing in reverse. But instead it plays sections, similar to what you'd expect from a DJ scratch and the like... I might just try that now... :D

Cheers,

Brett

Posted
Posted (edited)

Just some small helper functions for setting and getting volume of a channel. I think they are quite useful :D

; $nVol: 0(silent) ... 100(full)
Func _BASS_ChannelSetVolume($hChannel, $nVol)
    ; Author: Prog@ndy
    Local $ret = _BASS_ChannelSetAttribute($hChannel,$BASS_ATTRIB_VOL,$nVol/100)
    Return SetError(@error,@extended,$ret)
EndFunc
; returns Volume: 0(silent) ... 100(full)
Func _BASS_ChannelGetVolume($hChannel)
    ; Author: Prog@ndy
    Local $ret = _BASS_ChannelGetAttribute($hChannel,$BASS_ATTRIB_VOL)
    Return SetError(@error,@extended,$ret*100)
EndFunc

//Edit: in BASS.au3 the return value of _BASS_Startup is incorrect. To fix it, replace the last if-construct with this line:

;Check if the DLL was opened correctly.
    Return $_ghBassDll<>-1
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

Just some small helper functions for setting and getting volume of a channel. I think they are quite useful :huggles:

; $nVol: 0(silent) ... 100(full)
Func _BASS_ChannelSetVolume($hChannel, $nVol)
    ; Author: Prog@ndy
    Local $ret = _BASS_ChannelSetAttribute($hChannel,$BASS_ATTRIB_VOL,$nVol/100)
    Return SetError(@error,@extended,$ret)
EndFunc
; returns Volume: 0(silent) ... 100(full)
Func _BASS_ChannelGetVolume($hChannel)
    ; Author: Prog@ndy
    Local $ret = _BASS_ChannelGetAttribute($hChannel,$BASS_ATTRIB_VOL)
    Return SetError(@error,@extended,$ret*100)
EndFunc

Added, thank you.

//Edit: in BASS.au3 the return value of _BASS_Startup is incorrect. To fix it, replace the last if-construct with this line:

;Check if the DLL was opened correctly.
    Return $_ghBassDll<>-1

Error was carried over with all Startup functions. Fixed thank you! :D

Uploading Version 9 (7360KB) on dial up speeds...

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
  • Recently Browsing   0 members

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