Jump to content
Sign in to follow this  
Synapsee

Easy To Use - Bass Example (by nend)

Recommended Posts

Easy To Use - Bass Example (by nend) with _BASSChannelGetTags()

 

nend says :

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

Global $BASS_PAUSE_POS

Func Example()

    Local $MusicHandle

    _Audio_init_start()

    $MusicHandle = _Set_url("http://ice1.somafm.com/groovesalad-128.mp3")
    _Set_volume(50)

    _Audio_play($MusicHandle)

    while 1
        ConsoleWrite(_Get_streamtitle($MusicHandle) & @CRLF)
        Sleep(1000)
    WEnd

    _Audio_init_stop($MusicHandle)

EndFunc

Example()

Func _Audio_init_start()
    If _BASS_STARTUP(@ScriptDir & "\bass.dll") Then
        If _BASS_Init(0, -1, 44100, 0) Then
            If _BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1) = 0 Then
                SetError(3)
            EndIf
        Else
            SetError(2)
        EndIf
    Else
        SetError(@error)
    EndIf
EndFunc

Func _Set_buffer($buffer)
    _BASS_SetConfig($BASS_CONFIG_NET_BUFFER, $buffer)
EndFunc

Func _Audio_stop($MusicHandle)
    _BASS_ChannelStop($MusicHandle)
EndFunc

Func _Audio_play($MusicHandle)
    _BASS_ChannelPlay($MusicHandle, 1)
EndFunc

Func _Audio_pause($MusicHandle)
    If _Get_playstate($MusicHandle) = 2 Then
        $BASS_PAUSE_POS = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
        _BASS_ChannelPause($MusicHandle)
    ElseIf _Get_playstate($MusicHandle) = 3 Then
        _Audio_play($MusicHandle)
        _BASS_ChannelSetPosition($MusicHandle, $BASS_PAUSE_POS, $BASS_POS_BYTE)
    EndIf
EndFunc

Func _Audio_init_stop($MusicHandle)
    _BASS_StreamFree($MusicHandle)
    _BASS_Free()
EndFunc

Func _Set_url($file)
    If FileExists($file) Then
        $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0)
    Else
        $MusicHandle = _BASS_StreamCreateURL($file, 0, 1)
    EndIf
    If @error Then
        Return SetError(1)
    EndIf
    Return $MusicHandle
EndFunc

Func _Get_pos($MusicHandle)
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    Return Round(_Bass_ChannelBytes2Seconds($MusicHandle, $current))
EndFunc

Func _Get_len($MusicHandle)
    $current = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)
    Return Round(_Bass_ChannelBytes2Seconds($MusicHandle, $current))
EndFunc

Func _Set_pos($MusicHandle, $seconds)
    _BASS_ChannelSetPosition($MusicHandle, _BASS_ChannelSeconds2Bytes($MusicHandle, $seconds), $BASS_POS_BYTE)
EndFunc

Func _Set_volume($volume)
    _BASS_SetConfig($BASS_CONFIG_GVOL_STREAM, $volume * 100)
EndFunc

Func _Get_volume()
    Return _BASS_GetConfig($BASS_CONFIG_GVOL_STREAM) / 100
EndFunc

Func _Get_bitrate($MusicHandle)
    $a = Round(_Bass_ChannelBytes2Seconds($MusicHandle, _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)))
    $return = Round(_BASS_StreamGetFilePosition($MusicHandle, $BASS_FILEPOS_END) * 8/ $a/ 1000)
    If StringInStr($return, "-") Then
        $return = _BASS_StreamGetFilePosition($MusicHandle, $BASS_FILEPOS_END) * 8 / _BASS_GetConfig($BASS_CONFIG_NET_BUFFER)
    EndIf
    Return $return
EndFunc

