Esempio n. 1
0
int WavReader::read(unsigned max_samples)
{
    m_Dest.clear();

    if (m_ADPCM)
        return decodeADPCM(max_samples);

    unsigned left = m_SourceSize - m_SourceOffset;

    // 16 bit, 1 ch
    unsigned max_bytes = max_samples * 2;
    if (left > max_bytes)
        left = max_bytes;

    m_Dest.resize(left);
    memcpy(&m_Dest[0], &m_Source[m_SourceOffset], left);

    m_SourceOffset += left;
    return left;
}
Esempio n. 2
0
bool AudioStreamInstance::readPacket() {
	debugC(5, kDebugAudio, "readPacket()");

	if (_file->eos() || (_currentReadSize >= _totalSize)) {
		if (_looping) {
			_file->seek(8);
			_currentReadSize = 8;
			_lastSample = 0;
			_lastStepIndex = 0;
		} else {
			_bufferSize = 0;
			stopNow();
			return false;
		}
	}
	int16 numCompressedBytes = _file->readSint16LE();
	int16 numDecompressedBytes = _file->readSint16LE();
	_file->readSint32LE();

	if (numCompressedBytes > _compBufferSize) {
		delete[] _compBuffer;
		_compBufferSize = numCompressedBytes;
		_compBuffer = new uint8[_compBufferSize];
	}

	if (numDecompressedBytes > _bufferMaxSize) {
		delete[] _buffer;
		_bufferMaxSize = numDecompressedBytes;
		_buffer = new int16[numDecompressedBytes];
	}

	_bufferSize = numDecompressedBytes;
	_file->read(_compBuffer, numCompressedBytes);
	_currentReadSize += 8 + numCompressedBytes;

	decodeADPCM(_compBuffer, _buffer, numCompressedBytes);
	return true;
}
Esempio n. 3
0
// ***************************************************************************
void	CBufferFMod::loadDataToFMod(const uint8 *data)
{
    // Delete old one
    if(_FModSample)
    {
        FSOUND_Sample_Free(_FModSample);
        _FModSample= NULL;
    }

    // if some data, create new one
    if(data)
    {
        uint8 *tmpData = NULL;
        const uint8	*uploadData = data;

        // if format is ADPCM, decode into Mono16
        if(_Format==Mono16ADPCM)
        {
            // create Mono16 dest buffer
            uint	nbSample= _Size*2;
            tmpData= new uint8 [nbSample * sizeof(sint16)];

            // uncompress
            TADPCMState	state;
            state.PreviousSample = 0;
            state.StepIndex = 0;
            decodeADPCM(data, (sint16*)tmpData, nbSample, state);

            // change upload data, _Format and _Size to fit the new format
            uploadData= tmpData;
            _Format= Mono16;
            _Size= nbSample*2;
        }

        // create FMod sample and upload according to format
        uint32	type= 0;
        switch(_Format)
        {
        case Mono8:
            type= FSOUND_8BITS|FSOUND_MONO;
            break;
        case Mono16:
            type= FSOUND_16BITS|FSOUND_MONO;
            break;
        case Stereo8:
            type= FSOUND_8BITS|FSOUND_STEREO;
            break;
        case Stereo16:
            type= FSOUND_16BITS|FSOUND_STEREO;
            break;
        default:
            nlstop;
        };
        uint32	commonType= FSOUND_LOADRAW|FSOUND_LOOP_NORMAL|FSOUND_LOADMEMORY;
        // if can use hardware buffer
        if(!CSoundDriverFMod::getInstance()->forceSofwareBuffer())
            commonType|= FSOUND_HW3D;
        // create FMod sample
        _FModSample= FSOUND_Sample_Load(FSOUND_FREE, (const char*)uploadData, commonType|type, 0, _Size);

        // clear any temporary data
        if(tmpData)
        {
            delete [] tmpData;
        }
    }
}