Jump to content

Recommended Posts

Posted (edited)
  • 4 weeks later...
Posted

Hi,

I would like to play some data with bass which I have loaded into memory with FileOpen, which I will use later to load data from stdout, but how do I pass a string of data to bass?

I have this code after bass is initialised:

$file = fileopen(@ScriptDir & "\bass_example.wav", 16)
$MusicHandle = _BASS_StreamCreateFile(True, fileread($file), 0, 0, 0)
but it gives me an error 20.

In the manual it says to pass a memory location, how do I do that?

Regards,

Marc

  • 2 months later...
Posted

Hi,

Has someone found a solution to my question above, I just can't get it.

Marc

Do something like this.

$file = @ScriptDir & "\bass_example.wav"
Local $binData=FileRead($file)
Local $Size=FileGetSize($file)
Local $tData=DllStructCreate("byte[" & $Size & "]")
Local $pData=DllStructGetPtr($tData)
DllStructSetData($tData,1,$binData)
$MusicHandle = _BASS_StreamCreateFile(True,$pData , 0, $Size, 0)
$binData=0; Free

Saludos

Posted

Hi,

I don't know what that code is doing, but it Works, thanks!

I also need to get 7-zip to extract a file to memory to play, but I also asked about that in another topic.

Marc

Posted

Hi,

I don't know what that code is doing, but it Works, thanks!

I also need to get 7-zip to extract a file to memory to play, but I also asked about that in another topic.

Marc

$file = @ScriptDir & "\bass_example.wav" ;Your File Path
Local $binData=FileRead($file) ;Read the file an store to a variable
Local $Size=FileGetSize($file) ;Get File Size
Local $tData=DllStructCreate("byte[" & $Size & "]") ;Create a memory space with size of $Size
Local $pData=DllStructGetPtr($tData) ;get memory space pointer
DllStructSetData($tData,1,$binData) ;fill the memory space with your file data stored in the variable
$MusicHandle = _BASS_StreamCreateFile(True,$pData , 0, $Size, 0) ;Play
$binData=0; Free

Saludos

  • 5 months later...
Posted

Hi,

Is it possible to join 2 or more sounds opened with bass_streamcreatefile so they play after each other in one channel?

I think it would be great so that I don't need to constantly check the playing attribute.

Thanks,

Marc

  • 2 months later...
Posted

Dear developers, please show me how to play the two parts of the file so that they sounded like a single file?
I am trying to do this with the help of _SoundPlay function, but to no avail.
Audible a pause or clicks.

 

Re-read all this topic and I can not deal with this powerful UDF.

  • 1 year later...
Posted
1 hour ago, dost0011 said:

Is it possible to use bass.dll with several USB-Soundcards? If yes, how can I choose the right one?

Thanks. Great dll

You can use _BASS_ChannelSetDevice to set the output device you want to.
You can use _BASS_GetDeviceInfo to get all the listed audio devices.

Posted

Many thanks for the fast answer.

I tried it but have the following problem:

$return = _BASS_ChannelSetDevice($oPlayer1, 1)
if $return = 0 then MsgBox(0,"",@error)

$oPlayer1 = _BASS_StreamCreateFile(False, $Musikpath & $song1, 0, 0, 0)

I get the @error = 5 --> invalid handle.

Ok. If I change the lines:

$oPlayer1 = _BASS_StreamCreateFile(False, $Musikpath & $song1, 0, 0, 0)

$return = _BASS_ChannelSetDevice($oPlayer1, 1)
if $return = 0 then MsgBox(0,"",@error)

I get the error = 14 --> already initialized/paused/whatever

What can I do? Is there anywhere a small example? Didn't find one.

Thanks!

Posted (edited)

@dost0011, please show me a full script so that I can see what's wrong with it?
Did you set _BASS_Init?

Something like this:
 

; Get all the audio devices
For $i = 1 To 50
    $info = _BASS_GetDeviceInfo($i)
    If @error Then
        ExitLoop
    Else
        If $info[0] <> "" Then
            ReDim $a_audio_device[$i + 1]
            $a_audio_device[$i] = $info[0]
        EndIf   
    EndIf
Next

_ArrayDisplay($a_audio_device)



; Set Audo device
$i = 1; device number
_BASS_Init(0, $i, 44100, 0)
_BASS_ChannelSetDevice($a_station_info[0], $i)

 

Edited by nend
Posted

Hi,

you're right - it's easier to show it with code.

In the attachment you'll find example.au3. I tried to play the alarm01.wav on both soundcards (1 & 2) at the same time.

In _ArrayDisplay($a_audio_device) I can see both devices - that's ok.

But "_BASS_ChannelSetDevice($oPlayer1, 1)" doesn't work like supected - I get the @error = 14...

What's wrong?

Bass.zip

Posted

I got it :-)

I have to initialize (_BASS_INIT()) with EVERY Device I want to use. Now it's possible to play 2 separate Soundfiles on 2 separate Devices at the same time:

 

#include <Bass.au3>
#include <BassConstants.au3>
#include <array.au3>

