Problem with PlayMusic

Report any Hollywood bugs here
Post Reply
Randy
Posts: 4
Joined: Sat Jul 15, 2023 2:50 pm

Problem with PlayMusic

Post by Randy »

Hello,

Having problems with playing wav music file. I purchase some wav music file to play in a game. Started to code the music function. During testing the functions the music playing wound start to distort, then repeat a small part of the music, and finally exit with error code 135 error message Bus error. This would happen around the fourth music file. Change the order of music file and still the same error. I'm unable to upload the music files because of the license. So download some music file that allow me to share. But unable to reproduce the same error code, but during testing these music file will continue play without stopping. It repeats a small part of the song, but the positioning show it starting over from the beginning of the music.
Would like to find out if it's my system or Hollywood. Can someone please test to verify? I'm using Debian Linux System Version 10 4.19.0-26-amd64 #1 SMP Debian 4.19.304-1 (2024-01-09) x86_64 GNU/Linux

music.hws file:

Code: Select all

/*****************************************************************************
 *
 * Music
 *
 *****************************************************************************/

Const #MSC_CHANNEL = 1
Const #MSC_VOLUME  = 32

Const #MSC_IRRAT   = 0
Const #MSC_FELEX	 = 1

Const #MSC_MAX     = 1

Global gSongList = { 	"Irrational Machines.wav",
				"Felix de Natris.wav" }  ; This songs repeats a small part of song forever. Pos starts over?
											
Global gSongIndex
Global gSongID
Global gPlayMusic
Global gSongRandom
Global gSongCount
Global gMusicPos
Global gMusicFor
Global gMusicDur


Function p_InitMusic()
	;OpenAudio()
	gSongID = Nil
	gSongIndex = -1
	gPlayMusic = False
	gSongRandom = False
	gSongCount = 0
	gMusicPos = 0
	gMusicDur = 0
	gMusicFor = Nil
	DebugPrint("p_InitMusic: Initialized.")
EndFunction


Function p_SongRandomOn()
	gSongRandom = True
EndFunction


Function p_SongRandomOff()
	gSongRandom = False
EndFunction


