/[emacs]/emacs/src/sound.c
ViewVC logotype

Diff of /emacs/src/sound.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.29 by bkey1, Sun Nov 17 22:35:26 2002 UTC revision 1.30 by lektu, Tue Nov 19 13:05:28 2002 UTC
# Line 33  Boston, MA 02111-1307, USA.  */ Line 33  Boston, MA 02111-1307, USA.  */
33    
34    The Windows implementation of play-sound is implemented via the    The Windows implementation of play-sound is implemented via the
35    Win32 API functions mciSendString, waveOutGetVolume, and    Win32 API functions mciSendString, waveOutGetVolume, and
36    waveOutGetVolume which are exported by Winmm.dll.    waveOutSetVolume which are exported by Winmm.dll.
37  */  */
38    
39  #include <config.h>  #include <config.h>
# Line 900  vox_write (sd, buffer, nbytes) Line 900  vox_write (sd, buffer, nbytes)
900    
901  static int  static int
902  do_play_sound (psz_file, ui_volume)  do_play_sound (psz_file, ui_volume)
903      const char * psz_file;       const char *psz_file;
904      unsigned long ui_volume;       unsigned long ui_volume;
905  {  {
906    int i_result=0;    int i_result = 0;
907    MCIERROR mci_error=0;    MCIERROR mci_error = 0;
908    char sz_cmd_buf[520]={0};    char sz_cmd_buf[520] = {0};
909    char sz_ret_buf[520]={0};    char sz_ret_buf[520] = {0};
910    MMRESULT mm_result=MMSYSERR_NOERROR;    MMRESULT mm_result = MMSYSERR_NOERROR;
911    unsigned long ui_volume_org=0;    unsigned long ui_volume_org = 0;
912    BOOL b_reset_volume=FALSE;    BOOL b_reset_volume = FALSE;
913    
914    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));
915    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));
916    sprintf (    sprintf (sz_cmd_buf,
917      sz_cmd_buf,             "open \"%s\" alias GNUEmacs_PlaySound_Device wait",
918      "open \"%s\" alias GNUEmacs_PlaySound_Device wait",             psz_file);
919      psz_file);    mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL);
   mci_error=mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL);  
920    if (mci_error != 0)    if (mci_error != 0)
921      {      {
922        sound_warning (        sound_warning ("The open mciSendString command failed to open\n"
923          "The open mciSendString command failed to open\n"                       "the specified sound file");
924          "the specified sound file");        i_result = (int) mci_error;
       i_result=(int)mci_error;  
925        return i_result;        return i_result;
926      }      }
927    if ((ui_volume > 0) && (ui_volume != UINT_MAX))    if ((ui_volume > 0) && (ui_volume != UINT_MAX))
928      {      {
929        mm_result=waveOutGetVolume ((HWAVEOUT)WAVE_MAPPER, &ui_volume_org);        mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org);
930        if (mm_result == MMSYSERR_NOERROR)        if (mm_result == MMSYSERR_NOERROR)
931          {          {
932            b_reset_volume=TRUE;            b_reset_volume = TRUE;
933            mm_result=waveOutSetVolume ((HWAVEOUT)WAVE_MAPPER, ui_volume);            mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume);
934            if ( mm_result != MMSYSERR_NOERROR)            if ( mm_result != MMSYSERR_NOERROR)
935              {              {
936                sound_warning (                sound_warning ("waveOutSetVolume failed to set the volume level\n"
937                  "waveOutSetVolume failed to set the volume level\n"                               "of the WAVE_MAPPER device.\n"
938                  "of the WAVE_MAPPER device.\n"                               "As a result, the user selected volume level will\n"
939                  "As a result, the user selected volume level will\n"                               "not be used.");
                 "not be used.");  
940              }              }
941          }          }
942        else        else
943          {          {
944            sound_warning (            sound_warning ("waveOutGetVolume failed to obtain the original\n"
945              "waveOutGetVolume failed to obtain the original\n"                           "volume level of the WAVE_MAPPER device.\n"
946              "volume level of the WAVE_MAPPER device.\n"                           "As a result, the user selected volume level will\n"
947              "As a result, the user selected volume level will\n"                           "not be used.");
             "not be used.");  
948          }          }
949      }      }
950    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));
951    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));
952    strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait");    strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait");
953    mci_error=mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL);    mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL);
954    if (mci_error != 0)    if (mci_error != 0)
955      {      {
956        sound_warning (        sound_warning ("The play mciSendString command failed to play the\n"
957          "The play mciSendString command failed to play the\n"                       "opened sound file.");
958          "opened sound file.");        i_result = (int) mci_error;
       i_result=(int)mci_error;  
959      }      }
960    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));    memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf));
961    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));    memset (sz_ret_buf, 0, sizeof(sz_ret_buf));
962    strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait");    strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait");
963    mci_error=mciSendString ( sz_cmd_buf, sz_ret_buf, 520, NULL);    mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL);
964    if (b_reset_volume == TRUE)    if (b_reset_volume == TRUE)
965      {      {
966        mm_result=waveOutSetVolume ((HWAVEOUT)WAVE_MAPPER, ui_volume_org);        mm_result=waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org);
967        if (mm_result != MMSYSERR_NOERROR)        if (mm_result != MMSYSERR_NOERROR)
968          {          {
969            sound_warning (            sound_warning ("waveOutSetVolume failed to reset the original volume\n"
970              "waveOutSetVolume failed to reset the original volume\n"                           "level of the WAVE_MAPPER device.");
             "level of the WAVE_MAPPER device.");  
971          }          }
972      }      }
973    return i_result;    return i_result;
# Line 982  do_play_sound (psz_file, ui_volume) Line 977  do_play_sound (psz_file, ui_volume)
977    
978  #endif /* WINDOWSNT */  #endif /* WINDOWSNT */
979    
   