;Open Bass.DLL.  Required for all function calls.
$ret = _BASS_STARTUP("Bass.dll")
if $ret=0 then MsgBox(0,"Fehler","Bass.dll wurde nicht gefunden!")

Global $a_audio_device[50]
; Get all the audio devices
For $i = 1 To 50
    $info = _BASS_GetDeviceInfo($i)
    If @error Then
        ExitLoop
    Else
        If $info[0] <> "" Then
            ReDim $a_audio_device[$i + 1]
            $a_audio_device[$i] = $info[0]
            _BASS_Init(0, $i, 44100, 0, "")
        EndIf
    EndIf
Next

_ArrayDisplay($a_audio_device)

;Initalize bass.  Required for most functions.

$oPlayer1 = _BASS_StreamCreateFile(False, "Alarm01.wav", 0, 0, $BASS_SAMPLE_LOOP)
$oPlayer2 = _BASS_StreamCreateFile(False, "Alarm02.wav", 0, 0, $BASS_SAMPLE_LOOP)

; konfigure Device 1 for Player 1
_BASS_ChannelSetDevice($oPlayer1, 1)
; konfigure Device 2 for Player 2
_BASS_ChannelSetDevice($oPlayer2, 2)

_BASS_ChannelPlay($oPlayer1, 0)
_BASS_ChannelPlay($oPlayer2, 0)

While 1
   Sleep(100)
WEnd

 

Posted

Is it possible to generate distortion in the audio file (Key + and key -) using this udf?

  • 3 weeks later...
Posted

Does anyone know how to use bass.dll to raise and lower semi-tones (karaok efffect) in music?

 

Posted

@Belini, this is a example I found in a older version of the bass.dll udf, maybe this is what you looking for?
 

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

Global $hMusicHandle, $hMixerHandle, $iSongLength

_BASS_Startup()
_BASS_MIX_Startup()

_BASS_Init($BASS_DEVICE_SPEAKERS, -1, 44100, 0, "")
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

$hGui = GUICreate("Karaoke Mode Test", 320, 80)
$hSlider = GUICtrlCreateSlider(10, 10, 300, 30)
$hButtonLoad = GUICtrlCreateButton("Load Song", 10, 50, 145, 20)
$hButtonEnable = GUICtrlCreateButton("Enable Karaokemode", 165, 50, 145, 20)
GUISetState()


$bKaraoke = False
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            _Exit()
        Case $hButtonEnable
            Switch $bKaraoke
                Case True
                    $bKaraoke = False
                    SetMatrix($hMusicHandle, 1, 1)
                    GUICtrlSetData($hButtonEnable, "Enable KaraokeMode")
                Case Else
                    $bKaraoke = True
                    SetMatrix($hMusicHandle, 1, -1)
                    GUICtrlSetData($hButtonEnable, "Disable KaraokeMode")
            EndSwitch
        Case $hButtonLoad
            If $hMusicHandle Then
                _BASS_ChannelStop($hMixerHandle)
                _BASS_StreamFree($hMusicHandle)
            EndIf
            $sFile = FileOpenDialog("Open...", "..\audiofiles", "MP3 Files (*.mp3)")
            $hMusicHandle = _BASS_StreamCreateFile(False, $sFile, 0, 0, $BASS_STREAM_DECODE + $BASS_SAMPLE_FLOAT + $BASS_SAMPLE_LOOP)
            $aInfo = _BASS_ChannelGetInfo($hMusicHandle)
            $hMixerHandle = _BASS_Mixer_StreamCreate($aInfo[0], 1, 0)
            _BASS_Mixer_StreamAddChannel($hMixerHandle, $hMusicHandle, $BASS_MIXER_MATRIX)
            $iSongLength = _BASS_ChannelGetLength($hMusicHandle, $BASS_POS_BYTE)
            _BASS_ChannelPlay($hMixerHandle, False)
        Case $hSlider
            If $hMusicHandle And $iSongLength Then
                $iPos = Round(GUICtrlRead($hSlider) * $iSongLength / 100)
                _BASS_ChannelSetPosition($hMusicHandle, $iPos, $BASS_POS_BYTE)
            EndIf
    EndSwitch
    Sleep(20)
    $aInfo = GUIGetCursorInfo($hGui)
    If Not $aInfo[2] And $aInfo[4] <> $hSlider And $hMusicHandle And $iSongLength Then
        $iPos = _BASS_ChannelGetPosition($hMusicHandle, $BASS_POS_BYTE)
        GUICtrlSetData($hSlider, $iPos * 100 / $iSongLength)
    EndIf
WEnd


Func SetMatrix($handle, $left, $right)
    Local $tStruct = DllStructCreate("float;float")
    DllStructSetData($tStruct, 1, $left)
    DllStructSetData($tStruct, 2, $right)
    _BASS_Mixer_ChannelSetMatrix($handle, DllStructGetPtr($tStruct))
EndFunc   ;==>SetMatrix


Func _Exit()
    _BASS_Free()
    Exit
EndFunc   ;==>_Exit

 

Posted (edited)

Thanks @nend, I did some tests with the example you posted but I could not change the semi tones as I need, maybe I'm not using the right function!

Files to test

Edited by Belini

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...