comparison libao2/ao_alsa9.c @ 2059:3c390543302c

alsa9 pecs by joy_ping <joy@pingfm.org>
author pontscho
date Wed, 03 Oct 2001 18:09:51 +0000
parents bf18175dfad7
children a59f952fad34
comparison
equal deleted inserted replaced
2058:b840d0913383 2059:3c390543302c
39 static snd_pcm_t *alsa_handler; 39 static snd_pcm_t *alsa_handler;
40 static snd_pcm_format_t alsa_format; 40 static snd_pcm_format_t alsa_format;
41 static snd_pcm_hw_params_t *alsa_hwparams; 41 static snd_pcm_hw_params_t *alsa_hwparams;
42 static snd_pcm_sw_params_t *alsa_swparams; 42 static snd_pcm_sw_params_t *alsa_swparams;
43 static char *alsa_device; 43 static char *alsa_device;
44 #define ALSA_DEVICE_SIZE 48 44 #define ALSA_DEVICE_SIZE 48 /* war 48 */
45 45
46 static int alsa_fragsize = 8192; /* 4096 */ 46 static int alsa_fragsize = 8192; /* 4096 war 8192*/
47 static int alsa_fragcount = 8; 47 static int alsa_fragcount = 8; /* war 8 */
48 48
49 /* to set/get/query special features/parameters */ 49 /* to set/get/query special features/parameters */
50 static int control(int cmd, int arg) 50 static int control(int cmd, int arg)
51 { 51 {
52 switch(cmd) 52 switch(cmd)
67 } 67 }
68 } 68 }
69 return(CONTROL_UNKNOWN); 69 return(CONTROL_UNKNOWN);
70 } 70 }
71 71
72 #undef start 72 #undef start /* war undef */
73 #define buffersize 73 #define buffersize
74 #undef buffertime 74 #undef buffertime /* war undef? */
75 #define set_period 75 #define set_period
76 #undef sw_params 76 #define sw_params /* war undef */
77 #undef set_start_mode 77 #undef set_start_mode /* war undef */
78 78
79 /* 79 /*
80 open & setup audio device 80 open & setup audio device
81 return: 1=success 0=fail 81 return: 1=success 0=fail
82 */ 82 */
84 { 84 {
85 int err; 85 int err;
86 int cards = -1; 86 int cards = -1;
87 snd_pcm_info_t *alsa_info; 87 snd_pcm_info_t *alsa_info;
88 88
89 printf("alsa-init: Don't use this buggy driver, ALSA-0.9.x emulates OSS very well...\n"); 89 printf("alsa-init: Don't use this buggy driver, ALSA-0.9.x emulates OSS very well... modified by me\n");
90 90
91 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, 91 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
92 channels, audio_out_format_name(format)); 92 channels, audio_out_format_name(format));
93 93
94 alsa_handler = NULL; 94 alsa_handler = NULL;
95 95
96 if (verbose) 96 if (verbose)
97 printf("alsa-init: compiled for ALSA-%s (%d)\n", SND_LIB_VERSION_STR, 97 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR);
98 SND_LIB_VERSION);
99 98
100 if ((err = snd_card_next(&cards)) < 0 || cards < 0) 99 if ((err = snd_card_next(&cards)) < 0 || cards < 0)
101 { 100 {
102 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); 101 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err));
103 return(0); 102 return(0);
104 } 103 }
105 104
106 ao_samplerate = rate_hz; 105 ao_samplerate = rate_hz; /*war rate_hz */
107 ao_bps = channels; /* really this is bytes per frame so bad varname */ 106 ao_bps = channels; /* really this is bytes per frame so bad varname */
107 /* ao_bps = channels */
108 ao_format = format; 108 ao_format = format;
109 ao_channels = channels; 109 ao_channels = channels;
110 ao_outburst = OUTBURST; 110 ao_outburst = OUTBURST;
111 ao_buffersize = 16384; 111 ao_buffersize = 16384;
112 112
215 printf("alsa-init: unable to set channels: %s\n", 215 printf("alsa-init: unable to set channels: %s\n",
216 snd_strerror(err)); 216 snd_strerror(err));
217 return(0); 217 return(0);
218 } 218 }
219 219
220 if ((err = snd_pcm_hw_params_set_rate(alsa_handler, alsa_hwparams, 220 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_samplerate, 0)) < 0)
221 ao_samplerate, 0)) < 0) 221 /* war nur snd_pcm_hw_params_set_rate */
222 { 222 {
223 printf("alsa-init: unable to set samplerate: %s\n", 223 printf("alsa-init: unable to set samplerate-2: %s\n",
224 snd_strerror(err)); 224 snd_strerror(err));
225 return(0); 225 //snd_pcm_hw_params_dump(alsa_hwparams, errlog);
226 } 226 return(0);
227 }
227 228
228 #ifdef set_period 229 #ifdef set_period
229 { 230 {
230 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize / 4, 0)) < 0) 231 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize / 4, 0)) < 0)
231 { 232 {
255 } 256 }
256 #endif 257 #endif
257 258
258 #ifdef buffertime 259 #ifdef buffertime
259 { 260 {
260 int alsa_buffer_time = 60; 261 int alsa_buffer_time = 60; /* war 60 */
261 262
262 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, 263 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0)
263 alsa_buffer_time, 0)) < 0)
264 { 264 {
265 printf("alsa-init: unable to set buffer time near: %s\n", 265 printf("alsa-init: unable to set buffer time near: %s\n",
266 snd_strerror(err)); 266 snd_strerror(err));
267 return(0); 267 return(0);
268 } else 268 } else
269 alsa_buffer_time = err; 269 alsa_buffer_time = err;
270 270
271 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, 271 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/ao_bps, 0)) < 0)
272 alsa_buffer_time/ao_bps, 0)) < 0) 272 /* war alsa_buffer_time/ao_bps */
273 { 273 {
274 printf("alsa-init: unable to set period time: %s\n", 274 printf("alsa-init: unable to set period time: %s\n",
275 snd_strerror(err)); 275 snd_strerror(err));
276 return(0); 276 return(0);
277 } 277 }
449 */ 449 */
450 static int play(void* data, int len, int flags) 450 static int play(void* data, int len, int flags)
451 { 451 {
452 int got_len; 452 int got_len;
453 453
454 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps)) 454 got_len = snd_pcm_writei(alsa_handler, data, len / 4);
455 { 455
456 // war: if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps)) {
457
456 if (got_len == -EPIPE) /* underrun? */ 458 if (got_len == -EPIPE) /* underrun? */
457 { 459 {
458 printf("alsa-play: alsa underrun, resetting stream\n"); 460 printf("alsa-play: alsa underrun, resetting stream\n");
459 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0) 461 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0)
460 { 462 {
466 printf("alsa-play: write error after reset: %s - giving up\n", 468 printf("alsa-play: write error after reset: %s - giving up\n",
467 snd_strerror(got_len)); 469 snd_strerror(got_len));
468 return(0); 470 return(0);
469 } 471 }
470 return(len); /* 2nd write was ok */ 472 return(len); /* 2nd write was ok */
471 }
472 } 473 }
473 return(len); 474 return(len);
474 } 475 }
475 476
476 /* how many byes are free in the buffer */ 477 /* how many byes are free in the buffer */