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

LTCWRITE_TEMPLATE functions broken #6

Closed
jalexstark opened this issue Jul 26, 2013 · 2 comments
Closed

LTCWRITE_TEMPLATE functions broken #6

jalexstark opened this issue Jul 26, 2013 · 2 comments

Comments

@jalexstark
Copy link

These do not work for buffers over 1024 samples, because they copy the first bytes in the input buffer repeatedly into the ltc write buffer. Here is suggested code for ltc.c:

#define CONVERSION_BUF_SIZE 1024

#define LTCWRITE_TEMPLATE(FN, FORMAT, CONV) \
void ltc_decoder_write_ ## FN (LTCDecoder *d, FORMAT *buf, size_t size, ltc_off_t posinfo) { \
        ltcsnd_sample_t tmp[CONVERSION_BUF_SIZE]; \
        size_t copyStart = 0; \
        while (copyStart < size) { \
                int c = size - copyStart; \
                c = (c > CONVERSION_BUF_SIZE) ? CONVERSION_BUF_SIZE : c; \
                int i; \
                for (i=0; i<c; i++) { \
                        tmp[i] = CONV; \
                } \
                decode_ltc(d, tmp, c, posinfo + (ltc_off_t)c); \
                copyStart += c; \
        } \
}

LTCWRITE_TEMPLATE(float, float, 128 + (buf[copyStart+i] * 127.0))
/* this relies on the compiler to use an arithemtic right-shift for signed values */
LTCWRITE_TEMPLATE(s16, short, 128 + (buf[copyStart+i] >> 8))
/* this relies on the compiler to use a logical right-shift for unsigned values */
LTCWRITE_TEMPLATE(u16, unsigned short, (buf[copyStart+i] >> 8))
@jalexstark
Copy link
Author

Actually, there were two consequences of the bug. The following fixes the offsets as well.

#define CONVERSION_BUF_SIZE 1024

#define LTCWRITE_TEMPLATE(FN, FORMAT, CONV) \
void ltc_decoder_write_ ## FN (LTCDecoder *d, FORMAT *buf, size_t size, ltc_off_t posinfo) { \
        ltcsnd_sample_t tmp[CONVERSION_BUF_SIZE]; \
        size_t copyStart = 0; \
        while (copyStart < size) { \
                int c = size - copyStart; \
                c = (c > CONVERSION_BUF_SIZE) ? CONVERSION_BUF_SIZE : c; \
                int i; \
                for (i=0; i<c; i++) { \
                        tmp[i] = CONV; \
                } \
                decode_ltc(d, tmp, c, posinfo + (ltc_off_t)copyStart); \
                copyStart += c; \
        } \
}

LTCWRITE_TEMPLATE(float, float, 128 + (buf[copyStart+i] * 127.0))
/* this relies on the compiler to use an arithemtic right-shift for signed values */
LTCWRITE_TEMPLATE(s16, short, 128 + (buf[copyStart+i] >> 8))
/* this relies on the compiler to use a logical right-shift for unsigned values */
LTCWRITE_TEMPLATE(u16, unsigned short, (buf[copyStart+i] >> 8))

@x42
Copy link
Owner

x42 commented Jul 26, 2013

Could you please post a diff (or file a pull request)- also for issue #7. That'll make it much more obvious and allow to comment on the changes. thanks.

@x42 x42 closed this as completed in b2fd07c Jul 26, 2013
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