Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does LIBLTC support 16bit/24bit data encoding and decoding? #67

Open
MrWeng opened this issue May 10, 2023 · 5 comments
Open

How does LIBLTC support 16bit/24bit data encoding and decoding? #67

MrWeng opened this issue May 10, 2023 · 5 comments

Comments

@MrWeng
Copy link

MrWeng commented May 10, 2023

First of all, I am very grateful for providing an LTC encoding and decoding method. After my test, LIBLTC can only: encode and decode 8bit data, and does not support 16bit/24bit encoding and decoding. My steps are as follows:

  1. Use the website LTC gererate to generate a 1-minute LTC audio file (Frame Rate: 23.976, Sample Rat: 480000, Bit depth: 16bit).
  2. Use a binary editing tool to remove the header of the wav format, keep only the audio data (I think this is the source data of LTC), and modify the file suffix to raw.
  3. Run ltcdecoder to decode the file, and only one message(* reading fromD:\libltc\test\LTC_02030405_1mins_23976fps_480000x16.raw) will appear after running,without any other information.
  4. When I re-use the above website to generate an LTC audio file with bit depth=8bit, repeat steps 2 and 3. The LTC information can be parsed normally.The output information is as follows
  • *reading from: D:\libltc\test\LTC_02030405_1mins_23976fps_48000x8.raw
    2000-00-00 +0000 02:03:04:05 | -23 2002
    2000-00-00 +0000 02:03:04:06 | 2003 4004
    2000-00-00 +0000 02:03:04:07 | 4005 6006
    2000-00-00 +0000 02:03:04:08 | 6007 8008
    2000-00-00 +0000 02:03:04:09 | 8009 10010
    2000-00-00 +0000 02:03:04:10 | 10011 12009
    2000-00-00 +0000 02:03:04:11 | 12010 14011
    2000-00-00 +0000 02:03:04:12 | 14012 16013
    2000-00-00 +0000 02:03:04:13 | 16014 18015
    2000-00-00 +0000 02:03:04:14 | 18016 20017
    I have two questions
  1. Is the operation of the second step correct? Is the remaining data after removing the wav header file information the LTC data?
  2. What should be done to enable libltc to realize the encoding and decoding of 16bit/24bit data?
@x42
Copy link
Owner

x42 commented May 10, 2023

wav can contain multiple chunks, meta-data, and different encodings (signed, unsigned).
I highly recommend to use https://github.com/libsndfile/libsndfile (or a similar library) to get the raw PCM data from a wav file.

@MrWeng
Copy link
Author

MrWeng commented May 30, 2023

Thanks a lot, I've now been able to get and use PCM metadata correctly. But the sample format is 8bit unsigned mono, which cannot meet my needs. I want to change the sample format to 24bit mono, so what should I do?

@x42
Copy link
Owner

x42 commented May 31, 2023

If it is signed 24 bit, divide each sample value by 256 and then use ltc_decoder_write_s16 for unsigned 24 bit you can simply shift each sample by 8 and use ltc_decoder_write_u16.

@MrWeng
Copy link
Author

MrWeng commented May 31, 2023

It may be that I didn't express clearly, I only use encoding, not decoding. The current encoded data is implemented based on 8bit unsigned data. If it is encoded based on signed 24bit data, how should it be handled? By the way, I did not understand the meaning of enc_lo and enc_hi in the structure LTCEncoder? What role do enc_lo and enc_hi play in the entire encoding process?

@x42
Copy link
Owner

x42 commented May 31, 2023

For output you can likewise scale each sample:

ltcsnd_sample_t *buf;
ltc_encoder_encode_frame(encoder);
int len = ltc_encoder_get_bufferptr(encoder, &buf, 1);

for (int i = 0; i < len; ++i) {
  out_24bit_unsigned[i + off] = buf[i] << 16; // or ..
  out_24bit_signed[i +off] = buf[i] * 65535 - 8388480; //  * (2^16 -1) - 2^23
}

What role do enc_lo and enc_hi play in the entire encoding process?

LTC is a square wave. lo/hi are the signal levels for the waveform, you can change the default via ltc_encoder_set_volume()

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants