Exemple #1
0
bool InputSoundFile::openFromMemory(const void* data, std::size_t sizeInBytes)
{
    // If the file is already open, first close it
    close();

    // Find a suitable reader for the file type
    m_reader = SoundFileFactory::createReaderFromMemory(data, sizeInBytes);
    if (!m_reader)
        return false;

    // Wrap the memory file into a stream
    MemoryInputStream* memory = new MemoryInputStream;
    m_stream = memory;
    m_streamOwned = true;

    // Open it
    memory->open(data, sizeInBytes);

    // Pass the stream to the reader
    SoundFileReader::Info info;
    if (!m_reader->open(*memory, info))
    {
        close();
        return false;
    }

    // Retrieve the attributes of the open sound file
    m_sampleCount = info.sampleCount;
    m_channelCount = info.channelCount;
    m_sampleRate = info.sampleRate;

    return true;
}