Skip to content

Commit

Permalink
Add experimental support for int16 audio devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Feb 18, 2024
1 parent 4785c7d commit 12843c3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions source/src/node/io/output/soundio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int
{
for (int channel = 0; channel < layout->channel_count; channel += 1)
{
float *ptr = reinterpret_cast<float *>(areas[channel].ptr + areas[channel].step * frame);
*ptr = output->out[channel][frame];

/*-----------------------------------------------------------------------*
* Hard limiter.
*-----------------------------------------------------------------------*/
if (*ptr > 1.0)
*ptr = 1.0;
if (*ptr < -1.0)
*ptr = -1.0;
if (outstream->format == SoundIoFormatFloat32NE)
{
float *ptr = reinterpret_cast<float *>(areas[channel].ptr + areas[channel].step * frame);
*ptr = output->out[channel][frame];
/*-----------------------------------------------------------------------*
* Hard limiter.
*-----------------------------------------------------------------------*/
if (*ptr > 1.0)
*ptr = 1.0;
if (*ptr < -1.0)
*ptr = -1.0;
}
else if (outstream->format == SoundIoFormatS16LE)
{
int16_t *ptr = reinterpret_cast<int16_t *>(areas[channel].ptr + areas[channel].step * frame);
*ptr = (int16_t) (output->out[channel][frame] * 32768.0f);
}
}
}
}
Expand Down Expand Up @@ -203,12 +210,16 @@ int AudioOut_SoundIO::init()
{
this->outstream->format = SoundIoFormatFloat32NE;
}
else if (soundio_device_supports_format(device, SoundIoFormatS16LE))
{
this->outstream->format = SoundIoFormatS16LE;
}
else
{
/*-----------------------------------------------------------------------*
* SignalFlow currently only supports float32 sample output
*-----------------------------------------------------------------------*/
throw audio_io_exception("libsoundio error: Output device does not support float32 samples");
throw audio_io_exception("libsoundio error: Output device does not support float32 or int16le samples");
}
this->outstream->write_callback = write_callback;
if (!this->sample_rate)
Expand Down

0 comments on commit 12843c3

Please sign in to comment.