How to change bitpersample of audio ?
10 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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.
0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!