Sign in to follow this  
Followers 0
StungStang

Show a Bitrate

7 posts in this topic

Hi to all, im finally switched my player to bass.dll, but now i've a problem...i don't know how i can read the bitrate of radio streaming...how i can do this? This is the code:

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassEnc.au3>
#include <BassConstantsEx.au3>
#include <BassEncConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_BASS_Startup(@ScriptDir & '\bass.dll')
_BASS_Init(0, -1, 44100, 0)
If @error Then
       MsgBox(0, "Error", "Could not initialize audio")
       Exit
EndIf

_BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1)
$file = "http://stream.transmissionfm.com:8000/breaks-high.mp3"
Dim $MusicHandle = _BASS_StreamCreateURL($file, 0, 1)

If @error Then
       MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
       Exit
EndIf




$Form1 = GUICreate("", 156, 103, 192, 124)
$Start = GUICtrlCreateButton("Start", 8, 8, 139, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
               Case $GUI_EVENT_CLOSE
                       _BASS_Free()
                       Exit
               Case $Start
                       _BASS_ChannelPlay($MusicHandle, 1)
                       ;How i can know the bitrate of streaming radio?
       EndSwitch
WEnd

Hi to all!

Share this post


Link to post
Share on other sites



Up please :)

Share this post


Link to post
Share on other sites

Can anyone help me?...i can't find a solution on google...i've read a lot of topic but nothing for my problem :)

Hi!

Share this post


Link to post
Share on other sites

The answer to this is probably in every streaming player script on the forum...

check the dev website and read the bass.chm helpfile

anyway, try this, coded from example @: http://www.un4seen.com/forum/?topic=12314.0

bitrate is in ICY and HTTP tags

or can be calculated from _BASS_StreamGetFilePosition and BASS_CONFIG_NET_BUFFER values

I downloaded bass.dll sometime ago, but haven't used it,

so if it seems like this code is a bit carried away for answering you question,

I was giving it a bit of a test drive...

I can't use Opt("MustDeclareVars", 1) in this example as

_BASS_ChannelGetInfo() in Bass.au3 has an undeclared var: $dsInfo

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassEnc.au3>
;#include <BassConstantsEx.au3> ;not in Bass package I have
#include <BassEncConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>



_BASS_Startup(@ScriptDir & '\Bass.dll')
_BASS_Init(0, -1, 44100, 0)
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

_BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1)
_BASS_SetConfig($BASS_CONFIG_NET_BUFFER, 2000)
_BASS_SetConfig($BASS_CONFIG_GVOL_STREAM, 5000)


Local $file = "http://stream.transmissionfm.com:8000/breaks-high.mp3"
Local $MusicHandle = _BASS_StreamCreateURL($file, 0, 1)

If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf

Local $aRet = _BASS_ChannelGetInfo($MusicHandle)
For $i = 0 To UBound($aRet) - 1
    ConsoleWrite("+> " & $aRet & "[" & $i & "]: " & $aRet[$i] & @CRLF)
Next

ConsoleWrite("-Freq: " & $aRet[0] & " khz" & @CRLF)
If $aRet[3] = $BASS_CTYPE_STREAM_MP3 Then
    ConsoleWrite("-MPEG 1 layer 3 format stream" & @CRLF)
EndIf

;two methods for tags
Local $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_ICY)
ConsoleWrite("Error: " & @error & @CRLF); BASS_ERROR_NOTAVAIL = 37
If @error <> $BASS_OK Or IsPtr($pPtr) = 0 Then
    $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_HTTP)
    ConsoleWrite("Error: " & @error & @CRLF)
EndIf


Local $aStrLen, $iStrLen = 0, $sStr
;read channel tags
While $pPtr <> 0 ;bypass if no ptr returned from _BASS_ChannelGetTags()
    $iStrLen = _BASS_PtrStringLen($pPtr)
    If @error <> 0 Or $iStrLen <= 0 Then ExitLoop
    $sStr = _BASS_PtrStringRead($pPtr, False, $iStrLen)
    If @error <> 0 Then ExitLoop
    ConsoleWrite('-BASS_TAG_HTTP = ' & $sStr & @CRLF)
    $pPtr += $iStrLen + 1 ;advance memory address to get next tag entry - add 1 to skip NULL termination at end of string.
