-
Notifications
You must be signed in to change notification settings - Fork 323
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
Issue #35 - implemented missing Int32_to_Int24_Dither function #798
base: master
Are you sure you want to change the base?
Changes from all commits
b122784
806d4b9
f1733cc
dea6d98
8dc7928
76c10e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -935,13 +935,30 @@ static void Int32_To_Int24_Dither( | |||||
void *sourceBuffer, signed int sourceStride, | ||||||
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) | ||||||
{ | ||||||
(void) destinationBuffer; /* unused parameters */ | ||||||
(void) destinationStride; /* unused parameters */ | ||||||
(void) sourceBuffer; /* unused parameters */ | ||||||
(void) sourceStride; /* unused parameters */ | ||||||
(void) count; /* unused parameters */ | ||||||
(void) ditherGenerator; /* unused parameters */ | ||||||
/* IMPLEMENT ME */ | ||||||
|
||||||
PaInt32 *src = (PaInt32*)sourceBuffer; | ||||||
unsigned char *dest = (unsigned char*)destinationBuffer; | ||||||
PaInt32 *scaledDitherResult = (PaInt32*)destinationBuffer; | ||||||
PaInt32 dither; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
while ( count-- ) | ||||||
{ | ||||||
/* REVIEW */ | ||||||
dither = PaUtil_Generate16BitTriangularDither(ditherGenerator); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*scaledDitherResult = (PaInt32) ((((*src) >> 1) + dither) >> 7); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
#if defined(PA_LITTLE_ENDIAN) | ||||||
dest[0] = (unsigned char)(*scaledDitherResult); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the |
||||||
dest[1] = (unsigned char)(*scaledDitherResult >> 8); | ||||||
dest[2] = (unsigned char)(*scaledDitherResult >> 16); | ||||||
#elif defined(PA_BIG_ENDIAN) | ||||||
dest[0] = (unsigned char)(*scaledDitherResult >> 16); | ||||||
dest[1] = (unsigned char)(*scaledDitherResult >> 8); | ||||||
dest[2] = (unsigned char)(*scaledDitherResult); | ||||||
#endif | ||||||
src += sourceStride; | ||||||
dest += destinationStride * 3; | ||||||
} | ||||||
} | ||||||
|
||||||
/* -------------------------------------------------------------------------- */ | ||||||
|
@@ -1055,16 +1072,19 @@ static void Int32_To_UInt8_Dither( | |||||
void *sourceBuffer, signed int sourceStride, | ||||||
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) | ||||||
{ | ||||||
/* PaInt32 *src = (PaInt32*)sourceBuffer; | ||||||
unsigned char *dest = (unsigned char*)destinationBuffer; */ | ||||||
(void)ditherGenerator; /* unused parameter */ | ||||||
PaInt32 *src = (PaInt32*)sourceBuffer; | ||||||
unsigned char *dest = (unsigned char*)destinationBuffer; | ||||||
PaInt32 dither; | ||||||
|
||||||
while( count-- ) | ||||||
{ | ||||||
/* IMPLEMENT ME */ | ||||||
/* REVIEW */ | ||||||
dither = PaUtil_Generate16BitTriangularDither( ditherGenerator ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declare variable here as in previous function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dither could be declared here. |
||||||
|
||||||
/* src += sourceStride; | ||||||
dest += destinationStride; */ | ||||||
*dest = (unsigned char)((((*src) >> 1) + dither) >> 23); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UInt8 audio is centered around 128 and ranges from 0 to 255. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, you need to add an offset to convert Int32 to Uint8 format. |
||||||
|
||||||
src += sourceStride; | ||||||
dest += destinationStride; | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most obvious red flag here is that you're casting a non-aligned ptr to a 32-bit aligned pointer. But also, why is the scaled dither result being stored in the destination buffer? In any case there's no reason to be storing a temporary result in the destination buffer.