home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / hpplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  7.8 KB  |  279 lines

  1. /* Copyright (C) 1993 Free Software Foundation, Inc.
  2.  
  3. This file is part of XEmacs.
  4.  
  5. XEmacs is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option) any
  8. later version.
  9.  
  10. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13. for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with XEmacs; see the file COPYING.  If not, write to the Free
  17. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. /* Synched up with: Not in FSF. */
  20.  
  21.  
  22. /***
  23.    NAME
  24.      hpplay
  25.    PURPOSE
  26.      Play .au sound files on hp9000s700
  27.    BUGS
  28.      I have been unable to figure out how to use the volume feature, so no
  29.      attempts has been made to honor the volume arg of play_sound_*
  30.      This means that all sounds is played at 100%.
  31.      The gain parameter can be set by using the play-gain variable.
  32.  
  33.    NOTES
  34.      This file is mostly based on the player program found in the examples
  35.      directory of the audio software delivered on our machines. The path I
  36.      found it under was /usr/audio/examples/player.c
  37.      This file contained no credits and no copyrights. The original fileheader
  38.      is given below. 
  39.    HISTORY
  40.      lynbech - Feb 10, 1993: Created.
  41. ***/
  42.  
  43. /* ORIGINAL FILEHEADER:
  44.  * player - command-line audio file player
  45.  *   Aug. 28 1991
  46.  *    by three unknown, unsung audio programmers
  47.  *     (well, only two are unsung)
  48.  */
  49.  
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52. #include <config.h>        /* to get system rev level. */
  53. #ifdef HPUX10
  54. #include <Alib.h>
  55. #include <CUlib.h>
  56. #else /* !HPUX 10 */
  57. #include <audio/Alib.h>
  58. #include <audio/CUlib.h>
  59. #endif /* !HPUX 10 */
  60.  
  61. /* New Symbols */
  62. #include <config.h>
  63. #include "lisp.h"
  64.  
  65. Lisp_Object Vhp_play_server;
  66. Lisp_Object Vhp_play_speaker;
  67. int         play_gain;
  68.  
  69. /* Functions */
  70.  
  71. /* error handling */
  72. void player_error_internal(
  73.     Audio        * audio,
  74.     char         * text,
  75.     long         errorCode
  76.     )
  77. {
  78.     char    errorbuff[132],buf[256];
  79.  
  80.     AGetErrorText(audio, errorCode, errorbuff, 131);
  81.     sprintf(buf,"%s: %s\n",text,errorbuff);
  82.     error(buf);
  83. }
  84.  
  85. long myHandler(audio, err_event)
  86.     Audio  * audio;
  87.     AErrorEvent  * err_event;
  88. {
  89.   player_error_internal(audio, "Internal sound error", err_event->error_code);
  90.   return 1;            /* Must return something, was orig. an exit */
  91. }
  92.  
  93. /* Playing */
  94. void
  95. play_bucket_internal(audio, pSBucket, volume)
  96.      Audio           *audio;
  97.      SBucket     *pSBucket;
  98.      long         volume;
  99. {
  100.     SBPlayParams    playParams;
  101.     AGainEntry      gainEntry;
  102.     ATransID        xid;
  103.     long            status;
  104.     char            * speaker;
  105.  
  106.     playParams.priority = APriorityNormal;          /* normal priority */
  107.  
  108.     speaker = (char *) (string_data (XSYMBOL (Vhp_play_speaker)->name));
  109.     
  110.     /*
  111.      * setup the playback parameters
  112.      */
  113.  
  114.     /* speaker selection */
  115.     if ( strcmp(speaker,"external") == 0 ) {
  116.       gainEntry.u.o.out_dst = AODTMonoJack;
  117.     } else {
  118.       gainEntry.u.o.out_dst = AODTMonoIntSpeaker;
  119.     }
  120.  
  121.     gainEntry.u.o.out_ch = AOCTMono;
  122.     gainEntry.gain = AUnityGain;
  123.     playParams.gain_matrix.type = AGMTOutput;       /* gain matrix */
  124.     playParams.gain_matrix.num_entries = 1;
  125.     playParams.gain_matrix.gain_entries = &gainEntry;
  126.     playParams.play_volume = play_gain;            /* play volume */
  127.     playParams.pause_first = False;                 /* don't pause */
  128.     playParams.start_offset.type = ATTSamples;      /* start offset 0 */
  129.     playParams.start_offset.u.samples = 0;
  130.     playParams.duration.type = ATTFullLength;       /* play entire sample */
  131.     playParams.loop_count = 1;                      /* play sample just once */
  132.     playParams.previous_transaction = 0;            /* no linked transaction */
  133.     playParams.event_mask = 0;                      /* don't solicit any events */
  134.  
  135.     /*
  136.      * play the sound bucket
  137.      */
  138.     xid = APlaySBucket( audio, pSBucket, &playParams, NULL );
  139.  
  140.     /*
  141.      * set close mode to prevent playback from stopping 
  142.      *  when we close audio connection
  143.      */
  144.     ASetCloseDownMode( audio, AKeepTransactions, &status );
  145.  
  146.     /*
  147.      *  That's all, folks!
  148.      *  Always destroy bucket and close connection.
  149.      */
  150.     ADestroySBucket( audio, pSBucket, &status );
  151.     ACloseAudio( audio, &status );
  152. }
  153.  
  154. void
  155. play_sound_file (sound_file, volume)
  156.      char * sound_file;
  157.      int volume;
  158. {
  159.     SBucket         *pSBucket;
  160.     Audio           *audio;
  161.     long            status;
  162.     AErrorHandler   prevHandler;  /* pointer to previous handler */
  163.     char            *server;
  164.  
  165.     if (STRINGP(Vhp_play_server))
  166.       server = (char *) (string_data (XSTRING (Vhp_play_server)));
  167.     server = "";
  168.  
  169.     /*
  170.      *  open audio connection
  171.      */
  172.     audio = AOpenAudio( server, &status );
  173.     if( status ) {
  174.         player_error_internal( audio, "Open audio failed", status );
  175.     }
  176.  
  177.     /* replace default error handler */
  178.     prevHandler = ASetErrorHandler(myHandler);
  179.  
  180.     /*
  181.      *  Load the audio file into a sound bucket
  182.      */
  183.  
  184.     pSBucket = ALoadAFile( audio, sound_file, AFFUnknown, 0, NULL, NULL );
  185.  
  186.     /*
  187.      * Play the bucket
  188.      */
  189.  
  190.     play_bucket_internal(audio, pSBucket, volume);
  191.  
  192.     ASetErrorHandler(prevHandler);
  193. }
  194.  
  195.  
  196. void
  197. play_sound_data (data, length, volume)
  198.      unsigned char * data;
  199.      int length;
  200.      int volume;
  201. {
  202.     SBucket         *pSBucket;
  203.     Audio           *audio;
  204.     AErrorHandler   prevHandler;
  205.     SunHeader       *header;
  206.     long            status;
  207.     char            *server;
  208.  
  209.     if (STRINGP (Vhp_play_server))
  210.       server = (char *) (string_data (XSTRING (Vhp_play_server)));
  211.     server = "";
  212.  
  213.     /* open audio connection */
  214.     audio = AOpenAudio( server, &status );
  215.     if( status ) {
  216.         player_error_internal( audio, "Open audio failed", status );
  217.     }
  218.  
  219.     /* replace default error handler */
  220.     prevHandler = ASetErrorHandler (myHandler);
  221.  
  222.     /* Create sound bucket */
  223.     header = (SunHeader *) data;
  224.  
  225.     pSBucket = ACreateSBucket(audio, NULL, NULL, &status);
  226.     if (status)
  227.       player_error_internal( audio, "Bucket creation failed", status );
  228.  
  229.     APutSBucketData(audio, pSBucket, 0, (char *) (data + header->header_size), header->data_length, &status);
  230.  
  231.    if (status)
  232.       player_error_internal( audio, "Audio data copy failed", status );
  233.  
  234.     /* Play sound */
  235.     play_bucket_internal(audio, pSBucket, volume);
  236.  
  237.     ASetErrorHandler(prevHandler);
  238.     if (status)
  239.       player_error_internal( audio, "Audio data copy failed", status );
  240. }
  241.  
  242. void
  243. vars_of_hpplay (void)
  244. {
  245.   DEFVAR_LISP ("hp-play-server", &Vhp_play_server,
  246.     "A string, determining which server to play sound at.\n\
  247. Note that this is specific to the HP sound implementation, and you should\n\
  248. not make your functions depend on it.");
  249.  
  250.   Vhp_play_server = Qnil;
  251.  
  252.   DEFVAR_LISP ("hp-play-speaker", &Vhp_play_speaker,
  253.     "If this variable is the symbol `external', sound is played externally.\n\
  254. If the environment variable SPEAKER is set, that value is used for\n\
  255. initializing this variable.\n\
  256. Note that this is specific to the HP sound implementation, and you should\n\
  257. not make your functions depend on it.");
  258.  
  259.   Vhp_play_speaker = intern ("internal");
  260.  
  261.   DEFVAR_INT("hp-play-gain", &play_gain,
  262.     "Global gain value for playing sounds.\n\
  263. Default value is AUnityGain which means keep level.\n\
  264. Please refer to the HP documentation, for instance in\n\
  265. `Using the Audio Application Program Interface', for details on how to\n\
  266. interpret this variable.\n\
  267. Note that this is specific to the HP sound implementation, and you should\n\
  268. not make your functions depend on it.");
  269.  
  270.   play_gain = AUnityGain;
  271. }
  272.  
  273. void
  274. init_hpplay (void)
  275. {
  276.   if (getenv ("SPEAKER")) 
  277.     Vhp_play_speaker = intern (getenv ("SPEAKER"));
  278. }
  279.