aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-03-21 01:38:38 -0700
committerChris Robinson <[email protected]>2021-03-21 01:38:38 -0700
commitf0726f471f367eff97933772ba5dc042f471c99b (patch)
tree93aa20f172de53dc0cd1db7c55b0c75cae1fd8d6 /examples
parent7c697b9178b2f7bff6fec4fa9cbbf5390f13d2e5 (diff)
Use float formats in examples/alstreamcb
libsndfile apparently has issues reading floating-point wave files as 16-bit samples (produces silence). Even on other file formats, reading float samples as integer samples has no over/underflow protection, so this is better for those formats too.
Diffstat (limited to 'examples')
-rw-r--r--examples/alstreamcb.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/alstreamcb.cpp b/examples/alstreamcb.cpp
index 814e2214..424ed635 100644
--- a/examples/alstreamcb.cpp
+++ b/examples/alstreamcb.cpp
@@ -130,18 +130,18 @@ struct StreamPlayer {
mFormat = AL_NONE;
if(mSfInfo.channels == 1)
- mFormat = AL_FORMAT_MONO16;
+ mFormat = AL_FORMAT_MONO_FLOAT32;
else if(mSfInfo.channels == 2)
- mFormat = AL_FORMAT_STEREO16;
+ mFormat = AL_FORMAT_STEREO_FLOAT32;
else if(mSfInfo.channels == 3)
{
if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, NULL, 0) == SF_AMBISONIC_B_FORMAT)
- mFormat = AL_FORMAT_BFORMAT2D_16;
+ mFormat = AL_FORMAT_BFORMAT2D_FLOAT32;
}
else if(mSfInfo.channels == 4)
{
if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, NULL, 0) == SF_AMBISONIC_B_FORMAT)
- mFormat = AL_FORMAT_BFORMAT3D_16;
+ mFormat = AL_FORMAT_BFORMAT3D_FLOAT32;
}
if(!mFormat)
{
@@ -153,7 +153,7 @@ struct StreamPlayer {
}
/* Set a 1s ring buffer size. */
- mBufferDataSize = static_cast<ALuint>(mSfInfo.samplerate*mSfInfo.channels) * sizeof(short);
+ mBufferDataSize = static_cast<ALuint>(mSfInfo.samplerate*mSfInfo.channels) * sizeof(float);
mBufferData.reset(new ALbyte[mBufferDataSize]);
mReadPos.store(0, std::memory_order_relaxed);
mWritePos.store(0, std::memory_order_relaxed);
@@ -236,7 +236,7 @@ struct StreamPlayer {
alGetSourcei(mSource, AL_SAMPLE_OFFSET, &pos);
alGetSourcei(mSource, AL_SOURCE_STATE, &state);
- const size_t frame_size{static_cast<ALuint>(mSfInfo.channels) * sizeof(short)};
+ const size_t frame_size{static_cast<ALuint>(mSfInfo.channels) * sizeof(float)};
size_t woffset{mWritePos.load(std::memory_order_acquire)};
if(state != AL_INITIAL)
{
@@ -271,8 +271,8 @@ struct StreamPlayer {
const size_t writable{roffset-woffset-1};
if(writable < frame_size) break;
- sf_count_t num_frames{sf_readf_short(mSndfile,
- reinterpret_cast<short*>(&mBufferData[woffset]),
+ sf_count_t num_frames{sf_readf_float(mSndfile,
+ reinterpret_cast<float*>(&mBufferData[woffset]),
static_cast<sf_count_t>(writable/frame_size))};
if(num_frames < 1) break;
@@ -290,8 +290,8 @@ struct StreamPlayer {
(mBufferDataSize-woffset)};
if(writable < frame_size) break;
- sf_count_t num_frames{sf_readf_short(mSndfile,
- reinterpret_cast<short*>(&mBufferData[woffset]),
+ sf_count_t num_frames{sf_readf_float(mSndfile,
+ reinterpret_cast<float*>(&mBufferData[woffset]),
static_cast<sf_count_t>(writable/frame_size))};
if(num_frames < 1) break;