本文整理汇总了C++中audio::AudioStream::readBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioStream::readBuffer方法的具体用法?C++ AudioStream::readBuffer怎么用?C++ AudioStream::readBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audio::AudioStream
的用法示例。
在下文中一共展示了AudioStream::readBuffer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
extern "C" int SimpleRate_readFudge(Audio::AudioStream &input, int16 *a, int b)
{
#ifdef DEBUG_RATECONV
debug("Reading ptr=%x n%d", a, b);
#endif
return input.readBuffer(a, b);
}
示例2: preFetchCompSpeech
uint32 Sound::preFetchCompSpeech(uint32 speechId, uint16 **buf) {
int cd = _vm->_resman->getCD();
uint32 numSamples;
SoundFileHandle *fh = (cd == 1) ? &_speechFile[0] : &_speechFile[1];
Audio::AudioStream *input = getAudioStream(fh, "speech", cd, speechId, &numSamples);
if (!input)
return 0;
*buf = NULL;
// Decompress data into speech buffer.
uint32 bufferSize = 2 * numSamples;
*buf = (uint16 *)malloc(bufferSize);
if (!*buf) {
delete input;
fh->file.close();
return 0;
}
uint32 readSamples = input->readBuffer((int16 *)*buf, numSamples);
fh->file.close();
delete input;
return 2 * readSamples;
}
示例3: playSoundData
void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint sound, int pan, int vol, bool loop) {
byte *buffer, flags;
uint16 compType;
int blockAlign, rate;
int size = READ_LE_UINT32(soundData + 4);
Common::MemoryReadStream stream(soundData, size);
if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign)) {
error("playSoundData: Not a valid WAV data");
}
// The Feeble Files originally used DirectSound, which specifies volume
// and panning differently than ScummVM does, using a logarithmic scale
// rather than a linear one.
//
// Volume is a value between -10,000 and 0.
// Panning is a value between -10,000 and 10,000.
//
// In both cases, the -10,000 represents -100 dB. When panning, only
// one speaker's volume is affected - just like in ScummVM - with
// negative values affecting the left speaker, and positive values
// affecting the right speaker. Thus -10,000 means the left speaker is
// silent.
int v, p;
vol = CLIP(vol, -10000, 0);
pan = CLIP(pan, -10000, 10000);
if (vol) {
v = (int)((double)Audio::Mixer::kMaxChannelVolume * pow(10.0, (double)vol / 2000.0) + 0.5);
} else {
v = Audio::Mixer::kMaxChannelVolume;
}
if (pan < 0) {
p = (int)(255.0 * pow(10.0, (double)pan / 2000.0) + 127.5);
} else if (pan > 0) {
p = (int)(255.0 * pow(10.0, (double)pan / -2000.0) - 127.5);
} else {
p = 0;
}
if (loop == true)
flags |= Audio::Mixer::FLAG_LOOP;
if (compType == 2) {
Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
buffer = (byte *)malloc(size * 4);
size = sndStream->readBuffer((int16*)buffer, size * 2);
size *= 2; // 16bits.
delete sndStream;
} else {
buffer = (byte *)malloc(size);
memcpy(buffer, soundData + stream.pos(), size);
}
_mixer->playRaw(handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE, -1, v, p);
}
示例4: fprintf
extern "C" int SimpleRate_readFudge(Audio::AudioStream &input,
int16 *a, int b)
{
#ifdef DEBUG_RATECONV
fprintf(stderr, "Reading ptr=%x n%d\n", a, b);
fflush(stderr);
#endif
return input.readBuffer(a, b);
}
示例5: readBuffer
int LoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) {
if (!_loop) {
return _stream->readBuffer(buffer, numSamples);
}
int16 *buf = buffer;
int samplesLeft = numSamples;
while (samplesLeft > 0) {
int len = _stream->readBuffer(buf, samplesLeft);
if (len < samplesLeft) {
delete _stream;
_stream = _parent->makeAudioStream(_loopSound);
}
samplesLeft -= len;
buf += len;
}
return numSamples;
}
示例6: cmdRawToWav
bool Console::cmdRawToWav(int argc, const char **argv) {
if (argc != 3) {
debugPrintf("Use %s <rawFilePath> <wavFileName> to dump a .RAW file to .WAV\n", argv[0]);
return true;
}
Common::File file;
if (!_engine->getSearchManager()->openFile(file, argv[1])) {
warning("File not found: %s", argv[1]);
return true;
}
Audio::AudioStream *audioStream = makeRawZorkStream(argv[1], _engine);
Common::DumpFile output;
output.open(argv[2]);
output.writeUint32BE(MKTAG('R', 'I', 'F', 'F'));
output.writeUint32LE(file.size() * 2 + 36);
output.writeUint32BE(MKTAG('W', 'A', 'V', 'E'));
output.writeUint32BE(MKTAG('f', 'm', 't', ' '));
output.writeUint32LE(16);
output.writeUint16LE(1);
uint16 numChannels;
if (audioStream->isStereo()) {
numChannels = 2;
output.writeUint16LE(2);
} else {
numChannels = 1;
output.writeUint16LE(1);
}
output.writeUint32LE(audioStream->getRate());
output.writeUint32LE(audioStream->getRate() * numChannels * 2);
output.writeUint16LE(numChannels * 2);
output.writeUint16LE(16);
output.writeUint32BE(MKTAG('d', 'a', 't', 'a'));
output.writeUint32LE(file.size() * 2);
int16 *buffer = new int16[file.size()];
audioStream->readBuffer(buffer, file.size());
#ifndef SCUMM_LITTLE_ENDIAN
for (int i = 0; i < file.size(); ++i)
buffer[i] = TO_LE_16(buffer[i]);
#endif
output.write(buffer, file.size() * 2);
delete[] buffer;
return true;
}
示例7: getAudioStream
void AVIDecoder::AVIAudioTrack::skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime) {
Audio::Timestamp timeDiff = time.convertToFramerate(_wvInfo.samplesPerSec) - frameTime.convertToFramerate(_wvInfo.samplesPerSec);
int skipFrames = timeDiff.totalNumberOfFrames();
if (skipFrames <= 0)
return;
Audio::AudioStream *audioStream = getAudioStream();
if (!audioStream)
return;
if (audioStream->isStereo())
skipFrames *= 2;
int16 *tempBuffer = new int16[skipFrames];
audioStream->readBuffer(tempBuffer, skipFrames);
delete[] tempBuffer;
}
示例8: queueBuffer
void AppendableSnd::queueBuffer(Common::SeekableReadStream *bufferIn) {
assert (_as);
// Setup the ADPCM decoder
uint32 sizeIn = bufferIn->size();
Audio::AudioStream *adpcm = makeDecoder(bufferIn, sizeIn);
// Setup the output buffer
uint32 sizeOut = sizeIn * 2;
byte *bufferOut = new byte[sizeOut * 2];
// Decode to raw samples
sizeOut = adpcm->readBuffer((int16 *)bufferOut, sizeOut);
assert (adpcm->endOfData());
delete adpcm;
// Queue the decoded samples
_as->queueBuffer(bufferOut, sizeOut * 2);
}
示例9: convertRawToWav
void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Common::String &outputFile) {
Common::File file;
if (!file.open(inputFile))
return;
Audio::AudioStream *audioStream = makeRawZorkStream(inputFile, engine);
Common::DumpFile output;
output.open(outputFile);
output.writeUint32BE(MKTAG('R', 'I', 'F', 'F'));
output.writeUint32LE(file.size() * 2 + 36);
output.writeUint32BE(MKTAG('W', 'A', 'V', 'E'));
output.writeUint32BE(MKTAG('f', 'm', 't', ' '));
output.writeUint32LE(16);
output.writeUint16LE(1);
uint16 numChannels;
if (audioStream->isStereo()) {
numChannels = 2;
output.writeUint16LE(2);
} else {
numChannels = 1;
output.writeUint16LE(1);
}
output.writeUint32LE(audioStream->getRate());
output.writeUint32LE(audioStream->getRate() * numChannels * 2);
output.writeUint16LE(numChannels * 2);
output.writeUint16LE(16);
output.writeUint32BE(MKTAG('d', 'a', 't', 'a'));
output.writeUint32LE(file.size() * 2);
int16 *buffer = new int16[file.size()];
audioStream->readBuffer(buffer, file.size());
output.write(buffer, file.size() * 2);
delete[] buffer;
}
示例10: readBuffer
int readBuffer(int16 *buffer, const int numSamples) {
return _stream->readBuffer(buffer, numSamples);
}
示例11: playHESound
//.........这里部分代码省略.........
assert(heOffset >= 0 && heOffset < size);
// FIXME: Disabled sound offsets, due to asserts been triggered
heOffset = 0;
_vm->setHETimer(heChannel + 4);
_heChannel[heChannel].sound = soundID;
_heChannel[heChannel].priority = priority;
_heChannel[heChannel].rate = rate;
_heChannel[heChannel].sbngBlock = (codeOffs != -1) ? 1 : 0;
_heChannel[heChannel].codeOffs = codeOffs;
memset(_heChannel[heChannel].soundVars, 0, sizeof(_heChannel[heChannel].soundVars));
// TODO: Extra sound flags
if (heFlags & 1) {
_heChannel[heChannel].timer = 0;
} else {
_heChannel[heChannel].timer = size * 1000 / rate;
}
_mixer->stopHandle(_heSoundChannels[heChannel]);
if (compType == 17) {
Audio::AudioStream *voxStream = Audio::makeADPCMStream(&memStream, DisposeAfterUse::NO, size, Audio::kADPCMMSIma, rate, (flags & Audio::FLAG_STEREO) ? 2 : 1, blockAlign);
// FIXME: Get rid of this crude hack to turn a ADPCM stream into a raw stream.
// It seems it is only there to allow looping -- if that is true, we certainly
// can do without it, using a LoopingAudioStream.
byte *sound = (byte *)malloc(size * 4);
/* On systems where it matters, malloc will return
* even addresses, so the use of (void *) in the
* following cast shuts the compiler from warning
* unnecessarily. */
size = voxStream->readBuffer((int16*)(void *)sound, size * 2);
size *= 2; // 16bits.
delete voxStream;
_heChannel[heChannel].rate = rate;
if (_heChannel[heChannel].timer)
_heChannel[heChannel].timer = size * 1000 / rate;
// makeADPCMStream returns a stream in native endianness, but RawMemoryStream
// defaults to big endian. If we're on a little endian system, set the LE flag.
#ifdef SCUMM_LITTLE_ENDIAN
flags |= Audio::FLAG_LITTLE_ENDIAN;
#endif
stream = Audio::makeRawStream(sound + heOffset, size - heOffset, rate, flags);
} else {
stream = Audio::makeRawStream(ptr + memStream.pos() + heOffset, size - heOffset, rate, flags, DisposeAfterUse::NO);
}
_mixer->playStream(type, &_heSoundChannels[heChannel],
Audio::makeLoopingAudioStream(stream, (heFlags & 1) ? 0 : 1), soundID);
}
// Support for sound in Humongous Entertainment games
else if (READ_BE_UINT32(ptr) == MKTAG('D','I','G','I') || READ_BE_UINT32(ptr) == MKTAG('T','A','L','K')) {
byte *sndPtr = ptr;
int codeOffs = -1;
priority = (soundID > _vm->_numSounds) ? 255 : *(ptr + 18);
rate = READ_LE_UINT16(ptr + 22);
// Skip DIGI/TALK (8) and HSHD (24) blocks
ptr += 32;
if (_mixer->isSoundHandleActive(_heSoundChannels[heChannel])) {
int curSnd = _heChannel[heChannel].sound;
示例12: playHESound
//.........这里部分代码省略.........
size = READ_LE_UINT32(ptr + 4);
Common::MemoryReadStream stream(ptr, size);
if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign)) {
error("playHESound: Not a valid WAV file (%d)", soundID);
}
assert(heOffset >= 0 && heOffset < size);
// FIXME: Disabled sound offsets, due to asserts been triggered
heOffset = 0;
_vm->setHETimer(heChannel + 4);
_heChannel[heChannel].sound = soundID;
_heChannel[heChannel].priority = priority;
_heChannel[heChannel].rate = rate;
_heChannel[heChannel].sbngBlock = (codeOffs != -1) ? 1 : 0;
_heChannel[heChannel].codeOffs = codeOffs;
memset(_heChannel[heChannel].soundVars, 0, sizeof(_heChannel[heChannel].soundVars));
// TODO: Extra sound flags
if (heFlags & 1) {
flags |= Audio::Mixer::FLAG_LOOP;
_heChannel[heChannel].timer = 0;
} else {
_heChannel[heChannel].timer = size * 1000 / rate;
}
_mixer->stopHandle(_heSoundChannels[heChannel]);
if (compType == 17) {
Audio::AudioStream *voxStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
sound = (char *)malloc(size * 4);
size = voxStream->readBuffer((int16*)sound, size * 2);
size *= 2; // 16bits.
delete voxStream;
_heChannel[heChannel].rate = rate;
if (_heChannel[heChannel].timer)
_heChannel[heChannel].timer = size * 1000 / rate;
flags |= Audio::Mixer::FLAG_AUTOFREE;
_mixer->playRaw(type, &_heSoundChannels[heChannel], sound + heOffset, size - heOffset, rate, flags, soundID);
} else {
_mixer->playRaw(type, &_heSoundChannels[heChannel], ptr + stream.pos() + heOffset, size - heOffset, rate, flags, soundID);
}
}
// Support for sound in Humongous Entertainment games
else if (READ_BE_UINT32(ptr) == MKID_BE('DIGI') || READ_BE_UINT32(ptr) == MKID_BE('TALK')) {
byte *sndPtr = ptr;
int codeOffs = -1;
priority = (soundID > _vm->_numSounds) ? 255 : *(ptr + 18);
rate = READ_LE_UINT16(ptr + 22);
// Skip DIGI/TALK (8) and HSHD (24) blocks
ptr += 32;
if (_mixer->isSoundHandleActive(_heSoundChannels[heChannel])) {
int curSnd = _heChannel[heChannel].sound;
if (curSnd == 1 && soundID != 1)
return;
if (curSnd != 0 && curSnd != 1 && soundID != 1 && _heChannel[heChannel].priority > priority)
return;
}
示例13: load
//.........这里部分代码省略.........
} else {
// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded
if (!uncompressedSound && !scumm_stricmp(context->fileName(), "voicesd.rsc"))
resourceType = kSoundVOX;
}
}
buffer.buffer = NULL;
// Check for LE sounds
if (!context->isBigEndian())
buffer.flags |= Audio::FLAG_LITTLE_ENDIAN;
if ((context->fileType() & GAME_VOICEFILE) && (_vm->getFeatures() & GF_LE_VOICES))
buffer.flags |= Audio::FLAG_LITTLE_ENDIAN;
// Older Mac versions of ITE were Macbinary packed
int soundOffset = (context->fileType() & GAME_MACBINARY) ? 36 : 0;
switch (resourceType) {
case kSoundPCM:
buffer.size = soundResourceLength - soundOffset;
if (!onlyHeader) {
buffer.buffer = (byte *) malloc(buffer.size);
if (soundOffset > 0)
readS.skip(soundOffset);
readS.read(buffer.buffer, buffer.size);
}
result = true;
break;
case kSoundVOX:
buffer.size = soundResourceLength * 4;
if (!onlyHeader) {
voxStream = Audio::makeADPCMStream(&readS, DisposeAfterUse::NO, soundResourceLength, Audio::kADPCMOki);
buffer.buffer = (byte *)malloc(buffer.size);
voxStream->readBuffer((int16*)buffer.buffer, soundResourceLength * 2);
delete voxStream;
}
result = true;
break;
case kSoundWAV:
case kSoundAIFF:
case kSoundShorten:
case kSoundVOC:
if (resourceType == kSoundWAV) {
result = Audio::loadWAVFromStream(readS, size, rate, buffer.flags);
} else if (resourceType == kSoundAIFF) {
result = Audio::loadAIFFFromStream(readS, size, rate, buffer.flags);
#ifdef ENABLE_SAGA2
} else if (resourceType == kSoundShorten) {
result = loadShortenFromStream(readS, size, rate, buffer.flags);
#endif
} else if (resourceType == kSoundVOC) {
data = Audio::loadVOCFromStream(readS, size, rate);
result = (data != NULL);
if (onlyHeader)
free(data);
buffer.flags |= Audio::FLAG_UNSIGNED;
buffer.flags &= ~Audio::FLAG_16BITS;
buffer.flags &= ~Audio::FLAG_STEREO;
}
if (result) {
buffer.frequency = rate;
buffer.size = size;
if (!onlyHeader) {
if (resourceType == kSoundVOC) {