AutoHotkey Community

It is currently May 26th, 2012, 11:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Overlapping Sound
PostPosted: November 14th, 2008, 7:50 am 
Offline

Joined: June 7th, 2008, 6:00 am
Posts: 389
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2008, 1:18 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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 :(
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2008, 6:50 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: try this
PostPosted: November 15th, 2008, 9:42 am 
Offline

Joined: January 20th, 2007, 1:29 pm
Posts: 96
Location: Melbourne
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group