Func _Get_playstate($MusicHandle)
    Switch _BASS_ChannelIsActive($MusicHandle)
        Case $BASS_ACTIVE_STOPPED
            $returnstate = 1
        Case $BASS_ACTIVE_PLAYING
            $returnstate = 2
        Case $BASS_ACTIVE_PAUSED
            $returnstate = 3
        Case $BASS_ACTIVE_STALLED
            $returnstate = 4
    EndSwitch
    Return $returnstate
EndFunc

Func _Get_streamtitle($MusicHandle)
    $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_META)
    $sStr = _BASS_PtrStringRead($pPtr)
    If StringInStr($sStr, ";") Then
        $infosplit = StringSplit($sStr, ";")
        $infosplit[1] = StringReplace($infosplit[1], "'", "")
        $infosplit[1] = StringReplace($infosplit[1], "StreamTitle=", "")
        If StringInStr($infosplit[1], "-") Then
            Return $infosplit[1]
        EndIf
    EndIf
EndFunc

You need :

1 dll : bass.dll source : http://www.un4seen.com/bass.html (v2.4.12.1)

2 au3 : bass.au3 source : bass related forum post (patch 9.2/Constant from 9.0)

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ripdad
      This is a project that I have been working on for several months off and on.
      It's a simple "What You Hear" MP3 @ 320Kbps and WAV audio recorder.
      Features:
      - LoudMax, a Gain Controller and Look-Ahead Limiter
      - Auto Shut-Off after one minute of silence
      - Side-by-Side Simulated LED Meter
      - Running Time Counter
      It started off being a large project, but I eventually stripped it down to its
      bare essentials because I came to realize that it would be very difficult to
      deal with every sound card and every way a PC is set up for audio. It would
      have been a nightmare that I was not willing to go through.
      This project contains the most up-to-date BASS.dll v.2.4.15.0 - December 17, 2019.
      All BASS Dll's are 32bit. Those and the needed UDF's are included in the zip file.
      I will try to explain how it works in the next post.

      Download:
      BASS VST Recorder v1.1.zip
       
    • By ripdad
      This is an example script of how to load and use a VST using BASS in AutoIt.
      It is NOT immediately Plug and Play. You will need to download 2 VST's to run it.
      They are free for personal use.
      All information is in the header of the script.

      Download:
      BASS VST HOST v0.4.zip
       
    • By ripdad
      I have been working on audio graphical scripts these last several months.
      This is my last script on this subject for now. On to other projects.
      Credits: UEZ, Eukalyptus, BrettF, Prog@ndy, Authenticity and the AutoIt Community.
      Thanks to all that made these scripts possible!
      Please let me know if you have any problems with it.

      Download:
      LIVE Stereo Audio Waveform v2.zip
       

    • By ripdad
      I have been playing with this script off and on for about a month - trying to get the needles to look more realistic.
      It's best to use with an audio limiter on the source audio, or else you'll be tweaking the input levels on every song.
      It should work with any version of AutoIt, starting with 3.3.8.1.
      Please report any problems with it. Credits are in the script.

      Download: LIVE Analog Stereo Meter.au3
    • By nss
      Hi all,
       
      I am making a program in which I use Bass audio library (with the wrapper for autoit that I found here on forums I think) because of its support for dx effects.
      My problem, though, is that when effects as reverb or echo/delay are added, the channel length is not extended as to fit the tail of the effect, so if the file was really short, you wouldn't even hear the reverb at all.
      I've tried setting the  buffer parameter even to 60k ms, updating the channel length to 60k ms, but nothing makes it so that the effects aren't being cut off.
      I've heard that I could add silence manually to wave files by adding the chr(0) characters, but haven't had any luck doing that, either.
      What I'm doing:
      initialize bass use streamCreateFile to load the wave file with the fx flag and length parameter set to 60000 set the config buffer to 60000 use channel set fx to add dx8 reverb use channel play to play the sound use bass update to update the length to 60000  
      I even tried having only silence in one wave file and tried joining two wave files together, but that didn't work either.
       
      Any help would be very much appreciated.
×
×
  • Create New...