This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository wav_play.
View the commit online.
commit 6a3ae043a0b7c70cfc2078b6b90afef935c9f8da
Author: Vincent Torri <[email protected]>
AuthorDate: Wed Nov 25 23:34:53 2026 +0100
fix solaris code
---
src/bin/wav_audio_libaudio.c | 63 +++++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/src/bin/wav_audio_libaudio.c b/src/bin/wav_audio_libaudio.c
index f394f78..95bcb22 100644
--- a/src/bin/wav_audio_libaudio.c
+++ b/src/bin/wav_audio_libaudio.c
@@ -1,3 +1,10 @@
+/* Solaris / illumos (OpenIndiana...) backend.
+ *
+ * Despite its file name, this version does NOT use libaudio (its header
+ * libaudio.h is not installed on illumos): it talks directly to /dev/audio
+ * with the ioctl() of <sys/audioio.h> (see audio(7I)).
+ * Needs the package system/header/header-audio. No library to link. */
+
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -6,7 +13,8 @@
#include <fcntl.h>
#include <unistd.h>
-#include <libaudio.h>
+#include <sys/ioctl.h>
+#include <sys/audioio.h>
#include "wav_audio.h"
#include "wav_log.h"
@@ -43,7 +51,7 @@ wav_audio_init(void)
return NULL;
}
- /* like audioplay: try without waiting first */
+ /* try without waiting first */
wav_dev->fd = open(WAV_AUDIO_DEVICE, O_WRONLY | O_NONBLOCK);
if ((wav_dev->fd < 0) && (errno == EBUSY))
{
@@ -70,8 +78,7 @@ wav_audio_shutdown(Device *dev)
if (!dev)
return;
- /* close() waits for the queued data to be played (no flush here,
- * it would discard it) */
+ /* close() waits for the queued data to be played */
if (dev->fd >= 0)
close(dev->fd);
free(dev);
@@ -80,35 +87,50 @@ wav_audio_shutdown(Device *dev)
bool
wav_audio_set(Device *dev, const Wav_File *wav)
{
- Audio_hdr hdr;
+ audio_info_t info;
if (!dev || !wav || (wav->block_align == 0))
return false;
- /* only 16 bits signed linear PCM is handled here (8 bits WAV is
- * unsigned, 24/32 bits are not supported by the common drivers). */
+ /* only 16 bits signed linear PCM is handled here */
if (wav->bits_per_sample != 16)
{
WAV_LOG_ERR("unsupported bits per sample: %u", wav->bits_per_sample);
return false;
}
- memset(&hdr, 0, sizeof(hdr));
- hdr.sample_rate = wav->sample_rate;
- hdr.samples_per_unit = 1;
- hdr.bytes_per_unit = wav->bits_per_sample / 8;
- hdr.channels = wav->num_channels;
- hdr.encoding = AUDIO_ENCODING_LINEAR;
- hdr.data_size = AUDIO_UNKNOWN_SIZE;
+ AUDIO_INITINFO(&info);
+ info.play.sample_rate = wav->sample_rate;
+ info.play.channels = wav->num_channels;
+ info.play.precision = wav->bits_per_sample;
+ info.play.encoding = AUDIO_ENCODING_LINEAR;
- if (audio_set_play_config(dev->fd, &hdr) != AUDIO_SUCCESS)
+ if (ioctl(dev->fd, AUDIO_SETINFO, &info) == -1)
{
- WAV_LOG_ERR("audio_set_play_config() failed: the device does not "
- "support this format (%u Hz, %u channels, %u bits)",
+ WAV_LOG_ERR("AUDIO_SETINFO failed: the device does not support this "
+ "format (%u Hz, %u channels, %u bits)",
wav->sample_rate, wav->num_channels, wav->bits_per_sample);
return false;
}
+ /* check what the driver really uses */
+ if (ioctl(dev->fd, AUDIO_GETINFO, &info) == -1)
+ {
+ WAV_LOG_ERR("AUDIO_GETINFO failed");
+ return false;
+ }
+ if ((info.play.sample_rate != wav->sample_rate) ||
+ (info.play.channels != wav->num_channels) ||
+ (info.play.precision != wav->bits_per_sample) ||
+ (info.play.encoding != AUDIO_ENCODING_LINEAR))
+ {
+ WAV_LOG_ERR("format not accepted as is (got %u Hz, %u channels, "
+ "%u bits)",
+ info.play.sample_rate, info.play.channels,
+ info.play.precision);
+ return false;
+ }
+
dev->data = "" uint8_t *)wav->samples;
dev->data_size = wav->subchunk_2_size;
dev->block_align = wav->block_align;
@@ -170,8 +192,11 @@ wav_audio_play(Device *dev)
remaining -= n;
}
- /* The data is drained when the device is closed (wav_audio_shutdown()):
- * do not flush before. */
+#ifdef AUDIO_DRAIN
+ /* wait until everything has been played */
+ if (ioctl(dev->fd, AUDIO_DRAIN, 0) == -1)
+ WAV_LOG_WARN("AUDIO_DRAIN failed");
+#endif
return true;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.