[SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

InitSound failed me so I tried the code below and still nothing. What's going on?
Other apps play sound. Checked dxdiag and it shows directx 12:

Code: Select all

Debug "start"
Beep_(800,100) 
    Beep_(900,100) 
    Beep_(1070,100) 
    Delay(2000)
    Beep_(800,100) 
    Beep_(900,100) 
    Beep_(1070,100) 
    Delay(2000)
    Beep_(800,100) 
    Beep_(900,100) 
    Beep_(1070,100) 
    Debug "end"
Last edited by Randy Walker on Thu Mar 13, 2025 6:13 am, edited 2 times in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

Sorry. Just tested beep code in PB v6.20 and worked fine.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

Somebody marked my OP [Solved] when it was not??? Hmmmm.

Anyway, Here is a snippet from my PB v5.62 and it shows "InitSound OK" so why no sound and no errors?

Code: Select all

If FileSize("C:\Windows\Media\Alarm01.wav") > 0
  Debug "see the file"
  If InitSound() <> 0
    Debug "initSound OK"
    If LoadSound(0,"C:\Windows\Media\Alarm01.wav")
    EndIf
  Else
    Debug "Don't get the InitSound"
  EndIf
  Debug "Play Sound"
  PlaySound(0)
EndIf
As mentioned earlier I have Directx 12
Also same code on my PB v6.20 does not play.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: No Sound at All (Windows 11 Pro / PB v5.62)

Post by RASHAD »

Hi Randy
Which one you suspect Fred,freak,kiffi or idle :mrgreen: :mrgreen:
You need a proper delay time
Try the next

Code: Select all

If FileSize("C:\Windows\Media\Alarm01.wav") > 0
  Debug "see the file"
  If InitSound() <> 0
    Debug "initSound OK"
    If LoadSound(0,"C:\Windows\Media\Alarm01.wav")
    EndIf
  Else
    Debug "Don't get the InitSound"
  EndIf
  Debug "Play Sound"
  PlaySound(0, #PB_Sound_Loop)
  MessageRequester("Sound", "Playing the sound (loop)..."+#LF$+"Click to quit..", 0)
EndIf
Egypt my love
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

RASHAD wrote: Thu Mar 13, 2025 5:28 am Hi Randy
Which one you suspect Fred,freak,kiffi or idle :mrgreen: :mrgreen:
You need a proper delay time
Try the next

Code: Select all

If FileSize("C:\Windows\Media\Alarm01.wav") > 0
  Debug "see the file"
  If InitSound() <> 0
    Debug "initSound OK"
    If LoadSound(0,"C:\Windows\Media\Alarm01.wav")
    EndIf
  Else
    Debug "Don't get the InitSound"
  EndIf
  Debug "Play Sound"
  PlaySound(0, #PB_Sound_Loop)
  MessageRequester("Sound", "Playing the sound (loop)..."+#LF$+"Click to quit..", 0)
EndIf
Hi RASHAD. As always, you did it again. THANKS!!!!
Could have been any one of them. They've probaby all learned to hate the site of me by now :lol:
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

RASHAD wrote: Thu Mar 13, 2025 5:28 am Hi Randy
Which one you suspect Fred,freak,kiffi or idle :mrgreen: :mrgreen:
I'm going to go with Idle on that one. He's been Posting comments to my uptime code over there in the Windows forum Like I've never seen so I think he might be feeling a little guilty. :mrgreen:
Whoever... I take no offense. 8)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by AZJIO »

Code: Select all

ini_Signal$ = "C:\Windows\Media\Alarm01.wav"
;- InitSound
Global IsSound = 0
#RingTone = 0
If Asc(ini_Signal$) And FileSize(ini_Signal$) > 0 And InitSound()
	If LoadSound(#RingTone, ini_Signal$)
		IsSound = SoundLength(#RingTone, #PB_Sound_Millisecond)
		If IsSound > 3000
			IsSound = 3000
		EndIf
	EndIf
EndIf

success = 1
If success And IsSound
	PlaySound(#RingTone)
	Delay(IsSound)
EndIf
The sound in the thread does not block the window.

Code: Select all

EnableExplicit
Define x, success
Define ini_Signal$ = "C:\Windows\Media\Alarm01.wav"
Global IsSound = 0
#RingTone = 0
If Asc(ini_Signal$) And FileSize(ini_Signal$) > 0 And InitSound()
	If LoadSound(#RingTone, ini_Signal$)
		IsSound = SoundLength(#RingTone, #PB_Sound_Millisecond)
	EndIf
EndIf

Procedure Sound(*Value)
	If PeekI(*Value) = 1 And IsSound
		PlaySound(#RingTone)
		Delay(IsSound)
	EndIf
EndProcedure

If OpenWindow(0, 0, 0, 420, 100, "The sound in the thread does not block the window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget(1, 10, 10, 99, 30, "Sound")
	ButtonGadget(2, 10, 50, 242, 30, "click when a melody is playing")

	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 2
						x + 1
						SetGadgetText(2, Str(x))
					Case 1
						success = 1 ; some operation was successful, signaling with a sound
						CreateThread(@Sound(), @success)
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

AZJIO wrote: Thu Mar 13, 2025 10:26 am The sound in the thread does not block the window.
Hmmm. THANKS AZJIO -- I never messed with threads before. Maybe I should tick the thread safe option?
I can't pretend to know what Asc in this If line is doing:
If Asc(ini_Signal$) And FileSize(ini_Signal$) > 0 And InitSound()
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by AZJIO »

Randy Walker wrote: Thu Mar 13, 2025 7:24 pm I can't pretend to know what Asc in this If line is doing:
This checks that the row is not empty. If there is any character in it, it returns a number greater than zero. If Null, it returns 0. This is the fastest way to check that the row is not empty. This function takes the first character and returns the code of the number. More precisely, the string is binary data, the first binary code is taken, for example, for "A" it is 65. It is not necessary to read the entire string, just take the first character and check that it is not 00. An empty string ends with a null-terminated 00 character, so if we take an empty string, we get 0.
Randy Walker wrote: Thu Mar 13, 2025 7:24 pm Maybe I should tick the thread safe option?
yes
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

AZJIO wrote: Thu Mar 13, 2025 7:55 pm
Randy Walker wrote: Thu Mar 13, 2025 7:24 pm I can't pretend to know what Asc in this If line is doing:
This checks that the row is not empty. If there is any character in it...
Maybe I should tick the thread safe option?
yes
Got it. THANKS AZJIO !!!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by AZJIO »

Randy Walker wrote: Wed Mar 12, 2025 8:17 am

Code: Select all

Beep_(800,100)
Modern operating systems do not provide access to the system speaker, the squeaker. Sometimes this sound is emulated on an audio card. I used to play with this by creating melodies, now I realize that you can't hear it on many computers.
Randy Walker
Addict
Addict
Posts: 989
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: [SOLVED] No Sound at All (Windows 11 Pro / PB v5.62)

Post by Randy Walker »

AZJIO wrote: Thu Mar 13, 2025 8:07 pm
Randy Walker wrote: Wed Mar 12, 2025 8:17 am

Code: Select all

Beep_(800,100)
Modern operating systems do not provide access to the system speaker, the squeaker. Sometimes this sound is emulated on an audio card.
Yeah, works here ok but comes out sound card, yep.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply