/[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 744 by stargo, Mon Aug 9 11:39:49 2004 UTC revision 746 by astrand, Mon Aug 9 13:03:32 2004 UTC
# Line 56  static unsigned int queue_hi, queue_lo; Line 56  static unsigned int queue_hi, queue_lo;
56  BOOL  BOOL
57  wave_out_open(void)  wave_out_open(void)
58  {  {
59    ALparamInfo pinfo;          ALparamInfo pinfo;
60    
61  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
62      fprintf(stderr, "wave_out_open: begin\n");          fprintf(stderr, "wave_out_open: begin\n");
63  #endif  #endif
64    
65    if ( alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0 )          if (alGetParamInfo(AL_DEFAULT_OUTPUT, AL_GAIN, &pinfo) < 0)
66    {          {
67      fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n",                  fprintf(stderr, "wave_out_open: alGetParamInfo failed: %s\n",
68                                                  alGetErrorString(oserror()));                          alGetErrorString(oserror()));
69    }          }
70    min_volume = alFixedToDouble(pinfo.min.ll);          min_volume = alFixedToDouble(pinfo.min.ll);
71    max_volume = alFixedToDouble(pinfo.max.ll);          max_volume = alFixedToDouble(pinfo.max.ll);
72    volume_range = (max_volume - min_volume);          volume_range = (max_volume - min_volume);
73  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
74                  fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n",          fprintf(stderr, "wave_out_open: minvol = %lf, maxvol= %lf, range = %lf.\n",
75                                                  min_volume, max_volume, volume_range);                  min_volume, max_volume, volume_range);
76  #endif  #endif
77    
78          queue_lo = queue_hi = 0;          queue_lo = queue_hi = 0;
79    
80          audioconfig = alNewConfig();          audioconfig = alNewConfig();
81          if (audioconfig < 0) {          if (audioconfig < 0)
82      fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n",          {
83              alGetErrorString(oserror()));                  fprintf(stderr, "wave_out_open: alNewConfig failed: %s\n",
84                            alGetErrorString(oserror()));
85                  return False;                  return False;
86          }          }
87    
88          output_port = alOpenPort("rdpsnd", "w", 0);          output_port = alOpenPort("rdpsnd", "w", 0);
89          if (output_port == (ALport) 0) {          if (output_port == (ALport) 0)
90      fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n",          {
91                                                  alGetErrorString(oserror()));                  fprintf(stderr, "wave_out_open: alOpenPort failed: %s\n",
92                            alGetErrorString(oserror()));
93                  return False;                  return False;
94          }          }
95    
96  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
97      fprintf(stderr, "wave_out_open: returning\n");          fprintf(stderr, "wave_out_open: returning\n");
98  #endif  #endif
99          return True;          return True;
100  }  }
# Line 102  wave_out_close(void) Line 104  wave_out_close(void)
104  {  {
105          /* Ack all remaining packets */          /* Ack all remaining packets */
106  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
107      fprintf(stderr, "wave_out_close: begin\n");          fprintf(stderr, "wave_out_close: begin\n");
108  #endif  #endif
109            
110          while (queue_lo != queue_hi)          while (queue_lo != queue_hi)
111          {          {
112                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);
113                  free(packet_queue[queue_lo].s.data);                  free(packet_queue[queue_lo].s.data);
114                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                  queue_lo = (queue_lo + 1) % MAX_QUEUE;
115          }          }
116          alDiscardFrames(output_port, 0);                  alDiscardFrames(output_port, 0);
117            
118          alClosePort(output_port);          alClosePort(output_port);
119          alFreeConfig(audioconfig);          alFreeConfig(audioconfig);
120  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
121      fprintf(stderr, "wave_out_close: returning\n");          fprintf(stderr, "wave_out_close: returning\n");
122  #endif  #endif
123  }  }
124    
# Line 137  BOOL Line 139  BOOL
139  wave_out_set_format(WAVEFORMATEX * pwfx)  wave_out_set_format(WAVEFORMATEX * pwfx)
140  {  {
141          int channels;          int channels;
142    int frameSize, channelCount;          int frameSize, channelCount;
143    ALpv  params;          ALpv params;
144            
145  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
146                  fprintf(stderr, "wave_out_set_format: init...\n");          fprintf(stderr, "wave_out_set_format: init...\n");
147  #endif  #endif
148          /* limited support to configure an opened audio port in IRIX */          /* limited support to configure an opened audio port in IRIX */
149          /* have to reopen the audio port, using same config */          /* have to reopen the audio port, using same config */
# Line 151  wave_out_set_format(WAVEFORMATEX * pwfx) Line 153  wave_out_set_format(WAVEFORMATEX * pwfx)
153    
154          if (pwfx->wBitsPerSample == 8)          if (pwfx->wBitsPerSample == 8)
155                  width = AL_SAMPLE_8;                  width = AL_SAMPLE_8;
156          else if (pwfx->wBitsPerSample == 16) {          else if (pwfx->wBitsPerSample == 16)
157            {
158                  width = AL_SAMPLE_16;                  width = AL_SAMPLE_16;
159                  /* Do we need to swap the 16bit values? (Are we BigEndian) */                  /* Do we need to swap the 16bit values? (Are we BigEndian) */
160  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
# Line 171  wave_out_set_format(WAVEFORMATEX * pwfx) Line 174  wave_out_set_format(WAVEFORMATEX * pwfx)
174    
175          output_port = alOpenPort("rdpsnd", "w", audioconfig);          output_port = alOpenPort("rdpsnd", "w", audioconfig);
176    
177          if (output_port == (ALport) 0) {          if (output_port == (ALport) 0)
178      fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",          {
179              alGetErrorString(oserror()));                  fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",
180                            alGetErrorString(oserror()));
181                  return False;                  return False;
182          }          }
183    
184          resource = alGetResource(output_port);          resource = alGetResource(output_port);
185          maxFillable = alGetFillable(output_port);          maxFillable = alGetFillable(output_port);
186    channelCount = alGetChannels(audioconfig);          channelCount = alGetChannels(audioconfig);
187    frameSize = alGetWidth(audioconfig);          frameSize = alGetWidth(audioconfig);
188    
189            if (frameSize == 0 || channelCount == 0)
190            {
191                    fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n");
192                    return False;
193            }
194            combinedFrameSize = frameSize * channelCount;
195    
196    if (frameSize == 0 || channelCount == 0)          params.param = AL_RATE;
197    {          params.value.ll = (long long) g_snd_rate << 32;
198      fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n");  
199      return False;          if (alSetParams(resource, &params, 1) < 0)
200    }          {
201    combinedFrameSize = frameSize * channelCount;                  fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
202                            alGetErrorString(oserror()));
203    params.param = AL_RATE;                  return False;
204    params.value.ll = (long long) g_snd_rate << 32;          }
205            if (params.sizeOut < 0)
206    if (alSetParams(resource, &params, 1) < 0)          {
207    {                  fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
208      fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",                  return False;
209                                                  alGetErrorString(oserror()));          }
     return False;  
   }  
   if( params.sizeOut < 0 )  
   {  
     fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);  
     return False;  
   }  
