How to change bitpersample of audio ?

조회 수: 10 (최근 30일)
Sisi Misi
Sisi Misi 2021년 8월 24일
답변: Rahul 2024년 11월 6일 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

답변 (1개)

Rahul
Rahul 2024년 11월 6일 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.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by