184659b24SMichael Zeller /*- 2*32640292SAndy Fiddaman * SPDX-License-Identifier: BSD-2-Clause 384659b24SMichael Zeller * 484659b24SMichael Zeller * Copyright (c) 2016 Alex Teaca <iateaca@FreeBSD.org> 584659b24SMichael Zeller * All rights reserved. 684659b24SMichael Zeller * 784659b24SMichael Zeller * Redistribution and use in source and binary forms, with or without 884659b24SMichael Zeller * modification, are permitted provided that the following conditions 984659b24SMichael Zeller * are met: 1084659b24SMichael Zeller * 1. Redistributions of source code must retain the above copyright 1184659b24SMichael Zeller * notice, this list of conditions and the following disclaimer. 1284659b24SMichael Zeller * 2. Redistributions in binary form must reproduce the above copyright 1384659b24SMichael Zeller * notice, this list of conditions and the following disclaimer in the 1484659b24SMichael Zeller * documentation and/or other materials provided with the distribution. 1584659b24SMichael Zeller * 1684659b24SMichael Zeller * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 1784659b24SMichael Zeller * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1884659b24SMichael Zeller * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1984659b24SMichael Zeller * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2084659b24SMichael Zeller * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2184659b24SMichael Zeller * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2284659b24SMichael Zeller * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2384659b24SMichael Zeller * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2484659b24SMichael Zeller * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2584659b24SMichael Zeller * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2684659b24SMichael Zeller * SUCH DAMAGE. 2784659b24SMichael Zeller */ 2884659b24SMichael Zeller 296dc98349SAndy Fiddaman #ifndef _AUDIO_EMUL_H_ 3084659b24SMichael Zeller #define _AUDIO_EMUL_H_ 3184659b24SMichael Zeller 3284659b24SMichael Zeller #include <sys/types.h> 3384659b24SMichael Zeller #include <sys/soundcard.h> 3484659b24SMichael Zeller 3584659b24SMichael Zeller /* 3684659b24SMichael Zeller * Audio Player data structures 3784659b24SMichael Zeller */ 3884659b24SMichael Zeller 3984659b24SMichael Zeller struct audio; 4084659b24SMichael Zeller 4184659b24SMichael Zeller struct audio_params { 4284659b24SMichael Zeller int channels; 4384659b24SMichael Zeller int format; 4484659b24SMichael Zeller int rate; 4584659b24SMichael Zeller }; 4684659b24SMichael Zeller 4784659b24SMichael Zeller /* 4884659b24SMichael Zeller * Audio Player API 4984659b24SMichael Zeller */ 5084659b24SMichael Zeller 5184659b24SMichael Zeller /* 5284659b24SMichael Zeller * audio_init - initialize an instance of audio player 5384659b24SMichael Zeller * @dev_name - the backend sound device used to play / capture 5484659b24SMichael Zeller * @dir - dir = 1 for write mode, dir = 0 for read mode 5584659b24SMichael Zeller * Returns NULL on error and the address of the audio player instance 5684659b24SMichael Zeller */ 5784659b24SMichael Zeller struct audio *audio_init(const char *dev_name, uint8_t dir); 5884659b24SMichael Zeller 5984659b24SMichael Zeller /* 6084659b24SMichael Zeller * audio_set_params - reset the sound device and set the audio params 6184659b24SMichael Zeller * @aud - the audio player to be configured 6284659b24SMichael Zeller * @params - the audio parameters to be set 6384659b24SMichael Zeller * Returns -1 on error and 0 on success 6484659b24SMichael Zeller */ 6584659b24SMichael Zeller int audio_set_params(struct audio *aud, struct audio_params *params); 6684659b24SMichael Zeller 6784659b24SMichael Zeller /* 6884659b24SMichael Zeller * audio_playback - plays samples to the sound device using blocking operations 6984659b24SMichael Zeller * @aud - the audio player used to play the samples 7084659b24SMichael Zeller * @buf - the buffer containing the samples 7184659b24SMichael Zeller * @count - the number of bytes in buffer 7284659b24SMichael Zeller * Returns -1 on error and 0 on success 7384659b24SMichael Zeller */ 7459d65d31SAndy Fiddaman int audio_playback(struct audio *aud, const uint8_t *buf, size_t count); 7584659b24SMichael Zeller 7684659b24SMichael Zeller /* 7784659b24SMichael Zeller * audio_record - records samples from the sound device using blocking 7884659b24SMichael Zeller * operations. 7984659b24SMichael Zeller * @aud - the audio player used to capture the samples 8084659b24SMichael Zeller * @buf - the buffer to receive the samples 8184659b24SMichael Zeller * @count - the number of bytes to capture in buffer 8284659b24SMichael Zeller * Returns -1 on error and 0 on success 8384659b24SMichael Zeller */ 8459d65d31SAndy Fiddaman int audio_record(struct audio *aud, uint8_t *buf, size_t count); 8584659b24SMichael Zeller 8684659b24SMichael Zeller #endif /* _AUDIO_EMUL_H_ */ 87