Ejemplo n.º 1
0
void SoundFileWriterOgg::write(const Int16* samples, Uint64 count)
{
    // Vorbis has issues with buffers that are too large, so we ask for 64K
    static const int bufferSize = 65536;

    // A frame contains a sample from each channel
    int frameCount = static_cast<int>(count / m_channelCount);

    while (frameCount > 0)
    {
        // Prepare a buffer to hold our samples
        float** buffer = vorbis_analysis_buffer(&m_state, bufferSize);
        assert(buffer);

        // Write the samples to the buffer, converted to float
        for (int i = 0; i < std::min(frameCount, bufferSize); ++i)
            for (unsigned int j = 0; j < m_channelCount; ++j)
                buffer[j][i] = *samples++ / 32767.0f;

        // Tell the library how many samples we've written
        vorbis_analysis_wrote(&m_state, std::min(frameCount, bufferSize));
        
        frameCount -= bufferSize;

        // Flush any produced block
        flushBlocks();
    }
}
Ejemplo n.º 2
0
Block *ABFile::getWriteBlock(off_t offset) {

	Lock l(mMutex);
	int blocknr = BLOCKNR(offset);
	std::_Rb_tree_iterator<std::pair<const int, Block*> > blockit;
	blockit = mBlocks.find(blocknr);

	if (blockit == mBlocks.end()) {
		Block *block = new Block(this, blocknr);
		block->mLastUse = mCounter++;
		mBlocks[blocknr] = block;
		flushBlocks();
		return block;
	} else
		return blockit->second;

}
Ejemplo n.º 3
0
void SoundFileWriterOgg::close()
{
    if (m_file.is_open())
    {
        // Submit an empty packet to mark the end of stream
        vorbis_analysis_wrote(&m_state, 0);
        flushBlocks();

        // Close the file
        m_file.close();
    }

    // Clear all the ogg/vorbis structures
    ogg_stream_clear(&m_ogg);
    vorbis_dsp_clear(&m_state);
    vorbis_info_clear(&m_vorbis);
}