#ifndef _XAS_AUDIO_H #define _XAS_AUDIO_H #include #include #define XAS_AUDIO_STREAM_PCM_8_BIT 1 #define XAS_AUDIO_STREAM_PCM_16_BIT 2 #define XAS_AUDIO_STREAM_MONO 1 #define XAS_AUDIO_STREAM_STEREO 2 enum xas_audio_stream_type { XAS_AUDIO_STREAM_SINK, XAS_AUDIO_STREAM_SOURCE }; typedef struct _xas_audio_stream xas_audio_stream; typedef ssize_t (*xas_audio_drain)(void *ctx, void *samples, size_t count, xas_audio_stream *stream); typedef ssize_t (*xas_audio_fill)(void *ctx, void *samples, size_t count, xas_audio_stream *stream); typedef void (*xas_audio_cleanup)(void *ctx, xas_audio_stream *stream); struct _xas_audio_stream { enum xas_audio_stream_type type; size_t channels, sample_size, sample_rate; size_t buffer_size, buffer_count; union { void *callback; xas_audio_drain drain; xas_audio_fill fill; }; xas_audio_cleanup cleanup; void *ctx; }; xas_audio_stream *xas_audio_stream_new_sink(xas_audio_drain drain, xas_audio_cleanup cleanup, void *ctx, size_t channels, size_t sample_size, size_t sample_rate, size_t buffer_size); xas_audio_stream *xas_audio_stream_new_source(xas_audio_fill fill, xas_audio_cleanup cleanup, void *ctx, size_t channels, size_t sample_size, size_t sample_rate, size_t buffer_size); void xas_audio_stream_destroy(xas_audio_stream *stream); ssize_t xas_audio_stream_write(xas_audio_stream *stream, void *samples, size_t count); ssize_t xas_audio_stream_read(xas_audio_stream *stream, void **samples, size_t count); int xas_audio_stream_flush(xas_audio_stream *stream); #endif /* _XAS_AUDIO_H */