Lisp HUG Maillist Archive

Sounds?

hi,

In our LW-based stock trading application we'd like to have
user-defined alarm sounds instead of just the beep of beep-pane. I'd
be happy for any pointers on how to do this (we're developing under
linux and delivering for both linux and windows, but the latter is of
course more important in terms of numbers of customers)
-- 
  best regards,
    Espen Vestre
    Netfonds ASA, Oslo, Norway


Re: Sounds?

Unable to parse email body. Email id is 546

Re: Sounds?

davef@xanalys.com writes:

> LispWorks for Windows has an unsupported utility WW:SHELL-OPEN that
> calls ShellExecute. 

thanks, I have a look at that and Arthur's suggestion.

> I don't know what plays sounds on Linux but perhaps you do :) 
> 
>    X-Now-Playing: nrk-petre-128
> 
> You could call the sound player program from LispWorks using
> SYS:CALL-SYSTEM.

Sure. But firing up a shell and XMMS (which generates my
X-Now-Playing-headers) is _slightly_ overkill for a simple alert sound :-) 

I was thinking of a less heavy interface. But when I think of it:
Maybe I should let the linux version be more general and just run a
shell script (which could default to playing an alert, but could do
whatever the user wants...)....
-- 
  (espen)


Re: Sounds?

Espen Vestre wrote:

> In our LW-based stock trading application we'd like to have
> user-defined alarm sounds instead of just the beep of beep-pane. 

In addition to Dave's suggestions, you could also try using Microsoft's
MCI (Media Control Interface) API. This will only work on Windows,
of course.

Below is a quick hack that I wrote a few years ago. 

Arthur Lemmens

;;;;;;;;;;;;;;;;;;;;; MCI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Rudimentary interface to mciSendString (Win32),
;; so we can play audio files.

(fli:define-c-typedef fli-hwnd (:unsigned :long))

(fli:define-c-typedef mcierror :long)

(fli:define-foreign-function (mci-send-string "mciSendString" :dbcs)
  ((lpszCommand :pointer)
   (lpszReturnString :pointer)
   (cchReturn (:unsigned :int))
   (hwndCallBack fli-hwnd))
  :result-type mcierror)

(defun mci-eval (command)
  ;; Simplest possible version, ignoring return strings and callbacks.
  (fli:with-foreign-string
    (c-command element-count byte-count :external-format :ascii)
    command
    (declare (ignore element-count byte-count))
    (mci-send-string c-command nil 0 0)))

(defun play-audio (filename)
  ;; Just a crude hack.
  (mci-eval "close sound wait") ;; Close previously played file.
  (mci-eval (format nil "open ~A alias sound wait" filename))
  (mci-eval "play sound from 0"))


;; Test it.

(play-audio "c:\\windows\\media\\tada.wav")


Updated at: 2020-12-10 09:01 UTC