Confused about SoundPlay and Wave volume Topic is solved
-
- Posts: 343
- Joined: 08 Jun 2019, 17:36
Re: Confused about SoundPlay and Wave volume
I had that idea, thanks for putting it together. Unfortunately the WMPlayer comobject (or perhaps the while loops) is conflicting with my ocr code and causing async errors. I will be trying out bass.ahk for now and see how it goes. If you can take a look it's not overly complicated. The trouble is I have to set the volume *after* the sound begins and you can hear a small blip of full volume before it kicks in. I'm so close I just cant seem to get the hstream before the initial BASS_Play() call.
-
- Posts: 343
- Joined: 08 Jun 2019, 17:36
Re: Confused about SoundPlay and Wave volume
Ok had to update the library to add a Volume arg to BASS_Play() and BASS_StreamFileToChannel()
So now can do:
Code: Select all
BASS_Play(File="",Volume:=""){ ;plays a file or restarts it when paused and no file is specified (returns hStream on success, otherwise -1)
Return BASS_StreamFileToChannel("Play",File,Volume)
}
BASS_StreamFileToChannel(Modus,File="",Volume:=""){
static
If (File AND !FileExist(File)){ ;check if file exists when specified
MsgBox, 48, BASS error!,
(Ltrim
File does not exist:
%File%
)
Return -1
}
If (Modus = "Play" And File){ ;play file from beginning
If !(hStream := DllCall("BASS\BASS_StreamCreateFile", UInt,FromMem:=0
, UInt,&File, UInt64,Offset:=0, UInt64,Length:=0
, UInt,(A_IsUnicode ? 0x80000000 : 0x40000))){
ErrorLevel := BASS_ErrorGetCode()
MsgBox, 48, BASS error!,
(Ltrim
Failed to create a stream from file:
%File%
Error: %ErrorLevel%
)
Return -1
}
if (Volume)
BASS_SetSliding(hStream,2,Volume,0)
If !DllCall("BASS\BASS_ChannelPlay", UInt,hStream, Int,Restart:=1){
ErrorLevel := BASS_ErrorGetCode()
MsgBox, 48, BASS error!,
(Ltrim
Failed to play stream from file:
%File%
Error: %ErrorLevel%
)
Return -1
}
}Else If (Modus = "Play" And !File And hStream){ ;restart playback (when paused)
If !DllCall("BASS\BASS_ChannelPlay", UInt,hStream, Int,Restart:=0){
ErrorLevel := BASS_ErrorGetCode()
MsgBox, 48, BASS error!,
(Ltrim
Failed to restart stream from file:
%File%
Error: %ErrorLevel%
)
Return -1
}
}Else If (Modus = "Stop" And hStream){ ;stop playback
If BASS_IsPlaying(hStream)
If !DllCall("BASS\BASS_ChannelStop", UInt,hStream){
ErrorLevel := BASS_ErrorGetCode()
MsgBox, 48, BASS error!,
(Ltrim
Failed to stop stream from file:
%File%
Error: %ErrorLevel%
)
Return -1
}
hStream = ;clear hStream
}Else If (Modus = "Pause" And hStream){ ;toogle pause of playback
local IsPlaying
IsPlaying := BASS_IsPlaying(hStream) ;get status
If (IsPlaying = 3) ;stream is paused
hStream := BASS_Play() ;restart playback
Else If (IsPlaying = 1){ ;stream is playing
If !DllCall("BASS\BASS_ChannelPause", UInt,hStream){ ;pause playback
ErrorLevel := BASS_ErrorGetCode()
MsgBox, 48, BASS error!,
(Ltrim
Failed to pause stream from file:
%File%
Error: %ErrorLevel%
)
Return -1
}
}
}
Return hStream
}
Code: Select all
hStream := BASS_Play(mediaFilePath,.5) ; play file at 50% volume
Re: Confused about SoundPlay and Wave volume
Does anyone know how to reset back to master volume after a simple SoundPlay has run?
Edit** I figured it out. See Spoiler Below. Just used SoundGet, Master & SoundSet, Master
So... My simple SoundPlay code that works is as follows:
Here is a code I have for SoundBeep that resets to what the volume was before the beep sound which is exactly what I want but for SoundPlay.
I tried extracting parts but no luck
Edit** I figured it out. See Spoiler Below. Just used SoundGet, Master & SoundSet, Master
Spoiler
So... My simple SoundPlay code that works is as follows:
Code: Select all
z::
File := "C:\Users\Mylo\Downloads\New Recording.m4a"
SoundPlay(File,,8)
SoundPlay(File, Wait = 0, VolumePercent = 100) {
SoundSet, %VolumePercent%
SoundPlay, %File%, %Wait%
}
return
I tried extracting parts but no luck
Code: Select all
z::
SoundBeep(700, 33)
return
soundbeep(frequency:=523, volume:=50) {
global master_volume, volume_unset
static _ := onexit("on_exit_sb")
if not (volume_unset) {
soundget master_volume
volume_unset := true
} soundset % volume
soundbeep % frequency
settimer, return_master_volume, -150
}
return_master_volume() {
global master_volume, volume_unset
soundset master_volume
volume_unset := false
}
on_exit_sb() {
global master_volume, volume_unset
if (volume_unset) {
sleep 150
SoundSet % master_volume
}
}
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
Why not like this:
Code: Select all
soundbeep(900, 10)
soundbeep(frequency:=523, volume:=50) {
SoundGet, master_volume
SoundSet, volume
SoundBeep, frequency
SoundSet, master_volume
}
Re: Confused about SoundPlay and Wave volume
Yes that's easier, I pretty much used that in my ' Spoiler ' .
Also, your code needs a little sleep in there, cause the 1st time the script is run, it happens too quickly and the beep is at master volume
But thankyou very much
Re: Confused about SoundPlay and Wave volume
How do you include the bass.dll in your exe and then find it upon running the compiled exe?
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
So I used this and it failed to find the dll upon executing the exe. Note that my executable is NOT on the C: Maybe that has something to do with it?
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
Please show your code.
Re: Confused about SoundPlay and Wave volume
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
#MaxHotkeysPerInterval 200
#Include %A_ScriptDir%\bass.ahk
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
FileInstall, bass.dll, %A_ScriptDir%\bass.dll, 1
If ErrorLevel == 0
msgbox, "Error installing bass.dll " %ErrorLevel%
Else
BASS_Load("I:\Programs\bass.dll")
~$LButton::
PlaySong(snap.wav, 1.0)
PlaySong(File,Volume=0.5)
{
static stream
If stream
DllCall("Bass.dll\BASS_ChannelStop", UInt, stream)
If (Volume<0) or (Volume>1)
Volume:=0.5
Stream := DllCall("BASS\BASS_StreamCreateFile",UInt,0,UInt,&File,UInt64,0,UInt64,0,UInt,0x80000000)
DllCall("Bass.dll\BASS_ChannelSetAttribute",UInt,stream,UInt,2,Float,Volume)
DllCall("bass.dll\BASS_ChannelPlay",UInt,Stream,Int,0)
}
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
At least this part is wrong. If ErrorLevel = 0 it means that all is ok. See docs.Skrell wrote: ↑Code: Select all
FileInstall, bass.dll, %A_ScriptDir%\bass.dll, 1 If ErrorLevel == 0 msgbox, "Error installing bass.dll " %ErrorLevel% Else BASS_Load("I:\Programs\bass.dll")
Re: Confused about SoundPlay and Wave volume
Where can I find all these include files?teadrinker wrote: ↑20 Jun 2022, 16:00At least this part is wrong. If ErrorLevel = 0 it means that all is ok. See docs.Skrell wrote: ↑Code: Select all
FileInstall, bass.dll, %A_ScriptDir%\bass.dll, 1 If ErrorLevel == 0 msgbox, "Error installing bass.dll " %ErrorLevel% Else BASS_Load("I:\Programs\bass.dll")
;include effects & handlers
#Include *i basstags.ahk
#Include *i bassfx.ahk
#Include *i bassvfx.ahk
#Include *i bassenc.ahk
#Include *i bassmix.ahk
#Include *i bassvis.ahk
#Include *i bassvst.ahk
#Include *i basswadsp.ahk
#Include *i bassvideo.ahk
;include format plugins
#Include *i basscd.ahk
#Include *i bassmidi.ahk
#Include *i bassflac.ahk
#Include *i basswma.ahk
#Include *i basswv.ahk
#Include *i bassaac.ahk
#Include *i bassape.ahk
#Include *i bassmpc.ahk
#Include *i bassac3.ahk
#Include *i bassalac.ahk
#Include *i bassspx.ahk
#Include *i basstta.ahk
#Include *i bassofr.ahk
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
No idea, I've never used them.
Re: Confused about SoundPlay and Wave volume
No matter what I do I can't get the dll to load. Neither the 32bit nor 64bit (different errors in both cases). I wonder if the dll has changed since this code was written and hence the dllcall() functions need to change in the bass.ahk ? Can you please send me the *.dll file(s) you use with your ahk code that you said loads no problem?
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Confused about SoundPlay and Wave volume
Attached.
- Attachments
-
- bass.dll.zip
- (412.67 KiB) Downloaded 35 times
Re: Confused about SoundPlay and Wave volume
It worked!!! THANK YOU THANK YOU!! You made my weekend!!
Re: Confused about SoundPlay and Wave volume
Skrell wrote:It worked!!! THANK YOU THANK YOU!! You made my weekend!!
[youtube] https://youtu.be/vZCLA7boX1g[/youtube]