210    
211  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
212                  fprintf(stderr, "wave_out_set_format: returning...\n");          fprintf(stderr, "wave_out_set_format: returning...\n");
213  #endif  #endif
214          return True;          return True;
215  }  }
# Line 213  wave_out_set_format(WAVEFORMATEX * pwfx) Line 217  wave_out_set_format(WAVEFORMATEX * pwfx)
217  void  void
218  wave_out_volume(uint16 left, uint16 right)  wave_out_volume(uint16 left, uint16 right)
219  {  {
220    double gainleft, gainright;          double gainleft, gainright;
221    ALpv pv[1];          ALpv pv[1];
222    ALfixed gain[8];          ALfixed gain[8];
223    
224  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
225      fprintf(stderr, "wave_out_volume: begin\n");          fprintf(stderr, "wave_out_volume: begin\n");
226      fprintf(stderr, "left='%d', right='%d'\n", left, right);          fprintf(stderr, "left='%d', right='%d'\n", left, right);
227  #endif  #endif
228            
229          gainleft =  (double)  left / IRIX_MAX_VOL;          gainleft = (double) left / IRIX_MAX_VOL;
230          gainright = (double) right / IRIX_MAX_VOL;          gainright = (double) right / IRIX_MAX_VOL;
231    
232    gain[0] = alDoubleToFixed(min_volume + gainleft  * volume_range);          gain[0] = alDoubleToFixed(min_volume + gainleft * volume_range);
233    gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);          gain[1] = alDoubleToFixed(min_volume + gainright * volume_range);
234    
235    pv[0].param = AL_GAIN;          pv[0].param = AL_GAIN;
236    pv[0].value.ptr = gain;          pv[0].value.ptr = gain;
237    pv[0].sizeIn = 8;          pv[0].sizeIn = 8;
238    if( alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)          if (alSetParams(AL_DEFAULT_OUTPUT, pv, 1) < 0)
239    {          {
240      fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n", alGetErrorString(oserror()));                  fprintf(stderr, "wave_out_volume: alSetParams failed: %s\n",
241      return;                          alGetErrorString(oserror()));
242    }                  return;
243            }
244    
245  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
246      fprintf(stderr, "wave_out_volume: returning\n");          fprintf(stderr, "wave_out_volume: returning\n");
247  #endif  #endif
248  }  }
249    
# Line 316  wave_out_play(void) Line 321  wave_out_play(void)
321                  }                  }
322    
323                  len = out->end - out->p;                  len = out->end - out->p;
324                  gf = alGetFillable(output_port);                                  gf = alGetFillable(output_port);
325                  if (len > gf) {                  if (len > gf)
326                    {
327                          //len = gf * combinedFrameSize;                          //len = gf * combinedFrameSize;
328  #if (defined(IRIX_DEBUG))  #if (defined(IRIX_DEBUG))
329                          //fprintf(stderr,"Fillable...\n");                          //fprintf(stderr,"Fillable...\n");
330  #endif  #endif
331                  }                  }
332    
333                  alWriteFrames(output_port, out->p, len/combinedFrameSize);                  alWriteFrames(output_port, out->p, len / combinedFrameSize);
334    
335                  out->p += len;                  out->p += len;
336                  if (out->p == out->end)                  if (out->p == out->end)
# Line 334  wave_out_play(void) Line 340  wave_out_play(void)
340    
341                          gettimeofday(&tv, NULL);                          gettimeofday(&tv, NULL);
342                          duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate)));                          duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate)));
343                          elapsed =  (tv.tv_sec - startedat_s) * 1000000                          elapsed = (tv.tv_sec - startedat_s) * 1000000 + (tv.tv_usec - startedat_us);
                                        + (tv.tv_usec - startedat_us);  
344                          /* 7/10 is not good for IRIX audio port, 4x/100 is suitable */                          /* 7/10 is not good for IRIX audio port, 4x/100 is suitable */
345                          if (elapsed >= (duration * 485) / 1000)                          if (elapsed >= (duration * 485) / 1000)
346                          {                          {

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

  ViewVC Help
Powered by ViewVC 1.1.26