/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_sgi.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdpsnd_sgi.c

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

revision 746 by astrand, Mon Aug 9 13:03:32 2004 UTC revision 1032 by astrand, Fri Dec 16 07:48:02 2005 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Sound Channel Process Functions - SGI/IRIX     Sound Channel Process Functions - SGI/IRIX
4     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003
5     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
6     Copyright (C) Michael Gernoth mike@zerfleddert.de 2003     Copyright (C) Jeremy Meng void.foo@gmail.com 2004, 2005
7    
8     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 24  Line 24 
24  #include <errno.h>  #include <errno.h>
25  #include <dmedia/audio.h>  #include <dmedia/audio.h>
26    
27  #define IRIX_DEBUG 1  /* #define IRIX_DEBUG 1 */
28    
29  #define IRIX_MAX_VOL     65535  #define IRIX_MAX_VOL     65535
30    
# Line 38  BOOL g_dsp_busy = False; Line 38  BOOL g_dsp_busy = False;
38  static BOOL g_swapaudio;  static BOOL g_swapaudio;
39  static int g_snd_rate;  static int g_snd_rate;
40  static BOOL g_swapaudio;  static BOOL g_swapaudio;
 static short g_samplewidth;  
41  static int width = AL_SAMPLE_16;  static int width = AL_SAMPLE_16;
42    
43  double min_volume, max_volume, volume_range;  double min_volume, max_volume, volume_range;
# Line 78  wave_out_open(void) Line 77  wave_out_open(void)
77          queue_lo = queue_hi = 0;          queue_lo = queue_hi = 0;
78    
79          audioconfig = alNewConfig();          audioconfig = alNewConfig();
80          if (audioconfig < 0)          if (audioconfig == (ALconfig) 0)
81          {          {
82                  fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n",                  fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n",
83                          alGetErrorString(oserror()));                          alGetErrorString(oserror()));
# Line 145  wave_out_set_format(WAVEFORMATEX * pwfx) Line 144  wave_out_set_format(WAVEFORMATEX * pwfx)
144  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
145          fprintf(stderr, "wave_out_set_format: init...\n");          fprintf(stderr, "wave_out_set_format: init...\n");
146  #endif  #endif
         /* limited support to configure an opened audio port in IRIX */  
         /* have to reopen the audio port, using same config */  
         alClosePort(output_port);  
147    
148          g_swapaudio = False;          g_swapaudio = False;
   
149          if (pwfx->wBitsPerSample == 8)          if (pwfx->wBitsPerSample == 8)
150                  width = AL_SAMPLE_8;                  width = AL_SAMPLE_8;
151          else if (pwfx->wBitsPerSample == 16)          else if (pwfx->wBitsPerSample == 16)
152          {          {
153                  width = AL_SAMPLE_16;                  width = AL_SAMPLE_16;
154                  /* Do we need to swap the 16bit values? (Are we BigEndian) */                  /* Do we need to swap the 16bit values? (Are we BigEndian) */
155  #if (defined(IRIX_DEBUG))  #if (defined(B_ENDIAN))
156                  g_swapaudio = 1;                  g_swapaudio = 1;
157  #else  #else
158                  g_swapaudio = 0;                  g_swapaudio = 0;
159  #endif  #endif
160          }          }
161    
162          g_samplewidth = pwfx->wBitsPerSample / 8;          /* Limited support to configure an opened audio port in IRIX.  The
163               number of channels is a static setting and can not be changed after
164               a port is opened.  So if the number of channels remains the same, we
165               can configure other settings; otherwise we have to reopen the audio
166               port, using same config. */
167    
168          channels = pwfx->nChannels;          channels = pwfx->nChannels;
169          g_snd_rate = pwfx->nSamplesPerSec;          g_snd_rate = pwfx->nSamplesPerSec;
170    
171          alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);          alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
172          alSetWidth(audioconfig, width);          alSetWidth(audioconfig, width);
173          alSetChannels(audioconfig, channels);          if (channels != alGetChannels(audioconfig))
174            {
175                    alClosePort(output_port);
176                    alSetChannels(audioconfig, channels);
177                    output_port = alOpenPort("rdpsnd", "w", audioconfig);
178    
179          output_port = alOpenPort("rdpsnd", "w", audioconfig);                  if (output_port == (ALport) 0)
180                    {
181                            fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",
182                                    alGetErrorString(oserror()));
183                            return False;
184                    }
185    
         if (output_port == (ALport) 0)  
         {  
                 fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",  
                         alGetErrorString(oserror()));  
                 return False;  
186          }          }
187    
188          resource = alGetResource(output_port);          resource = alGetResource(output_port);
# Line 281  wave_out_play(void) Line 285  wave_out_play(void)
285          unsigned int i;          unsigned int i;
286          uint8 swap;          uint8 swap;
287          STREAM out;          STREAM out;
         static long startedat_us;  
         static long startedat_s;  
         static BOOL started = False;  
288          static BOOL swapped = False;          static BOOL swapped = False;
         struct timeval tv;  
289          int gf;          int gf;
         static long long temp;  
290    
291          while (1)          while (1)
292          {          {
# Line 312  wave_out_play(void) Line 311  wave_out_play(void)
311                          swapped = True;                          swapped = True;
312                  }                  }
313    
                 if (!started)  
                 {  
                         gettimeofday(&tv, NULL);  
                         startedat_us = tv.tv_usec;  
                         startedat_s = tv.tv_sec;  
                         started = True;  
                 }  
   
314                  len = out->end - out->p;                  len = out->end - out->p;
                 gf = alGetFillable(output_port);  
                 if (len > gf)  
                 {  
                         //len = gf * combinedFrameSize;  
 #if (defined(IRIX_DEBUG))  
                         //fprintf(stderr,"Fillable...\n");  
 #endif  
                 }  
315    
316                  alWriteFrames(output_port, out->p, len / combinedFrameSize);                  alWriteFrames(output_port, out->p, len / combinedFrameSize);
317    
318                  out->p += len;                  out->p += len;
319                  if (out->p == out->end)                  if (out->p == out->end)
320                  {                  {
321                          long long duration;                          gf = alGetFilled(output_port);
322                          long elapsed;                          if (gf < (4 * maxFillable / 10))
   
                         gettimeofday(&tv, NULL);  
                         duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate)));  
                         elapsed = (tv.tv_sec - startedat_s) * 1000000 + (tv.tv_usec - startedat_us);  
                         /* 7/10 is not good for IRIX audio port, 4x/100 is suitable */  
                         if (elapsed >= (duration * 485) / 1000)  
323                          {                          {
324                                  rdpsnd_send_completion(packet->tick, packet->index);                                  rdpsnd_send_completion(packet->tick, packet->index);
325                                  free(out->data);                                  free(out->data);
326                                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                                  queue_lo = (queue_lo + 1) % MAX_QUEUE;
                                 started = False;  
327                                  swapped = False;                                  swapped = False;
328                          }                          }
329                          else                          else
330                          {                          {
331  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
332                                  //fprintf(stderr,"Busy playing...\n");  /*                              fprintf(stderr,"Busy playing...\n"); */
333  #endif  #endif
334                                  g_dsp_busy = True;                                  g_dsp_busy = True;
335                                    usleep(10);
336                                  return;                                  return;
337                          }                          }
338                  }                  }

Legend:
Removed from v.746  
changed lines
  Added in v.1032

  ViewVC Help
Powered by ViewVC 1.1.26