/[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 840 by stargo, Tue Mar 8 17:03:08 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      64
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    int g_channels;
37  BOOL g_dsp_busy = False;  BOOL g_dsp_busy = False;
38  static short g_samplewidth;  static short g_samplewidth;
39    
# Line 52  wave_out_open(void) Line 55  wave_out_open(void)
55    
56          format.bits = 16;          format.bits = 16;
57          format.channels = 2;          format.channels = 2;
58            g_channels = 2;
59          format.rate = 44100;          format.rate = 44100;
60            g_samplerate = 44100;
61          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
62    
63          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 85  wave_out_close(void)
85    
86          if (o_device != NULL)          if (o_device != NULL)
87                  ao_close(o_device);                  ao_close(o_device);
88    
89          ao_shutdown();          ao_shutdown();
90  }  }
91    
# Line 93  wave_out_format_supported(WAVEFORMATEX * Line 99  wave_out_format_supported(WAVEFORMATEX *
99          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
100                  return False;                  return False;
101          /* 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
102             44100, windows gives a max of 22050. we need to upsample that...             44100, we need to upsample 22050 to it */
103             TODO: support 11025, too */          if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
         if (pwfx->nSamplesPerSec != 22050)  
104                  return False;                  return False;
105    
106          return True;          return True;
# Line 106  wave_out_set_format(WAVEFORMATEX * pwfx) Line 111  wave_out_set_format(WAVEFORMATEX * pwfx)
111  {  {
112          ao_sample_format format;          ao_sample_format format;
113    
         printf("%d\n",pwfx->wBitsPerSample);  
114          format.bits = pwfx->wBitsPerSample;          format.bits = pwfx->wBitsPerSample;
115          format.channels = pwfx->nChannels;          format.channels = pwfx->nChannels;
116            g_channels = pwfx->nChannels;
117          format.rate = 44100;          format.rate = 44100;
118            g_samplerate = pwfx->nSamplesPerSec;
119          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
120    
121          g_samplewidth = pwfx->wBitsPerSample / 8;          g_samplewidth = pwfx->wBitsPerSample / 8;
122    
123          if(o_device != NULL)          if (o_device != NULL)
124                  ao_close(o_device);                  ao_close(o_device);
125    
126          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 136  wave_out_set_format(WAVEFORMATEX * pwfx)
136  void  void
137  wave_out_volume(uint16 left, uint16 right)  wave_out_volume(uint16 left, uint16 right)
138  {  {
139            warning("volume changes not supported with libao-output\n");
140  }  }
141    
142  void  void
# Line 163  wave_out_play(void) Line 170  wave_out_play(void)
170  {  {
171          struct audio_packet *packet;          struct audio_packet *packet;
172          STREAM out;          STREAM out;
173          unsigned char expanded[8];          unsigned char outbuf[WAVEOUTBUF];
174            int offset, len, i;
175    
176          while (1)          if (queue_lo == queue_hi)
177          {          {
178                  if (queue_lo == queue_hi)                  g_dsp_busy = 0;
179                  {                  return;
180                          g_dsp_busy = 0;          }
                         return;  
                 }  
   
                 packet = &packet_queue[queue_lo];  
                 out = &packet->s;  
181    
182                  /* Resample 22050 -> 44100 */          packet = &packet_queue[queue_lo];
183                  /* 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;  
184    
185                  ao_play(o_device, expanded, g_samplewidth*4);          len = 0;
186    
187                  if (out->p == out->end)          if (g_samplerate == 22050)
188            {
189                    /* Resample to 44100 */
190                    for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end);
191                         i++)
192                  {                  {
193                          rdpsnd_send_completion(packet->tick, packet->index);                          if (g_channels == 2)
194                          free(out->data);                                  offset = ((i * 2) - (i & 1)) * g_samplewidth;
195                          queue_lo = (queue_lo + 1) % MAX_QUEUE;                          else
196                  } else {                                  offset = (i * 2) * g_samplewidth;
197                          g_dsp_busy = 1;  
198                          return;                          memcpy(&outbuf[offset], out->p, g_samplewidth);
199                            memcpy(&outbuf[g_channels * g_samplewidth + offset], out->p, g_samplewidth);
200                            out->p += 2;
201    
202                            len += 2 * g_samplewidth;
203                  }                  }
204          }          }
205            else
206            {
207                    len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF;
208                    memcpy(outbuf, out->p, len);
209                    out->p += len;
210            }
211    
212            ao_play(o_device, outbuf, len);
213    
214            if (out->p == out->end)
215            {
216                    rdpsnd_send_completion(packet->tick, packet->index);
217                    free(out->data);
218                    queue_lo = (queue_lo + 1) % MAX_QUEUE;
219            }
220    
221            g_dsp_busy = 1;
222            return;
223  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26