OGG Loader + Musikplayer

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

Jan_

Ehemaliger Admin

Betreff: OGG Loader + Musikplayer

BeitragSa, Apr 15, 2006 21:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Moin Leute,

Hier ein Kleiner Quellcode,
er besteht aus 3 Teilen.

1. Meine Musikplayer Routine
2. Inaries OGG Tag loader
3. Vertex sein MP3 Idv 1 Tag Loader

eine Ogg zum testen:
http://eastwestgames.de/file.php?id=324

BlitzBasic: [AUSKLAPPEN]
Graphics 1024,768,32,2
SetBuffer BackBuffer()
Global BGMusikChannel%
Global BGMusikPlaying.BGMusikFile
Global BGMusikFileName$
Global BGMusikDir$ = CurrentDir$()
Global BGMusikPan#=0,BGMusikPitch%=0,BGMusikVolume#=1


Type BGMusikFile
Field Pfad$
Field InPlaylist%
End Type

;------------------------------------
;Testbereich zum Zeigen der Funktion!
;------------------------------------
BGMusikFind(CurrentDir())
Repeat
t1=MilliSecs()
Cls
Text 0,0,t1-t2
Text 0,15,BGMusikFileName$
BGMusikUpdate()
If KeyHit(57) Then BGMusikNextSong()
Flip 0
Delay 100
t2=t1
Until KeyHit(1)
End
;------------------------------------

Function BGMusikSetdir(Dir$)
BGMusikDir$ = Dir$
End Function

Function BGMusikFree()
BGMusikNextSong()
For BGMusikPlaying.BGMusikFile = Each BGMusikFile
Delete BGMusikPlaying
Next
BGMusikPlaying = Null
End Function

Function BGMusikNextSong()
StopChannel BGMusikChannel%
End Function

Function BGMusikPitch(Frequenz%)
BGMusikPitch%= Frequenz%
ChannelPitch BGMusikChannel%,BGMusikPitch%
End Function

