How to change bitpersample of audio ?

10 views (last 30 days)
Sisi Misi
Sisi Misi on 24 Aug 2021
Answered: Rahul on 6 Nov 2024 at 6:35
Hi everyone
Is it possible to change the audio bitpersample outside the range of 16 (default) | 8 | 24 | 32 | 64 with flac or wav codec format?
If possible how to do it?
For example : within the range 10, 12, 14, etc

Answers (1)

Rahul
Rahul on 6 Nov 2024 at 6:35
Hi Sisi,
In order to sample your audio with non-standard bit ranges like 10, 12, 14 you can consider to quantize the audio data to the desired bit depth. Here is a sample code:
% Considering 'audioData' and 'sampleRate' as the variables with signal data and it's sampling rate
desiredBits = 12; % Can be adjusted
% Calculating 'quantizedAudio' by 'maxIntValue' according to the 'desiredBits'
maxIntValue = 2^(desiredBits - 1) - 1;
quantizedAudio = round(audioData * maxIntValue) / maxIntValue;
% Writing the 'quantizedaudio' as a .wav file
audiowrite('output.wav', quantizedAudio, sampleRate);
You can also refer to this MATLAB Answer, which mentions the use of 'quantiz' and 'discretize' functions:
Hope this helps! Thanks.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!