1 /* -*- mode: c; c-file-style: "linux"; -*- */
3 Copyright (C) 2001 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <sys/types.h>
34 #include <jack/internal.h>
35 #include <jack/engine.h>
36 #include <jack/messagebuffer.h>
38 #include <sysdeps/time.h>
40 #include "alsa_driver.h"
41 #include "hammerfall.h"
47 extern void store_work_time (int);
48 extern void store_wait_time (int);
49 extern void show_wait_times ();
50 extern void show_work_times ();
54 /* Delay (in process calls) before jackd will report an xrun */
55 #define XRUN_REPORT_DELAY 0
58 alsa_driver_release_channel_dependent_memory (alsa_driver_t
*driver
)
60 bitset_destroy (&driver
->channels_done
);
61 bitset_destroy (&driver
->channels_not_done
);
63 if (driver
->playback_addr
) {
64 free (driver
->playback_addr
);
65 driver
->playback_addr
= 0;
68 if (driver
->capture_addr
) {
69 free (driver
->capture_addr
);
70 driver
->capture_addr
= 0;
73 if (driver
->playback_interleave_skip
) {
74 free (driver
->playback_interleave_skip
);
75 driver
->playback_interleave_skip
= NULL
;
78 if (driver
->capture_interleave_skip
) {
79 free (driver
->capture_interleave_skip
);
80 driver
->capture_interleave_skip
= NULL
;
84 free (driver
->silent
);
88 if (driver
->dither_state
) {
89 free (driver
->dither_state
);
90 driver
->dither_state
= 0;
95 alsa_driver_check_capabilities (alsa_driver_t
*driver
)
101 alsa_driver_check_card_type (alsa_driver_t
*driver
)
104 snd_ctl_card_info_t
*card_info
;
108 snd_ctl_card_info_alloca (&card_info
);
110 regcomp(&expression
,"(plug)?hw:[0-9](,[0-9])?",REG_ICASE
|REG_EXTENDED
);
112 if (!regexec(&expression
,driver
->alsa_name_playback
,0,NULL
,0)) {
113 /* the user wants a hw or plughw device, the ctl name
114 * should be hw:x where x is the card number */
117 strncpy(tmp
,strstr(driver
->alsa_name_playback
,"hw"),4);
119 printf("control device %s\n",tmp
);
120 ctl_name
= strdup(tmp
);
122 ctl_name
= strdup(driver
->alsa_name_playback
);
125 // XXX: I don't know the "right" way to do this. Which to use
126 // driver->alsa_name_playback or driver->alsa_name_capture.
127 if ((err
= snd_ctl_open (&driver
->ctl_handle
, ctl_name
, 0)) < 0) {
128 jack_error ("control open \"%s\" (%s)", ctl_name
,
130 } else if ((err
= snd_ctl_card_info(driver
->ctl_handle
, card_info
)) < 0) {
131 jack_error ("control hardware info \"%s\" (%s)",
132 driver
->alsa_name_playback
, snd_strerror (err
));
133 snd_ctl_close (driver
->ctl_handle
);
136 driver
->alsa_driver
= strdup(snd_ctl_card_info_get_driver (card_info
));
138 regfree(&expression
);
141 return alsa_driver_check_capabilities (driver
);
145 alsa_driver_hammerfall_hardware (alsa_driver_t
*driver
)
147 driver
->hw
= jack_alsa_hammerfall_hw_new (driver
);
152 alsa_driver_hdsp_hardware (alsa_driver_t
*driver
)
154 driver
->hw
= jack_alsa_hdsp_hw_new (driver
);
159 alsa_driver_ice1712_hardware (alsa_driver_t
*driver
)
161 driver
->hw
= jack_alsa_ice1712_hw_new (driver
);
166 alsa_driver_usx2y_hardware (alsa_driver_t
*driver
)
168 driver
->hw
= jack_alsa_usx2y_hw_new (driver
);
173 alsa_driver_generic_hardware (alsa_driver_t
*driver
)
175 driver
->hw
= jack_alsa_generic_hw_new (driver
);
180 alsa_driver_hw_specific (alsa_driver_t
*driver
, int hw_monitoring
,
185 if (!strcmp(driver
->alsa_driver
, "RME9652")) {
186 if ((err
= alsa_driver_hammerfall_hardware (driver
)) != 0) {
189 } else if (!strcmp(driver
->alsa_driver
, "H-DSP")) {
190 if ((err
= alsa_driver_hdsp_hardware (driver
)) !=0) {
193 } else if (!strcmp(driver
->alsa_driver
, "ICE1712")) {
194 if ((err
= alsa_driver_ice1712_hardware (driver
)) !=0) {
197 } else if (!strcmp(driver
->alsa_driver
, "USB US-X2Y")) {
198 if ((err
= alsa_driver_usx2y_hardware (driver
)) !=0) {
202 if ((err
= alsa_driver_generic_hardware (driver
)) != 0) {
207 if (driver
->hw
->capabilities
& Cap_HardwareMonitoring
) {
208 driver
->has_hw_monitoring
= TRUE
;
209 /* XXX need to ensure that this is really FALSE or
211 driver
->hw_monitoring
= hw_monitoring
;
213 driver
->has_hw_monitoring
= FALSE
;
214 driver
->hw_monitoring
= FALSE
;
217 if (driver
->hw
->capabilities
& Cap_ClockLockReporting
) {
218 driver
->has_clock_sync_reporting
= TRUE
;
220 driver
->has_clock_sync_reporting
= FALSE
;
223 if (driver
->hw
->capabilities
& Cap_HardwareMetering
) {
224 driver
->has_hw_metering
= TRUE
;
225 driver
->hw_metering
= hw_metering
;
227 driver
->has_hw_metering
= FALSE
;
228 driver
->hw_metering
= FALSE
;
235 alsa_driver_setup_io_function_pointers (alsa_driver_t
*driver
)
237 switch (driver
->playback_sample_bytes
) {
239 if (driver
->playback_interleaved
) {
240 driver
->channel_copy
= memcpy_interleave_d16_s16
;
242 driver
->channel_copy
= memcpy_fake
;
245 switch (driver
->dither
) {
247 printf("Rectangular dithering at 16 bits\n");
248 driver
->write_via_copy
= driver
->quirk_bswap
?
249 sample_move_dither_rect_d16_sSs
:
250 sample_move_dither_rect_d16_sS
;
254 printf("Triangular dithering at 16 bits\n");
255 driver
->write_via_copy
= driver
->quirk_bswap
?
256 sample_move_dither_tri_d16_sSs
:
257 sample_move_dither_tri_d16_sS
;
261 printf("Noise-shaped dithering at 16 bits\n");
262 driver
->write_via_copy
= driver
->quirk_bswap
?
263 sample_move_dither_shaped_d16_sSs
:
264 sample_move_dither_shaped_d16_sS
;
268 driver
->write_via_copy
= driver
->quirk_bswap
?
269 sample_move_d16_sSs
: sample_move_d16_sS
;
275 if (driver
->playback_interleaved
) {
276 driver
->channel_copy
= memcpy_interleave_d24_s24
;
278 driver
->channel_copy
= memcpy_fake
;
281 switch (driver
->dither
) {
283 printf("Rectangular dithering at 16 bits\n");
284 driver
->write_via_copy
= driver
->quirk_bswap
?
285 sample_move_dither_rect_d24_sSs
:
286 sample_move_dither_rect_d24_sS
;
290 printf("Triangular dithering at 16 bits\n");
291 driver
->write_via_copy
= driver
->quirk_bswap
?
292 sample_move_dither_tri_d24_sSs
:
293 sample_move_dither_tri_d24_sS
;
297 printf("Noise-shaped dithering at 16 bits\n");
298 driver
->write_via_copy
= driver
->quirk_bswap
?
299 sample_move_dither_shaped_d24_sSs
:
300 sample_move_dither_shaped_d24_sS
;
304 driver
->write_via_copy
= driver
->quirk_bswap
?
305 sample_move_d24_sSs
: sample_move_d24_sS
;
311 if (driver
->playback_interleaved
) {
312 driver
->channel_copy
= memcpy_interleave_d32_s32
;
314 driver
->channel_copy
= memcpy_fake
;
317 switch (driver
->dither
) {
319 printf("Rectangular dithering at 16 bits\n");
320 driver
->write_via_copy
= driver
->quirk_bswap
?
321 sample_move_dither_rect_d32u24_sSs
:
322 sample_move_dither_rect_d32u24_sS
;
326 printf("Triangular dithering at 16 bits\n");
327 driver
->write_via_copy
= driver
->quirk_bswap
?
328 sample_move_dither_tri_d32u24_sSs
:
329 sample_move_dither_tri_d32u24_sS
;
333 printf("Noise-shaped dithering at 16 bits\n");
334 driver
->write_via_copy
= driver
->quirk_bswap
?
335 sample_move_dither_shaped_d32u24_sSs
:
336 sample_move_dither_shaped_d32u24_sS
;
340 driver
->write_via_copy
= driver
->quirk_bswap
?
341 sample_move_d32u24_sSs
: sample_move_d32u24_sS
;
347 switch (driver
->capture_sample_bytes
) {
349 driver
->read_via_copy
= driver
->quirk_bswap
?
350 sample_move_dS_s16s
: sample_move_dS_s16
;
353 driver
->read_via_copy
= driver
->quirk_bswap
?
354 sample_move_dS_s24s
: sample_move_dS_s24
;
357 driver
->read_via_copy
= driver
->quirk_bswap
?
358 sample_move_dS_s32u24s
: sample_move_dS_s32u24
;
364 alsa_driver_configure_stream (alsa_driver_t
*driver
, char *device_name
,
365 const char *stream_name
,
367 snd_pcm_hw_params_t
*hw_params
,
368 snd_pcm_sw_params_t
*sw_params
,
369 unsigned int *nperiodsp
,
371 unsigned long sample_width
)
374 unsigned int frame_rate
;
375 snd_pcm_uframes_t stop_th
;
378 snd_pcm_format_t format
;
381 {"32bit little-endian", SND_PCM_FORMAT_S32_LE
, IS_LE
},
382 {"32bit big-endian", SND_PCM_FORMAT_S32_BE
, IS_BE
},
383 {"24bit little-endian", SND_PCM_FORMAT_S24_3LE
, IS_LE
},
384 {"24bit big-endian", SND_PCM_FORMAT_S24_3BE
, IS_BE
},
385 {"16bit little-endian", SND_PCM_FORMAT_S16_LE
, IS_LE
},
386 {"16bit big-endian", SND_PCM_FORMAT_S16_BE
, IS_BE
},
388 #define NUMFORMATS (sizeof(formats)/sizeof(formats[0]))
389 #define FIRST_16BIT_FORMAT 4
391 if ((err
= snd_pcm_hw_params_any (handle
, hw_params
)) < 0) {
392 jack_error ("ALSA: no playback configurations available (%s)",
397 if ((err
= snd_pcm_hw_params_set_periods_integer (handle
, hw_params
))
399 jack_error ("ALSA: cannot restrict period size to integral"
404 if ((err
= snd_pcm_hw_params_set_access (handle
, hw_params
, SND_PCM_ACCESS_MMAP_NONINTERLEAVED
)) < 0) {
405 if ((err
= snd_pcm_hw_params_set_access (handle
, hw_params
, SND_PCM_ACCESS_MMAP_INTERLEAVED
)) < 0) {
406 if ((err
= snd_pcm_hw_params_set_access (
408 SND_PCM_ACCESS_MMAP_COMPLEX
)) < 0) {
409 jack_error ("ALSA: mmap-based access is not possible"
411 "stream of this audio interface",
418 format
= (sample_width
== 4) ? 0 : NUMFORMATS
- 1;
421 if ((err
= snd_pcm_hw_params_set_format (
422 handle
, hw_params
, formats
[format
].format
)) < 0) {
424 if ((sample_width
== 4
425 ? format
++ >= NUMFORMATS
- 1
427 jack_error ("Sorry. The audio interface \"%s\""
428 " doesn't support any of the"
429 " hardware sample formats that"
430 " JACK's alsa-driver can use.",
435 if (formats
[format
].swapped
) {
436 driver
->quirk_bswap
= 1;
438 driver
->quirk_bswap
= 0;
440 jack_error ("ALSA: final selected sample format for %s: %s", stream_name
, formats
[format
].Name
);
445 frame_rate
= driver
->frame_rate
;
446 err
= snd_pcm_hw_params_set_rate_near (handle
, hw_params
,
448 driver
->frame_rate
= frame_rate
;
450 jack_error ("ALSA: cannot set sample/frame rate to %"
451 PRIu32
" for %s", driver
->frame_rate
,
456 /*if not user-specified, try to find the maximum
457 * number of channels */
458 unsigned int channels_max
;
459 err
= snd_pcm_hw_params_get_channels_max (hw_params
,
461 *nchns
= channels_max
;
465 /* the hapless user is an unwitting victim of
466 the "default" ALSA PCM device, which can
467 support up to 16 million channels. since
468 they can't be bothered to set up a proper
469 default device, limit the number of
470 channels for them to a sane default.
474 "You appear to be using the ALSA software \"plug\" layer, probably\n"
475 "a result of using the \"default\" ALSA device. This is less\n"
476 "efficient than it could be. Consider using a hardware device\n"
477 "instead rather than using the plug layer. Usually the name of the\n"
478 "hardware device that corresponds to the first sound card is hw:0\n"
484 if ((err
= snd_pcm_hw_params_set_channels (handle
, hw_params
,
486 jack_error ("ALSA: cannot set channel count to %u for %s",
487 *nchns
, stream_name
);
491 if ((err
= snd_pcm_hw_params_set_period_size (handle
, hw_params
,
492 driver
->frames_per_cycle
,
495 jack_error ("ALSA: cannot set period size to %" PRIu32
496 " frames for %s", driver
->frames_per_cycle
,
501 *nperiodsp
= driver
->user_nperiods
;
502 snd_pcm_hw_params_set_periods_min (handle
, hw_params
, nperiodsp
, NULL
);
503 if (*nperiodsp
< driver
->user_nperiods
)
504 *nperiodsp
= driver
->user_nperiods
;
505 if (snd_pcm_hw_params_set_periods_near (handle
, hw_params
,
506 nperiodsp
, NULL
) < 0) {
507 jack_error ("ALSA: cannot set number of periods to %u for %s",
508 *nperiodsp
, stream_name
);
512 if (*nperiodsp
< driver
->user_nperiods
) {
513 jack_error ("ALSA: got smaller periods %u than %u for %s",
514 *nperiodsp
, (unsigned int) driver
->user_nperiods
,
518 jack_error ("ALSA: use %d periods for %s", *nperiodsp
, stream_name
);
520 if (!jack_power_of_two(driver
->frames_per_cycle
)) {
521 jack_error("JACK: frames must be a power of two "
522 "(64, 512, 1024, ...)\n");
526 if ((err
= snd_pcm_hw_params_set_buffer_size (handle
, hw_params
,
528 driver
->frames_per_cycle
))
530 jack_error ("ALSA: cannot set buffer length to %" PRIu32
532 *nperiodsp
* driver
->frames_per_cycle
,
537 if ((err
= snd_pcm_hw_params (handle
, hw_params
)) < 0) {
538 jack_error ("ALSA: cannot set hardware parameters for %s",
543 snd_pcm_sw_params_current (handle
, sw_params
);
545 if ((err
= snd_pcm_sw_params_set_start_threshold (handle
, sw_params
,
547 jack_error ("ALSA: cannot set start mode for %s", stream_name
);
551 stop_th
= *nperiodsp
* driver
->frames_per_cycle
;
552 if (driver
->soft_mode
) {
553 stop_th
= (snd_pcm_uframes_t
)-1;
556 if ((err
= snd_pcm_sw_params_set_stop_threshold (
557 handle
, sw_params
, stop_th
)) < 0) {
558 jack_error ("ALSA: cannot set stop mode for %s",
563 if ((err
= snd_pcm_sw_params_set_silence_threshold (
564 handle
, sw_params
, 0)) < 0) {
565 jack_error ("ALSA: cannot set silence threshold for %s",
571 fprintf (stderr
, "set silence size to %lu * %lu = %lu\n",
572 driver
->frames_per_cycle
, *nperiodsp
,
573 driver
->frames_per_cycle
* *nperiodsp
);
575 if ((err
= snd_pcm_sw_params_set_silence_size (
577 driver
->frames_per_cycle
* *nperiodsp
)) < 0) {
578 jack_error ("ALSA: cannot set silence size for %s",
584 if (handle
== driver
->playback_handle
)
585 err
= snd_pcm_sw_params_set_avail_min (
587 driver
->frames_per_cycle
588 * (*nperiodsp
- driver
->user_nperiods
+ 1));
590 err
= snd_pcm_sw_params_set_avail_min (
591 handle
, sw_params
, driver
->frames_per_cycle
);
594 jack_error ("ALSA: cannot set avail min for %s", stream_name
);
598 if ((err
= snd_pcm_sw_params (handle
, sw_params
)) < 0) {
599 jack_error ("ALSA: cannot set software parameters for %s\n",
608 alsa_driver_set_parameters (alsa_driver_t
*driver
,
609 jack_nframes_t frames_per_cycle
,
610 jack_nframes_t user_nperiods
,
614 snd_pcm_uframes_t p_period_size
= 0;
615 snd_pcm_uframes_t c_period_size
= 0;
621 driver
->frame_rate
= rate
;
622 driver
->frames_per_cycle
= frames_per_cycle
;
623 driver
->user_nperiods
= user_nperiods
;
625 fprintf (stderr
, "configuring for %" PRIu32
"Hz, period = %"
626 PRIu32
" frames, buffer = %" PRIu32
" periods\n",
627 rate
, frames_per_cycle
, user_nperiods
);
629 if (driver
->capture_handle
) {
630 if (alsa_driver_configure_stream (
632 driver
->alsa_name_capture
,
634 driver
->capture_handle
,
635 driver
->capture_hw_params
,
636 driver
->capture_sw_params
,
637 &driver
->capture_nperiods
,
638 &driver
->capture_nchannels
,
639 driver
->capture_sample_bytes
)) {
640 jack_error ("ALSA: cannot configure capture channel");
645 if (driver
->playback_handle
) {
646 if (alsa_driver_configure_stream (
648 driver
->alsa_name_playback
,
650 driver
->playback_handle
,
651 driver
->playback_hw_params
,
652 driver
->playback_sw_params
,
653 &driver
->playback_nperiods
,
654 &driver
->playback_nchannels
,
655 driver
->playback_sample_bytes
)) {
656 jack_error ("ALSA: cannot configure playback channel");
661 /* check the rate, since thats rather important */
663 if (driver
->playback_handle
) {
664 snd_pcm_hw_params_get_rate (driver
->playback_hw_params
,
668 if (driver
->capture_handle
) {
669 snd_pcm_hw_params_get_rate (driver
->capture_hw_params
,
673 if (driver
->capture_handle
&& driver
->playback_handle
) {
675 jack_error ("playback and capture sample rates do "
676 "not match (%d vs. %d)", pr
, cr
);
679 /* only change if *both* capture and playback rates
680 * don't match requested certain hardware actually
681 * still works properly in full-duplex with slightly
682 * different rate values between adc and dac
684 if (cr
!= driver
->frame_rate
&& pr
!= driver
->frame_rate
) {
685 jack_error ("sample rate in use (%d Hz) does not "
686 "match requested rate (%d Hz)",
687 cr
, driver
->frame_rate
);
688 driver
->frame_rate
= cr
;
692 else if (driver
->capture_handle
&& cr
!= driver
->frame_rate
) {
693 jack_error ("capture sample rate in use (%d Hz) does not "
694 "match requested rate (%d Hz)",
695 cr
, driver
->frame_rate
);
696 driver
->frame_rate
= cr
;
698 else if (driver
->playback_handle
&& pr
!= driver
->frame_rate
) {
699 jack_error ("playback sample rate in use (%d Hz) does not "
700 "match requested rate (%d Hz)",
701 pr
, driver
->frame_rate
);
702 driver
->frame_rate
= pr
;
706 /* check the fragment size, since thats non-negotiable */
708 if (driver
->playback_handle
) {
709 snd_pcm_access_t access
;
711 err
= snd_pcm_hw_params_get_period_size (
712 driver
->playback_hw_params
, &p_period_size
, &dir
);
713 err
= snd_pcm_hw_params_get_format (
714 driver
->playback_hw_params
,
715 &(driver
->playback_sample_format
));
716 err
= snd_pcm_hw_params_get_access (driver
->playback_hw_params
,
718 driver
->playback_interleaved
=
719 (access
== SND_PCM_ACCESS_MMAP_INTERLEAVED
)
720 || (access
== SND_PCM_ACCESS_MMAP_COMPLEX
);
722 if (p_period_size
!= driver
->frames_per_cycle
) {
723 jack_error ("alsa_pcm: requested an interrupt every %"
725 " frames but got %u frames for playback",
726 driver
->frames_per_cycle
, p_period_size
);
731 if (driver
->capture_handle
) {
732 snd_pcm_access_t access
;
734 err
= snd_pcm_hw_params_get_period_size (
735 driver
->capture_hw_params
, &c_period_size
, &dir
);
736 err
= snd_pcm_hw_params_get_format (
737 driver
->capture_hw_params
,
738 &(driver
->capture_sample_format
));
739 err
= snd_pcm_hw_params_get_access (driver
->capture_hw_params
,
741 driver
->capture_interleaved
=
742 (access
== SND_PCM_ACCESS_MMAP_INTERLEAVED
)
743 || (access
== SND_PCM_ACCESS_MMAP_COMPLEX
);
745 if (c_period_size
!= driver
->frames_per_cycle
) {
746 jack_error ("alsa_pcm: requested an interrupt every %"
748 " frames but got %uc frames for capture",
749 driver
->frames_per_cycle
, p_period_size
);
754 driver
->playback_sample_bytes
=
755 snd_pcm_format_physical_width (driver
->playback_sample_format
)
757 driver
->capture_sample_bytes
=
758 snd_pcm_format_physical_width (driver
->capture_sample_format
)
761 if (driver
->playback_handle
) {
762 switch (driver
->playback_sample_format
) {
763 case SND_PCM_FORMAT_S32_LE
:
764 case SND_PCM_FORMAT_S24_3LE
:
765 case SND_PCM_FORMAT_S24_3BE
:
766 case SND_PCM_FORMAT_S16_LE
:
767 case SND_PCM_FORMAT_S32_BE
:
768 case SND_PCM_FORMAT_S16_BE
:
772 jack_error ("programming error: unhandled format "
773 "type for playback");
778 if (driver
->capture_handle
) {
779 switch (driver
->capture_sample_format
) {
780 case SND_PCM_FORMAT_S32_LE
:
781 case SND_PCM_FORMAT_S24_3LE
:
782 case SND_PCM_FORMAT_S24_3BE
:
783 case SND_PCM_FORMAT_S16_LE
:
784 case SND_PCM_FORMAT_S32_BE
:
785 case SND_PCM_FORMAT_S16_BE
:
789 jack_error ("programming error: unhandled format "
795 if (driver
->playback_interleaved
) {
796 const snd_pcm_channel_area_t
*my_areas
;
797 snd_pcm_uframes_t offset
, frames
;
798 if (snd_pcm_mmap_begin(driver
->playback_handle
,
799 &my_areas
, &offset
, &frames
) < 0) {
800 jack_error ("ALSA: %s: mmap areas info error",
801 driver
->alsa_name_playback
);
804 driver
->interleave_unit
=
805 snd_pcm_format_physical_width (
806 driver
->playback_sample_format
) / 8;
808 driver
->interleave_unit
= 0; /* NOT USED */
811 if (driver
->capture_interleaved
) {
812 const snd_pcm_channel_area_t
*my_areas
;
813 snd_pcm_uframes_t offset
, frames
;
814 if (snd_pcm_mmap_begin(driver
->capture_handle
,
815 &my_areas
, &offset
, &frames
) < 0) {
816 jack_error ("ALSA: %s: mmap areas info error",
817 driver
->alsa_name_capture
);
822 if (driver
->playback_nchannels
> driver
->capture_nchannels
) {
823 driver
->max_nchannels
= driver
->playback_nchannels
;
824 driver
->user_nchannels
= driver
->capture_nchannels
;
826 driver
->max_nchannels
= driver
->capture_nchannels
;
827 driver
->user_nchannels
= driver
->playback_nchannels
;
830 alsa_driver_setup_io_function_pointers (driver
);
832 /* Allocate and initialize structures that rely on the
835 Set up the bit pattern that is used to record which
836 channels require action on every cycle. any bits that are
837 not set after the engine's process() call indicate channels
838 that potentially need to be silenced.
841 bitset_create (&driver
->channels_done
, driver
->max_nchannels
);
842 bitset_create (&driver
->channels_not_done
, driver
->max_nchannels
);
844 if (driver
->playback_handle
) {
845 driver
->playback_addr
= (char **)
846 malloc (sizeof (char *) * driver
->playback_nchannels
);
847 memset (driver
->playback_addr
, 0,
848 sizeof (char *) * driver
->playback_nchannels
);
849 driver
->playback_interleave_skip
= (unsigned long *)
850 malloc (sizeof (unsigned long *) * driver
->playback_nchannels
);
851 memset (driver
->playback_interleave_skip
, 0,
852 sizeof (unsigned long *) * driver
->playback_nchannels
);
853 driver
->silent
= (unsigned long *)
854 malloc (sizeof (unsigned long)
855 * driver
->playback_nchannels
);
857 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
858 driver
->silent
[chn
] = 0;
861 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
862 bitset_add (driver
->channels_done
, chn
);
865 driver
->dither_state
= (dither_state_t
*)
866 calloc ( driver
->playback_nchannels
,
867 sizeof (dither_state_t
));
870 if (driver
->capture_handle
) {
871 driver
->capture_addr
= (char **)
872 malloc (sizeof (char *) * driver
->capture_nchannels
);
873 memset (driver
->capture_addr
, 0,
874 sizeof (char *) * driver
->capture_nchannels
);
875 driver
->capture_interleave_skip
= (unsigned long *)
876 malloc (sizeof (unsigned long *) * driver
->capture_nchannels
);
877 memset (driver
->capture_interleave_skip
, 0,
878 sizeof (unsigned long *) * driver
->capture_nchannels
);
881 driver
->clock_sync_data
= (ClockSyncStatus
*)
882 malloc (sizeof (ClockSyncStatus
) * driver
->max_nchannels
);
884 driver
->period_usecs
=
885 (jack_time_t
) floor ((((float) driver
->frames_per_cycle
) /
886 driver
->frame_rate
) * 1000000.0f
);
887 driver
->poll_timeout
= (int) floor (1.5f
* driver
->period_usecs
);
889 if (driver
->engine
) {
890 driver
->engine
->set_buffer_size (driver
->engine
,
891 driver
->frames_per_cycle
);
898 alsa_driver_reset_parameters (alsa_driver_t
*driver
,
899 jack_nframes_t frames_per_cycle
,
900 jack_nframes_t user_nperiods
,
903 /* XXX unregister old ports ? */
904 alsa_driver_release_channel_dependent_memory (driver
);
905 return alsa_driver_set_parameters (driver
,
907 user_nperiods
, rate
);
911 alsa_driver_get_channel_addresses (alsa_driver_t
*driver
,
912 snd_pcm_uframes_t
*capture_avail
,
913 snd_pcm_uframes_t
*playback_avail
,
914 snd_pcm_uframes_t
*capture_offset
,
915 snd_pcm_uframes_t
*playback_offset
)
921 if ((err
= snd_pcm_mmap_begin (
922 driver
->capture_handle
, &driver
->capture_areas
,
923 (snd_pcm_uframes_t
*) capture_offset
,
924 (snd_pcm_uframes_t
*) capture_avail
)) < 0) {
925 jack_error ("ALSA: %s: mmap areas info error",
926 driver
->alsa_name_capture
);
930 for (chn
= 0; chn
< driver
->capture_nchannels
; chn
++) {
931 const snd_pcm_channel_area_t
*a
=
932 &driver
->capture_areas
[chn
];
933 driver
->capture_addr
[chn
] = (char *) a
->addr
934 + ((a
->first
+ a
->step
* *capture_offset
) / 8);
935 driver
->capture_interleave_skip
[chn
] = (unsigned long ) (a
->step
/ 8);
939 if (playback_avail
) {
940 if ((err
= snd_pcm_mmap_begin (
941 driver
->playback_handle
, &driver
->playback_areas
,
942 (snd_pcm_uframes_t
*) playback_offset
,
943 (snd_pcm_uframes_t
*) playback_avail
)) < 0) {
944 jack_error ("ALSA: %s: mmap areas info error ",
945 driver
->alsa_name_playback
);
949 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
950 const snd_pcm_channel_area_t
*a
=
951 &driver
->playback_areas
[chn
];
952 driver
->playback_addr
[chn
] = (char *) a
->addr
953 + ((a
->first
+ a
->step
* *playback_offset
) / 8);
954 driver
->playback_interleave_skip
[chn
] = (unsigned long ) (a
->step
/ 8);
962 alsa_driver_start (alsa_driver_t
*driver
)
965 snd_pcm_uframes_t poffset
, pavail
;
968 driver
->poll_last
= 0;
969 driver
->poll_next
= 0;
971 if (driver
->playback_handle
) {
972 if ((err
= snd_pcm_prepare (driver
->playback_handle
)) < 0) {
973 jack_error ("ALSA: prepare error for playback on "
974 "\"%s\" (%s)", driver
->alsa_name_playback
,
980 if ((driver
->capture_handle
&& driver
->capture_and_playback_not_synced
)
981 || !driver
->playback_handle
) {
982 if ((err
= snd_pcm_prepare (driver
->capture_handle
)) < 0) {
983 jack_error ("ALSA: prepare error for capture on \"%s\""
984 " (%s)", driver
->alsa_name_capture
,
990 if (driver
->hw_monitoring
) {
991 if (driver
->input_monitor_mask
|| driver
->all_monitor_in
) {
992 if (driver
->all_monitor_in
) {
993 driver
->hw
->set_input_monitor_mask (driver
->hw
, ~0U);
995 driver
->hw
->set_input_monitor_mask (
996 driver
->hw
, driver
->input_monitor_mask
);
999 driver
->hw
->set_input_monitor_mask (driver
->hw
,
1000 driver
->input_monitor_mask
);
1004 if (driver
->playback_handle
) {
1005 driver
->playback_nfds
=
1006 snd_pcm_poll_descriptors_count (driver
->playback_handle
);
1008 driver
->playback_nfds
= 0;
1011 if (driver
->capture_handle
) {
1012 driver
->capture_nfds
=
1013 snd_pcm_poll_descriptors_count (driver
->capture_handle
);
1015 driver
->capture_nfds
= 0;
1022 driver
->pfd
= (struct pollfd
*)
1023 malloc (sizeof (struct pollfd
) *
1024 (driver
->playback_nfds
+ driver
->capture_nfds
+ 2));
1026 if (driver
->playback_handle
) {
1027 /* fill playback buffer with zeroes, and mark
1028 all fragments as having data.
1031 pavail
= snd_pcm_avail_update (driver
->playback_handle
);
1034 driver
->frames_per_cycle
* driver
->playback_nperiods
) {
1035 jack_error ("ALSA: full buffer not available at start");
1039 if (alsa_driver_get_channel_addresses (driver
,
1040 0, &pavail
, 0, &poffset
)) {
1044 /* XXX this is cheating. ALSA offers no guarantee that
1045 we can access the entire buffer at any one time. It
1046 works on most hardware tested so far, however, buts
1047 its a liability in the long run. I think that
1048 alsa-lib may have a better function for doing this
1049 here, where the goal is to silence the entire
1053 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
1054 alsa_driver_silence_on_channel (
1056 driver
->user_nperiods
1057 * driver
->frames_per_cycle
);
1060 snd_pcm_mmap_commit (driver
->playback_handle
, poffset
,
1061 driver
->user_nperiods
1062 * driver
->frames_per_cycle
);
1064 if ((err
= snd_pcm_start (driver
->playback_handle
)) < 0) {
1065 jack_error ("ALSA: could not start playback (%s)",
1066 snd_strerror (err
));
1071 if ((driver
->capture_handle
&& driver
->capture_and_playback_not_synced
)
1072 || !driver
->playback_handle
) {
1073 if ((err
= snd_pcm_start (driver
->capture_handle
)) < 0) {
1074 jack_error ("ALSA: could not start capture (%s)",
1075 snd_strerror (err
));
1084 alsa_driver_stop (alsa_driver_t
*driver
)
1090 /* silence all capture port buffers, because we might
1091 be entering offline mode.
1094 for (chn
= 0, node
= driver
->capture_ports
; node
;
1095 node
= jack_slist_next (node
), chn
++) {
1099 jack_nframes_t nframes
= driver
->engine
->control
->buffer_size
;
1101 port
= (jack_port_t
*) node
->data
;
1102 buf
= jack_port_get_buffer (port
, nframes
);
1103 memset (buf
, 0, sizeof (jack_default_audio_sample_t
) * nframes
);
1106 if (driver
->playback_handle
) {
1107 if ((err
= snd_pcm_drop (driver
->playback_handle
)) < 0) {
1108 jack_error ("ALSA: channel flush for playback "
1109 "failed (%s)", snd_strerror (err
));
1114 if (!driver
->playback_handle
1115 || driver
->capture_and_playback_not_synced
) {
1116 if (driver
->capture_handle
) {
1117 if ((err
= snd_pcm_drop (driver
->capture_handle
)) < 0) {
1118 jack_error ("ALSA: channel flush for "
1119 "capture failed (%s)",
1120 snd_strerror (err
));
1126 if (driver
->hw_monitoring
) {
1127 driver
->hw
->set_input_monitor_mask (driver
->hw
, 0);
1134 alsa_driver_restart (alsa_driver_t
*driver
)
1136 if (driver
->nt_stop((struct _jack_driver_nt
*) driver
))
1138 return driver
->nt_start((struct _jack_driver_nt
*) driver
);
1142 alsa_driver_xrun_recovery (alsa_driver_t
*driver
, float *delayed_usecs
)
1144 snd_pcm_status_t
*status
;
1147 snd_pcm_status_alloca(&status
);
1149 if (driver
->capture_handle
) {
1150 if ((res
= snd_pcm_status(driver
->capture_handle
, status
))
1152 jack_error("status error: %s", snd_strerror(res
));
1155 if ((res
= snd_pcm_status(driver
->playback_handle
, status
))
1157 jack_error("status error: %s", snd_strerror(res
));
1161 if (snd_pcm_status_get_state(status
) == SND_PCM_STATE_XRUN
1162 && driver
->process_count
> XRUN_REPORT_DELAY
) {
1163 struct timeval now
, diff
, tstamp
;
1164 driver
->xrun_count
++;
1165 gettimeofday(&now
, 0);
1166 snd_pcm_status_get_trigger_tstamp(status
, &tstamp
);
1167 timersub(&now
, &tstamp
, &diff
);
1168 *delayed_usecs
= diff
.tv_sec
* 1000000.0 + diff
.tv_usec
;
1169 MESSAGE("\n\n**** alsa_pcm: xrun of at least %.3f "
1171 *delayed_usecs
/ 1000.0);
1174 if (alsa_driver_restart (driver
)) {
1181 alsa_driver_silence_untouched_channels (alsa_driver_t
*driver
,
1182 jack_nframes_t nframes
)
1185 jack_nframes_t buffer_frames
=
1186 driver
->frames_per_cycle
* driver
->playback_nperiods
;
1188 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
1189 if (bitset_contains (driver
->channels_not_done
, chn
)) {
1190 if (driver
->silent
[chn
] < buffer_frames
) {
1191 alsa_driver_silence_on_channel_no_mark (
1192 driver
, chn
, nframes
);
1193 driver
->silent
[chn
] += nframes
;
1200 alsa_driver_set_clock_sync_status (alsa_driver_t
*driver
, channel_t chn
,
1201 ClockSyncStatus status
)
1203 driver
->clock_sync_data
[chn
] = status
;
1204 alsa_driver_clock_sync_notify (driver
, chn
, status
);
1207 static int under_gdb
= FALSE
;
1209 static jack_nframes_t
1210 alsa_driver_wait (alsa_driver_t
*driver
, int extra_fd
, int *status
, float
1213 snd_pcm_sframes_t avail
= 0;
1214 snd_pcm_sframes_t capture_avail
= 0;
1215 snd_pcm_sframes_t playback_avail
= 0;
1216 int xrun_detected
= FALSE
;
1220 jack_time_t poll_enter
;
1221 jack_time_t poll_ret
= 0;
1226 need_capture
= driver
->capture_handle
? 1 : 0;
1228 if (extra_fd
>= 0) {
1231 need_playback
= driver
->playback_handle
? 1 : 0;
1236 while (need_playback
|| need_capture
) {
1238 unsigned int p_timed_out
, c_timed_out
;
1239 unsigned int ci
= 0;
1244 if (need_playback
) {
1245 snd_pcm_poll_descriptors (driver
->playback_handle
,
1247 driver
->playback_nfds
);
1248 nfds
+= driver
->playback_nfds
;
1252 snd_pcm_poll_descriptors (driver
->capture_handle
,
1254 driver
->capture_nfds
);
1256 nfds
+= driver
->capture_nfds
;
1259 /* ALSA doesn't set POLLERR in some versions of 0.9.X */
1261 for (i
= 0; i
< nfds
; i
++) {
1262 driver
->pfd
[i
].events
|= POLLERR
;
1265 if (extra_fd
>= 0) {
1266 driver
->pfd
[nfds
].fd
= extra_fd
;
1267 driver
->pfd
[nfds
].events
=
1268 POLLIN
|POLLERR
|POLLHUP
|POLLNVAL
;
1272 poll_enter
= jack_get_microseconds ();
1274 if (poll_enter
> driver
->poll_next
) {
1276 * This processing cycle was delayed past the
1277 * next due interrupt! Do not account this as
1280 driver
->poll_next
= 0;
1281 driver
->poll_late
++;
1284 if (poll (driver
->pfd
, nfds
, driver
->poll_timeout
) < 0) {
1286 if (errno
== EINTR
) {
1287 printf ("poll interrupt\n");
1288 // this happens mostly when run
1289 // under gdb, or when exiting due to a signal
1297 jack_error ("ALSA: poll call failed (%s)",
1304 poll_ret
= jack_get_microseconds ();
1307 if (driver
->poll_next
&& poll_ret
> driver
->poll_next
) {
1308 *delayed_usecs
= poll_ret
- driver
->poll_next
;
1310 driver
->poll_last
= poll_ret
;
1311 driver
->poll_next
= poll_ret
+ driver
->period_usecs
;
1312 driver
->engine
->transport_cycle_start (driver
->engine
,
1317 fprintf (stderr
, "%" PRIu64
": checked %d fds, %" PRIu64
1318 " usecs since poll entered\n", poll_ret
, nfds
,
1319 poll_ret
- poll_enter
);
1322 /* check to see if it was the extra FD that caused us
1323 * to return from poll */
1325 if (extra_fd
>= 0) {
1327 if (driver
->pfd
[nfds
-1].revents
== 0) {
1328 /* we timed out on the extra fd */
1334 /* if POLLIN was the only bit set, we're OK */
1337 return (driver
->pfd
[nfds
-1].revents
== POLLIN
) ? 0 : -1;
1342 if (need_playback
) {
1343 for (i
= 0; i
< driver
->playback_nfds
; i
++) {
1344 if (driver
->pfd
[i
].revents
& POLLERR
) {
1345 xrun_detected
= TRUE
;
1348 if (driver
->pfd
[i
].revents
== 0) {
1351 fprintf (stderr
, "%" PRIu64
1352 " playback stream timed out\n",
1358 if (p_timed_out
== 0) {
1361 fprintf (stderr
, "%" PRIu64
1362 " playback stream ready\n",
1371 for (i
= ci
; i
< nfds
; i
++) {
1372 if (driver
->pfd
[i
].revents
& POLLERR
) {
1373 xrun_detected
= TRUE
;
1376 if (driver
->pfd
[i
].revents
== 0) {
1379 fprintf (stderr
, "%" PRIu64
1380 " capture stream timed out\n",
1386 if (c_timed_out
== 0) {
1389 fprintf (stderr
, "%" PRIu64
1390 " capture stream ready\n",
1396 if ((p_timed_out
&& (p_timed_out
== driver
->playback_nfds
)) &&
1397 (c_timed_out
&& (c_timed_out
== driver
->capture_nfds
))){
1398 jack_error ("ALSA: poll time out, polled for %" PRIu64
1400 poll_ret
- poll_enter
);
1407 if (driver
->capture_handle
) {
1408 if ((capture_avail
= snd_pcm_avail_update (
1409 driver
->capture_handle
)) < 0) {
1410 if (capture_avail
== -EPIPE
) {
1411 xrun_detected
= TRUE
;
1413 jack_error ("unknown ALSA avail_update return"
1414 " value (%u)", capture_avail
);
1418 /* odd, but see min() computation below */
1419 capture_avail
= INT_MAX
;
1422 if (driver
->playback_handle
) {
1423 if ((playback_avail
= snd_pcm_avail_update (
1424 driver
->playback_handle
)) < 0) {
1425 if (playback_avail
== -EPIPE
) {
1426 xrun_detected
= TRUE
;
1428 jack_error ("unknown ALSA avail_update return"
1429 " value (%u)", playback_avail
);
1433 /* odd, but see min() computation below */
1434 playback_avail
= INT_MAX
;
1437 if (xrun_detected
) {
1438 *status
= alsa_driver_xrun_recovery (driver
, delayed_usecs
);
1443 driver
->last_wait_ust
= poll_ret
;
1445 avail
= capture_avail
< playback_avail
? capture_avail
: playback_avail
;
1448 fprintf (stderr
, "wakeup complete, avail = %lu, pavail = %lu "
1450 avail
, playback_avail
, capture_avail
);
1453 /* mark all channels not done for now. read/write will change this */
1455 bitset_copy (driver
->channels_not_done
, driver
->channels_done
);
1457 /* constrain the available count to the nearest (round down) number of
1461 return avail
- (avail
% driver
->frames_per_cycle
);
1465 alsa_driver_null_cycle (alsa_driver_t
* driver
, jack_nframes_t nframes
)
1468 snd_pcm_uframes_t offset
;
1469 snd_pcm_uframes_t contiguous
;
1472 if (nframes
> driver
->frames_per_cycle
) {
1476 if (driver
->capture_handle
) {
1482 if (snd_pcm_mmap_begin (
1483 driver
->capture_handle
,
1484 &driver
->capture_areas
,
1485 (snd_pcm_uframes_t
*) &offset
,
1486 (snd_pcm_uframes_t
*) &contiguous
)) {
1490 if (snd_pcm_mmap_commit (driver
->capture_handle
,
1491 offset
, contiguous
) < 0) {
1499 if (driver
->playback_handle
) {
1505 if (snd_pcm_mmap_begin (
1506 driver
->playback_handle
,
1507 &driver
->playback_areas
,
1508 (snd_pcm_uframes_t
*) &offset
,
1509 (snd_pcm_uframes_t
*) &contiguous
)) {
1513 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
1514 alsa_driver_silence_on_channel (driver
, chn
,
1518 if (snd_pcm_mmap_commit (driver
->playback_handle
,
1519 offset
, contiguous
) < 0) {
1531 alsa_driver_bufsize (alsa_driver_t
* driver
, jack_nframes_t nframes
)
1533 return alsa_driver_reset_parameters (driver
, nframes
,
1534 driver
->user_nperiods
,
1535 driver
->frame_rate
);
1539 alsa_driver_read (alsa_driver_t
*driver
, jack_nframes_t nframes
)
1541 snd_pcm_sframes_t contiguous
;
1542 snd_pcm_sframes_t nread
;
1543 snd_pcm_uframes_t offset
;
1544 jack_nframes_t orig_nframes
;
1545 jack_default_audio_sample_t
* buf
;
1551 if (!driver
->capture_handle
|| driver
->engine
->freewheeling
) {
1554 if (nframes
> driver
->frames_per_cycle
) {
1560 orig_nframes
= nframes
;
1564 contiguous
= nframes
;
1566 if (alsa_driver_get_channel_addresses (
1568 (snd_pcm_uframes_t
*) &contiguous
,
1569 (snd_pcm_uframes_t
*) 0,
1574 for (chn
= 0, node
= driver
->capture_ports
; node
;
1575 node
= jack_slist_next (node
), chn
++) {
1577 port
= (jack_port_t
*) node
->data
;
1579 if (!jack_port_connected (port
)) {
1580 /* no-copy optimization */
1583 buf
= jack_port_get_buffer (port
, orig_nframes
);
1584 alsa_driver_read_from_channel (driver
, chn
,
1585 buf
+ nread
, contiguous
);
1588 if ((err
= snd_pcm_mmap_commit (driver
->capture_handle
,
1589 offset
, contiguous
)) < 0) {
1590 jack_error ("ALSA: could not complete read of %"
1591 PRIu32
" frames: error = %d\n", contiguous
, err
);
1595 nframes
-= contiguous
;
1596 nread
+= contiguous
;
1603 alsa_driver_write (alsa_driver_t
* driver
, jack_nframes_t nframes
)
1608 jack_default_audio_sample_t
* buf
;
1609 jack_default_audio_sample_t
* monbuf
;
1610 jack_nframes_t orig_nframes
;
1611 snd_pcm_sframes_t nwritten
;
1612 snd_pcm_sframes_t contiguous
;
1613 snd_pcm_uframes_t offset
;
1617 driver
->process_count
++;
1619 if (!driver
->playback_handle
|| driver
->engine
->freewheeling
) {
1622 if (nframes
> driver
->frames_per_cycle
) {
1628 orig_nframes
= nframes
;
1630 /* check current input monitor request status */
1632 driver
->input_monitor_mask
= 0;
1634 for (chn
= 0, node
= driver
->capture_ports
; node
;
1635 node
= jack_slist_next (node
), chn
++) {
1636 if (((jack_port_t
*) node
->data
)->shared
->monitor_requests
) {
1637 driver
->input_monitor_mask
|= (1<<chn
);
1641 if (driver
->hw_monitoring
) {
1642 if ((driver
->hw
->input_monitor_mask
1643 != driver
->input_monitor_mask
)
1644 && !driver
->all_monitor_in
) {
1645 driver
->hw
->set_input_monitor_mask (
1646 driver
->hw
, driver
->input_monitor_mask
);
1652 contiguous
= nframes
;
1654 if (alsa_driver_get_channel_addresses (
1656 (snd_pcm_uframes_t
*) 0,
1657 (snd_pcm_uframes_t
*) &contiguous
,
1662 for (chn
= 0, node
= driver
->playback_ports
, mon_node
=driver
->monitor_ports
;
1664 node
= jack_slist_next (node
), chn
++) {
1666 port
= (jack_port_t
*) node
->data
;
1668 if (!jack_port_connected (port
)) {
1671 buf
= jack_port_get_buffer (port
, orig_nframes
);
1672 alsa_driver_write_to_channel (driver
, chn
,
1673 buf
+ nwritten
, contiguous
);
1676 port
= (jack_port_t
*) mon_node
->data
;
1677 if (!jack_port_connected (port
)) {
1680 monbuf
= jack_port_get_buffer (port
, orig_nframes
);
1681 memcpy (monbuf
+ nwritten
, buf
+ nwritten
, contiguous
* sizeof(jack_default_audio_sample_t
));
1682 mon_node
= jack_slist_next (mon_node
);
1687 if (!bitset_empty (driver
->channels_not_done
)) {
1688 alsa_driver_silence_untouched_channels (driver
,
1692 if ((err
= snd_pcm_mmap_commit (driver
->playback_handle
,
1693 offset
, contiguous
)) < 0) {
1694 jack_error ("ALSA: could not complete playback of %"
1695 PRIu32
" frames: error = %d", contiguous
, err
);
1696 if (err
!= EPIPE
&& err
!= ESTRPIPE
)
1700 nframes
-= contiguous
;
1701 nwritten
+= contiguous
;
1708 alsa_driver_run_cycle (alsa_driver_t
*driver
)
1710 jack_engine_t
*engine
= driver
->engine
;
1712 float delayed_usecs
;
1713 jack_nframes_t nframes
;
1715 DEBUG ("alsa run cycle wait\n");
1717 nframes
= alsa_driver_wait (driver
, -1, &wait_status
, &delayed_usecs
);
1719 DEBUG ("alsaback from wait, nframes = %lu", nframes
);
1721 if (unlikely(wait_status
< 0))
1722 return -1; /* driver failed */
1724 if (unlikely(nframes
== 0)) {
1726 /* we detected an xrun and restarted: notify
1727 * clients about the delay.
1729 engine
->delay (engine
, delayed_usecs
);
1733 return engine
->run_cycle (engine
, nframes
, delayed_usecs
);
1737 alsa_driver_attach (alsa_driver_t
*driver
)
1744 driver
->engine
->set_buffer_size (driver
->engine
, driver
->frames_per_cycle
);
1745 driver
->engine
->set_sample_rate (driver
->engine
, driver
->frame_rate
);
1747 port_flags
= JackPortIsOutput
|JackPortIsPhysical
|JackPortIsTerminal
;
1749 if (driver
->has_hw_monitoring
) {
1750 port_flags
|= JackPortCanMonitor
;
1753 for (chn
= 0; chn
< driver
->capture_nchannels
; chn
++) {
1755 snprintf (buf
, sizeof(buf
) - 1, "capture_%lu", chn
+1);
1757 if ((port
= jack_port_register (driver
->client
, buf
,
1758 JACK_DEFAULT_AUDIO_TYPE
,
1759 port_flags
, 0)) == NULL
) {
1760 jack_error ("ALSA: cannot register port for %s", buf
);
1764 jack_port_set_latency (port
, driver
->frames_per_cycle
+ driver
->capture_frame_latency
);
1766 driver
->capture_ports
=
1767 jack_slist_append (driver
->capture_ports
, port
);
1770 port_flags
= JackPortIsInput
|JackPortIsPhysical
|JackPortIsTerminal
;
1772 for (chn
= 0; chn
< driver
->playback_nchannels
; chn
++) {
1773 jack_port_t
*monitor_port
;
1775 snprintf (buf
, sizeof(buf
) - 1, "playback_%lu", chn
+1);
1777 if ((port
= jack_port_register (driver
->client
, buf
,
1778 JACK_DEFAULT_AUDIO_TYPE
,
1779 port_flags
, 0)) == NULL
) {
1780 jack_error ("ALSA: cannot register port for %s", buf
);
1784 jack_port_set_latency (port
, (driver
->frames_per_cycle
* (driver
->user_nperiods
- 1)) + driver
->playback_frame_latency
);
1786 driver
->playback_ports
=
1787 jack_slist_append (driver
->playback_ports
, port
);
1789 if (driver
->with_monitor_ports
) {
1790 snprintf (buf
, sizeof(buf
) - 1, "monitor_%lu", chn
+1);
1792 if ((monitor_port
= jack_port_register (
1793 driver
->client
, buf
,
1794 JACK_DEFAULT_AUDIO_TYPE
,
1795 JackPortIsOutput
, 0)) == NULL
) {
1796 jack_error ("ALSA: cannot register monitor "
1797 "port for %s", buf
);
1800 jack_port_set_latency (monitor_port
, driver
->frames_per_cycle
);
1802 driver
->monitor_ports
=
1803 jack_slist_append (driver
->monitor_ports
, monitor_port
);
1810 return jack_activate (driver
->client
);
1814 alsa_driver_detach (alsa_driver_t
*driver
)
1818 if (driver
->engine
== NULL
) {
1822 for (node
= driver
->capture_ports
; node
;
1823 node
= jack_slist_next (node
)) {
1824 jack_port_unregister (driver
->client
,
1825 ((jack_port_t
*) node
->data
));
1828 jack_slist_free (driver
->capture_ports
);
1829 driver
->capture_ports
= 0;
1831 for (node
= driver
->playback_ports
; node
;
1832 node
= jack_slist_next (node
)) {
1833 jack_port_unregister (driver
->client
,
1834 ((jack_port_t
*) node
->data
));
1837 jack_slist_free (driver
->playback_ports
);
1838 driver
->playback_ports
= 0;
1840 if (driver
->monitor_ports
) {
1841 for (node
= driver
->monitor_ports
; node
;
1842 node
= jack_slist_next (node
)) {
1843 jack_port_unregister (driver
->client
,
1844 ((jack_port_t
*) node
->data
));
1847 jack_slist_free (driver
->monitor_ports
);
1848 driver
->monitor_ports
= 0;
1855 static int /* UNUSED */
1856 alsa_driver_change_sample_clock (alsa_driver_t
*driver
, SampleClockMode mode
)
1859 return driver
->hw
->change_sample_clock (driver
->hw
, mode
);
1862 static void /* UNUSED */
1863 alsa_driver_request_all_monitor_input (alsa_driver_t
*driver
, int yn
)
1866 if (driver
->hw_monitoring
) {
1868 driver
->hw
->set_input_monitor_mask (driver
->hw
, ~0U);
1870 driver
->hw
->set_input_monitor_mask (
1871 driver
->hw
, driver
->input_monitor_mask
);
1875 driver
->all_monitor_in
= yn
;
1878 static void /* UNUSED */
1879 alsa_driver_set_hw_monitoring (alsa_driver_t
*driver
, int yn
)
1882 driver
->hw_monitoring
= TRUE
;
1884 if (driver
->all_monitor_in
) {
1885 driver
->hw
->set_input_monitor_mask (driver
->hw
, ~0U);
1887 driver
->hw
->set_input_monitor_mask (
1888 driver
->hw
, driver
->input_monitor_mask
);
1891 driver
->hw_monitoring
= FALSE
;
1892 driver
->hw
->set_input_monitor_mask (driver
->hw
, 0);
1896 static ClockSyncStatus
/* UNUSED */
1897 alsa_driver_clock_sync_status (channel_t chn
)
1904 alsa_driver_delete (alsa_driver_t
*driver
)
1908 for (node
= driver
->clock_sync_listeners
; node
;
1909 node
= jack_slist_next (node
)) {
1912 jack_slist_free (driver
->clock_sync_listeners
);
1914 if (driver
->capture_handle
) {
1915 snd_pcm_close (driver
->capture_handle
);
1916 driver
->capture_handle
= 0;
1919 if (driver
->playback_handle
) {
1920 snd_pcm_close (driver
->playback_handle
);
1921 driver
->capture_handle
= 0;
1924 if (driver
->capture_hw_params
) {
1925 snd_pcm_hw_params_free (driver
->capture_hw_params
);
1926 driver
->capture_hw_params
= 0;
1929 if (driver
->playback_hw_params
) {
1930 snd_pcm_hw_params_free (driver
->playback_hw_params
);
1931 driver
->playback_hw_params
= 0;
1934 if (driver
->capture_sw_params
) {
1935 snd_pcm_sw_params_free (driver
->capture_sw_params
);
1936 driver
->capture_sw_params
= 0;
1939 if (driver
->playback_sw_params
) {
1940 snd_pcm_sw_params_free (driver
->playback_sw_params
);
1941 driver
->playback_sw_params
= 0;
1949 driver
->hw
->release (driver
->hw
);
1952 free(driver
->alsa_name_playback
);
1953 free(driver
->alsa_name_capture
);
1954 free(driver
->alsa_driver
);
1956 alsa_driver_release_channel_dependent_memory (driver
);
1957 jack_driver_nt_finish ((jack_driver_nt_t
*) driver
);
1961 static jack_driver_t
*
1962 alsa_driver_new (char *name
, char *playback_alsa_device
,
1963 char *capture_alsa_device
,
1964 jack_client_t
*client
,
1965 jack_nframes_t frames_per_cycle
,
1966 jack_nframes_t user_nperiods
,
1967 jack_nframes_t rate
,
1972 DitherAlgorithm dither
,
1975 int user_capture_nchnls
,
1976 int user_playback_nchnls
,
1978 jack_nframes_t capture_latency
,
1979 jack_nframes_t playback_latency
1984 alsa_driver_t
*driver
;
1986 printf ("creating alsa driver ... %s|%s|%" PRIu32
"|%" PRIu32
1987 "|%" PRIu32
"|%" PRIu32
"|%" PRIu32
"|%s|%s|%s|%s\n",
1988 playing
? playback_alsa_device
: "-",
1989 capturing
? capture_alsa_device
: "-",
1990 frames_per_cycle
, user_nperiods
, rate
,
1991 user_capture_nchnls
,user_playback_nchnls
,
1992 hw_monitoring
? "hwmon": "nomon",
1993 hw_metering
? "hwmeter":"swmeter",
1994 soft_mode
? "soft-mode":"-",
1995 shorts_first
? "16bit":"32bit");
1997 driver
= (alsa_driver_t
*) calloc (1, sizeof (alsa_driver_t
));
1999 jack_driver_nt_init ((jack_driver_nt_t
*) driver
);
2001 driver
->nt_attach
= (JackDriverNTAttachFunction
) alsa_driver_attach
;
2002 driver
->nt_detach
= (JackDriverNTDetachFunction
) alsa_driver_detach
;
2003 driver
->read
= (JackDriverReadFunction
) alsa_driver_read
;
2004 driver
->write
= (JackDriverReadFunction
) alsa_driver_write
;
2005 driver
->null_cycle
=
2006 (JackDriverNullCycleFunction
) alsa_driver_null_cycle
;
2007 driver
->nt_bufsize
= (JackDriverNTBufSizeFunction
) alsa_driver_bufsize
;
2008 driver
->nt_start
= (JackDriverNTStartFunction
) alsa_driver_start
;
2009 driver
->nt_stop
= (JackDriverNTStopFunction
) alsa_driver_stop
;
2010 driver
->nt_run_cycle
= (JackDriverNTRunCycleFunction
) alsa_driver_run_cycle
;
2012 driver
->playback_handle
= NULL
;
2013 driver
->capture_handle
= NULL
;
2014 driver
->ctl_handle
= 0;
2016 driver
->capture_and_playback_not_synced
= FALSE
;
2017 driver
->max_nchannels
= 0;
2018 driver
->user_nchannels
= 0;
2019 driver
->playback_nchannels
= user_playback_nchnls
;
2020 driver
->capture_nchannels
= user_capture_nchnls
;
2021 driver
->playback_sample_bytes
= (shorts_first
? 2:4);
2022 driver
->capture_sample_bytes
= (shorts_first
? 2:4);
2023 driver
->capture_frame_latency
= capture_latency
;
2024 driver
->playback_frame_latency
= playback_latency
;
2026 driver
->playback_addr
= 0;
2027 driver
->capture_addr
= 0;
2028 driver
->playback_interleave_skip
= NULL
;
2029 driver
->capture_interleave_skip
= NULL
;
2033 driver
->all_monitor_in
= FALSE
;
2034 driver
->with_monitor_ports
= monitor
;
2036 driver
->clock_mode
= ClockMaster
; /* XXX is it? */
2037 driver
->input_monitor_mask
= 0; /* XXX is it? */
2039 driver
->capture_ports
= 0;
2040 driver
->playback_ports
= 0;
2041 driver
->monitor_ports
= 0;
2044 driver
->playback_nfds
= 0;
2045 driver
->capture_nfds
= 0;
2047 driver
->dither
= dither
;
2048 driver
->soft_mode
= soft_mode
;
2050 driver
->quirk_bswap
= 0;
2052 pthread_mutex_init (&driver
->clock_sync_lock
, 0);
2053 driver
->clock_sync_listeners
= 0;
2055 driver
->poll_late
= 0;
2056 driver
->xrun_count
= 0;
2057 driver
->process_count
= 0;
2059 driver
->alsa_name_playback
= strdup (playback_alsa_device
);
2060 driver
->alsa_name_capture
= strdup (capture_alsa_device
);
2062 if (alsa_driver_check_card_type (driver
)) {
2063 alsa_driver_delete (driver
);
2067 alsa_driver_hw_specific (driver
, hw_monitoring
, hw_metering
);
2070 if (snd_pcm_open (&driver
->playback_handle
,
2071 playback_alsa_device
,
2072 SND_PCM_STREAM_PLAYBACK
,
2073 SND_PCM_NONBLOCK
) < 0) {
2076 jack_error ("the playback device \"%s\" is "
2077 "already in use. Please stop the"
2078 " application using it and "
2080 playback_alsa_device
);
2081 alsa_driver_delete (driver
);
2086 jack_error ("you do not have permission to open "
2087 "the audio device \"%s\" for playback",
2088 playback_alsa_device
);
2089 alsa_driver_delete (driver
);
2094 driver
->playback_handle
= NULL
;
2097 if (driver
->playback_handle
) {
2098 snd_pcm_nonblock (driver
->playback_handle
, 0);
2103 if (snd_pcm_open (&driver
->capture_handle
,
2104 capture_alsa_device
,
2105 SND_PCM_STREAM_CAPTURE
,
2106 SND_PCM_NONBLOCK
) < 0) {
2109 jack_error ("the capture device \"%s\" is "
2110 "already in use. Please stop the"
2111 " application using it and "
2113 capture_alsa_device
);
2114 alsa_driver_delete (driver
);
2119 jack_error ("you do not have permission to open "
2120 "the audio device \"%s\" for capture",
2121 capture_alsa_device
);
2122 alsa_driver_delete (driver
);
2127 driver
->capture_handle
= NULL
;
2130 if (driver
->capture_handle
) {
2131 snd_pcm_nonblock (driver
->capture_handle
, 0);
2135 if (driver
->playback_handle
== NULL
) {
2138 /* they asked for playback, but we can't do it */
2140 jack_error ("ALSA: Cannot open PCM device %s for "
2141 "playback. Falling back to capture-only"
2144 if (driver
->capture_handle
== NULL
) {
2145 /* can't do anything */
2146 alsa_driver_delete (driver
);
2154 if (driver
->capture_handle
== NULL
) {
2157 /* they asked for capture, but we can't do it */
2159 jack_error ("ALSA: Cannot open PCM device %s for "
2160 "capture. Falling back to playback-only"
2163 if (driver
->playback_handle
== NULL
) {
2164 /* can't do anything */
2165 alsa_driver_delete (driver
);
2173 driver
->playback_hw_params
= 0;
2174 driver
->capture_hw_params
= 0;
2175 driver
->playback_sw_params
= 0;
2176 driver
->capture_sw_params
= 0;
2178 if (driver
->playback_handle
) {
2179 if ((err
= snd_pcm_hw_params_malloc (
2180 &driver
->playback_hw_params
)) < 0) {
2181 jack_error ("ALSA: could not allocate playback hw"
2182 " params structure");
2183 alsa_driver_delete (driver
);
2187 if ((err
= snd_pcm_sw_params_malloc (
2188 &driver
->playback_sw_params
)) < 0) {
2189 jack_error ("ALSA: could not allocate playback sw"
2190 " params structure");
2191 alsa_driver_delete (driver
);
2196 if (driver
->capture_handle
) {
2197 if ((err
= snd_pcm_hw_params_malloc (
2198 &driver
->capture_hw_params
)) < 0) {
2199 jack_error ("ALSA: could not allocate capture hw"
2200 " params structure");
2201 alsa_driver_delete (driver
);
2205 if ((err
= snd_pcm_sw_params_malloc (
2206 &driver
->capture_sw_params
)) < 0) {
2207 jack_error ("ALSA: could not allocate capture sw"
2208 " params structure");
2209 alsa_driver_delete (driver
);
2214 if (alsa_driver_set_parameters (driver
, frames_per_cycle
,
2215 user_nperiods
, rate
)) {
2216 alsa_driver_delete (driver
);
2220 driver
->capture_and_playback_not_synced
= FALSE
;
2222 if (driver
->capture_handle
&& driver
->playback_handle
) {
2223 if (snd_pcm_link (driver
->playback_handle
,
2224 driver
->capture_handle
) != 0) {
2225 driver
->capture_and_playback_not_synced
= TRUE
;
2229 driver
->client
= client
;
2231 return (jack_driver_t
*) driver
;
2235 alsa_driver_listen_for_clock_sync_status (alsa_driver_t
*driver
,
2236 ClockSyncListenerFunction func
,
2239 ClockSyncListener
*csl
;
2241 csl
= (ClockSyncListener
*) malloc (sizeof (ClockSyncListener
));
2242 csl
->function
= func
;
2244 csl
->id
= driver
->next_clock_sync_listener_id
++;
2246 pthread_mutex_lock (&driver
->clock_sync_lock
);
2247 driver
->clock_sync_listeners
=
2248 jack_slist_prepend (driver
->clock_sync_listeners
, csl
);
2249 pthread_mutex_unlock (&driver
->clock_sync_lock
);
2254 alsa_driver_stop_listening_to_clock_sync_status (alsa_driver_t
*driver
,
2260 pthread_mutex_lock (&driver
->clock_sync_lock
);
2261 for (node
= driver
->clock_sync_listeners
; node
;
2262 node
= jack_slist_next (node
)) {
2263 if (((ClockSyncListener
*) node
->data
)->id
== which
) {
2264 driver
->clock_sync_listeners
=
2265 jack_slist_remove_link (
2266 driver
->clock_sync_listeners
, node
);
2268 jack_slist_free_1 (node
);
2273 pthread_mutex_unlock (&driver
->clock_sync_lock
);
2278 alsa_driver_clock_sync_notify (alsa_driver_t
*driver
, channel_t chn
,
2279 ClockSyncStatus status
)
2283 pthread_mutex_lock (&driver
->clock_sync_lock
);
2284 for (node
= driver
->clock_sync_listeners
; node
;
2285 node
= jack_slist_next (node
)) {
2286 ClockSyncListener
*csl
= (ClockSyncListener
*) node
->data
;
2287 csl
->function (chn
, status
, csl
->arg
);
2289 pthread_mutex_unlock (&driver
->clock_sync_lock
);
2294 dither_opt (char c
, DitherAlgorithm
* dither
)
2303 *dither
= Rectangular
;
2311 *dither
= Triangular
;
2315 fprintf (stderr
, "ALSA driver: illegal dithering mode %c\n", c
);
2322 /* DRIVER "PLUGIN" INTERFACE */
2324 const char driver_client_name
[] = "alsa_pcm";
2326 const jack_driver_desc_t
*
2327 driver_get_descriptor ()
2329 jack_driver_desc_t
* desc
;
2330 jack_driver_param_desc_t
* params
;
2333 desc
= calloc (1, sizeof (jack_driver_desc_t
));
2335 strcpy (desc
->name
,"alsa");
2338 params
= calloc (desc
->nparams
, sizeof (jack_driver_param_desc_t
));
2341 strcpy (params
[i
].name
, "capture");
2342 params
[i
].character
= 'C';
2343 params
[i
].type
= JackDriverParamString
;
2344 strcpy (params
[i
].value
.str
, "none");
2345 strcpy (params
[i
].short_desc
,
2346 "Provide capture ports. Optionally set device");
2347 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2350 strcpy (params
[i
].name
, "playback");
2351 params
[i
].character
= 'P';
2352 params
[i
].type
= JackDriverParamString
;
2353 strcpy (params
[i
].value
.str
, "none");
2354 strcpy (params
[i
].short_desc
,
2355 "Provide playback ports. Optionally set device");
2356 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2359 strcpy (params
[i
].name
, "device");
2360 params
[i
].character
= 'd';
2361 params
[i
].type
= JackDriverParamString
;
2362 strcpy (params
[i
].value
.str
, "hw:0");
2363 strcpy (params
[i
].short_desc
, "ALSA device name");
2364 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2367 strcpy (params
[i
].name
, "rate");
2368 params
[i
].character
= 'r';
2369 params
[i
].type
= JackDriverParamUInt
;
2370 params
[i
].value
.ui
= 48000U;
2371 strcpy (params
[i
].short_desc
, "Sample rate");
2372 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2375 strcpy (params
[i
].name
, "period");
2376 params
[i
].character
= 'p';
2377 params
[i
].type
= JackDriverParamUInt
;
2378 params
[i
].value
.ui
= 1024U;
2379 strcpy (params
[i
].short_desc
, "Frames per period");
2380 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2383 strcpy (params
[i
].name
, "nperiods");
2384 params
[i
].character
= 'n';
2385 params
[i
].type
= JackDriverParamUInt
;
2386 params
[i
].value
.ui
= 2U;
2387 strcpy (params
[i
].short_desc
, "Number of periods of playback latency");
2388 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2391 strcpy (params
[i
].name
, "hwmon");
2392 params
[i
].character
= 'H';
2393 params
[i
].type
= JackDriverParamBool
;
2394 params
[i
].value
.i
= 0;
2395 strcpy (params
[i
].short_desc
,"Hardware monitoring, if available");
2396 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2399 strcpy (params
[i
].name
, "hwmeter");
2400 params
[i
].character
= 'M';
2401 params
[i
].type
= JackDriverParamBool
;
2402 params
[i
].value
.i
= 0;
2403 strcpy (params
[i
].short_desc
, "Hardware metering, if available");
2404 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2407 strcpy (params
[i
].name
, "duplex");
2408 params
[i
].character
= 'D';
2409 params
[i
].type
= JackDriverParamBool
;
2410 params
[i
].value
.i
= 1;
2411 strcpy (params
[i
].short_desc
,
2412 "Provide both capture and playback ports");
2413 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2416 strcpy (params
[i
].name
, "softmode");
2417 params
[i
].character
= 's';
2418 params
[i
].type
= JackDriverParamBool
;
2419 params
[i
].value
.i
= 0;
2420 strcpy (params
[i
].short_desc
, "Soft-mode, no xrun handling");
2421 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2424 strcpy (params
[i
].name
, "monitor");
2425 params
[i
].character
= 'm';
2426 params
[i
].type
= JackDriverParamBool
;
2427 params
[i
].value
.i
= 0;
2428 strcpy (params
[i
].short_desc
, "Provide monitor ports for the output");
2429 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2432 strcpy (params
[i
].name
, "dither");
2433 params
[i
].character
= 'z';
2434 params
[i
].type
= JackDriverParamChar
;
2435 params
[i
].value
.c
= 'n';
2436 strcpy (params
[i
].short_desc
, "Dithering mode");
2437 strcpy (params
[i
].long_desc
,
2440 " r - rectangular\n"
2445 strcpy (params
[i
].name
, "inchannels");
2446 params
[i
].character
= 'i';
2447 params
[i
].type
= JackDriverParamUInt
;
2448 params
[i
].value
.i
= 0;
2449 strcpy (params
[i
].short_desc
,
2450 "Number of capture channels (defaults to hardware max)");
2451 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2454 strcpy (params
[i
].name
, "outchannels");
2455 params
[i
].character
= 'o';
2456 params
[i
].type
= JackDriverParamUInt
;
2457 params
[i
].value
.i
= 0;
2458 strcpy (params
[i
].short_desc
,
2459 "Number of playback channels (defaults to hardware max)");
2460 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2463 strcpy (params
[i
].name
, "shorts");
2464 params
[i
].character
= 'S';
2465 params
[i
].type
= JackDriverParamBool
;
2466 params
[i
].value
.i
= FALSE
;
2467 strcpy (params
[i
].short_desc
, "Try 16-bit samples before 32-bit");
2468 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2472 strcpy (params
[i
].name
, "input-latency");
2473 params
[i
].character
= 'I';
2474 params
[i
].type
= JackDriverParamUInt
;
2475 params
[i
].value
.i
= 0;
2476 strcpy (params
[i
].short_desc
, "Extra input latency (frames)");
2477 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2480 strcpy (params
[i
].name
, "output-latency");
2481 params
[i
].character
= 'O';
2482 params
[i
].type
= JackDriverParamUInt
;
2483 params
[i
].value
.i
= 0;
2484 strcpy (params
[i
].short_desc
, "Extra output latency (frames)");
2485 strcpy (params
[i
].long_desc
, params
[i
].short_desc
);
2487 desc
->params
= params
;
2493 driver_initialize (jack_client_t
*client
, const JSList
* params
)
2495 jack_nframes_t srate
= 48000;
2496 jack_nframes_t frames_per_interrupt
= 1024;
2497 unsigned long user_nperiods
= 2;
2498 char *playback_pcm_name
= "hw:0";
2499 char *capture_pcm_name
= "hw:0";
2500 int hw_monitoring
= FALSE
;
2501 int hw_metering
= FALSE
;
2502 int capture
= FALSE
;
2503 int playback
= FALSE
;
2504 int soft_mode
= FALSE
;
2505 int monitor
= FALSE
;
2506 DitherAlgorithm dither
= None
;
2507 int user_capture_nchnls
= 0;
2508 int user_playback_nchnls
= 0;
2509 int shorts_first
= FALSE
;
2510 jack_nframes_t systemic_input_latency
= 0;
2511 jack_nframes_t systemic_output_latency
= 0;
2512 const JSList
* node
;
2513 const jack_driver_param_t
* param
;
2515 for (node
= params
; node
; node
= jack_slist_next (node
)) {
2516 param
= (const jack_driver_param_t
*) node
->data
;
2518 switch (param
->character
) {
2522 if (strcmp (param
->value
.str
, "none") != 0) {
2523 capture_pcm_name
= strdup (param
->value
.str
);
2529 if (strcmp (param
->value
.str
, "none") != 0) {
2530 playback_pcm_name
= strdup (param
->value
.str
);
2540 playback_pcm_name
= strdup (param
->value
.str
);
2541 capture_pcm_name
= strdup (param
->value
.str
);
2545 hw_monitoring
= param
->value
.i
;
2549 monitor
= param
->value
.i
;
2553 hw_metering
= param
->value
.i
;
2557 srate
= param
->value
.ui
;
2558 fprintf (stderr
, "apparent rate = %d\n", srate
);
2562 frames_per_interrupt
= param
->value
.ui
;
2566 user_nperiods
= param
->value
.ui
;
2567 if (user_nperiods
< 2) /* enforce minimum value */
2572 soft_mode
= param
->value
.i
;
2576 if (dither_opt (param
->value
.c
, &dither
)) {
2582 user_capture_nchnls
= param
->value
.ui
;
2585 user_playback_nchnls
= param
->value
.ui
;
2589 shorts_first
= param
->value
.i
;
2593 systemic_input_latency
= param
->value
.ui
;
2597 systemic_output_latency
= param
->value
.ui
;
2603 /* duplex is the default */
2604 if (!capture
&& !playback
) {
2609 return alsa_driver_new ("alsa_pcm", playback_pcm_name
,
2610 capture_pcm_name
, client
,
2611 frames_per_interrupt
,
2612 user_nperiods
, srate
, hw_monitoring
,
2613 hw_metering
, capture
, playback
, dither
,
2615 user_capture_nchnls
, user_playback_nchnls
,
2617 systemic_input_latency
,
2618 systemic_output_latency
);
2622 driver_finish (jack_driver_t
*driver
)
2624 alsa_driver_delete ((alsa_driver_t
*) driver
);