Function BGMusikPan(Ballance#)
BGMusikPan#=Ballance#
ChannelPan BGMusikChannel%,BGMusikPan#
End Function

Function BGMusikVolume(Volume#)
BGMusikVolume#=Volume#
ChannelVolume BGMusikChannel%,BGMusikVolume#
End Function

Function BGMusikUpdate()
Local H%,G%,LTS%

If BGMusikPlaying = Null Then
BGMusikFind(BGMusikDir$ )
BGMusikPlaying = First BGMusikFile
EndIf
If Not ChannelPlaying(BGMusikChannel%) Then BGMusikChannel%=0
If Not BGMusikChannel%

BGMusikChannel%=PlayMusic(BGMusikPlaying\Pfad$)

If BGMusikPitch% <> 0 Then BGMusikPitch(BGMusikPitch%)
BGMusikPan(BGMusikPan#)
BGMusikVolume(BGMusikVolume#)
G=1
Repeat
H=G+1
LTS=G
G=Instr(BGMusikPlaying\Pfad$,"\",H)
Until G=0

BGMusikFileName$=Mid(BGMusikPlaying\Pfad$,LTS+1,Len(BGMusikPlaying\Pfad$)-LTS)
BGMusikInfos()
If BGMusikPlaying = Last BGMusikFile Then
BGMusikPlaying = First BGMusikFile
Else
BGMusikPlaying = After BGMusikPlaying
EndIf
EndIf
End Function

Function BGMusikFind(Pfad$)
Local Verzeichniss
Local Datei$
Local Aus%,Ein%
Local File.BGMusikFile

Verzeichniss=ReadDir(Pfad$)
Datei$=NextFile$(Verzeichniss)
Repeat
If FileType(Pfad$+Datei$) = 2 Then
If datei$ <> "." And datei$ <> ".."
BGMusikFind(Pfad$+Datei$+"\")
EndIf
Else
Ein%=0
If Upper(Right(Datei$,3))="RAW" Then Ein%=1
If Upper(Right(Datei$,3))="MOD" Then Ein%=1
If Upper(Right(Datei$,3))="S3M" Then Ein%=1
If Upper(Right(Datei$,2))="XM" Then Ein%=1
If Upper(Right(Datei$,2))="IT" Then Ein%=1
If Upper(Right(Datei$,3))="MID" Then Ein%=1
If Upper(Right(Datei$,3))="RMI" Then Ein%=1
If Upper(Right(Datei$,3))="WAV" Then Ein%=1
If Upper(Right(Datei$,3))="MP2" Then Ein%=1
If Upper(Right(Datei$,3))="MP3" Then Ein%=1
If Upper(Right(Datei$,3))="OGG" Then Ein%=1
If Upper(Right(Datei$,3))="WMA" Then Ein%=1
If Upper(Right(Datei$,3))="ASF" Then Ein%=1
If ein%
File = New BGMusikFile
File\Pfad$ = Pfad$+Datei$
File\InPlaylist% = True
EndIf
End If
Datei$=NextFile$(Verzeichniss)
If Datei$="" Then Aus=1
Until Aus
CloseDir Verzeichniss
End Function



;##############################################################################
;######## ID3v1.0 - TAG READER ##################### by Vertex ########
;##############################################################################

Function BGMusikInfos()
Local Info%
If Upper(Right(BGMusikFileName$,3))="MP3" Then
info=Get_ID3v1_Info(BGMusikPlaying\Pfad$)
BGMusikFileName$=Get_ID3v1_Interpreter$(Info)+" : "+Get_ID3v1_Titel$(Info)
ElseIf Upper(Right(BGMusikFileName$,3))="OGG"
;Get_Ogg_ID3v1_Info(BGMusikPlaying\Pfad$)
BGMusikFileName$=Ini_Ogg_Parse(bgmusikplaying\pfad$)
;Get_OGG_Artist$(BGMusikPlaying\Pfad$) +" : "+Get_OGG_Title$(BGMusikPlaying\Pfad$)

EndIf
If Trim(BGMusikFileName$) = Trim("Unknown : Unknown")
BGMusikFileName$= BGMusikPlaying\Pfad$
EndIf

End Function

; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------

Function Get_ID3v1_Info(File$)
Local datei = ReadFile(File$)
Local Info = CreateBank(127)
Local B,ID3$,TAG$


; Poke the infos in the Info-Bank
SeekFile datei,FileSize(File$) - 128
For B = 0 To 126
PokeByte Info,B,ReadByte(datei)
Next
; Check For "TAG"
For B = 0 To 2
TAG$ = TAG$ + Chr$(PeekByte(Info,B))
Next

If TAG$ <> "TAG" Then
CloseFile datei
FreeBank Info
Return False
EndIf

; Close the file
CloseFile datei

; Return the handle of the Info-Bank
Return Info
End Function
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Read the titel
Function Get_ID3v1_Titel$(Info)
Local B,Byte,Titel$
For B = 3 To 3 + 29
Byte = PeekByte(Info,B)
If Byte <> 0 Then Titel$ = Titel$ + Chr$(Byte)
Next
If Len(Titel$) > 0 Then
Return Trim$(Titel$)
Else
Return "Unknown"
EndIf

End Function

; Read the interpreter
Function Get_ID3v1_Interpreter$(Info)
Local B,Byte,Interpreter$
For B = 33 To 32 + 30
Byte = PeekByte(Info,B)
If Byte <> 0 Then Interpreter$ = Interpreter$ + Chr$(Byte)
Next
If Len(Interpreter$) > 0 Then
Return Trim$(Interpreter$)
Else
Return "Unknown"
EndIf

End Function


;##############################################################################
;######## OGG ID Tag reader ####################### by Inarie #############
;##############################################################################

;oggheader-reader by inarie
;Inarie:" gibt einen string, der enige titelinfos enthält, zurück
; die funktion bruacht ohne debugger normalerweise keine millisekunde"
;Jan_:"mit debuger ist ja auch egal."
Function Ini_Ogg_Parse$(file$)
Local txt$, Datei% = ReadFile(File$)
Local b%, st$, verndor$, count%, i%, com$
Local artist$, title$, tracknumber%, date$, location$, genre$

Repeat
b = ReadByte(datei)
St$ = st + Chr(b)
If Right(st,6) = "vorbis" ; jeder oggheader beginnt mit vorbis

Select Asc(Mid(st,Len(st)-6,1)) ; davor steht, um was für einen header es sich handelt
Case 1 ; identification header
; da ist nichts interessantes
Case 3 ; comment header <- der interessiert uns
vendor$ = ReadString(datei) ; brauchen wir wohl nicht...
DebugLog vendor

count = ReadInt(datei) ; anzahl der kommentare
DebugLog count

For i = 1 To count
com$ = ReadString(datei)
If Util_GetParas(com$)
Select Lower(paras[0]) ; informationen aus keys holen
Case "artist"
If Len(artist$)>0 Then artist$ = artist$ + ";"
artist$ = artist$ + paras[1]
Case "title"
If Len(title$)>0 Then title$ = title$ + ";"
title$ = title$ + paras[1]
Case "tracknumber"
tracknumber%= paras[1]
Case "date"
date$ = paras[1]
Case "location"
location$ = paras[1]
Case "description"
description$= paras[1]
Case "genre"
If Len(genre$)>0 Then genre$ = genre$ + ";"
genre$ = genre$ + paras[1]
; man kann nach belieben weitere tags hinzufügen..
End Select
EndIf
Next

Case 5 ; setupheader
; den brauchen wir nicht
Exit
End Select

EndIf
Until Eof(Datei)
CloseFile datei

; einen hübschen string aus den informationen machen...
If artist<>"" Then txt$ = txt + artist + ": "
If title<>"" Then txt = txt + "'" + title + "' "
If tracknumber Then txt = txt + tracknumber + " "
If genre Then txt = txt + "(" + genre + ") "
If date Or location Then txt = txt + "recorded "
If location Then txt = txt + "in " + location + " "
If date Then txt = txt + date + " "
If description Then txt = txt + description

Return txt$
End Function

; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------

Function Get_Ogg_Info(File$)
Local datei = ReadFile(File$)
Local Info = CreateBank(8)
Local B,ID3$,TAG$


; Poke the infos in the Info-Bank
SeekFile datei,10*4;KHZ
PokeInt Info,0,ReadInt(datei)
SeekFile datei,12*4;Kbit
PokeInt Info,4,ReadInt(datei)

CloseFile datei

Return Info
End Function
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Read the titel
Function Get_OGG_Artist$(File$)
Local txt$,Datei%=ReadFile(File$)
Local g%,Out$,i%

Repeat

txt$=ReadLine(Datei%)
g= Instr(txt$,"ARTIST=")

Until Eof(Datei) Or g > 0

If g > 0 Then
i%=g
Repeat
g= Asc(Mid(txt$,i,1))
i=i+1
Out$=Out$+Chr(g)
Until g=0
Out$=Left(Out$,Len(Out$)-2)
Else
Out$="Unknown"
EndIf

CloseFile Datei%
Return out$
End Function

Function Get_OGG_Title$(File$)
Local txt$,Datei%=ReadFile(File$)
Local g%,Out$,i%

Repeat

txt$=ReadLine(Datei%)
g= Instr(txt$,"TITLE=")

Until Eof(Datei) Or g > 0

If g > 0 Then
i%=g
Repeat
g= Asc(Mid(txt$,i,1))
i=i+1
Out$=Out$+Chr(g)
Until g=0
Out$=Left(Out$,Len(Out$)-2)
Else
Out$="Unknown"
EndIf

CloseFile Datei%
Return out$
End Function

Global paras$[1] ; Notwendig für Util_GetParas
Function Util_GetParas(txt$,trenn$="=") ; Diese Function sucht nach einem Zeichen in einem String und
tpos = Instr(txt$,trenn$) ; unterteilt ihn an diesem in zwei Teile.
If tpos>0
paras[0] = Trim(Left(txt$,tpos-1))
paras[1] = Trim(Right(txt$,Len(txt$)-tpos))

;paras[1] = Replace(paras[1],"g~",Left(gfxd$,3))
;paras[1] = Replace(paras[1],"d~",Left(datad$,4))
;paras[1] = Replace(paras[1],"s~",Left(sfxd$,3))
DebugLog "Para1: "+paras[0]+" Para2: "+paras[1]
Return 1
EndIf
End Function
between angels and insects

Mr.Keks

BeitragFr, Apr 21, 2006 17:09
Antworten mit Zitat
Benutzer-Profile anzeigen
Hihi, das war noch ne Zeit, als wir das geschrieben haben. Smile
MrKeks.net

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group