本文整理汇总了C++中ov_open_callbacks函数的典型用法代码示例。如果您正苦于以下问题:C++ ov_open_callbacks函数的具体用法?C++ ov_open_callbacks怎么用?C++ ov_open_callbacks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ov_open_callbacks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file
OggSoundFile::OggSoundFile(PHYSFS_file* file_, double loop_begin_, double loop_at_) :
file(),
vorbis_file(),
loop_begin(),
loop_at(),
normal_buffer_loop()
{
this->file = file_;
ov_callbacks callbacks = { cb_read, cb_seek, cb_close, cb_tell };
ov_open_callbacks(file, &vorbis_file, 0, 0, callbacks);
vorbis_info* vi = ov_info(&vorbis_file, -1);
channels = vi->channels;
rate = vi->rate;
bits_per_sample = 16;
size = static_cast<size_t> (ov_pcm_total(&vorbis_file, -1) * 2);
double samples_begin = loop_begin_ * rate;
double sample_loop = loop_at_ * rate;
this->loop_begin = (ogg_int64_t) samples_begin;
if(loop_begin_ < 0) {
this->loop_at = (ogg_int64_t) -1;
} else {
this->loop_at = (ogg_int64_t) sample_loop;
}
}
示例2: StreamingBuffer
//----------------------------------------------------------------------------//
OggStream::OggStream(const Ogre::String& name, SoundSource* source, int bufferCount) :
StreamingBuffer(name, source, bufferCount)
{
ov_callbacks vorbisCallbacks;
// read file to memory
mStream = Ogre::ResourceGroupManager::getSingleton().openResource(name);
// open ogg stream
vorbisCallbacks.read_func = OggBuffer::vorbisRead;
vorbisCallbacks.close_func = OggBuffer::vorbisClose;
vorbisCallbacks.seek_func = OggBuffer::vorbisSeek;
vorbisCallbacks.tell_func = OggBuffer::vorbisTell;
if (ov_open_callbacks(&mStream, &mOggStream, nullptr, 0, vorbisCallbacks) < 0)
{
throw Ogre::Exception(1, "Could not open Ogg stream.",__FUNCTION__);
}
mVorbisInfo = ov_info(&mOggStream, -1);
mVorbisComment = ov_comment(&mOggStream, -1);
mChannels = mVorbisInfo->channels;
mFrequency = mVorbisInfo->rate;
mDuration = float(ov_time_total(&mOggStream, -1));
mBits = 16;
if(mChannels == 1)
mFormat = AL_FORMAT_MONO16;
else
mFormat = AL_FORMAT_STEREO16;
mSize = mDuration * float(mBits * mFrequency * mChannels) / 8.0f;
}
示例3: memset
RageSoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open( RageFileBasic *pFile )
{
m_pFile = pFile;
vf = new OggVorbis_File;
memset( vf, 0, sizeof(*vf) );
ov_callbacks callbacks;
callbacks.read_func = OggRageFile_read_func;
callbacks.seek_func = OggRageFile_seek_func;
callbacks.close_func = OggRageFile_close_func;
callbacks.tell_func = OggRageFile_tell_func;
int ret = ov_open_callbacks( pFile, vf, NULL, 0, callbacks );
if( ret < 0 )
{
SetError( ov_ssprintf(ret, "ov_open failed") );
delete vf;
vf = NULL;
switch( ret )
{
case OV_ENOTVORBIS:
return OPEN_UNKNOWN_FILE_FORMAT;
default:
return OPEN_FATAL_ERROR;
}
}
eof = false;
read_offset = (int) ov_pcm_tell(vf);
vorbis_info *vi = ov_info( vf, -1 );
channels = vi->channels;
return OPEN_OK;
}
示例4: ogg_vorbis_open
/*!
* \brief Create a new OGG/Vorbis filestream and set it up for reading.
* \param s File that points to on disk storage of the OGG/Vorbis data.
* \return The new filestream.
*/
static int ogg_vorbis_open(struct ast_filestream *s)
{
int result;
struct ogg_vorbis_desc *desc = (struct ogg_vorbis_desc *) s->_private;
/* initialize private description block */
memset(desc, 0, sizeof(struct ogg_vorbis_desc));
desc->writing = 0;
/* actually open file */
result = ov_open_callbacks(s->f, &desc->ov_f, NULL, 0, OV_CALLBACKS_NOCLOSE);
if (result != 0) {
ast_log(LOG_ERROR, "Error opening Ogg/Vorbis file stream.\n");
return -1;
}
/* check stream(s) type */
if (desc->ov_f.vi->channels != 1) {
ast_log(LOG_ERROR, "Only monophonic OGG/Vorbis files are currently supported!\n");
ov_clear(&desc->ov_f);
return -1;
}
if (desc->ov_f.vi->rate != DEFAULT_SAMPLE_RATE) {
ast_log(LOG_ERROR, "Only 8000Hz OGG/Vorbis files are currently supported!\n");
ov_clear(&desc->ov_f);
return -1;
}
return 0;
}
示例5: Decoder
VorbisDecoder::VorbisDecoder(Data * data, const std::string & ext, int bufferSize)
: Decoder(data, ext, bufferSize)
{
// Initialize callbacks
vorbisCallbacks.close_func = vorbisClose;
vorbisCallbacks.seek_func = vorbisSeek;
vorbisCallbacks.read_func = vorbisRead;
vorbisCallbacks.tell_func = vorbisTell;
// Check endianness
#ifdef LOVE_BIG_ENDIAN
endian = 1;
#else
endian = 0;
#endif
// Initialize OGG file
oggFile.dataPtr = (char *) data->getData();
oggFile.dataSize = data->getSize();
oggFile.dataRead = 0;
// Open Vorbis handle
if(ov_open_callbacks(&oggFile, &handle, NULL, 0, vorbisCallbacks) < 0)
throw love::Exception("Could not read Ogg bitstream");
// Get info and comments
vorbisInfo = ov_info(&handle, -1);
vorbisComment = ov_comment(&handle, -1);
}
示例6: ov_open_callbacks
unsigned int OggResourceLoader::VGetLoadedResourceSize(char *rawBuffer, unsigned int rawSize){
OggVorbis_File vf;
ov_callbacks oggCallbacks;
OggMemoryFile *vorbisMemoryFile = new OggMemoryFile;
vorbisMemoryFile->dataRead = 0;
vorbisMemoryFile->dataSize = rawSize;
vorbisMemoryFile->dataPtr = (unsigned char *)rawBuffer;
oggCallbacks.read_func = VorbisRead;
oggCallbacks.close_func = VorbisClose;
oggCallbacks.seek_func = VorbisSeek;
oggCallbacks.tell_func = VorbisTell;
int ov_ret = ov_open_callbacks(vorbisMemoryFile, &vf, NULL, 0, oggCallbacks);
//DEBUG_LOG(ov_ret >= 0);
//read in vorbis
vorbis_info *vi = ov_info(&vf, -1);
DWORD size = 4096 * 16;
DWORD pos = 0;
int sec = 0;
int ret = 1;
DWORD bytes = (DWORD)ov_pcm_total(&vf, -1);
bytes *= 2 * vi->channels;
ov_clear(&vf);
SafeDelete(vorbisMemoryFile);
return bytes;
}
示例7: logg_open_file_for_streaming
static int logg_open_file_for_streaming(LOGG_Stream* s)
{
FILE* file;
vorbis_info* vi;
file = fopen(s->filename, "rb");
if (!file) {
uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, "Unable to open file: %s", s->filename);
return 1;
}
if (ov_open_callbacks(file, &s->ovf, 0, 0, OV_CALLBACKS_DEFAULT) != 0) {
strncpy(allegro_error, "ov_open_callbacks failed.", ALLEGRO_ERROR_SIZE);
fclose(file);
return 1;
}
vi = ov_info(&s->ovf, -1);
s->bits = 16;
s->stereo = vi->channels > 1 ? 1 : 0;
s->freq = vi->rate;
s->len = ov_pcm_total(&s->ovf, -1);
return 0;
}
示例8: CI_ASSERT
void SourceFileImplOggVorbis::init()
{
CI_ASSERT( mDataSource );
if( mDataSource->isFilePath() ) {
int status = ov_fopen( mDataSource->getFilePath().string().c_str(), &mOggVorbisFile );
if( status )
throw AudioFileExc( string( "Failed to open Ogg Vorbis file with error: " ), (int32_t)status );
}
else {
mStream = mDataSource->createStream();
ov_callbacks callbacks;
callbacks.read_func = readFn;
callbacks.seek_func = seekFn;
callbacks.close_func = closeFn;
callbacks.tell_func = tellFn;
int status = ov_open_callbacks( this, &mOggVorbisFile, NULL, 0, callbacks );
CI_ASSERT( status == 0 );
}
vorbis_info *info = ov_info( &mOggVorbisFile, -1 );
mSampleRate = mNativeSampleRate = info->rate;
mNumChannels = mNativeNumChannels = info->channels;
ogg_int64_t totalFrames = ov_pcm_total( &mOggVorbisFile, -1 );
mNumFrames = mFileNumFrames = static_cast<uint32_t>( totalFrames );
}
示例9: CreateFromMemory
OggAudio* OggAudio::CreateFromMemory(const FileIdRef& fileId, MemoryData data)
{
ov_callbacks callbacks;
callbacks.read_func = ogg_read_func;
callbacks.seek_func = ogg_seek_func;
callbacks.close_func = ogg_close_func;
callbacks.tell_func = ogg_tell_func;
OggVorbis_File vf;
MemoryStream oggStream = MemoryStream::OpenRead(data);
if (ov_open_callbacks(&oggStream, &vf, nullptr, 0, callbacks))
{
Log::FormatError("{} does not appear to be an Ogg bitstream.", fileId.Name);
return nullptr;
}
vorbis_info* vi = ov_info(&vf, -1);
uintp sampleCount = (uintp)ov_pcm_total(&vf, -1);
bool seekable = ov_seekable(&vf)!=0;
uint bigEndian = !BitConverter::IsLittle();
int currentSection = 0;
uintp pcmSize = sampleCount*vi->channels*sizeof(short);
MemoryStream pcmSteam(pcmSize);
while (true)
{
long readSize = ov_read(&vf, (char*)pcmSteam.MutablePtr(), (int)pcmSteam.LeftLength(), bigEndian, 2, 1, ¤tSection);
if (readSize == 0)
{
//end of file
break;
}
else if (readSize > 0)
{
pcmSteam.Seek(readSize, SeekOrigin::Current);
}
else
{
if (readSize == OV_EBADLINK)
{
Log::FormatError("{} Corrupt bitstream section!", fileId.Name);
return nullptr;
}
}
}
auto audioData = pcmSteam.CurrentBuffer();
OggAudio* audio = new OggAudio(audioData, fileId);
audio->SetSampleCount(sampleCount);
audio->SetChannelCount(vi->channels);
audio->SetSampleRate(vi->rate);
audio->SetBitsPerSample(16);
audio->SetSeekable(seekable);
return audio;
}
示例10: _inStream
VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
_inStream(inStream),
_disposeAfterUse(dispose),
_length(0, 1000),
_bufferEnd(_buffer + ARRAYSIZE(_buffer)) {
int res = ov_open_callbacks(inStream, &_ovFile, NULL, 0, g_stream_wrap);
if (res < 0) {
warning("Could not create Vorbis stream (%d)", res);
_pos = _bufferEnd;
return;
}
// Read in initial data
if (!refill())
return;
// Setup some header information
_isStereo = ov_info(&_ovFile, -1)->channels >= 2;
_rate = ov_info(&_ovFile, -1)->rate;
#ifdef USE_TREMOR
_length = Timestamp(ov_time_total(&_ovFile, -1), getRate());
#else
_length = Timestamp(uint32(ov_time_total(&_ovFile, -1) * 1000.0), getRate());
#endif
}
示例11: memset
void OggWrapper::LoadFromMemory(char * data, int dataSize, SoundInfo * soundinfo)
{
oggFile_.curPtr = oggFile_.filePtr = data;
oggFile_.fileSize = dataSize;
ovFile_ = new OggVorbis_File;
memset(ovFile_, 0, sizeof OggVorbis_File);
ov_open_callbacks((void*)&oggFile_, ovFile_, nullptr, -1, callbacks_ogg);
vorbis_info * vorbisinfo = ov_info(ovFile_, -1);
memset(soundinfo, 0, sizeof SoundInfo);
soundinfo->channels = vorbisinfo->channels;
soundinfo->bitrateLower = vorbisinfo->bitrate_lower;
soundinfo->bitrateUpper = vorbisinfo->bitrate_upper;
soundinfo->bitrateNominal = vorbisinfo->bitrate_nominal;
soundinfo->bitrateWindow = vorbisinfo->bitrate_window;
soundinfo->frequency = vorbisinfo->rate;
soundinfo->bpc = 16;
if (ov_seekable(ovFile_) == 0)
{
soundinfo->seekable = false;
seekable_ = false;
}
else
{
soundinfo->seekable = true;
seekable_ = true;
}
}
示例12: vorbis_stream_decoder_open
int
vorbis_stream_decoder_open(decoder_t * dec, http_session_t * session) {
vorbis_pdata_t * pd = (vorbis_pdata_t *)dec->pdata;
file_decoder_t * fdec = dec->fdec;
ov_callbacks ov_cb;
ov_cb.read_func = read_vorbis_stream;
ov_cb.seek_func = seek_vorbis_stream;
ov_cb.close_func = close_vorbis_stream;
ov_cb.tell_func = tell_vorbis_stream;
if (ov_open_callbacks((void *)session, &(pd->vf), NULL, 0, ov_cb) != 0) {
/* not an Ogg Vorbis stream */
return DECODER_OPEN_BADLIB;
}
fdec->is_stream = 1;
pd->session = session;
dec->pause = pause_vorbis_stream;
dec->resume = resume_vorbis_stream;
return vorbis_decoder_finish_open(dec);
}
示例13: VorbisAudioIO_loadOggVorbisData
PCMAudio * VorbisAudioIO_loadOggVorbisData(const void * data, size_t length) {
struct memreadContext readContext;
ov_callbacks callbacks;
OggVorbis_File file;
int status;
vorbis_info * info;
unsigned int channelCount;
unsigned int sampleRate;
unsigned int sampleCount;
long readResult;
struct memwriteContext writeContext;
char buffer[BUFFER_SIZE];
int currentSection;
PCMAudio * audio;
readContext = memreadContextInit(data, length);
callbacks.read_func = VorbisAudioIO_memreadFunc;
callbacks.seek_func = VorbisAudioIO_memseekFunc;
callbacks.close_func = NULL;
callbacks.tell_func = VorbisAudioIO_memtellFunc;
status = ov_open_callbacks(&readContext, &file, NULL, 0, callbacks);
if (status != 0) {
fprintf(stderr, "Error: ov_open_callbacks returned %d\n", status);
return NULL;
}
info = ov_info(&file, -1);
if (info == NULL) {
fprintf(stderr, "Error: ov_info returned NULL\n");
return NULL;
}
channelCount = info->channels;
sampleRate = info->rate;
sampleCount = ov_pcm_total(&file, -1);
writeContext = memwriteContextInit(malloc(1), 0, 1, true);
for (;;) {
readResult = ov_read(&file, buffer, BUFFER_SIZE, OV_READ_ENDIANNESS, 2, 1, ¤tSection);
if (readResult == 0) {
break;
}
if (readResult < 0) {
fprintf(stderr, "Error: ov_read returned %ld\n", readResult);
break;
}
memwrite(&writeContext, readResult, buffer);
}
ov_clear(&file);
if (readResult < 0) {
free(writeContext.data);
return NULL;
}
audio = PCMAudio_create(2, channelCount, sampleRate, sampleCount, writeContext.data, true);
free(writeContext.data);
return audio;
}
示例14: sizeof
void AudioSourceOJM::parseM30()
{
M30Header Head;
size_t sizeLeft;
ifile->read(reinterpret_cast<char*>(&Head), sizeof(M30Header));
std::vector<char> Buffer(Head.payload_size);
sizeLeft = Head.payload_size;
for (int i = 0; i < Head.sample_count; i++)
{
if (sizeLeft < 52)
break; // wrong number of samples
M30Entry Entry;
ifile->read(reinterpret_cast<char*>(&Entry), sizeof(M30Entry));
sizeLeft -= sizeof(M30Entry);
sizeLeft -= Entry.sample_size;
int OJMIndex = Entry.ref;
if (Entry.codec_code == 0)
OJMIndex += 1000;
else if (Entry.codec_code != 5) continue; // Unknown sample id type.
std::vector<char> SampleData(Entry.sample_size);
ifile->read(&SampleData[0], Entry.sample_size);
if (Head.encryption_flag & 16)
NamiXOR(&SampleData[0], Entry.sample_size);
else if (Head.encryption_flag & 32)
F412XOR(&SampleData[0], Entry.sample_size);
// Sample data is done. Now the bits that are specific to raindrop..
auto NewSample = std::make_shared<SoundSample>();
SFM30 ToLoad;
ToLoad.Buffer = std::move(SampleData);
ToLoad.DataLength = Entry.sample_size;
OggVorbis_File vf;
ov_open_callbacks(&ToLoad, &vf, nullptr, 0, M30InterfaceOgg);
TemporaryState.File = &vf;
TemporaryState.Info = vf.vi;
if (vf.vi)
{
TemporaryState.Enabled = OJM_OGG;
NewSample->SetPitch(Speed);
NewSample->Open(this);
TemporaryState.Enabled = 0;
}
ov_clear(&vf);
Arr[OJMIndex] = NewSample;
}
}
示例15: S_OpenBackgroundTrack
/*
=================
S_OpenBackgroundTrack
=================
*/
static qboolean S_OpenBackgroundTrack (char *name, bgTrack_t *track)
{
OggVorbis_File *vorbisFile;
vorbis_info *vorbisInfo;
ov_callbacks vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
#ifdef OGG_DIRECT_FILE
char filename[1024];
char *path = NULL;
#endif
// Com_Printf("Opening background track: %s\n", name);
#ifdef OGG_DIRECT_FILE
do {
path = FS_NextPath( path );
Com_sprintf( filename, sizeof(filename), "%s/%s", path, name );
if ( (track->file = fopen(filename, "rb")) != 0)
break;
} while ( path );
#else
FS_FOpenFile(name, &track->file);
#endif
if (!track->file)
{
Com_Printf("S_OpenBackgroundTrack: couldn't find %s\n", name);
return false;
}
track->vorbisFile = vorbisFile = Z_Malloc(sizeof(OggVorbis_File));
// Com_Printf("Opening callbacks for background track\n");
// bombs out here- ovc_read, FS_Read 0 bytes error
if (ov_open_callbacks(track, vorbisFile, NULL, 0, vorbisCallbacks) < 0)
{
Com_Printf("S_OpenBackgroundTrack: couldn't open OGG stream (%s)\n", name);
return false;
}
// Com_Printf("Getting info for background track\n");
vorbisInfo = ov_info(vorbisFile, -1);
if (vorbisInfo->channels != 1 && vorbisInfo->channels != 2)
{
Com_Printf("S_OpenBackgroundTrack: only mono and stereo OGG files supported (%s)\n", name);
return false;
}
track->start = ov_raw_tell(vorbisFile);
track->rate = vorbisInfo->rate;
track->width = 2;
track->channels = vorbisInfo->channels; // Knightmare added
track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
// Com_Printf("Vorbis info: frequency: %i channels: %i bitrate: %i\n",
// vorbisInfo->rate, vorbisInfo->channels, vorbisInfo->bitrate_nominal);
return true;
}