/[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 836 by stargo, Tue Mar 8 12:09:20 2005 UTC revision 841 by stargo, Tue Mar 8 17:23:26 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  #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;  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 54  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;          g_samplerate = 44100;
61          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
# Line 83  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 110  wave_out_set_format(WAVEFORMATEX * pwfx) Line 113  wave_out_set_format(WAVEFORMATEX * pwfx)
113    
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;          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 132  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 165  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[WAVEOUTBUF];          unsigned char outbuf[WAVEOUTBUF];
174          int offset,len,i;          int offset, len, i;
175    
176          if (queue_lo == queue_hi)          if (queue_lo == queue_hi)
177          {          {
# Line 179  wave_out_play(void) Line 184  wave_out_play(void)
184    
185          len = 0;          len = 0;
186    
187          if (g_samplerate == 22050 )          if (g_samplerate == 22050)
188          {          {
189                  /* Resample to 44100 */                  /* Resample to 44100 */
190                  for(i=0; (i<((WAVEOUTBUF/8)*(3-g_samplewidth))) && (out->p < out->end); i++)                  for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end);
191                         i++)
192                  {                  {
193                          offset=i*4*g_samplewidth;                          /* On a stereo-channel we must make sure that left and right
194                          memcpy(&expanded[0*g_samplewidth+offset],out->p,g_samplewidth);                             does not get mixed up, so we need to expand the sample-
195                          memcpy(&expanded[2*g_samplewidth+offset],out->p,g_samplewidth);                             data with channels in mind: 1234 -> 12123434
196                          out->p += 2;                             If we have a mono-channel, we can expand the data by simply
197                               doubling the sample-data: 1234 -> 11223344 */
198                          memcpy(&expanded[1*g_samplewidth+offset],out->p,g_samplewidth);                          if (g_channels == 2)
199                          memcpy(&expanded[3*g_samplewidth+offset],out->p,g_samplewidth);                                  offset = ((i * 2) - (i & 1)) * g_samplewidth;
200                          out->p += 2;                          else
201                          len += 4*g_samplewidth;                                  offset = (i * 2) * g_samplewidth;
202    
203                            memcpy(&outbuf[offset], out->p, g_samplewidth);
204                            memcpy(&outbuf[g_channels * g_samplewidth + offset], out->p, g_samplewidth);
205    
206                            out->p += g_samplewidth;
207                            len += 2 * g_samplewidth;
208                  }                  }
209          }          }
210          else          else
211          {          {
212                  len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF;                  len = (WAVEOUTBUF > (out->end - out->p)) ? (out->end - out->p) : WAVEOUTBUF;
213                  memcpy(expanded,out->p,len);                  memcpy(outbuf, out->p, len);
214                  out->p += len;                  out->p += len;
215          }          }
216    
217          ao_play(o_device, expanded, len);          ao_play(o_device, outbuf, len);
218    
219          if (out->p == out->end)          if (out->p == out->end)
220          {          {

Legend:
Removed from v.836  
changed lines
  Added in v.841

  ViewVC Help
Powered by ViewVC 1.1.26