AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Overlapping Sound

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Wicked



Joined: 07 Jun 2008
Posts: 369

PostPosted: Fri Nov 14, 2008 6:50 am    Post subject: Overlapping Sound Reply with quote

The Help File said:
Quote:
If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play.


I found a way around it to play overlapping sounds. ^^

You big-shots probably know an easier way, which I'm curious to hear, but this is what I came up with (This example reqs Windows XP):
Code:
^1::
SoundFile = %A_WinDIR%\Media\Windows XP Startup.wav
GoSub, PlaySound
Return

^2::
SoundFile = %A_WinDIR%\Media\Windows XP Shutdown.wav
GoSub, PlaySound
Return

PlaySound:
FileDelete, %A_ScriptDIR%\Sound1.AHK
FileAppend,
(
#NoTrayIcon
SoundPlay, %SoundFile%, Wait
), %A_ScriptDir%\Sound1.AHK
Run, %A_ScriptDIR%\Sound1.AHK
Return


It's odd that while Sound1.AHK is running, you can delete it, write another one, run the other one... And the original Sound1.AHK will still finish o.O

Further condensed by Lexikos:
Code:
^1::PlaySound(A_WinDIR "\Media\Windows XP Startup.wav")
^2::PlaySound(A_WinDIR "\Media\Windows XP Shutdown.wav")
^3::PlaySound(A_WinDIR "\Media\flourish.mid")
^4::PlaySound(A_WinDIR "\Media\onestop.mid")

PlaySound(SoundFile) {
    FileDelete, %A_ScriptDIR%\Sound1.AHK
    FileAppend,
    (
    #NoTrayIcon
    SoundPlay, %SoundFile%, Wait
    ), %A_ScriptDir%\Sound1.AHK
    Run, %A_ScriptDIR%\Sound1.AHK
}
Back to top
View user's profile Send private message
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Fri Nov 14, 2008 12:18 pm    Post subject: Reply with quote

Code:
^1::ToolTip, % "1: " . PlaySound(A_WinDir . "\Media\Windows Startup.wav", "s1")
^2::ToolTip, % "2: " . PlaySound(A_WinDir . "\Media\Windows Shutdown.wav", "s2")
^3::ToolTip, % "3: " . PlaySound(A_WinDir . "\Media\flourish.mid", "s3")
^4::ToolTip, % "4: " . PlaySound(A_WinDir . "\Media\onestop.mid", "s4")
~*Esc::ExitApp

PlaySound(src, alias) {
   DllCall("winmm.dll\mciSendStringA", "Str", "open """ . src . """ alias " . alias, "UInt", 0, "UInt", 0, "UInt", 0)
   Return, DllCall("winmm.dll\mciSendStringA", "Str", "play " . alias, "UInt", 0, "UInt", 0, "UInt", 0)
}

... gives error MCIERR_SEQ_PORT_INUSE when playing more than one Sad
Maybe it checks per thread, if so you can write a workaround. Alternatively you can try k3phs bass library.
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Fri Nov 14, 2008 5:50 pm    Post subject: Reply with quote

In my Vista PC the scripts in the first post do not play sound overlappingly, but after each other. There is no obvious way to stop the playback.

Also, the file "Windows Startup.wav" exists, but it does not play back.
Back to top
View user's profile Send private message
Trubbleguy



Joined: 20 Jan 2007
Posts: 96
Location: Melbourne

PostPosted: Sat Nov 15, 2008 8:42 am    Post subject: try this Reply with quote

compile this to wav.exe and send anything you like to it all at the same time, it will load up to 30 instances at once and play all sounds at the same time.
Code:
#NoTrayIcon
SoundPlay,%1%,wait
exitapp


and use my sound effects engine below to test wav.exe
Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
;------------------------------------------------------------------------------------------
; @@@@                           @@@      @@@@@@   @@@    @@@                   @          ;
;@@  @@                           @@      @@      @@ @@  @@ @@                 @@          ;
;@@@     @@@@  @@  @@  @@@@@      @@      @@      @@     @@     @@@@   @@@@   @@@@@  @@@@@ ;
; @@@   @@  @@ @@  @@  @@  @@  @@@@@      @@@@   @@@@   @@@@   @@  @@ @@  @@   @@   @@     ;
;   @@@ @@  @@ @@  @@  @@  @@ @@  @@      @@      @@     @@    @@@@@@ @@       @@    @@@@  ;
;@@  @@ @@  @@ @@  @@  @@  @@ @@  @@      @@      @@     @@    @@     @@  @@   @@ @     @@ ;
; @@@@   @@@@   @@@ @@ @@  @@  @@@ @@     @@@@@@ @@@@   @@@@    @@@@   @@@@     @@  @@@@@  ;
;------------------------------------------------------------------------------------------;
;Sound Effects:

`::Gosub sfx  ;press the key to the left of 1 to trigger sound effector

sfx:
   Input, UserInput,T1 L1,{Escape},0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
   If ErrorLevel = Timeout
         Return
   SetKeyDelay, -1
   ifnotexist,%A_ScriptDir%\se\%UserInput%      ;looks in SE folder for a folder named the same as the key you pressed
   {
   filecreatedir,%A_ScriptDir%\se\%UserInput%  ;creates folder if it doesnt exist, then put sounds in it
;   Return
   }
Loop, %A_ScriptDir%\se\%UserInput%\*.*
         Run, %A_ScriptDir%\Wav.exe "%A_ScriptDir%\se\%UserInput%\%A_LoopFileName%"   ;plays all the files in that folder
   vkey=done
   Goto sfx
Return


makes a SE folder wherever you run this script and will make sub folders from 1 to z if you press a key that is not yet defined and then you dump one or as many sounds as you like into that folder, it will play all sounds at once if there are more than one, even video files.....you have ONE second from pressing the `~ key to keep pressing multiple trigger letters, as long as each letter is pressed withing one second it will play the next Sound effect, if you take to long, press the `~ key again to trigger the one second input window.
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group