/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2016 Alex Teaca <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _AUDIO_EMUL_H_29#define _AUDIO_EMUL_H_3031#include <sys/types.h>32#include <sys/soundcard.h>3334/*35* Audio Player data structures36*/3738struct audio;3940struct audio_params {41int channels;42int format;43int rate;44};4546/*47* Audio Player API48*/4950/*51* audio_init - initialize an instance of audio player52* @dev_name - the backend sound device used to play / capture53* @dir - dir = 1 for write mode, dir = 0 for read mode54* Returns NULL on error and the address of the audio player instance55*/56struct audio *audio_init(const char *dev_name, uint8_t dir);5758/*59* audio_set_params - reset the sound device and set the audio params60* @aud - the audio player to be configured61* @params - the audio parameters to be set62* Returns -1 on error and 0 on success63*/64int audio_set_params(struct audio *aud, struct audio_params *params);6566/*67* audio_playback - plays samples to the sound device using blocking operations68* @aud - the audio player used to play the samples69* @buf - the buffer containing the samples70* @count - the number of bytes in buffer71* Returns -1 on error and 0 on success72*/73int audio_playback(struct audio *aud, const uint8_t *buf, size_t count);7475/*76* audio_record - records samples from the sound device using blocking77* operations.78* @aud - the audio player used to capture the samples79* @buf - the buffer to receive the samples80* @count - the number of bytes to capture in buffer81* Returns -1 on error and 0 on success82*/83int audio_record(struct audio *aud, uint8_t *buf, size_t count);8485#endif /* _AUDIO_EMUL_H_ */868788