Function p_PlaySong(Idx)
  If Idx < 0 or Idx > #MSC_MAX
		DebugPrint("p_PlaySong: Song index out of range. Idx:", Idx)
		Return
	EndIf
  If gSongID <> Nil
		StopMusic(gSongID)
	  ;CloseMusic(gSongID)
		DebugPrint("p_PlaySong: Close-->", gSongList[Idx])
	EndIf
	
	gSongID = Nil
	DebugPrint("p_PlaySong: Open--->", gSongList[Idx])
	gSongID = OpenMusic(Nil, GetDirectoryEntry(3, gSongList[Idx]))
	gMusicDur = GetAttribute(#MUSIC, gSongID, #ATTRDURATION)
	gMusicFor = GetAttribute(#MUSIC, gSongID, #ATTRFORMAT)
	gMusicPos = GetAttribute(#MUSIC, gSongID, #ATTRPOSITION)
	gSongIndex = Idx
	If gPlayMusic = True
		DebugPrint("p_PlaySong: Play--->", gSongList[Idx])
		PlayMusic(gSongID, {Channel = #MSC_CHANNEL})
		gSongCount = gSongCount + 1
		DebugPrint("p_PlaySong: gSongCount -->", gSongCount)
	EndIf
	
EndFunction	


Function p_MusicOff()
 gPlayMusic = False
 If gSongID <> Nil
  StopMusic(gSongID)
 EndIf
 DebugPrint("p_MusicOff: gPlayMusic =", gPlayMusic)
EndFunction


Function p_MusicOn()
 gPlayMusic = True
 If gSongID <> Nil
  PLayMusic(gSongID)
 EndIf
 DebugPrint("p_MusicOn: gPlayMusic =", gPlayMusic)
EndFunction


; 0 = mute, 1 to 64
Function p_SetMusicVolume( volume)
	If volume > 64 Then volume = 64
	If volume < 0 Then volume = 0
	DebugPrint("p_SetMusicVolume:", volume)
	SetChannelVolume(#MSC_CHANNEL, volume)
EndFunction


Function p_PlayNextSong()

	If gPlayMusic = False Then Return
  If gSongID <> Nil
	  If IsMusicPlaying(gSongID) = True
			gMusicPos = GetAttribute(#MUSIC, gSongID, #ATTRPOSITION)
			Return
		EndIf
		DebugPrint("p_PlayNextSong: IsMusicPlaying = False")
		;StopMusic(gSongID)
		;CloseMusic(gSongID)
		gSongID = Nil
	EndIf
	
	DebugPrint("p_PlayNextSong: Old gSongnIndex:", gSongIndex)
	
	If gSongRandom = False
			gSongIndex = gSongIndex + 1
			DebugPrint("p_PlayNextSong: New gSongnIndex:", gSongIndex)
		Else
			gSongIndex = Rnd(#MSC_MAX)
			DebugPrint("p_PlayNextSong: Random Song:", gSongIndex)
	Endif
	
	If gSongIndex > #MSC_MAX Or gSongIndex < 0 Then gSongIndex = 0
	
	If IsMusic(GetDirectoryEntry(3, gSongList[gSongIndex])) = True
			DebugPrint("p_PlayNextSong: Open--->", gSongList[gSongIndex])
			gSongID = OpenMusic(Nil, GetDirectoryEntry(3, gSongList[gSongIndex]))
			DebugPrint("p_PlayNextSong: Play--->", gSongList[gSongIndex])
			PlayMusic(gSongID, {Channel = #MSC_CHANNEL})
			gMusicDur = GetAttribute(#MUSIC, gSongID, #ATTRDURATION)
			gMusicFor = GetAttribute(#MUSIC, gSongID, #ATTRFORMAT)
			gMusicPos = GetAttribute(#MUSIC, gSongID, #ATTRPOSITION)
		Else
			DebugPrint("p_PlayNextSong: Unsupported Music Format -->", gSongList[gSongIndex])
			gMusicDur = 0
			gMusicFor = Nil
			gMusicPos = 0
			Return
	EndIf

  gSongCount = gSongCount + 1
	DebugPrint("p_PlayNextSong: gSongCount -->", gSongCount)

EndFunction


main.hws file:

Code: Select all

/****************************************************************
**                                                             **
** playmusic bug
** Interpreter: Hollywood 10.0                                 **
**                                                             **
**                                                             **
****************************************************************/

/*
** For Hollywood 10.0
*/
@VERSION 10,0

@OPTIONS {EnableDebug = True}
@OPTIONS {ConsoleMode = True}

/*
** Information about this app
*/
@APPTITLE "PlayMusic Bug"
@APPVERSION "$VER: Bug .1 (1/20/24)"
@APPCOPYRIGHT "(C) 2024 Randy Butler"
@APPAUTHOR "Randy Butler"
@APPDESCRIPTION "PlayMusic Bug"

Const #MUSIC_DIR_LOC = "music"
@DIRECTORY 3, #MUSIC_DIR_LOC

@INCLUDE "music.hws"


@DISPLAY {Title = "Playmusic", Width = 800, Height = 600} ;Borderless = True


Function p_MainMenu()
	
	p_PlayNextSong()
	
	Cls
	SetFontColor(#YELLOW)
		
	/* Music Information */
	TextOut(20, 100, "FILENAME:")
	TextOut(20, 110, "FORMAT:")
	TextOut(20, 120, "DURATION:")
	TextOut(20, 130, "POSITION:")
	TextOut(20, 150, "COUNT:")
	
	TextOut(100, 100, gSongList[gSongIndex])
	TextOut(100, 110, gMusicFor)
	TextOut(100, 120, gMusicDur)
	TextOut(100, 130, gMusicPos)
	TextOut(100, 150, gSongCount)
	
	Flip
	
	;Wait(10)
EndFunction



;LegacyControl("SingleMusic", False)

;Initialize 
p_InitMusic()
p_MusicOn()
;p_SongRandomOn()

;LeftMouseQuit(TRUE)
EscapeQuit(TRUE)
BeginDoubleBuffer(True)

SetInterval(1, p_MainMenu, 1000/30) ; 30fps

Repeat
	info = WaitEvent()
	;DebugPrint("WaitEvent", info.Action, info.ID, info.Triggered)
Forever

Music files
https://familybusinesssoftware.com/imag ... sic.tar.gz
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Problem with PlayMusic

Post by Flinx »

Just a first impression (I've only looked at it under Windows):
You call the functions IsMusicPlaying(gSongID) and GetAttribute(#MUSIC, gSongID, #ATTRPOSITION) at 30Hz.
Instead of IsMusicPlaying, I would try an event handler for OnMusicEnd, and as for the position: is it really needed that precisely?
Regardless of the problem, WAV doesn't seem very resource efficient to me either. How about FLAC, if it has to be lossless?
User avatar
Juan Carlos
Posts: 891
Joined: Mon Sep 06, 2010 1:02 pm

Re: Problem with PlayMusic

Post by Juan Carlos »

Hollywood to play wav files use the internal codes from OS host, here it be the problem, incompatibilities, for example in 68k use the wav dataypes but the quality depends of this datatype, to make games or programs using sounds the best choice is convert the wav files to other format for example oggvorbis to can use the Hollywood plugin or if the quality isn't very important convert the wav file to 8svx format.
Flinx
Posts: 192
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Problem with PlayMusic

Post by Flinx »

Now I have also tried it on Linux (Mint 21.2) and can confirm the problem with the two files.
IsMusicPlaying() remains True at the end, the playback repeats the last buffer content and the position starts again from the beginning.
An OnMusicEnd event does not occur either.
Strangely enough, this does not happen with two music files converted to the same WAV format.
Then I converted the two files to FLAC using ffmpeg and it works as it should.
Randy
Posts: 4
Joined: Sat Jul 15, 2023 2:50 pm

Re: Problem with PlayMusic

Post by Randy »

The problem/bug is with mp3, wav, and flac music files I have tested. The some of the mp3 and wav file will repeat over and over a small part of the song. Some times the wav and flac music files will exit with error code 135 and the message is "Bus Error" It's very hard to trace this bug because it's not very file, just one or two. Every format I have try as some problem. At first I thought is was a corrupt file so I just deleted the file and moved on. But the problem repeat every so often. Then I tested the music file I thought were corrupted and found out they play without any problems with other players. I would like to thank every who tested and confirmed there is a bug with Hollywood and not with my systems. Thank you!
User avatar
airsoftsoftwair
Posts: 5450
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Problem with PlayMusic

Post by airsoftsoftwair »

I think this might not be related to the audio files but it's an issue with Hollywood's sound driver on Linux. There have been some major audio changes to Linux recently and Hollywood might need some fixes here and there to be compatible with them. It's on my list already.
Post Reply