|
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
Cherry
Anmeldungsdatum: 20.06.2007 Beiträge: 249
|
Verfasst am: 02.04.2008, 14:05 Titel: Irgendwas stimmt mit FMOD nicht ;_; |
|
|
Ich stehe vor einem Problem. Ich habe mir ein System zum einfachen abspielen von Sounds und Hintergrundmusik gebastelt. Klappt eigentlich alles wunderbar, nur eines nicht:
1. Das erste Laden einer MIDI-Datei (z.B. durch .TBGM.PlayM oder .LoadFile) dauert 5-10 Sekunden (!)
2. MIDIs krachen im Lautsprecher, aber total. Wenn ich mit der Lautstärke (Standard ist 255) auf 128 runtergehe, klappt es, ist aber zu leise (klar).
(Alles nur bei Elementen, die das FMUSIC-System verwenden (z.B. MIDI), bei FSOUND (z.B. MP3) gibts kein Problem)
Diese Probleme hatte ich mit FMOD noch nie, und ich kann einfach keinen Fehler oder dergleichen in dem Code finden, daher muss ich um Hilfe bitte...
Wäre sehr dankbar, wenn es lösbar wäre.
Hier der Code:
Code: | #Define _UMML_SOUND_INC
#Define _MIN_COMPATIBLITY_ERROR
#Define TRUE 1
#Define FALSE 0
#Define NULL 0
#Include Once "file.bi"
#Include Once "fmod.bi"
#Ifndef _UMML_MAX_SONGS
#Define _UMML_MAX_SONGS 1024
#EndIf
#Ifndef _UMML_MAX_SOUNDS
#Define _UMML_MAX_SOUNDS 2048
#EndIf
Namespace UMML
Enum
VERSION_ERROR = 1
FMOD_INIT_ERROR
DATA_LIMIT_EXCEEDED
FILE_NOT_FOUND
LOADING_ERROR
End Enum
Dim Shared LastError As Integer
Function CheckLastError() As Integer
Dim LastError_ As Integer = LastError
LastError = NULL
Return LastError_
End Function
Type TLoadedData_Songs
FileName As String
Handle As FMUSIC_MODULE Ptr
End Type
Type TLoadedData_Sounds
FileName As String
Handle As FSOUND_SAMPLE Ptr
End Type
Type TLoadedData
Songs(_UMML_MAX_SONGS) As TLoadedData_Songs
Sounds(_UMML_MAX_SONGS) As TLoadedData_Sounds
End Type
Declare Function LoadSong(FileName As String) As FMUSIC_MODULE Ptr
Declare Function LoadSound(FileName As String) As FSOUND_SAMPLE Ptr
Declare Function SongHandle(FileName As String) As FMUSIC_MODULE Ptr
Declare Function SoundHandle(FileName As String) As FSOUND_SAMPLE Ptr
Type TBGM
Enum _Types
NONE
FMUSIC
FSOUND
End Enum
_Type As _Types
ID As Integer
FMUSIC_Ptr As FMUSIC_MODULE Ptr
FSOUND_Ptr As FSOUND_SAMPLE Ptr
Channel As Integer
Declare Property FileName() As String
Declare Property FileName(newval As String)
Declare Property Volume() As UByte
Declare Property Volume(newval As UByte)
Declare Property Paused() As Boolean
Declare Property Paused(newval As Boolean)
Declare Sub PlayM(FileName As String, Volume As UByte = 255, Paused As Boolean = FALSE)
Declare Sub StopM()
Declare Sub RestartM()
Private:
_FileName As String
_Volume As UByte
_Paused As Boolean
End Type
Property TBGM.FileName() As String
Return This._FileName
End Property
Property TBGM.FileName(newval As String)
LastError = NULL
If Trim(newval) = "" Then This.StopM(): Exit Property
If Trim(UCase(This._FileName)) = Trim(UCase(newval)) Then Exit Property
If FileExists(newval) = FALSE Then LastError = FILE_NOT_FOUND: This._Type = TBGM.NONE: This.StopM(): Exit Property
If SongHandle(newval) = NULL Then
LastError = NULL
If SoundHandle(newval) = NULL Then Exit Property
This._Type = TBGM.FSOUND
This._FileName = newval
This.FMUSIC_Ptr = NULL
This.FSOUND_Ptr = SoundHandle(newval)
This.Channel = FSOUND_PlaySound(FSOUND_FREE, This.FSOUND_Ptr)
FSOUND_SetLoopMode(This.Channel, FSOUND_LOOP_NORMAL)
This.Volume = This._Volume
This.Paused = This._Paused
Else
LastError = NULL
This._Type = TBGM.FMUSIC
This.Channel = NULL
This._FileName = newval
This.FMUSIC_Ptr = SongHandle(newval)
This.FSOUND_Ptr = NULL
FMUSIC_PlaySong(This.FMUSIC_Ptr)
This.Paused = This._Paused
This.Volume = This._Volume
EndIf
If LastError <> NULL Then This._Type = TBGM.NONE: This.StopM()
End Property
Property TBGM.Volume() As UByte
Return This._Volume
End Property
Property TBGM.Volume(newval As UByte)
Select Case This._Type
Case TBGM.FSOUND
FSOUND_SetVolume(This.Channel, newval)
Case TBGM.FMUSIC
FMUSIC_SetMasterVolume(This.FMUSIC_Ptr, newval)
End Select
End Property
Property TBGM.Paused() As Boolean
Return This._Paused
End Property
Property TBGM.Paused(newval As Boolean)
Select Case This._Type
Case TBGM.FSOUND
FSOUND_SetPaused(This.Channel, newval)
Case TBGM.FMUSIC
FMUSIC_SetPaused(This.FMUSIC_Ptr, newval)
End Select
End Property
Sub TBGM.PlayM(FileNameX As String, VolumeX As UByte = 255, PausedX As Boolean = FALSE)
If Trim(FileNameX) = "" Then This.StopM(): Exit Sub
This.Paused = TRUE
This.FileName = FileNameX
This.Volume = VolumeX
If PausedX = FALSE Then This.Paused = FALSE
End Sub
Sub TBGM.StopM()
Select Case This._Type
Case TBGM.FSOUND
FSOUND_StopSound(This.Channel)
Case TBGM.FMUSIC
FMUSIC_StopSong(This.FMUSIC_Ptr)
End Select
This._Type = TBGM.NONE
This._FileName = ""
This._Volume = 255
This._Paused = FALSE
End Sub
Sub TBGM.RestartM()
Dim FileNameX As String = This._FileName
This.FileName = ""
This.FileName = FileNameX
End Sub
Dim Shared LoadedData As TLoadedData
Dim Shared BGM As TBGM
Function LoadSong(FileName As String) As FMUSIC_MODULE Ptr
If FileExists(FileName) = FALSE Then LastError = FILE_NOT_FOUND: Return NULL
For i As Integer = 0 To UBound(LoadedData.Songs)
LastError = NULL
If LoadedData.Songs(i).FileName = "" Then
LoadedData.Songs(i).Handle = FMUSIC_LoadSong(FileName)
If LoadedData.Songs(i).Handle = NULL Then LastError = LOADING_ERROR: Return NULL
LoadedData.Songs(i).FileName = FileName
Return LoadedData.Songs(i).Handle
EndIf
Next
LastError = DATA_LIMIT_EXCEEDED: Return NULL
End Function
Function LoadSound(FileName As String) As FSOUND_SAMPLE Ptr
If FileExists(FileName) = FALSE Then LastError = FILE_NOT_FOUND: Return NULL
For i As Integer = 0 To UBound(LoadedData.Sounds)
LastError = NULL
If LoadedData.Sounds(i).FileName = "" Then
LoadedData.Sounds(i).Handle = FSOUND_Sample_Load(FSOUND_FREE, FileName, FSOUND_NORMAL, NULL, NULL)
If LoadedData.Sounds(i).Handle = NULL Then LastError = LOADING_ERROR: Return NULL
LoadedData.Sounds(i).FileName = FileName
Return LoadedData.Sounds(i).Handle
EndIf
Next
LastError = DATA_LIMIT_EXCEEDED: Return NULL
End Function
Sub LoadFile(FileName As String)
LastError = NULL
If FileExists(FileName) = FALSE Then LastError = FILE_NOT_FOUND: Exit Sub
SongHandle(FileName)
LastError = NULL
SoundHandle(FileName)
End Sub
Function SongHandle(FileName As String) As FMUSIC_MODULE Ptr
For i As Integer = 0 To UBound(LoadedData.Songs)
LastError = NULL
If Trim(UCase(LoadedData.Songs(i).FileName)) = Trim(UCase(FileName)) Then Return LoadedData.Songs(i).Handle
Next
LastError = NULL
Return LoadSong(FileName)
End Function
Function SoundHandle(FileName As String) As FSOUND_SAMPLE Ptr
For i As Integer = 0 To UBound(LoadedData.Sounds)
LastError = NULL
If Trim(UCase(LoadedData.Sounds(i).FileName)) = Trim(UCase(FileName)) Then Return LoadedData.Sounds(i).Handle
Next
LastError = NULL
Return LoadSound(FileName)
End Function
Function PlaySound(FileName As String, Volume As UByte = 255, Looping As Boolean = FALSE, Pan As Integer = FSOUND_STEREOPAN, Surround As Boolean = FALSE) As Integer
LastError = NULL
Dim Handle As FSOUND_SAMPLE Ptr = SoundHandle(FileName)
If Handle = NULL Then Return -1
Dim Channel As Integer = FSOUND_PlaySoundEx(FSOUND_FREE, Handle, NULL, TRUE)
FSOUND_SetVolume(Channel, Volume)
FSOUND_SetPan(Channel, Pan)
FSOUND_SetSurround(Channel, Surround)
FSOUND_SetLoopMode(Channel, IIf(Looping, FSOUND_LOOP_NORMAL, FSOUND_LOOP_OFF))
FSOUND_SetPaused(Channel, FALSE)
Return Channel
End Function
Sub Init(Freq As Integer = 44100, Channels As Integer = 32, Flags As Integer = 0)
LastError = NULL
If FSOUND_GetVersion() < FMOD_VERSION Then LastError = VERSION_ERROR: Exit Sub
If FSOUND_Init(Freq, Channels, Flags) = FALSE Then LastError = FMOD_INIT_ERROR: Exit Sub
End Sub
Sub Unload()
FMUSIC_StopAllSongs()
FSOUND_StopSound(FSOUND_ALL)
For i As Integer = 0 To UBound(LoadedData.Songs)
If LoadedData.Songs(i).Handle <> NULL Then FMUSIC_FreeSong(LoadedData.Songs(i).Handle)
Next
For i As Integer = 0 To UBound(LoadedData.Sounds)
If LoadedData.Sounds(i).Handle <> NULL Then FSOUND_Sample_Free(LoadedData.Sounds(i).Handle)
Next
FSOUND_Close()
End Sub
End Namespace |
Hier ein Beispiel, das die Problematik gut erläutert:
Code: | #Include "sound.bi"
Print "Starting FMOD...";
UMML.Init()
Print "OK"
Print "Playing onestop.mid...";
UMML.BGM.PlayM(Environ("windir") & "\media\onestop.mid")
Print "OK"
Print "Press a key...";
Sleep
Print "OK"
Print "Playing town.mid...";
UMML.BGM.PlayM(Environ("windir") & "\media\town.mid")
Print "OK"
Print "Press a key...";
Sleep
Print "OK"
Print "Playing onestop.mid again...";
UMML.BGM.PlayM(Environ("windir") & "\media\onestop.mid")
Print "OK"
Print "Press a key...";
Sleep
Print "OK"
Print "Shutting down...";
UMML.Unload()
Print "OK"
Print "Press a key...";
Sleep
Print "OK"
End |
mfG Cherry |
|
Nach oben |
|
|
Jojo alter Rang
Anmeldungsdatum: 12.02.2005 Beiträge: 9736 Wohnort: Neben der Festplatte
|
Verfasst am: 02.04.2008, 14:36 Titel: |
|
|
ich würd sagen, es liegt einfach an midi. midi ist schlecht kontrollierbar, vor allem die maximallautstärke ist nicht berechenbar (hängt von verwendeter soundfont und anzahl der stimmen ab). _________________ » Die Mathematik wurde geschaffen, um Probleme zu lösen, die es nicht gäbe, wenn die Mathematik nicht erschaffen worden wäre.
|
|
Nach oben |
|
|
Cherry
Anmeldungsdatum: 20.06.2007 Beiträge: 249
|
Verfasst am: 02.04.2008, 16:27 Titel: |
|
|
nein. wenn ich die Datei einfach so abspiele, also ohne sound.bi und nur mit fmusic_loadsong und fmusic_playsong, dann klappt alles! |
|
Nach oben |
|
|
Jojo alter Rang
Anmeldungsdatum: 12.02.2005 Beiträge: 9736 Wohnort: Neben der Festplatte
|
Verfasst am: 02.04.2008, 16:49 Titel: |
|
|
dann vergleiche doch bitte genau, wie sich die aufrufe in der sound.bi und der direkte aufruf unterschieden, z.B. bezüglich den parametern. das werde ich nämlich bestimmt nicht aufs genausete untersuchen... _________________ » Die Mathematik wurde geschaffen, um Probleme zu lösen, die es nicht gäbe, wenn die Mathematik nicht erschaffen worden wäre.
|
|
Nach oben |
|
|
Cherry
Anmeldungsdatum: 20.06.2007 Beiträge: 249
|
Verfasst am: 02.04.2008, 19:04 Titel: |
|
|
gar nicht, das ist das komische |
|
Nach oben |
|
|
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|