2

Do WAV files allow any arbitrary number of bitsPerSample?

I have failed to get it to work with anything less than 8. I am not sure how to define the blockAlign for one thing.

Dim ss As New Speech.Synthesis.SpeechSynthesizer
Dim info As New Speech.AudioFormat.SpeechAudioFormatInfo(AudioFormat.EncodingFormat.Pcm, 5000, 4, 1, 2500, 1, Nothing) ' FAILS
ss.SetOutputToWaveFile("TEST4bit.wav", info)
ss.Speak("I am 4 bit.")
My.Computer.Audio.Play("TEST4bit.wav")
mcu
  • 3,302
  • 8
  • 38
  • 64

1 Answers1

1

AFAIK no, 4-bit PCM format is undefined, it wouldn't make much sense to have 16 volume levels of audio; quality would be horrible.

While technically possible, I know no decent software (e.g. Wavelab) that supports it, your very own player could though.

Formula: blockAlign = channels * (bitsPerSample / 8)

So for a mono 4-bit it would be : blockAlign = 1 * ((double)4 / 8) = 0.5

Note the usage of double being necessary to not end up with 0.

But if you look at the block align definition below, it really does not make much sense to have an alignment of 0.5 bytes, one would have to work at the bit-level (painful and useless because at this quality, non-compressed PCM would just sound horrible):

wBlockAlign

The block alignment (in bytes) of the waveform data. Playback software needs to process a multiple of wBlockAlign bytes of data at a time, so the value of wBlockAlign can be used for buffer alignment.

Reference:

http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf page 59

Workaround:

If you really need 4-bit, switch to ADPCM format.

aybe
  • 15,516
  • 9
  • 57
  • 105
  • Thanks. It seems, the WAV files define `ADPCM` as a valid option, however .NET's `AudioFormat.EncodingFormat` enumeration only has `Pcm`, `ALaw` and `ULaw`. Does it mean I cannot generate ADPCM WAV files from .NET? – mcu Aug 28 '16 at 16:51
  • I don't think you can, but take a look at this library : http://stackoverflow.com/questions/4917346/algorithm-for-converting-pcm-to-ima-adpcm – aybe Aug 28 '16 at 16:54
  • So, the `bitsPerSample` has to be a multiple of 8? – mcu Aug 28 '16 at 18:00
  • It is commonly a multiple of 8, could be anything else, though (but likely not to be supported unless a specific software is used). – aybe Aug 28 '16 at 18:11
  • 1
    @MCU No it can be any number of bits. wBlockAlign would be 1, not 0.5. So it would be stored like 8-bit audio, just without using the least significant bits of each byte. – endolith Apr 30 '20 at 05:15
  • Yes you're right it's an old answer, should be (4+7)/8=1 – aybe May 01 '20 at 07:17