"Fossies" - the Fresh Open Source Software Archive

Member "speech_tools/audio/esd.cc" (4 Sep 2017, 5165 Bytes) of package /linux/misc/speech_tools-2.5.0-release.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "esd.cc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.4-release_vs_2.5.0-release.

    1  /*************************************************************************/
    2  /*                                                                       */
    3  /*                Centre for Speech Technology Research                  */
    4  /*                     University of Edinburgh, UK                       */
    5  /*                      Copyright (c) 1995,1996                          */
    6  /*                        All Rights Reserved.                           */
    7  /*                                                                       */
    8  /*  Permission is hereby granted, free of charge, to use and distribute  */
    9  /*  this software and its documentation without restriction, including   */
   10  /*  without limitation the rights to use, copy, modify, merge, publish,  */
   11  /*  distribute, sublicense, and/or sell copies of this work, and to      */
   12  /*  permit persons to whom this work is furnished to do so, subject to   */
   13  /*  the following conditions:                                            */
   14  /*   1. The code must retain the above copyright notice, this list of    */
   15  /*      conditions and the following disclaimer.                         */
   16  /*   2. Any modifications must be clearly marked as such.                */
   17  /*   3. Original authors' names are not deleted.                         */
   18  /*   4. The authors' names are not used to endorse or promote products   */
   19  /*      derived from this software without specific prior written        */
   20  /*      permission.                                                      */
   21  /*                                                                       */
   22  /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
   23  /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
   24  /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
   25  /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
   26  /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
   27  /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
   28  /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
   29  /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
   30  /*  THIS SOFTWARE.                                                       */
   31  /*                                                                       */
   32  /*************************************************************************/
   33  /*                                                                       */
   34  /*                Author :  Richard Caley                                */
   35  /* -------------------------------------------------------------------   */
   36  /* EST audio module using the enlightenment speech daemon.               */
   37  /*                                                                       */
   38  /*************************************************************************/
   39 
   40 
   41 #include <cstdio>
   42 #include <cstring>
   43 #include <cstdlib>
   44 #include <cctype>
   45 #include <sys/stat.h>
   46 #include "EST_Wave.h"
   47 #include "EST_Option.h"
   48 #include "audioP.h"
   49 #include "EST_io_aux.h"
   50 
   51 #ifdef SUPPORT_ESD
   52 
   53 // Hack hack. aupvlist.h is broken at least on FBSD 3.1.1
   54 
   55 #undef __cplusplus
   56 
   57 extern "C"
   58 {
   59 #include <aupvlist.h>
   60 }
   61 #define __cplusplus
   62 
   63 #include <esd.h>
   64 
   65 #define au_serverrate 16000
   66 
   67 bool esd_supported = TRUE;
   68 
   69 static int endian_int = 1;
   70 #define ESD_BIG_ENDIAN (((char *)&endian_int)[0] == 0)
   71 
   72 EST_String server;
   73 
   74 void get_server(EST_Option &al)
   75 {
   76   if (al.present("-display"))
   77     {
   78         EST_String display = (const char *)al.val("-display");
   79       if (display.contains(":"))
   80     {
   81       server = display.before(":");
   82     }
   83       else
   84     {
   85       server = display;
   86     }
   87     }
   88   else
   89     server = "";
   90 }
   91 
   92 int play_esd_wave(EST_Wave &inwave, EST_Option &al)
   93 {
   94 
   95   get_server(al);
   96 
   97   int format;
   98 
   99   switch (inwave.num_channels())
  100     {
  101     case 1: format=ESD_MONO;
  102       break;
  103       
  104     case 2: format=ESD_STEREO;
  105       break;
  106 
  107     default:
  108       cerr << "EST: " << inwave.num_channels() << " channel data not supported\n";
  109       return -1;
  110     }
  111 
  112   format |= ESD_BITS16 | ESD_STREAM | ESD_PLAY;
  113       
  114   int sample_rate = inwave.sample_rate();
  115 
  116   int esd =  esd_play_stream( format, sample_rate, 
  117                   server==EST_String::Empty?NULL:(const char *)server, "from est");
  118 
  119   int n = inwave.num_samples() * sizeof(short) * inwave.num_channels();
  120   int nw=0, tot=0;
  121   const char *data = (const char *)(inwave.values().memory());
  122 
  123   while(n > 0 && (nw = write(esd, data+tot, n)) >0)
  124     {
  125       n -= nw;
  126       tot+=nw;
  127     }
  128 
  129   if (nw < 0)
  130     {
  131       cerr << "ESD: error writing - " << strerror(errno) << "\n";
  132     }
  133 
  134   esd_close(esd);
  135 
  136   return 1;
  137 }
  138 
  139 int record_esd_wave(EST_Wave &wave, EST_Option &al)
  140 {
  141     (void)wave;
  142     (void)al;
  143 
  144     cerr << "ESD: record not written yet\n";
  145     return -1;
  146 }
  147 
  148 #else
  149 int esd_supported = FALSE;
  150 
  151 int play_esd_wave(EST_Wave &inwave, EST_Option &al)
  152 {
  153     (void)inwave;
  154     (void)al;
  155     cerr << "ESD playback not supported" << endl;
  156     return -1;
  157 }
  158 
  159 
  160 int record_esd_wave(EST_Wave &wave, EST_Option &al)
  161 {
  162     (void)wave;
  163     (void)al;
  164     cerr << "ESD record not supported" << endl;
  165     return -1;
  166 }
  167 
  168 #endif