You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to write 32-bit samples using AiffFileWriter. Here's the code for it:
WaveFormat format = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Extensible, 44100, 1, 0, 0, 32);
AiffFileWriter writer = new AiffFileWriter("output.aiff", format);
for (int i = -100; i <= 100; i++)
{
writer.WriteSample(((float)i) / 100.0f);
}
writer.Dispose();
The resulting file doesn't have correct samples. It's just filled with zeros.
If I change the code to write 16-bit samples: WaveFormat format = new WaveFormat(44100, 16, 1);, then output.aiff looks correct.
I had a look at the code for AiffFileWriter and I don't understand how it could work for 32-bit output. It is converting a floating point value in the range [-1.0, 1.0] to Int32 by casting it: (Int32)sample. It means that the values become integer values -1, 0 or 1. Shouldn't the conversion be something like this: (Int32)(Int32.MaxValue * sample)?
Also, should the error message in AiffFileWriter.WriteSample() be changed from "Only 16, 24 or 32 bit PCM or IEEE float audio data supported" to "Only 16, 24 or 32 bit PCM audio data supported"? I thought it supports "IEEE float audio data", so I was trying to use WaveFormat format = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1) but it just gave an error message.
The text was updated successfully, but these errors were encountered:
I'm trying to write 32-bit samples using AiffFileWriter. Here's the code for it:
The resulting file doesn't have correct samples. It's just filled with zeros.
If I change the code to write 16-bit samples:
WaveFormat format = new WaveFormat(44100, 16, 1);
, thenoutput.aiff
looks correct.I had a look at the code for AiffFileWriter and I don't understand how it could work for 32-bit output. It is converting a floating point value in the range [-1.0, 1.0] to Int32 by casting it:
(Int32)sample
. It means that the values become integer values -1, 0 or 1. Shouldn't the conversion be something like this:(Int32)(Int32.MaxValue * sample)
?Also, should the error message in AiffFileWriter.WriteSample() be changed from "Only 16, 24 or 32 bit PCM or IEEE float audio data supported" to "Only 16, 24 or 32 bit PCM audio data supported"? I thought it supports "IEEE float audio data", so I was trying to use
WaveFormat format = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1)
but it just gave an error message.The text was updated successfully, but these errors were encountered: