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

Unable to sample_seekg to the last sample in an AIFF file #52

Open
ghost opened this issue Dec 16, 2020 · 0 comments
Open

Unable to sample_seekg to the last sample in an AIFF file #52

ghost opened this issue Dec 16, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 16, 2020

Using an AIFF file as input, I am unable to sample_seekg to the last sample in the file. If, however, I read the file sequentially using the extraction operator, I can read all samples in the file (including the last one). I tested this on 7e2de4b.

The following example shows the issue:

    auto in = audio::ifstream{getSamplePath("sample.aif")};
    const auto inputSampleCount =
      static_cast<int>(in.seekg(0, std::ios::end).sample_tellg());

    float value;
    if (in.sample_seekg(inputSampleCount - 1) >> value)
    {
        // this code is never executed
    }

My expectation would have been to be able to sample_seekg to all samples in the file, understanding its argument as an index from zero to inputSampleCount - 1.

Consider the following code, using the same input as above:

    auto in = audio::ifstream{getSamplePath("sample.aif")};
    const auto inputSampleCount =
      static_cast<int>(in.seekg(0, std::ios::end).sample_tellg());

    auto readCount = 0;
    float value;
    in.seekg(0, std::ios::beg);
    while (in >> value)
    {
      ++readCount;
    }

At the end of the execution, readCount == inputSampleCount (as expected).

Furthermore, consider the following example in which each sample is sample_seekg to individually:

    auto in = audio::ifstream{getSamplePath("sample.aif")};
    const auto inputSampleCount =
      static_cast<int>(in.seekg(0, std::ios::end).sample_tellg());

    auto readCount = 0;
    float value;
    in.seekg(0, std::ios::beg);
    while (in.sample_seekg(readCount) >> value)
    {
      ++readCount;
      if (readCount == inputSampleCount)
      {
        break;
      }
    }

At the end of the execution, readCount == inputSampleCount - 1, which is not what I expected (I expected readCount == inputSampleCount).

Am I understanding the API incorrectly here?

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

0 participants