xref: /freebsd/usr.sbin/bhyve/audio.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
16b021cc2SWarner Losh /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33e21da8aSMarcelo Araujo  *
46b021cc2SWarner Losh  * Copyright (c) 2016 Alex Teaca <iateaca@FreeBSD.org>
56b021cc2SWarner Losh  * All rights reserved.
66b021cc2SWarner Losh  *
76b021cc2SWarner Losh  * Redistribution and use in source and binary forms, with or without
86b021cc2SWarner Losh  * modification, are permitted provided that the following conditions
96b021cc2SWarner Losh  * are met:
106b021cc2SWarner Losh  * 1. Redistributions of source code must retain the above copyright
116b021cc2SWarner Losh  *    notice, this list of conditions and the following disclaimer.
126b021cc2SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
136b021cc2SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
146b021cc2SWarner Losh  *    documentation and/or other materials provided with the distribution.
156b021cc2SWarner Losh  *
166b021cc2SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
176b021cc2SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
186b021cc2SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
196b021cc2SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
206b021cc2SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
216b021cc2SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
226b021cc2SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
236b021cc2SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246b021cc2SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256b021cc2SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266b021cc2SWarner Losh  * SUCH DAMAGE.
276b021cc2SWarner Losh  */
286b021cc2SWarner Losh 
296b021cc2SWarner Losh #ifndef _AUDIO_EMUL_H_
306b021cc2SWarner Losh #define _AUDIO_EMUL_H_
316b021cc2SWarner Losh 
326b021cc2SWarner Losh #include <sys/types.h>
336b021cc2SWarner Losh #include <sys/soundcard.h>
346b021cc2SWarner Losh 
356b021cc2SWarner Losh /*
366b021cc2SWarner Losh  * Audio Player data structures
376b021cc2SWarner Losh  */
386b021cc2SWarner Losh 
396b021cc2SWarner Losh struct audio;
406b021cc2SWarner Losh 
416b021cc2SWarner Losh struct audio_params {
426b021cc2SWarner Losh 	int channels;
436b021cc2SWarner Losh 	int format;
446b021cc2SWarner Losh 	int rate;
456b021cc2SWarner Losh };
466b021cc2SWarner Losh 
476b021cc2SWarner Losh /*
486b021cc2SWarner Losh  * Audio Player API
496b021cc2SWarner Losh  */
506b021cc2SWarner Losh 
516b021cc2SWarner Losh /*
526b021cc2SWarner Losh  * audio_init - initialize an instance of audio player
536b021cc2SWarner Losh  * @dev_name - the backend sound device used to play / capture
546b021cc2SWarner Losh  * @dir - dir = 1 for write mode, dir = 0 for read mode
556b021cc2SWarner Losh  * Returns NULL on error and the address of the audio player instance
566b021cc2SWarner Losh  */
576b021cc2SWarner Losh struct audio *audio_init(const char *dev_name, uint8_t dir);
586b021cc2SWarner Losh 
596b021cc2SWarner Losh /*
606b021cc2SWarner Losh  * audio_set_params - reset the sound device and set the audio params
616b021cc2SWarner Losh  * @aud - the audio player to be configured
626b021cc2SWarner Losh  * @params - the audio parameters to be set
636b021cc2SWarner Losh  * Returns -1 on error and 0 on success
646b021cc2SWarner Losh  */
656b021cc2SWarner Losh int audio_set_params(struct audio *aud, struct audio_params *params);
666b021cc2SWarner Losh 
676b021cc2SWarner Losh /*
686b021cc2SWarner Losh  * audio_playback - plays samples to the sound device using blocking operations
696b021cc2SWarner Losh  * @aud - the audio player used to play the samples
706b021cc2SWarner Losh  * @buf - the buffer containing the samples
716b021cc2SWarner Losh  * @count - the number of bytes in buffer
726b021cc2SWarner Losh  * Returns -1 on error and 0 on success
736b021cc2SWarner Losh  */
74ee83710bSMark Johnston int audio_playback(struct audio *aud, const uint8_t *buf, size_t count);
756b021cc2SWarner Losh 
766b021cc2SWarner Losh /*
776b021cc2SWarner Losh  * audio_record - records samples from the sound device using blocking
786b021cc2SWarner Losh  * operations.
796b021cc2SWarner Losh  * @aud - the audio player used to capture the samples
806b021cc2SWarner Losh  * @buf - the buffer to receive the samples
816b021cc2SWarner Losh  * @count - the number of bytes to capture in buffer
826b021cc2SWarner Losh  * Returns -1 on error and 0 on success
836b021cc2SWarner Losh  */
84ee83710bSMark Johnston int audio_record(struct audio *aud, uint8_t *buf, size_t count);
856b021cc2SWarner Losh 
866b021cc2SWarner Losh #endif  /* _AUDIO_EMUL_H_ */
87