I am using the length of my PCM data buffer to calculate the number of
frames; depending if its mono or stereo or 8bit or 16bit.

For example, if it is a mono/8bit then the number of frames is the
length of the buffer. if it is stereo/16bit the number of frames is
the length / 4.

The problem is that the buffer, I create by reading the PCM raw
resource (file), seems to be too long (look below) . Therefore the
number of frames is also too heigh. why am I getting the buffer longer
then it should be?

there is another way to calculate the number of frames;



Number of Frames = <Sample Rate> * <duration of the PCM sample in [ms]
>

for example 11.025[kHz] * 4000 [ms] = 44100 [frames]

the above calculations should yield the same result, yet they don’t
(the problem is with the buffer length). I am certain that the second
result is correct. am I doing something wrong with the way I read in
the data? I should put it into the WHILE loop when reading. But that’s
not it.



Here is how I create the buffer;



private byte[] readResource (int resourceId)
{
    InputStream inputStream = null;
    byte[]  inputBuffer = null;
    try
    {
        inputStream = _Context.getResources().openRawResource
(resourceId);
        inputBuffer = new byte [inputStream.available()];
        inputStream.read(inputBuffer);
    }
    catch (IOException e)
    {
        Log.e(this.getClass().getName(), String.format("readResource:
Exception: %s", e.getMessage()));
    }
    finally
    {
        try
        {
            inputStream.close();
        }
        catch (IOException e)
        {
            Log.e(this.getClass().getName(), String.format
("readResource: Exception: %s", e.getMessage()));
        }
    }
    return inputBuffer;
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to