view src/ntplay.c @ 578:190b164ddcac

[xemacs-hg @ 2001-05-25 11:26:50 by ben] device-msw.c, eldap.c, emodules.c, hpplay.c, process-unix.c, sound.h, tooltalk.c, win32.c: Revert Martin's attempted compile-warnings fix. It does fix the warnings, but not the right way. We are trying to eliminate the raw use of `char' and `unsigned char' absolutely everywhere. There is never an occasion to reintroduce these. buffer.h: Instead, we fix these macros so they don't care about the type of their lvalues. We already do this for the non-C-string equivalents of these, and it's correct because it should be OK to pass in an SBufbyte *, for example. In any case, we do not need any type-correctness checking here -- errors will be caught for sure as soon as we remove the -Wno-sign-compare switch. mule-charset.c: Use invalid_argument, not generic signal_error (Qerror, ). alloc.c, chartab.c, console-gtk.c, console-msw.c, console-stream.c, console-stream.h, console-tty.c, console-tty.h, console-x.c, console.c, console.h, device-x.c, device.c, elhash.c, eval.c, faces.c, faces.h, fns.c, glyphs.c, glyphs.h, gui.c, gui.h, lisp.h, lread.c, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-tty.c, objects-x.c, objects.c, process-unix.c, rangetab.c, search.c, specifier.c, toolbar.c, window.c, window.h: Rename Error_behavior to Error_Behavior, to be consistent with general naming practices (Lisp_Object, Char_Binary, etc.).
author ben
date Fri, 25 May 2001 11:27:01 +0000
parents 183866b06e0b
children 5fd7ba8b56e7
line wrap: on
line source

/* Sound in windows nt XEmacs.
   Copyright (C) 1998 Andy Piper.

This file is part of XEmacs.

XEmacs is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

XEmacs is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with XEmacs; see the file COPYING.  If not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.*/

/* Synched up with: Not in FSF. */

/* This file Mule-ized by Ben Wing, 5-15-01. */

#include <config.h>
#include "lisp.h"

#include "sound.h"
#include "nt.h"

#include "sysfile.h"

static int play_sound_data_1 (UChar_Binary *data, int length,
			      int volume, int convert);

void
play_sound_file (Extbyte *sound_file, int volume)
{
  DWORD flags = SND_ASYNC | SND_NODEFAULT | SND_FILENAME;
  OFSTRUCT ofs;
  Lisp_Object fname =
    Ffile_name_nondirectory (build_ext_string (sound_file, Qmswindows_tstr));
  Extbyte *fnameext;

  CHECK_STRING (fname);
  LISP_STRING_TO_EXTERNAL (fname, fnameext, Qmswindows_tstr);

  if (OpenFile (fnameext, &ofs, OF_EXIST) < 0)
    {
      /* file isn't in the path so read it as data */
      int size;
      UChar_Binary* data;
      int ofd = open (sound_file, O_RDONLY | OPEN_BINARY, 0);
      
      if (ofd <0)
	return;

      size = lseek (ofd, 0, SEEK_END);
      data = (UChar_Binary *)xmalloc (size);
      lseek (ofd, 0, SEEK_SET);
      
      if (!data)
	{
	  close (ofd);
	  return;
	}

      if (read (ofd, data, size) != size)
	{
	  close (ofd);
	  xfree (data);
	  return;
	}
      close (ofd);
      
      play_sound_data_1 (data, size, 100, FALSE);
    }
  else 
    PlaySound (fnameext, NULL, flags);
}

/* mswindows can't cope with playing a sound from alloca space so we
   have to convert if necessary */
static int
play_sound_data_1 (UChar_Binary *data, int length, int volume,
		   int convert_to_malloc)
{
  DWORD flags = SND_ASYNC | SND_MEMORY | SND_NODEFAULT;
  static UChar_Binary* sound_data=0;
  if (sound_data)
    {
      PlaySound (NULL, NULL, flags);
      xfree (sound_data);
      sound_data=0;
    }

  if (convert_to_malloc)
    {
      sound_data = (UChar_Binary *)xmalloc (length);
      memcpy (sound_data, data, length);
    }
  else
    sound_data = data;

  PlaySound(sound_data, NULL, flags);

  /* #### Error handling? */ 
  return 1;
}

int
play_sound_data (UChar_Binary *data, int length, int volume)
{
  return play_sound_data_1 (data, length, volume, TRUE);
}