980  DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1, 0,  DEFUN ("play-sound-internal", Fplay_sound_internal, Splay_sound_internal, 1, 1, 0,
981         doc: /* Play sound SOUND.         doc: /* Play sound SOUND.
982    
# Line 1000  Internal use only, use `play-sound' inst Line 994  Internal use only, use `play-sound' inst
994    struct sound s;    struct sound s;
995    Lisp_Object args[2];    Lisp_Object args[2];
996  #else /* WINDOWSNT */  #else /* WINDOWSNT */
997    int len=0;    int len = 0;
998    Lisp_Object lo_file={0};    Lisp_Object lo_file = {0};
999    char * psz_file=NULL;    char * psz_file = NULL;
1000    unsigned long ui_volume_tmp=UINT_MAX;    unsigned long ui_volume_tmp = UINT_MAX;
1001    unsigned long ui_volume=UINT_MAX;    unsigned long ui_volume = UINT_MAX;
1002    int i_result=0;    int i_result = 0;
1003  #endif /* WINDOWSNT */  #endif /* WINDOWSNT */
1004    
1005    /* Parse the sound specification.  Give up if it is invalid.  */    /* Parse the sound specification.  Give up if it is invalid.  */
# Line 1087  Internal use only, use `play-sound' inst Line 1081  Internal use only, use `play-sound' inst
1081    current_sound_device = NULL;    current_sound_device = NULL;
1082    current_sound = NULL;    current_sound = NULL;
1083    UNGCPRO;    UNGCPRO;
1084    
1085  #else /* WINDOWSNT */  #else /* WINDOWSNT */
1086          lo_file=Fexpand_file_name (attrs[SOUND_FILE], Qnil);  
1087    len=XSTRING (lo_file)->size;    lo_file = Fexpand_file_name (attrs[SOUND_FILE], Qnil);
1088    psz_file=(char *)alloca (len+1);    len = XSTRING (lo_file)->size;
1089      psz_file = (char *) alloca (len + 1);
1090    strcpy (psz_file, XSTRING (lo_file)->data);    strcpy (psz_file, XSTRING (lo_file)->data);
1091    if (INTEGERP (attrs[SOUND_VOLUME]))    if (INTEGERP (attrs[SOUND_VOLUME]))
1092      {      {
1093        ui_volume_tmp=XFASTINT (attrs[SOUND_VOLUME]);        ui_volume_tmp = XFASTINT (attrs[SOUND_VOLUME]);
1094      }      }
1095    else if (FLOATP (attrs[SOUND_VOLUME]))    else if (FLOATP (attrs[SOUND_VOLUME]))
1096      {      {
1097        ui_volume_tmp=(unsigned long)XFLOAT_DATA (attrs[SOUND_VOLUME])*100;        ui_volume_tmp = (unsigned long) XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;
1098      }      }
1099    /*    /*
1100      Based on some experiments I have conducted, a value of 100 or less      Based on some experiments I have conducted, a value of 100 or less
# Line 1106  Internal use only, use `play-sound' inst Line 1102  Internal use only, use `play-sound' inst
1102      A value of UINT_MAX indicates that you wish for the sound to played      A value of UINT_MAX indicates that you wish for the sound to played
1103      at the maximum possible volume.  A value of UINT_MAX/2 plays the      at the maximum possible volume.  A value of UINT_MAX/2 plays the
1104      sound at 50% maximum volume.  Therefore the value passed to do_play_sound      sound at 50% maximum volume.  Therefore the value passed to do_play_sound
1105      (and thus to waveOutSetVolume must be some fraction of UINT_MAX.      (and thus to waveOutSetVolume) must be some fraction of UINT_MAX.
1106      The following code adjusts the user specified volume level appropriately.      The following code adjusts the user specified volume level appropriately.
1107     */    */
1108    if ((ui_volume_tmp > 0) && (ui_volume_tmp <= 100))    if ((ui_volume_tmp > 0) && (ui_volume_tmp <= 100))
1109      {      {
1110        ui_volume=ui_volume_tmp * (UINT_MAX / 100);        ui_volume = ui_volume_tmp * (UINT_MAX / 100);
1111      }      }
1112    i_result=do_play_sound (psz_file, ui_volume);    i_result = do_play_sound (psz_file, ui_volume);
1113    
1114  #endif /* WINDOWSNT */  #endif /* WINDOWSNT */
1115    
1116    unbind_to (count, Qnil);    unbind_to (count, Qnil);
1117    return Qnil;    return Qnil;
1118  }  }

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26