WEnd

;initialize Shoutcast metadata stream name for monitoring in loop
Local $sBuffer, $nMsg, $iBitRate
$pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_META)


Local $Form1 = GUICreate("", 156, 103, 192, 124)
Local $Start = GUICtrlCreateButton("Start", 8, 8, 139, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _BASS_StreamFree($MusicHandle)
            _BASS_Free()
            Exit
        Case $Start
            _BASS_ChannelPlay($MusicHandle, 1)
            ;How i can know the bitrate of streaming radio?
            $iBitRate = _BASS_StreamGetFilePosition($MusicHandle, $BASS_FILEPOS_END) * 8 / _
                    _BASS_GetConfig($BASS_CONFIG_NET_BUFFER)
            ConsoleWrite('-BitRate = ' & $iBitRate & " kbps" & @CRLF)
    EndSwitch
    ;monitor stream for track change
    $sStr = _BASS_PtrStringRead($pPtr)
    If $sBuffer == $sStr Then ContinueLoop
    $sBuffer = $sStr
    ConsoleWrite(">" & $sBuffer & @CRLF)
WEnd

I see fascists...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@Rover your function work only on http radio streaming...i've try with an wma radio streaming but dont work well

It's my code :

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassEnc.au3>
;#include <BassConstantsEx.au3> ;not in Bass package I have
#include <BassEncConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $Bass_WMAdll = @ScriptDir & "\basswma.dll"
Local $BASS_CONFIG_WMA_ASX = 0x10102

_BASS_Startup(@ScriptDir & '\Bass.dll')
_BASS_Init(0, -1, 44100, 0)
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

_BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1)
_BASS_SetConfig($BASS_CONFIG_NET_BUFFER, 2000)
_BASS_SetConfig($BASS_CONFIG_GVOL_STREAM, 5000)
$BASS_WMA = _BASS_PluginLoad($Bass_WMAdll, 0)


Local $file = "http://onair5.xdevel.com/RadioSubasio"
Local $MusicHandle = _BASS_StreamCreateURL($file, 0, 1)

If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf

Local $aRet = _BASS_ChannelGetInfo($MusicHandle)
For $i = 0 To UBound($aRet) - 1
    ConsoleWrite("+> " & $aRet & "[" & $i & "]: " & $aRet[$i] & @CRLF)
Next

ConsoleWrite("-Freq: " & $aRet[0] & " khz" & @CRLF)
If $aRet[3] = $BASS_CTYPE_STREAM_MP3 Then
    ConsoleWrite("-MPEG 1 layer 3 format stream" & @CRLF)
EndIf

;two methods for tags
Local $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_ICY)
ConsoleWrite("Error: " & @error & @CRLF); BASS_ERROR_NOTAVAIL = 37
If @error <> $BASS_OK Or IsPtr($pPtr) = 0 Then
    $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_HTTP)
    ConsoleWrite("Error: " & @error & @CRLF)
EndIf


Local $aStrLen, $iStrLen = 0, $sStr
;read channel tags
While $pPtr <> 0 ;bypass if no ptr returned from _BASS_ChannelGetTags()
    $iStrLen = _BASS_PtrStringLen($pPtr)
    If @error <> 0 Or $iStrLen <= 0 Then ExitLoop
    $sStr = _BASS_PtrStringRead($pPtr, False, $iStrLen)
    If @error <> 0 Then ExitLoop
    ConsoleWrite('-BASS_TAG_HTTP = ' & $sStr & @CRLF)
    $pPtr += $iStrLen + 1 ;advance memory address to get next tag entry - add 1 to skip NULL termination at end of string.
WEnd

;initialize Shoutcast metadata stream name for monitoring in loop
Local $sBuffer, $nMsg, $iBitRate
$pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_META)


