/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_libao.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_libao.c

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

revision 833 by stargo, Tue Mar 8 03:33:36 2005 UTC revision 838 by stargo, Tue Mar 8 12:29:19 2005 UTC
# Line 27  Line 27 
27  #include <ao/ao.h>  #include <ao/ao.h>
28    
29  #define MAX_QUEUE       10  #define MAX_QUEUE       10
30    #define WAVEOUTBUF      32
31    
32  int g_dsp_fd;  int g_dsp_fd;
33  ao_device *o_device = NULL;  ao_device *o_device = NULL;
34  int default_driver;  int default_driver;
35    int g_samplerate;
36  BOOL g_dsp_busy = False;  BOOL g_dsp_busy = False;
37  static short g_samplewidth;  static short g_samplewidth;
38    
# Line 53  wave_out_open(void) Line 55  wave_out_open(void)
55          format.bits = 16;          format.bits = 16;
56          format.channels = 2;          format.channels = 2;
57          format.rate = 44100;          format.rate = 44100;
58            g_samplerate = 44100;
59          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
60    
61          o_device = ao_open_live(default_driver, &format, NULL);          o_device = ao_open_live(default_driver, &format, NULL);
# Line 80  wave_out_close(void) Line 83  wave_out_close(void)
83    
84          if (o_device != NULL)          if (o_device != NULL)
85                  ao_close(o_device);                  ao_close(o_device);
86    
87          ao_shutdown();          ao_shutdown();
88  }  }
89    
# Line 93  wave_out_format_supported(WAVEFORMATEX * Line 97  wave_out_format_supported(WAVEFORMATEX *
97          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
98                  return False;                  return False;
99          /* The only common denominator between libao output drivers is a sample-rate of          /* The only common denominator between libao output drivers is a sample-rate of
100             44100, windows gives a max of 22050. we need to upsample that...             44100, we need to upsample 22050 to it */
101             TODO: support 11025, too */          if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
         if (pwfx->nSamplesPerSec != 22050)  
102                  return False;                  return False;
103    
104          return True;          return True;
# Line 106  wave_out_set_format(WAVEFORMATEX * pwfx) Line 109  wave_out_set_format(WAVEFORMATEX * pwfx)
109  {  {
110          ao_sample_format format;          ao_sample_format format;
111    
         printf("%d\n",pwfx->wBitsPerSample);  
112          format.bits = pwfx->wBitsPerSample;          format.bits = pwfx->wBitsPerSample;
113          format.channels = pwfx->nChannels;          format.channels = pwfx->nChannels;
114          format.rate = 44100;          format.rate = 44100;
115            g_samplerate = pwfx->nSamplesPerSec;
116          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
117    
118          g_samplewidth = pwfx->wBitsPerSample / 8;          g_samplewidth = pwfx->wBitsPerSample / 8;
119    
120          if(o_device != NULL)          if (o_device != NULL)
121                  ao_close(o_device);                  ao_close(o_device);
122    
123          o_device = ao_open_live(default_driver, &format, NULL);          o_device = ao_open_live(default_driver, &format, NULL);
# Line 130  wave_out_set_format(WAVEFORMATEX * pwfx) Line 133  wave_out_set_format(WAVEFORMATEX * pwfx)
133  void  void
134  wave_out_volume(uint16 left, uint16 right)  wave_out_volume(uint16 left, uint16 right)
135  {  {
136            warning("volume changes not supported with libao-output\n");
137  }  }
138    
139  void  void
# Line 163  wave_out_play(void) Line 167  wave_out_play(void)
167  {  {
168          struct audio_packet *packet;          struct audio_packet *packet;
169          STREAM out;          STREAM out;
170          unsigned char expanded[8];          unsigned char outbuf[WAVEOUTBUF];
171            int offset, len, i;
172    
173          while (1)          if (queue_lo == queue_hi)
174          {          {
175                  if (queue_lo == queue_hi)                  g_dsp_busy = 0;
176                  {                  return;
177                          g_dsp_busy = 0;          }
                         return;  
                 }  
   
                 packet = &packet_queue[queue_lo];  
                 out = &packet->s;  
178    
179                  /* Resample 22050 -> 44100 */          packet = &packet_queue[queue_lo];
180                  /* TODO: Do this for 11025, too... */          out = &packet->s;
                 memcpy(&expanded[0],out->p,g_samplewidth);  
                 memcpy(&expanded[2*g_samplewidth],out->p,g_samplewidth);  
                 out->p += 2;  
                 memcpy(&expanded[1*g_samplewidth],out->p,g_samplewidth);  
                 memcpy(&expanded[3*g_samplewidth],out->p,g_samplewidth);  
                 out->p += 2;  
181    
182                  ao_play(o_device, expanded, g_samplewidth*4);          len = 0;
183    
184                  if (out->p == out->end)          if (g_samplerate == 22050)
185            {
186                    /* Resample to 44100 */
187                    for (i = 0; (i < ((WAVEOUTBUF / 8) * (3 - g_samplewidth))) && (out->p < out->end);
188                         i++)
189                  {                  {
190                          rdpsnd_send_completion(packet->tick, packet->index);                          offset = i * 4 * g_samplewidth;
191                          free(out->data);                          memcpy(&outbuf[0 * g_samplewidth + offset], out->p, g_samplewidth);
192                          queue_lo = (queue_lo + 1) % MAX_QUEUE;                          memcpy(&outbuf[2 * g_samplewidth + offset], out->p, g_samplewidth);
193                  } else {                          out->p += 2;
194                          g_dsp_busy = 1;  
195                          return;                          memcpy(&outbuf[1 * g_samplewidth + offset], out->p, g_samplewidth);
196                            memcpy(&outbuf[3 * g_samplewidth + offset], out->p, g_samplewidth);
197                            out->p += 2;
198                            len += 4 * g_samplewidth;
199                  }                  }
200          }          }
201            else
202            {
203                    len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF;
204                    memcpy(outbuf, out->p, len);
205                    out->p += len;
206            }
207    
208            ao_play(o_device, outbuf, len);
209    
210            if (out->p == out->end)
211            {
212                    rdpsnd_send_completion(packet->tick, packet->index);
213                    free(out->data);
214                    queue_lo = (queue_lo + 1) % MAX_QUEUE;
215            }
216    
217            g_dsp_busy = 1;
218            return;
219  }  }

Legend:
Removed from v.833  
changed lines
  Added in v.838

  ViewVC Help
Powered by ViewVC 1.1.26