188447a05SGarrett D'Amore /* 288447a05SGarrett D'Amore * CDDL HEADER START 388447a05SGarrett D'Amore * 488447a05SGarrett D'Amore * The contents of this file are subject to the terms of the 588447a05SGarrett D'Amore * Common Development and Distribution License (the "License"). 688447a05SGarrett D'Amore * You may not use this file except in compliance with the License. 788447a05SGarrett D'Amore * 888447a05SGarrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 988447a05SGarrett D'Amore * or http://www.opensolaris.org/os/licensing. 1088447a05SGarrett D'Amore * See the License for the specific language governing permissions 1188447a05SGarrett D'Amore * and limitations under the License. 1288447a05SGarrett D'Amore * 1388447a05SGarrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each 1488447a05SGarrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1588447a05SGarrett D'Amore * If applicable, add the following below this CDDL HEADER, with the 1688447a05SGarrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying 1788447a05SGarrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner] 1888447a05SGarrett D'Amore * 1988447a05SGarrett D'Amore * CDDL HEADER END 2088447a05SGarrett D'Amore */ 2188447a05SGarrett D'Amore /* 2288447a05SGarrett D'Amore * Copyright (C) 4Front Technologies 1996-2008. 2388447a05SGarrett D'Amore * 24*2c30fa45SGarrett D'Amore * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2588447a05SGarrett D'Amore */ 2688447a05SGarrett D'Amore 2788447a05SGarrett D'Amore #ifndef _AUDIO_IMPL_H 2888447a05SGarrett D'Amore #define _AUDIO_IMPL_H 2988447a05SGarrett D'Amore 3088447a05SGarrett D'Amore #include <sys/types.h> 3188447a05SGarrett D'Amore #include <sys/list.h> 3288447a05SGarrett D'Amore #include <sys/poll.h> 3388447a05SGarrett D'Amore 3488447a05SGarrett D'Amore #include <sys/audio/audio_driver.h> 3588447a05SGarrett D'Amore #include "audio_client.h" 3688447a05SGarrett D'Amore 3788447a05SGarrett D'Amore #define AUDIO_MAX_OPENS 256 3888447a05SGarrett D'Amore #define AUDIO_MAX_CHANNELS 16 3988447a05SGarrett D'Amore #define AUDIO_UNIT_EXPAND 1024 4088447a05SGarrett D'Amore #define AUDIO_CHBUFS 2048 /* samples for mixing */ 4188447a05SGarrett D'Amore #define AUDIO_VOL_SCALE 256 4288447a05SGarrett D'Amore #define AUDIO_DB_SIZE 50 4388447a05SGarrett D'Amore 4468c47f65SGarrett D'Amore #define AUDIO_INTRHZ 100 4568c47f65SGarrett D'Amore #define AUDIO_INTRHZ_MIN 50 /* 20 msec max */ 4668c47f65SGarrett D'Amore #define AUDIO_INTRHZ_MAX 500 4768c47f65SGarrett D'Amore 4888447a05SGarrett D'Amore struct audio_parms { 4988447a05SGarrett D'Amore int p_format; 5088447a05SGarrett D'Amore int p_rate; 5188447a05SGarrett D'Amore int p_nchan; 5288447a05SGarrett D'Amore }; 5388447a05SGarrett D'Amore 5488447a05SGarrett D'Amore typedef int (*audio_cnv_func_t)(audio_stream_t *, int); 5588447a05SGarrett D'Amore 5688447a05SGarrett D'Amore struct audio_buffer { 5788447a05SGarrett D'Amore caddr_t b_data; 5888447a05SGarrett D'Amore uint64_t b_head; 5988447a05SGarrett D'Amore uint64_t b_tail; 6068c47f65SGarrett D'Amore uint_t b_hidx; /* head % nframes */ 6168c47f65SGarrett D'Amore uint_t b_tidx; /* tail % nframes */ 6268c47f65SGarrett D'Amore uint_t b_nframes; /* total frames */ 6368c47f65SGarrett D'Amore uint_t b_framesz; /* bytes per frame */ 6488447a05SGarrett D'Amore }; 6588447a05SGarrett D'Amore 6688447a05SGarrett D'Amore /* 6788447a05SGarrett D'Amore * struct audio_stream: This structure represents a virtual stream exposed 6888447a05SGarrett D'Amore * to a single client. Each client will have at most two of these (one for 6988447a05SGarrett D'Amore * record, one for playback.) 7088447a05SGarrett D'Amore */ 7188447a05SGarrett D'Amore struct audio_stream { 7288447a05SGarrett D'Amore audio_buffer_t s_buf; 7388447a05SGarrett D'Amore #define s_data s_buf.b_data 7488447a05SGarrett D'Amore #define s_bufsz s_buf.b_size 7588447a05SGarrett D'Amore #define s_head s_buf.b_head 7688447a05SGarrett D'Amore #define s_tail s_buf.b_tail 7788447a05SGarrett D'Amore #define s_framesz s_buf.b_framesz 7888447a05SGarrett D'Amore #define s_nframes s_buf.b_nframes 7988447a05SGarrett D'Amore #define s_tidx s_buf.b_tidx 8088447a05SGarrett D'Amore #define s_hidx s_buf.b_hidx 8168c47f65SGarrett D'Amore uint_t s_nfrags; 8268c47f65SGarrett D'Amore uint_t s_fragfr; 8368c47f65SGarrett D'Amore uint_t s_nbytes; 8468c47f65SGarrett D'Amore uint_t s_fragbytes; 8588447a05SGarrett D'Amore ddi_umem_cookie_t s_cookie; 86a702341cSGarrett D'Amore uint32_t s_allocsz; 87a702341cSGarrett D'Amore uint32_t s_hintsz; /* latency hints */ 88a702341cSGarrett D'Amore uint16_t s_hintfrags; 8988447a05SGarrett D'Amore 9088447a05SGarrett D'Amore /* 9188447a05SGarrett D'Amore * Various counters. 9288447a05SGarrett D'Amore */ 9388447a05SGarrett D'Amore uint64_t s_samples; 9488447a05SGarrett D'Amore uint64_t s_errors; /* underrun or overrun count */ 9588447a05SGarrett D'Amore 9688447a05SGarrett D'Amore boolean_t s_running; 9788447a05SGarrett D'Amore boolean_t s_paused; /* stream paused */ 9888447a05SGarrett D'Amore boolean_t s_draining; /* stream draining */ 9988447a05SGarrett D'Amore 10088447a05SGarrett D'Amore /* 10188447a05SGarrett D'Amore * Sample rate conversion (SRC) and format conversion details. 10288447a05SGarrett D'Amore */ 10388447a05SGarrett D'Amore struct grc3state *s_src_state[AUDIO_MAX_CHANNELS]; 10468c47f65SGarrett D'Amore uint_t s_src_quality; 10588447a05SGarrett D'Amore int s_cnv_max; 10688447a05SGarrett D'Amore audio_cnv_func_t s_converter; 10788447a05SGarrett D'Amore uint32_t *s_cnv_buf0; 10888447a05SGarrett D'Amore uint32_t *s_cnv_buf1; 10988447a05SGarrett D'Amore void *s_cnv_src; 11088447a05SGarrett D'Amore void *s_cnv_dst; 11188447a05SGarrett D'Amore audio_parms_t s_cnv_src_parms; 11288447a05SGarrett D'Amore #define s_cnv_src_nchan s_cnv_src_parms.p_nchan 11388447a05SGarrett D'Amore #define s_cnv_src_rate s_cnv_src_parms.p_rate 11488447a05SGarrett D'Amore #define s_cnv_src_format s_cnv_src_parms.p_format 11588447a05SGarrett D'Amore 11688447a05SGarrett D'Amore audio_parms_t s_cnv_dst_parms; 11788447a05SGarrett D'Amore #define s_cnv_dst_nchan s_cnv_dst_parms.p_nchan 11888447a05SGarrett D'Amore #define s_cnv_dst_rate s_cnv_dst_parms.p_rate 11988447a05SGarrett D'Amore #define s_cnv_dst_format s_cnv_dst_parms.p_format 12088447a05SGarrett D'Amore 12188447a05SGarrett D'Amore size_t s_cnv_cnt; 12288447a05SGarrett D'Amore int32_t *s_cnv_ptr; 12388447a05SGarrett D'Amore 12488447a05SGarrett D'Amore audio_parms_t *s_user_parms; 12588447a05SGarrett D'Amore audio_parms_t *s_phys_parms; 12688447a05SGarrett D'Amore 12788447a05SGarrett D'Amore /* 12888447a05SGarrett D'Amore * Volume. 12988447a05SGarrett D'Amore */ 13088447a05SGarrett D'Amore uint8_t s_gain_master; 13188447a05SGarrett D'Amore uint8_t s_gain_pct; 13288447a05SGarrett D'Amore uint16_t s_gain_scaled; 13388447a05SGarrett D'Amore uint16_t s_gain_eff; 13488447a05SGarrett D'Amore boolean_t s_muted; 13588447a05SGarrett D'Amore 13688447a05SGarrett D'Amore /* 13788447a05SGarrett D'Amore * Callbacks. 13888447a05SGarrett D'Amore */ 13988447a05SGarrett D'Amore uint64_t s_drain_idx; /* engine index */ 14088447a05SGarrett D'Amore 14188447a05SGarrett D'Amore /* 14288447a05SGarrett D'Amore * Other per stream details, e.g. channel offset, etc. 14388447a05SGarrett D'Amore */ 14488447a05SGarrett D'Amore kmutex_t s_lock; 14588447a05SGarrett D'Amore kcondvar_t s_cv; 14688447a05S