Local $Form1 = GUICreate("", 156, 103, 192, 124)
Local $Start = GUICtrlCreateButton("Start", 8, 8, 139, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _BASS_StreamFree($MusicHandle)
            _BASS_Free()
            Exit
        Case $Start
            _BASS_ChannelPlay($MusicHandle, 1)
            ;How i can know the bitrate of streaming radio?
            $iBitRate = _BASS_StreamGetFilePosition($MusicHandle, $BASS_FILEPOS_END) * 8 / _
                    _BASS_GetConfig($BASS_CONFIG_NET_BUFFER)
            ConsoleWrite('-BitRate = ' & $iBitRate & " kbps" & @CRLF)
    EndSwitch
    ;monitor stream for track change
    $sStr = _BASS_PtrStringRead($pPtr)
    If $sBuffer == $sStr Then ContinueLoop
    $sBuffer = $sStr
    ConsoleWrite(">" & $sBuffer & @CRLF)
WEnd

You can download basswma here...it give me a bitrate of -0.004 kbps...How i can fix it? thanks for your help!

Edited by StungStang

Share this post


Link to post
Share on other sites

BassWMA has not been integrated into the Bass.au3 UDF, so I suggest using the forum at un4seen.com,

and search Google and the helpfiles that come with bass.dll and basswma.dll.

Have a look at the other streaming scripts on the forum.

You are going to have to code for each media type.

The _BASS_ChannelGetInfo function returns media types of stream, but it seems not WMA.

The calculated bitrate method was the second method suggested by the admin on un4seen.com.

The calculated bitrate does not work because _BASS_StreamGetFilePosition() is returning BASS_ERROR_UNKNOWN = -1

Not every stream is going to support these features, but the bitrate is available in the meta data from

_BASS_ChannelGetTags() with $BASS_TAG_WMA.

Re: I'm giving up - how to calculate bitrate for WMA stream?

http://www.un4seen.com/forum/?topic=9224.msg65764;hl=bitrate;topicseen#msg65764

The admin at un4seen.com has suggested another method.

QWORD filepos=BASS_StreamGetFilePosition(handle, BASS_FILEPOS_CURRENT); // get encoded file position

QWORD playpos=BASS_ChannelGetPosition(handle, BASS_POS_BYTE)

+BASS_ChannelGetData(handle, NULL, BASS_DATA_AVAILABLE); // get decoded position, including the output buffer

float bitrate=filepos*8/BASS_ChannelBytes2Seconds(handle, playpos);

But _BASS_StreamGetFilePosition(handle, BASS_FILEPOS_CURRENT) still returns -1

This text from the BASSWMA documentation seems to explains why _BASS_StreamGetFilePosition returns -1

BASS_CONFIG_WMA_BASSFILE:

"BASS will only handle the reading of local WMA files.

Internet files/streams will always be handled by the Windows Media modules,

regardless of this config setting."

BASS_WMA_StreamCreateFile:

"Unless the BASS_CONFIG_WMA_BASSFILE config option is enabled,

the Windows Media modules uses its own file reading routines,

and the offset and length parameters are ignored,

except that length is still the length when playing from memory.

Also, BASS_StreamGetFilePosition isn't fully supported.

The file size (BASS_FILEPOS_END) can be retrieved,

but the decode position (BASS_FILEPOS_CURRENT) is not available.

The download progress of streamed files (BASS_FILEPOS_DOWNLOAD) can also be retrieved.

The buffering progress (percentage) can be retrieved using the BASS_FILEPOS_WMA_BUFFER mode."

So, for WMA, get the bitrate from the BASS_TAG_WMA channel tags as this example shows.

Good Luck

#include <Bass.au3>
#include <BassConstants.au3>
#include <BassEnc.au3>
#include <BassEncConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

;// Additional BASS_ChannelGetTags types
Global Const $BASS_TAG_WMA = 8  ;// WMA header tags : series of null-terminated UTF-8 strings
Global Const $BASS_TAG_WMA_META = 11    ;// WMA mid-stream tag : UTF-8 string
Local $Bass_WMAdll = @ScriptDir & "\basswma.dll"
Global Const $BASS_CONFIG_WMA_ASX = 0x10102
Global Const $BASS_CONFIG_WMA_BASSFILE = 0x10103

_BASS_Startup(@ScriptDir & '\Bass.dll')
_BASS_Init(0, -1, 44100, 0)
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

_BASS_SetConfig($BASS_CONFIG_NET_PLAYLIST, 1)
_BASS_SetConfig($BASS_CONFIG_NET_BUFFER, 2000)
_BASS_SetConfig($BASS_CONFIG_GVOL_STREAM, 5000)
_BASS_SetConfig($BASS_CONFIG_WMA_BASSFILE, 1)

$BASS_WMA = _BASS_PluginLoad($Bass_WMAdll, 0)


Local $file = "http://onair5.xdevel.com/RadioSubasio"
Local $MusicHandle = _BASS_StreamCreateURL($file, 0, 1)

If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
EndIf

Local $aRet = _BASS_ChannelGetInfo($MusicHandle)
For $i = 0 To UBound($aRet) - 1
    ConsoleWrite("+> " & $aRet & "[" & $i & "]: " & $aRet[$i] & @CRLF)
Next

ConsoleWrite("-Freq: " & $aRet[0] & " khz" & @CRLF)
If $aRet[3] = $BASS_CTYPE_STREAM_MP3 Then
    ConsoleWrite("-MPEG 1 layer 3 format stream" & @CRLF)
EndIf

;two methods for tags
Local $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_WMA)
ConsoleWrite("Error: " & @error & @CRLF); BASS_ERROR_NOTAVAIL = 37
If @error <> $BASS_OK Or IsPtr($pPtr) = 0 Then
    $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_WMA_META)
    ConsoleWrite("Error: " & @error & @CRLF)
