hdl-util / hdmi

Send video/audio over HDMI on an FPGA
https://purisa.me/blog/hdmi-released/
Other
1.04k stars 111 forks source link

16-bits low audio output #6

Closed LMN128 closed 4 years ago

LMN128 commented 4 years ago

Hi Sameer, I have a problem with audio output. I would like to use 16 bits resolution, but it sounds with very low volume in compare 24 bit. I uses same data (i suppose proper) in follow examples:

16-bits: hdmi #(.VIDEO_ID_CODE(17), .VIDEO_REFRESH_RATE(50), .AUDIO_RATE(48000), .AUDIO_BIT_WIDTH(16)) hdmi(.clk_pixel_x10(clk_tmds), .clk_pixel(clk_pixel), .clk_audio(audio_clk), .rgb(rgb), .audio_sample_word('{{audio_l}, {audio_r}}), .tmds_p(data_p), .tmds_clock_p(clk_p), .tmds_n(data_n), .tmds_clock_n(clk_n), .cx(cx), .cy(cy));

24-bits: hdmi #(.VIDEO_ID_CODE(17), .VIDEO_REFRESH_RATE(50), .AUDIO_RATE(48000), .AUDIO_BIT_WIDTH(24)) hdmi(.clk_pixel_x10(clk_tmds), .clk_pixel(clk_pixel), .clk_audio(audio_clk), .rgb(rgb), .audio_sample_word('{{audio_l,8'b0}, {audio_r,8'b0}}), .tmds_p(data_p), .tmds_clock_p(clk_p), .tmds_n(data_n), .tmds_clock_n(clk_n), .cx(cx), .cy(cy)); 24bits sounds good, but 16bit not. Thanks for help.

sameer commented 4 years ago

Hi Jan,

That is odd, there is no audio postprocessing being done by the HDMI module. It could be monitor related, or I missed something in the HDMI spec. I will investigate on my FPGA and get back to you.

Glad it is otherwise working out.

LMN128 commented 4 years ago

Hi, It is maybe related this issue: in the module: audio_clock_regeneration_packet i got this error on row 36: localparam CTS_WIDTH = $clog2(20'(CTS_IDEAL * 1.1)); error:

size casting a real expression violates IEEE 1800 LRM

I use Vivado 2019.2.1

sameer commented 4 years ago

The CTS should not affect this, unless you are hearing jittering in the 16-bit audio that is not in the 24-bit audio. I should have some time to look at this today evening / tomorrow.

LMN128 commented 4 years ago

Hi, It is maybe related this issue: in the module: audio_clock_regeneration_packet i got this error on row 36: localparam CTS_WIDTH = $clog2(20'(CTS_IDEAL * 1.1)); error:

size casting a real expression violates IEEE 1800 LRM

I use Vivado 2019.2.1

It's "problem" of Vivado. It looks don't like real number in function $clog2, but it didn't resolve issue with low audio output.

LMN128 commented 4 years ago

Hi Sameer, look at the picture i attached, please. It's audio output from TV. I used your example of Sawtooth wave generator. The saw tooth is damage. It looks like some samples words or bits of audio are not represented. I hope it helps you. SCR01

sameer commented 4 years ago

I've been checking the code dependent on audio bit width but haven't found anything yet. Logically, I think everything is fine. If there is an issue, it is either in the internal audio buffer or the on-the-fly clock regeneration. The internal audio buffer is reset every time an audio packet is sent (every ~2 samples for 48kHz) so it would happen a lot. But I think if either of these were the problem we'd also see it in the 16 bit audio waveform. Could you capture a 16-bit waveform with your oscilloscope?

When using the sawtooth wave generator, did you set the bit width to be the SAME as the audio bit width? i.e.

localparam AUDIO_BIT_WIDTH = 16;
hdmi #(.AUDIO_BIT_WIDTH(AUDIO_BIT_WIDTH)) hdmi ();
sawtooth #(.BIT_WIDTH(AUDIO_BIT_WIDTH)) sawtooth ();

and then for 24-bit

localparam AUDIO_BIT_WIDTH = 24;
hdmi #(.AUDIO_BIT_WIDTH(AUDIO_BIT_WIDTH)) hdmi ();
sawtooth #(.BIT_WIDTH(AUDIO_BIT_WIDTH)) sawtooth ();

What I've checked so far in the code:

sameer commented 4 years ago

Updated plots after correcting sawtooth: 16-bit plot: image

24-bit plot: image Visible approximation: image

Yeah it's definitely quieter. My working theory is that even though it's been set to 16-bit audio, the HDMI sink is actually perceiving the sample as 24-bit audio. The frequency is right, but the dynamic range is MUCH lower. Have to investigate why it's ignoring the 16-bit audio setting in the channel status.

sameer commented 4 years ago

Graphs from my computer for 24-bit sawtooth generated with SoX looks exactly the same as the output from the FPGA:

image

sameer commented 4 years ago

After fixing the padding, 16-bit is output correctly: image

Approximation looks about the same: image