Convert 2's complement to integer and calculate rms value
A similar question has been asked at Need fastest way to convert 2's complement to decimal in C, but I couldn't use it to get my answer, so posting this...
I have 32-bit data coming from an audio sensor in the following format:-
The Data Format is I2S, 24-bit, 2’s compliment, MSB first. The data precision is 18 bits; unused bits are zeros.
Without any audio input, I am able to read the following data from the sensor:-
- 0xFA578000
- 0xFA8AC000
- 0xFA85C000
- 0xFA828000
- 0xFA800000
- 0xFA7E4000
- 0xFA7D0000
- 0xFA7BC000
and so on...
I need to use these data samples to calculate their RMS value, then further use this RMS value to calculate the decibels (20 * log(rms)).
Here is my code with comments:-
//I have 32-bits, with data in the most-significant 24 bits.
inputVal &= 0xFFFFFF00; //Mask the least significant 8 bits.
inputVal = inputVal >> 8; //Data is shifted to least 24 bits. 24th bit is the sign bit.
inputVal &= 0x00FFFFC0; //Mask the least 6 bits, since data precision is 18 bits.
//So, I have got 24-bit data with masked 6 lsb bits. 24th bit is sign bit.
//Converting from 2's complement.
const int negative = (inputVal & (1 << 23)) != 0;
int nativeInt;
if (negative)
nativeInt = inputVal | ~((1 << 24) - 1);
else
nativeInt = inputVal;
return (nativeInt * nativeInt); //Returning the squared value to calculate RMS
After this, I take the average of sum of squared values and calculate its root to get the RMS value.
My questions are,
- Am I doing the data bit-manipulations correctly?
- Is it necessary to convert the data samples from 2's complement to integer to calculate their RMS values?
***********************************************Part-2*****************************************************
Continuing further with @Johnny Johansson's answer:-
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
To normalize the sample set, I have calculated the mean value of the sample set and subtracted it from each value in the sample set.
Then, I found the maximum and minimum values form the sample set and calculated the peak-to-peak value.
// I have the sample set, get the mean
float meanval = 0;
for (int i=0; i <actualNumberOfSamples ; i++)
{
meanval += samples[i];
}
meanval /= actualNumberOfSamples;
printf("Average is: %fn", meanval);
// subtract it from all samples to get a 'normalized' output
for (int i = 0; i < actualNumberOfSamples; i++)
{
samples[i] -= meanval;
}
// find the 'peak to peak' max
float minsample = 100000;
float maxsample = -100000;
float peakToPeakMax = 0.0;
for (int i = 0; i < actualNumberOfSamples; i++)
{
minsample = fmin(minsample, samples[i]);
maxsample = fmax(maxsample, samples[i]);
}
peakToPeakMax = (maxsample - minsample);
printf("The peak-to-peak maximum value is: %fn", peakToPeakMax);
(This does not include the RMS part, which comes after you have correct signed integer values)
Now, I calculate the rms value by dividing the peak-to-peak value by square-root of 2.
Then, 20 * log10(rms) gives me the corresponding decibel value.
rmsValue = peak2peakValue / sqrt2;
DB_Val = 20 * log10(rmsValue);
- Does the above code take care of the " offset " that you mentioned?
- I am yet to find a test plan to verify the calculated decibels, but have I mathematically calculated the decibel value correctly?
c bit-manipulation twos-complement
add a comment |
A similar question has been asked at Need fastest way to convert 2's complement to decimal in C, but I couldn't use it to get my answer, so posting this...
I have 32-bit data coming from an audio sensor in the following format:-
The Data Format is I2S, 24-bit, 2’s compliment, MSB first. The data precision is 18 bits; unused bits are zeros.
Without any audio input, I am able to read the following data from the sensor:-
- 0xFA578000
- 0xFA8AC000
- 0xFA85C000
- 0xFA828000
- 0xFA800000
- 0xFA7E4000
- 0xFA7D0000
- 0xFA7BC000
and so on...
I need to use these data samples to calculate their RMS value, then further use this RMS value to calculate the decibels (20 * log(rms)).
Here is my code with comments:-
//I have 32-bits, with data in the most-significant 24 bits.
inputVal &= 0xFFFFFF00; //Mask the least significant 8 bits.
inputVal = inputVal >> 8; //Data is shifted to least 24 bits. 24th bit is the sign bit.
inputVal &= 0x00FFFFC0; //Mask the least 6 bits, since data precision is 18 bits.
//So, I have got 24-bit data with masked 6 lsb bits. 24th bit is sign bit.
//Converting from 2's complement.
const int negative = (inputVal & (1 << 23)) != 0;
int nativeInt;
if (negative)
nativeInt = inputVal | ~((1 << 24) - 1);
else
nativeInt = inputVal;
return (nativeInt * nativeInt); //Returning the squared value to calculate RMS
After this, I take the average of sum of squared values and calculate its root to get the RMS value.
My questions are,
- Am I doing the data bit-manipulations correctly?
- Is it necessary to convert the data samples from 2's complement to integer to calculate their RMS values?
***********************************************Part-2*****************************************************
Continuing further with @Johnny Johansson's answer:-
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
To normalize the sample set, I have calculated the mean value of the sample set and subtracted it from each value in the sample set.
Then, I found the maximum and minimum values form the sample set and calculated the peak-to-peak value.
// I have the sample set, get the mean
float meanval = 0;
for (int i=0; i <actualNumberOfSamples ; i++)
{
meanval += samples[i];
}
meanval /= actualNumberOfSamples;
printf("Average is: %fn", meanval);
// subtract it from all samples to get a 'normalized' output
for (int i = 0; i < actualNumberOfSamples; i++)
{
samples[i] -= meanval;
}
// find the 'peak to peak' max
float minsample = 100000;
float maxsample = -100000;
float peakToPeakMax = 0.0;
for (int i = 0; i < actualNumberOfSamples; i++)
{
minsample = fmin(minsample, samples[i]);
maxsample = fmax(maxsample, samples[i]);
}
peakToPeakMax = (maxsample - minsample);
printf("The peak-to-peak maximum value is: %fn", peakToPeakMax);
(This does not include the RMS part, which comes after you have correct signed integer values)
Now, I calculate the rms value by dividing the peak-to-peak value by square-root of 2.
Then, 20 * log10(rms) gives me the corresponding decibel value.
rmsValue = peak2peakValue / sqrt2;
DB_Val = 20 * log10(rmsValue);
- Does the above code take care of the " offset " that you mentioned?
- I am yet to find a test plan to verify the calculated decibels, but have I mathematically calculated the decibel value correctly?
c bit-manipulation twos-complement
The masking in the first lineinputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway
– phuclv
Nov 27 '18 at 12:12
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56
add a comment |
A similar question has been asked at Need fastest way to convert 2's complement to decimal in C, but I couldn't use it to get my answer, so posting this...
I have 32-bit data coming from an audio sensor in the following format:-
The Data Format is I2S, 24-bit, 2’s compliment, MSB first. The data precision is 18 bits; unused bits are zeros.
Without any audio input, I am able to read the following data from the sensor:-
- 0xFA578000
- 0xFA8AC000
- 0xFA85C000
- 0xFA828000
- 0xFA800000
- 0xFA7E4000
- 0xFA7D0000
- 0xFA7BC000
and so on...
I need to use these data samples to calculate their RMS value, then further use this RMS value to calculate the decibels (20 * log(rms)).
Here is my code with comments:-
//I have 32-bits, with data in the most-significant 24 bits.
inputVal &= 0xFFFFFF00; //Mask the least significant 8 bits.
inputVal = inputVal >> 8; //Data is shifted to least 24 bits. 24th bit is the sign bit.
inputVal &= 0x00FFFFC0; //Mask the least 6 bits, since data precision is 18 bits.
//So, I have got 24-bit data with masked 6 lsb bits. 24th bit is sign bit.
//Converting from 2's complement.
const int negative = (inputVal & (1 << 23)) != 0;
int nativeInt;
if (negative)
nativeInt = inputVal | ~((1 << 24) - 1);
else
nativeInt = inputVal;
return (nativeInt * nativeInt); //Returning the squared value to calculate RMS
After this, I take the average of sum of squared values and calculate its root to get the RMS value.
My questions are,
- Am I doing the data bit-manipulations correctly?
- Is it necessary to convert the data samples from 2's complement to integer to calculate their RMS values?
***********************************************Part-2*****************************************************
Continuing further with @Johnny Johansson's answer:-
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
To normalize the sample set, I have calculated the mean value of the sample set and subtracted it from each value in the sample set.
Then, I found the maximum and minimum values form the sample set and calculated the peak-to-peak value.
// I have the sample set, get the mean
float meanval = 0;
for (int i=0; i <actualNumberOfSamples ; i++)
{
meanval += samples[i];
}
meanval /= actualNumberOfSamples;
printf("Average is: %fn", meanval);
// subtract it from all samples to get a 'normalized' output
for (int i = 0; i < actualNumberOfSamples; i++)
{
samples[i] -= meanval;
}
// find the 'peak to peak' max
float minsample = 100000;
float maxsample = -100000;
float peakToPeakMax = 0.0;
for (int i = 0; i < actualNumberOfSamples; i++)
{
minsample = fmin(minsample, samples[i]);
maxsample = fmax(maxsample, samples[i]);
}
peakToPeakMax = (maxsample - minsample);
printf("The peak-to-peak maximum value is: %fn", peakToPeakMax);
(This does not include the RMS part, which comes after you have correct signed integer values)
Now, I calculate the rms value by dividing the peak-to-peak value by square-root of 2.
Then, 20 * log10(rms) gives me the corresponding decibel value.
rmsValue = peak2peakValue / sqrt2;
DB_Val = 20 * log10(rmsValue);
- Does the above code take care of the " offset " that you mentioned?
- I am yet to find a test plan to verify the calculated decibels, but have I mathematically calculated the decibel value correctly?
c bit-manipulation twos-complement
A similar question has been asked at Need fastest way to convert 2's complement to decimal in C, but I couldn't use it to get my answer, so posting this...
I have 32-bit data coming from an audio sensor in the following format:-
The Data Format is I2S, 24-bit, 2’s compliment, MSB first. The data precision is 18 bits; unused bits are zeros.
Without any audio input, I am able to read the following data from the sensor:-
- 0xFA578000
- 0xFA8AC000
- 0xFA85C000
- 0xFA828000
- 0xFA800000
- 0xFA7E4000
- 0xFA7D0000
- 0xFA7BC000
and so on...
I need to use these data samples to calculate their RMS value, then further use this RMS value to calculate the decibels (20 * log(rms)).
Here is my code with comments:-
//I have 32-bits, with data in the most-significant 24 bits.
inputVal &= 0xFFFFFF00; //Mask the least significant 8 bits.
inputVal = inputVal >> 8; //Data is shifted to least 24 bits. 24th bit is the sign bit.
inputVal &= 0x00FFFFC0; //Mask the least 6 bits, since data precision is 18 bits.
//So, I have got 24-bit data with masked 6 lsb bits. 24th bit is sign bit.
//Converting from 2's complement.
const int negative = (inputVal & (1 << 23)) != 0;
int nativeInt;
if (negative)
nativeInt = inputVal | ~((1 << 24) - 1);
else
nativeInt = inputVal;
return (nativeInt * nativeInt); //Returning the squared value to calculate RMS
After this, I take the average of sum of squared values and calculate its root to get the RMS value.
My questions are,
- Am I doing the data bit-manipulations correctly?
- Is it necessary to convert the data samples from 2's complement to integer to calculate their RMS values?
***********************************************Part-2*****************************************************
Continuing further with @Johnny Johansson's answer:-
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
To normalize the sample set, I have calculated the mean value of the sample set and subtracted it from each value in the sample set.
Then, I found the maximum and minimum values form the sample set and calculated the peak-to-peak value.
// I have the sample set, get the mean
float meanval = 0;
for (int i=0; i <actualNumberOfSamples ; i++)
{
meanval += samples[i];
}
meanval /= actualNumberOfSamples;
printf("Average is: %fn", meanval);
// subtract it from all samples to get a 'normalized' output
for (int i = 0; i < actualNumberOfSamples; i++)
{
samples[i] -= meanval;
}
// find the 'peak to peak' max
float minsample = 100000;
float maxsample = -100000;
float peakToPeakMax = 0.0;
for (int i = 0; i < actualNumberOfSamples; i++)
{
minsample = fmin(minsample, samples[i]);
maxsample = fmax(maxsample, samples[i]);
}
peakToPeakMax = (maxsample - minsample);
printf("The peak-to-peak maximum value is: %fn", peakToPeakMax);
(This does not include the RMS part, which comes after you have correct signed integer values)
Now, I calculate the rms value by dividing the peak-to-peak value by square-root of 2.
Then, 20 * log10(rms) gives me the corresponding decibel value.
rmsValue = peak2peakValue / sqrt2;
DB_Val = 20 * log10(rmsValue);
- Does the above code take care of the " offset " that you mentioned?
- I am yet to find a test plan to verify the calculated decibels, but have I mathematically calculated the decibel value correctly?
c bit-manipulation twos-complement
c bit-manipulation twos-complement
edited Nov 28 '18 at 8:45
Sandrocottus
asked Nov 20 '18 at 13:58
SandrocottusSandrocottus
198
198
The masking in the first lineinputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway
– phuclv
Nov 27 '18 at 12:12
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56
add a comment |
The masking in the first lineinputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway
– phuclv
Nov 27 '18 at 12:12
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56
The masking in the first line
inputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway– phuclv
Nov 27 '18 at 12:12
The masking in the first line
inputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway– phuclv
Nov 27 '18 at 12:12
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56
add a comment |
1 Answer
1
active
oldest
votes
The 2'complement part seems like it should work, but it is unnecessarily complicated, since regular integers are represented using 2'complement (unless you are on some very exotic hardware). You could simply do this instead:
signed int signedInputVal = (signed int)inputVal;
signedInputVal >>= 14;
This will give you a value in the range -(2^17) to (2^17-1).
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
(This does not include the RMS part, which comes after you have correct signed integer values)
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394650%2fconvert-2s-complement-to-integer-and-calculate-rms-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The 2'complement part seems like it should work, but it is unnecessarily complicated, since regular integers are represented using 2'complement (unless you are on some very exotic hardware). You could simply do this instead:
signed int signedInputVal = (signed int)inputVal;
signedInputVal >>= 14;
This will give you a value in the range -(2^17) to (2^17-1).
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
(This does not include the RMS part, which comes after you have correct signed integer values)
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
add a comment |
The 2'complement part seems like it should work, but it is unnecessarily complicated, since regular integers are represented using 2'complement (unless you are on some very exotic hardware). You could simply do this instead:
signed int signedInputVal = (signed int)inputVal;
signedInputVal >>= 14;
This will give you a value in the range -(2^17) to (2^17-1).
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
(This does not include the RMS part, which comes after you have correct signed integer values)
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
add a comment |
The 2'complement part seems like it should work, but it is unnecessarily complicated, since regular integers are represented using 2'complement (unless you are on some very exotic hardware). You could simply do this instead:
signed int signedInputVal = (signed int)inputVal;
signedInputVal >>= 14;
This will give you a value in the range -(2^17) to (2^17-1).
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
(This does not include the RMS part, which comes after you have correct signed integer values)
The 2'complement part seems like it should work, but it is unnecessarily complicated, since regular integers are represented using 2'complement (unless you are on some very exotic hardware). You could simply do this instead:
signed int signedInputVal = (signed int)inputVal;
signedInputVal >>= 14;
This will give you a value in the range -(2^17) to (2^17-1).
It looks like all your sample values are close to -6800, so I assume that is an offset that you need to account for.
(This does not include the RMS part, which comes after you have correct signed integer values)
answered Nov 27 '18 at 13:11
Johnny JohanssonJohnny Johansson
2107
2107
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
add a comment |
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
Thanks a lot! This worked. Also, I will subtract the offset from the samples. I will open the discussion for the rms part once I arrange my samples in order. Btw, I do not have enough reputation to up-vote your answer, but I have accepted it. Thanks a ton again.
– Sandrocottus
Nov 27 '18 at 13:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394650%2fconvert-2s-complement-to-integer-and-calculate-rms-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The masking in the first line
inputVal &= 0xFFFFFF00
is redundant, since you're going to shift those bits out anyway– phuclv
Nov 27 '18 at 12:12
Regarding Part-2: The offset part looks good, but beyond that I am not sure what is happening. I see no sign of any RMS calculations and using the peak values looks weird to me. (Although I don't actually know how to calculate dB from this kind of data). Perhaps it would be better to ask a new question specifically about converting the data you have to a dB value...
– Johnny Johansson
Nov 29 '18 at 8:43
Thanks a lot! I will ask a new question regarding the converting the values to dB. Your suggestions were very helpful. Thanks once again :-)
– Sandrocottus
Nov 29 '18 at 8:56