EndIf


Local $aStrLen, $iStrLen = 0, $sStr
;read channel tags
While $pPtr <> 0 ;bypass if no ptr returned from _BASS_ChannelGetTags()
    $iStrLen = _BASS_PtrStringLen($pPtr)
    If @error <> 0 Or $iStrLen <= 0 Then ExitLoop
    $sStr = _BASS_PtrStringRead($pPtr, False, $iStrLen)
    If @error <> 0 Then ExitLoop
    ConsoleWrite('-BASS_TAG = ' & $sStr & @CRLF)
    $pPtr += $iStrLen + 1 ;advance memory address to get next tag entry - add 1 to skip NULL termination at end of string.
WEnd

;initialize Shoutcast metadata stream name for monitoring in loop
Local $sBuffer, $nMsg, $iBitRate
;~ $pPtr = _BASS_ChannelGetTags($MusicHandle, $BASS_TAG_META)


Local $Form1 = GUICreate("", 156, 103, 192, 124)
Local $Start = GUICtrlCreateButton("Start", 8, 8, 139, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _BASS_StreamFree($MusicHandle)
            _BASS_PluginFree($BASS_WMA)
            _BASS_Free()
            Exit
        Case $Start
            _BASS_ChannelPlay($MusicHandle, 1)
            ;How i can know the bitrate of streaming radio?
;~             $iBitRate = _BASS_StreamGetFilePosition($MusicHandle, $BASS_FILEPOS_END)* 8 / _
;~                     _BASS_GetConfig($BASS_CONFIG_NET_BUFFER)
;~             ConsoleWrite('-BitRate = ' & $iBitRate & " kbps" & @CRLF)
    EndSwitch
    ;monitor stream for track change
;~     $sStr = _BASS_PtrStringRead($pPtr)
;~     If $sBuffer == $sStr Then ContinueLoop
;~     $sBuffer = $sStr
;~     ConsoleWrite(">" & $sBuffer & @CRLF)
WEnd

I see fascists...

Share this post


Link to post
Share on other sites

All work good :)...only a question...with this metod now i can know bitrate for WMA,MP3 and OGG streaming...you know the tag for "ACC" and "AC3" streaming ? ;)

Thanks for your help :idiot:

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  
Followers 0