Sound - help please
Blitz3D Forums/Blitz3D Beginners Area/Sound - help please
| ||
| I've finally got around to doing sound in Blitz, after taming Tokamak, I thought it would be easy, but... I just can't get anything to play. to test, I put this in the main body (before the loop) /// sound1 = LoadSound("x.wav") PlaySound(sound1)" /// where x.wav is in the same directory as my bb file. No luck. I though perhaps 2D sound was disabled in Blitz3D in favour of the 3D 'listener method'. So I tried this: /// chime = Load3DSound (" x.wav") mic = CreateListener(cam2) EmitSound(chime,cam2) /// now I realise that blitz doesn't check for the existence of "x.wav" (there's no 'sound does not exist' error message), but the files is there and present. Any help would be appeciated, as having blitz mute isn't great! |
| ||
Try
sound1=LoadSound("x.wav")
Print sound1
( You can replace print with DebugLog if you prefer. ) Tell me what it prints/logs. |
| ||
| Hi Sybixsus, thanks for quick reply. In the debug log is says '3888944'. |
| ||
| make sure x.wav is a valid pcm wav, try playing a sound from your windows\media folder |
| ||
| Hey again, I copied across 'ding.wav', and did the debug log again, and got the same number '3888944'. Hmm. |
| ||
Try removing the peroid from the file name.
chime = Load3DSound (" x.wav")
to
chime = Load3DSound (" x_wav")
|
| ||
| try using a different thing than x, name it "sound1.wav" |
| ||
| ..is the sample sampled at cd quality, 16bit sound? - if its not, it wont play...or ive experienced this - in the past...it must be hardcoded into blitz..perhaps - for simplicity..hmmmm check the sample rate....... |
| ||
| ..is the sample sampled at cd quality, 16bit sound? Yes, it will. - if its not, it wont play |
| ||
| It might be worth trying a 'LoopSound' just to see if you hear anything - perchance the sound is playing and finishing too quick. I mention it as you appear to be doing it as a one-off outside the main loop. Check for any other sound commands that are killing it prior to the game even reaching the main loop. Of course, you may have done this already - thought I'd mention it. |
| ||
| are you sure gfk - have you tried the lower sample frequencies? - cuz they didnt work on my system..hmmm |
| ||
| are you sure gfk 100% Sure. have you tried the lower sample Yup. frequencies? |
| ||
Try this. I know this works.
; Press space to initiate interactive mode!
Const GW = 320
Const GH = 240
Const TexSize = 256 ; Reduce this to 256 for extra FPS.
Const ScrollRate = 4 ; Number of pixels to scroll per frame.
Const MIN_BALL_SPEED = 4
Const MAX_BALL_SPEED = 8
; Init
Graphics GW, GH, 16, 1
SeedRnd MilliSecs()
BLx = GW/2
BLy = GH/2
BLvx = -1
BLvy = -1
BallWidth = GW/64
BallSpeed = MIN_BALL_SPEED
PaddleWidth = GW/64
PaddleHeight = GH/8
P1x = GW/32
P2x = GW-((GW/32)+PaddleWidth)
PaddleSpeed = MIN_BALL_SPEED
P1AI = True ; Enable to have P1 controlled by AI by default. Disable to have P1 controlled by mouse.
; Precalc
Dim TxL(GW, GH)
Dim TyL(GW, GH)
For By = 0 To GH-1
For Bx = 0 To GW-1
YLoc# = Float(By) / Float(GH)
XLoc# = Float(Bx) / Float(GW)
Radius# = YLoc# * Float(TexSize)
Angle# = XLoc# * 360.0
TxL(Bx, By) = Floor((TexSize/2.0) + (Radius# * Cos(Angle)))
TyL(Bx, By) = Floor((TexSize/2.0) + (Radius# * Sin(Angle)))
Next
Next
; Text
Dim Txt$(14)
Data "!", "?", ":)", ":(", "X", "O", "1", "0", "-", "+", "<", ">", "\", "/"
For D = 0 To 13
Read Txt$(D)
Next
; Font
FONT_Arial1 = LoadFont("Arial Black", 30, False, False, False)
FONT_Arial2 = LoadFont("System", GH/6, False, False, False)
; Texture
Tex = CreateImage(TexSize, TexSize)
TexBuffer = ImageBuffer(Tex)
TexSize2 = TexSize / 2
; Timer init
Min_Frame_Time = Floor(1000.0/Float(MAX_FPS))
Frame_Period = Min_Frame_Time
Current_Time = MilliSecs()
Game_Start_Time = Current_Time
; Sounds.
Gosub MakeSounds
SND_Ping1 = LoadSound("ping1.wav")
SND_Ping2 = LoadSound("ping2.wav")
SND_Expl = LoadSound("expl.wav")
SetBuffer TexBuffer
Repeat
PaddleSpeed = BallSpeed - Rand(-1, 2)
; Distort.
LockBuffer BackBuffer()
LockBuffer TexBuffer
For By = 0 To (GH/2)-1
For Bx = 0 To GW-1
YLoc# = Float(By) / Float(GH) ; YLoc will never be greater than 0.5.
; Get pixel from texture and manipulate it.
Pixel = ReadPixelFast(TxL(Bx, By), TyL(Bx, By), TexBuffer)
Shade# = Yloc#*2.0 ; Dark edges
; Get green only.
Pixel = ((((Pixel Shr 8) And 255) * Shade#) Shl 8) ; Or ($ff000000)
; Full RGB copy.
;Pr = ((Pixel Shr 16) And 255) * Shade#
;Pg = ((Pixel Shr 8) And 255) * Shade#
;Pb = (Pixel And 255) * Shade#
;Pixel = Pb Or (Pg Shl 8) Or (Pr Shl 16) Or ($ff000000)
; Write top and mirror bottom pixels.
WritePixelFast Bx, By, Pixel, BackBuffer()
WritePixelFast Bx, (GH-1)-By, Pixel, BackBuffer()
Next
Next
UnlockBuffer BackBuffer()
UnlockBuffer TexBuffer
; Scroll, fill.
CopyRect 0, 0, TexSize, TexSize-ScrollRate, 0, ScrollRate, TexBuffer, TexBuffer
Color 0,0,0
Rect 0,0, TexSize, ScrollRate, 1
; Draw green text.
SetFont FONT_Arial1
Color 0, Rand(0, 196), 0
Text Rand(0, TexSize-1), 0, Txt$(Rand(0, 13))
; Draw paddles and ball.
SetBuffer BackBuffer()
Color 0, 255, 0
; P1 AI
If Not P1AI
; Player input.
; If mouse is so far down the screen that the paddle is partially off the screen, reposition it.
If MouseY() > (GH-PaddleHeight) Then MoveMouse MouseX(), (GH-PaddleHeight)
P1y = MouseY()
Else
; If ball is moving towards paddle...
If BLvx < 0
; If center of paddle is lower than ball, then move paddle up. Otherwise, move paddle down.
If ((P1y+(PaddleHeight/2)) > BLy)
P1y = P1y - PaddleSpeed
Else
P1y = P1y + PaddleSpeed
EndIf
EndIf
EndIf
; Keep paddle on screen.
If P1y < 0 Then P1y = 0
If P1y > (GH-PaddleHeight) Then P1y = GH-PaddleHeight
; P2 ai
; If ball is moving towards paddle...
If BLvx > 0
; If center of paddle is lower than ball, then move paddle up. Otherwise, move paddle down.
If ((P2y+(PaddleHeight/2)) > BLy)
P2y = P2y - PaddleSpeed
Else
P2y = P2y + PaddleSpeed
EndIf
EndIf
; Keep paddle on screen.
If P2y < 0 Then P2y = 0
If P2y > (GH-PaddleHeight) Then P2y = GH-PaddleHeight
; Ball Ai
; Ball collide with paddle.
; If ball moving towards paddle...
; (Prevents multiple collisions from occuring.)
If BLvx < 0
; If ball collides with paddle...
If RectsOverlap(P1x, P1y, PaddleWidth, PaddleHeight, BLx, BLy, BallWidth, BallWidth)
BLvx = -BLvx
PlaySound SND_Ping1
BallSpeed = BallSpeed + 1
EndIf
EndIf
If BLvx > 0
If RectsOverlap(P2x, P2y, PaddleWidth, PaddleHeight, BLx, BLy, BallWidth, BallWidth)
BLvx = -BLvx
PlaySound SND_Ping2
BallSpeed = BallSpeed + 1
EndIf
EndIf
; Keep ball from going so fast that it ignores paddle collisions.
If (BallSpeed > MAX_BALL_SPEED) Then BallSpeed = MAX_BALL_SPEED
; Left wall
If BLx < 0
P2Score = P2Score + 1
BLx = GW/2
BLy = GH/2
BLvx = -BLvx
BLvy = -BLvy
PlaySound SND_Expl
BallSpeed = MIN_BALL_SPEED
EndIf
; Right wall
If BLx > GW
P1Score = P1Score + 1
BLx = GW/2
BLy = GH/2
BLvx = -BLvx
BLvy = -BLvy
PlaySound SND_Expl
BallSpeed = MIN_BALL_SPEED
EndIf
; Top/Bottom wall
If (BLy < 0) Or (BLy > (GH-BallWidth)) Then BLvy = - BLvy
; Move ball
BLx = BLx + (BLvx * BallSpeed)
BLy = BLy + (BLvy * BallSpeed)
; Draw P1
Rect P1x, P1y, PaddleWidth, PaddleHeight, 1
; Draw P2
Rect P2x, P2y, PaddleWidth, PaddleHeight, 1
; Draw ball.
Rect BLx, BLy, BallWidth, BallWidth, 1
; Draw scores
SetFont FONT_Arial2
Text (GW/2)-(GW/8), GH/32, P1Score, True, False
Text (GW/2)+(GW/8), GH/32, P2Score, True, False
SetBuffer TexBuffer
; Flip!
Flip True
; Toggle interactive mode via space.
If KeyHit(57) Then P1AI = Not P1AI
Until KeyHit(1)
DeleteFile "expl.wav"
DeleteFile "ping1.wav"
DeleteFile "ping2.wav"
End
.MakeSounds
DeleteFile "expl.wav"
DeleteFile "ping1.wav"
DeleteFile "ping2.wav"
File = WriteFile("expl.wav")
WriteWavHeader(File, 1, 44000, 16, 44000)
For SampleLoop = 0 To 44000-1
Loc# = Float(SampleLoop) / 44000.0
If (SampleLoop Mod 4) = 0 Then Sample = Rand(-32767, 32767) * (1.0 - Loc#)
WriteShort File, Sample
Next
CloseFile File
File = WriteFile("ping1.wav")
Freq# = 440
WriteWavHeader(File, 1, 44000, 16, 20000)
For SampleLoop = 0 To 20000-1
Loc# = Float(SampleLoop) / 20000.0
Sample = (Sin(Loc#*Freq#*360.0)*32767.0) * (1.0-Loc#)
WriteShort File, Sample
Next
CloseFile File
File = WriteFile("ping2.wav")
Freq# = 220
WriteWavHeader(File, 1, 44000, 16, 20000)
For SampleLoop = 0 To 20000-1
Loc# = Float(SampleLoop) / 20000.0
Sample = (Sin(Loc#*Freq#*360.0)*32767.0) * (1.0-Loc#)
WriteShort File, Sample
Next
CloseFile File
Return
; This function writes a header to a wav file which you've already opened.
; File is the handle of the file.
Function WriteWavHeader(File, Channels, Frequency, Bits, Samples)
Local SampleSize = Channels * (Bits / 8)
Local WavSize = (Samples * SampleSize) + 52 ; Size of the wave file - include room for headers
; "RIFF"
WriteByte File, 82
WriteByte File, 73
WriteByte File, 70
WriteByte File, 70
; Size of the wav file not including the "RIFF" header and this 4-byte file size.
WriteInt File, WavSize - 8
; "WAVE"
WriteByte File, 87
WriteByte File, 65
WriteByte File, 86
WriteByte File, 69
; "fmt "
WriteByte File, 102
WriteByte File, 109
WriteByte File, 116
WriteByte File, 32
; Size of the format section.
WriteInt File, 18
; Format = PCM
WriteByte File, $01
WriteByte File, $00
; Channels
WriteByte File, Channels And $FF
WriteByte File, (Channels And $FF00) Shr 8
; Samples per second.
WriteInt File, Frequency
; Average bytes per second.
WriteInt File, Frequency * SampleSize
; Block align
WriteByte File, SampleSize And $FF
WriteByte File, (SampleSize And $FF00) Shr 8
; Bits per sample.
WriteByte File, Bits And $FF
WriteByte File, (Bits And $FF00) Shr 8
; Total extra information bytes.
WriteByte File, $00
WriteByte File, $00
; "data"
WriteByte File, 100
WriteByte File, 97
WriteByte File, 116
WriteByte File, 97
; Size of the data section.
WriteInt File, WavSize - 52
End Function
|
| ||
| showoff :) |
| ||
| Thanks to everyone for the help so far, I really appreciate it. But... I've done some more fiddling and discovered: -I just can't get .wav files to play in Blitz. Neither within the program, or in compiled Blitz files other people have made. Perhaps it's some hardware compatability thing? I've run Sswifts program and got no wave sound. I've run the demos that come with blitz ('tunnel' and 'wing ring') and their wave sound doesn't play either. I've run the compiled programs on the Blitz demostration CD and go not wave sound. Damn. Thing is, I'm running a vanilla Sound Blaster Audigy, so I wouldn't have thought wave compatability would be a big issue. -I CAN get midi files to work. Big whoop. "Wing Ring"'s midi file plays back fine, which makes the lack of wave support bizarre. -Here a tip. Although 'loadsound' and 'playsound' don't check to see if it was a valid sound file to begin with, 'loopsound' does check this. So 'loopsound' is a valuable tool to have in the sound debugging process. Any help of suggestions would be appreciated. |
| ||
| What version of the drivers are you using? Are they the latest version? What version directX do you have installed? What version blitz are you using? Can you play wav files in other programs? Do you have your speakers plugged in? Is the wave volume muted or set low in your volume controls (if you have a speaker icon in the taskbar, double click it, alternatively, check the control panel). |
| ||
| Joe: Find out what kind of sound card onboard motherboard sound you have, in your control panel system device manager, and then download new drivers for it. Also reinstall the latest version of DirectX. |
| ||
| Thing is, I'm running a vanilla Sound Blaster Audigy, I'm guessing it's a SB Audigy. :) |
| ||
| showoff :) What happened to the thread with all that demo stuff in? (Eveything was generated with no external files.) It was bloody marvelous, all that. |
| ||
| THANK YOU EVERYBODY. I have solved the problem. Here's the solution for those of you with whetted minds... Under the 'Control Panel', -> 'Audio Devices' -> 'Audio' -> 'Advanced Options' there is a slider to set the level of hardware acceleration for audio. It was on 'full acceleration'. Changing this to 'standard acceleration' gets all Blitz sound working. Again, thank you to everyone who responded, and without your help I definietely wouldn't have tracked down and eliminated the source of the incompatability so quickly. Viva la audio! |
| ||
| that might suggest a driver or directX issue. |
| ||
| Yeah you should be able to use Full Acceleration - check your drivers as Perbutabitio says. Also if you have sound on your motherboard too, as well as your Audigy 2, you might want to try disabling the onboard sound somewhere in the BIOS. |