Ejemplo n.º 1
0
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;
  }
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------//
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;
}
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;
}
Ejemplo n.º 4
0
OggStream::OggStream(const std::string &fname) {
	_file = fopen(fname.c_str(), "rb");
	if (_file == NULL) {
		perror("fopen");
		throw std::runtime_error("cannot open file");
	}

	ov_callbacks ov_cb;
	memset(&ov_cb, 0, sizeof(ov_cb));

	ov_cb.read_func = stream_read_func;
	ov_cb.seek_func = stream_seek_func;
	ov_cb.tell_func = stream_tell_func;
	ov_cb.close_func = stream_close_func;

	int r = ov_open_callbacks(_file, &_ogg_stream, NULL, 0, ov_cb);
	if (r < 0) {
		throw std::runtime_error("ov_open_callbacks failed");
	}
	
	_vorbis_info = ov_info(&_ogg_stream, -1);

	sample_rate = _vorbis_info->rate;
	//LOG_DEBUG(("open(%s) : %d", fname.c_str(), sample_rate));
	format = AUDIO_S16LSB;
	channels = _vorbis_info->channels;

	//_vorbis_comment = ov_comment(&_ogg_stream, -1);
	assert(_vorbis_info != NULL);
}
Ejemplo n.º 5
0
/*!
 * \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;
}
Ejemplo n.º 6
0
	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);
	}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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 );
}
Ejemplo n.º 10
0
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, &currentSection);
        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;
}
Ejemplo n.º 11
0
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
}
Ejemplo n.º 12
0
	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;
		}
	}
Ejemplo n.º 13
0
	void OggWrapper::LoadFromFile(FILE * file, SoundInfo * soundinfo)
	{
		ovFile_ = new OggVorbis_File;
		memset(ovFile_, 0, sizeof OggVorbis_File);

		ov_open_callbacks(file, ovFile_, nullptr, -1, OV_CALLBACKS_DEFAULT);

		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;
		}
	}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
0
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, &currentSection);
		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;
}
Ejemplo n.º 16
0
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;
    }
}
Ejemplo n.º 17
0
/*
=================
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;
}
Ejemplo n.º 18
0
int main(){
  OggVorbis_File vf;
  int eof=0;
  int current_section;

#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
  /* Beware the evil ifdef. We avoid these where we can, but this one we 
     cannot. Don't add any more, you'll probably go to hell if you do. */
  _setmode( _fileno( stdin ), _O_BINARY );
  _setmode( _fileno( stdout ), _O_BINARY );
#endif

  if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
      fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
      exit(1);
  }

  /* Throw the comments plus a few lines about the bitstream we're
     decoding */
  {
    char **ptr=ov_comment(&vf,-1)->user_comments;
    vorbis_info *vi=ov_info(&vf,-1);
    while(*ptr){
      fprintf(stderr,"%s\n",*ptr);
      ++ptr;
    }
    fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
    fprintf(stderr,"\nDecoded length: %ld samples\n",
            (long)ov_pcm_total(&vf,-1));
    fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
  }
  
  while(!eof){
    long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,&current_section);
    if (ret == 0) {
      /* EOF */
      eof=1;
    } else if (ret < 0) {
      if(ret==OV_EBADLINK){
        fprintf(stderr,"Corrupt bitstream section! Exiting.\n");
        exit(1);
      }

      /* some other error in the stream.  Not a problem, just reporting it in
         case we (the app) cares.  In this case, we don't. */
    } else {
      /* we don't bother dealing with sample rate changes, etc, but
         you'll have to*/
      fwrite(pcmout,1,ret,stdout);
    }
  }

  /* cleanup */
  ov_clear(&vf);
    
  fprintf(stderr,"Done.\n");
  return(0);
}
Ejemplo n.º 19
0
static qboolean S_VORBIS_CodecOpenStream (snd_stream_t *stream)
{
	OggVorbis_File *ovFile;
	vorbis_info *ovf_info;
	long numstreams;
	int res;

	ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File), Z_MAINZONE);
	stream->priv = ovFile;
	res = ov_open_callbacks(&stream->fh, ovFile, NULL, 0, ovc_qfs);
	if (res != 0)
	{
		Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n",
				stream->name, res);
		goto _fail;
	}

	if (!ov_seekable(ovFile))
	{
		Con_Printf("Stream %s not seekable.\n", stream->name);
		goto _fail;
	}

	ovf_info = ov_info(ovFile, 0);
	if (!ovf_info)
	{
		Con_Printf("Unable to get stream info for %s.\n", stream->name);
		goto _fail;
	}

	/* FIXME: handle section changes */
	numstreams = ov_streams(ovFile);
	if (numstreams != 1)
	{
		Con_Printf("More than one (%ld) stream in %s.\n",
					numstreams, stream->name);
		goto _fail;
	}

	if (ovf_info->channels != 1 && ovf_info->channels != 2)
	{
		Con_Printf("Unsupported number of channels %d in %s\n",
					ovf_info->channels, stream->name);
		goto _fail;
	}

	stream->info.rate = ovf_info->rate;
	stream->info.channels = ovf_info->channels;
	stream->info.bits = VORBIS_SAMPLEBITS;
	stream->info.width = VORBIS_SAMPLEWIDTH;

	return true;
_fail:
	if (res == 0)
		ov_clear(ovFile);
	Z_Free(ovFile);
	return false;
}
Ejemplo n.º 20
0
int AudioStreamPlaybackOGGVorbis::mix(int16_t* p_bufer,int p_frames) {

	if (!playing)
		return 0;

	int total=p_frames;
	while (true) {

		int todo = p_frames;

		if (todo==0 || todo<MIN_MIX) {
			break;
		}

		//printf("to mix %i - mix me %i bytes\n",to_mix,to_mix*stream_channels*sizeof(int16_t));

		#ifdef BIG_ENDIAN_ENABLED
		long ret=ov_read(&vf,(char*)p_bufer,todo*stream_channels*sizeof(int16_t), 1, 2, 1, &current_section);
		#else
		long ret=ov_read(&vf,(char*)p_bufer,todo*stream_channels*sizeof(int16_t), 0, 2, 1, &current_section);
		#endif

		if (ret<0) {

			playing = false;
			ERR_EXPLAIN("Error reading OGG Vorbis File: "+file);
			ERR_BREAK(ret<0);
		} else if (ret==0) { // end of song, reload?

			ov_clear(&vf);

			_close_file();

			if (!has_loop()) {

				playing=false;
				repeats=1;
				break;
			}

			f=FileAccess::open(file,FileAccess::READ);

			int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks);
			if (errv!=0) {
				playing=false;
				break;; // :(
			}

			if (loop_restart_time) {
				bool ok = ov_time_seek(&vf,loop_restart_time)==0;
				if (!ok) {
					playing=false;
					//ERR_EXPLAIN("loop restart time rejected");
					ERR_PRINT("loop restart time rejected")
				}

				frames_mixed=stream_srate*loop_restart_time;
			} else {
Ejemplo n.º 21
0
bool OggStream::open(const MessageAudio &ma)
{
    mCallbacks.read_func = MessageAudio_read;
    mCallbacks.close_func = MessageAudio_close;
    mCallbacks.seek_func = MessageAudio_seek;
    mCallbacks.tell_func = MessageAudio_tell;

    currentAudio = ma;
    int audioid = ma.getAudioid();
    int error = ov_open_callbacks(&currentAudio, &mStream, NULL, 0, mCallbacks);

    ostringstream oss;
    oss << "MessageAudio:" << audioid;
    mStreamInfo = oss.str();

    if(error) {
        switch(error) {
            case OV_EREAD:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid << " A read from media returned an error");
                break;
            case OV_ENOTVORBIS:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid << " Bitstream is not Vorbis data");
                break;
            case OV_EVERSION:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid << " Vorbis version mismatch");
                break;
            case OV_EBADHEADER:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid << " Invalid Vorbis bitstream header");
                break;
            case OV_EFAULT:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid<< " Internal logic fault");
                break;
            default:
                LOG4CXX_ERROR(narratorOsLog, "MessageAudio id: " << audioid << " unknown error occurred");
                break;
        }
        return false;
    }

    vorbis_info *vi = ov_info(&mStream,-1);

    isOpen = true;
    mChannels = vi->channels;
    mRate = vi->rate;

    /*
       char **ptr = ov_comment(&mStream,-1)->user_comments;
       while(*ptr){
       LOG4CXX_DEBUG(narratorOsLog, "comment: " << *ptr);
       ++ptr;
       }

       size_t total_size = ov_pcm_total(&mStream, -1);
       LOG4CXX_DEBUG(narratorOsLog, "total size: " << total_size);
       */
    return true;
}
Ejemplo n.º 22
0
CAudioDecoderVorbis::CAudioDecoderVorbis(NLMISC::IStream *stream, bool loop)
    : _Stream(stream), _Loop(loop), _IsMusicEnded(false), _StreamSize(0)
{
    _StreamOffset = stream->getPos();
    stream->seek(0, NLMISC::IStream::end);
    _StreamSize = stream->getPos();
    stream->seek(_StreamOffset, NLMISC::IStream::begin);
    ov_open_callbacks(this, &_OggVorbisFile, NULL, 0, OV_CALLBACKS_NLMISC_STREAM);
}
Ejemplo n.º 23
0
/**
 * \brief OGG read Callback.
 * \param[in] name File name to open.
 * \param[in/out] Music track data structure.
 * \return False on error, otherwise true.
 * \note
 */
PRIVATE _boolean Sound_OpenBGTrack( const char *name, musicTrack_t *track )
{
	OggVorbis_File	*vorbisFile;
	vorbis_info		*vorbisInfo;
	ov_callbacks	vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
	int ret;

	track->hFile = FS_OpenFile( name, 0 );
	if( ! track->hFile )
	{
		return false;
	}


	track->vorbisFile = vorbisFile = Z_Malloc( sizeof( OggVorbis_File ) );

	if( (ret = ov_open_callbacks( track, vorbisFile, NULL, 0, vorbisCallbacks )) < 0 )
	{
		switch( ret )
		{
			case OV_EREAD:
				Com_DPrintf( "A read from media returned an error.(%s)\n", name );
				break;
			case OV_ENOTVORBIS:
				Com_DPrintf( "Bitstream is not Vorbis data.(%s)\n", name );
				break;
			case OV_EVERSION:
				Com_DPrintf( "Vorbis version mismatch.(%s)\n", name );
				break;
			case OV_EBADHEADER:
				Com_DPrintf( "Invalid Vorbis bitstream header.(%s)\n", name );
				break;
			case OV_EFAULT:
				Com_DPrintf( "Internal logic fault; indicates a bug or heap/stack corruption.(%s)\n", name );
				break;

		}
		Com_DPrintf( "Could not open OGG stream (%s)\n", name );

		return false;
	}

	vorbisInfo = ov_info( vorbisFile, -1 );
	if( vorbisInfo->channels != 1 && vorbisInfo->channels != 2 )
	{
		Com_DPrintf( "Only mono and stereo OGG files supported (%s)\n", name );

		return false;
	}

	track->start = ov_raw_tell( vorbisFile );
	track->rate = vorbisInfo->rate;
	track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;

	return true;
}
Ejemplo n.º 24
0
static void *decompress_vorbis(const BYTE *data, const DWORD size, ALsizei *decompressed_size, ALenum *fmt, ALsizei *freq)
{
#ifdef __POWERPC__
	const int bigendian = 1;
#else
	const int bigendian = 0;
#endif

	oggcbdata cbdata = { data, size, 0 };
	OggVorbis_File vf;
	memset(&vf, '\0', sizeof (vf));
	if (ov_open_callbacks(&cbdata, &vf, NULL, 0, oggcb) == 0)
    {
        int bitstream = 0;
        vorbis_info *info = ov_info(&vf, -1);

        *decompressed_size = 0;
        *fmt = (info->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
        *freq = info->rate;

        if ((info->channels != 1) && (info->channels != 2))
        {
            ov_clear(&vf);
            return NULL;
        }

        char buf[1024 * 16];
        long rc = 0;
        size_t allocated = 64 * 1024;
        BYTE *retval = (ALubyte *) malloc(allocated);
        while ( (rc = ov_read(&vf, buf, sizeof (buf), bigendian, 2, 1, &bitstream)) != 0 )
        {
            if (rc > 0)
            {
                *decompressed_size += rc;
                if (*decompressed_size >= allocated)
                {
                    allocated *= 2;
                    ALubyte *tmp = (ALubyte *) realloc(retval, allocated);
                    if (tmp == NULL)
                    {
                        free(retval);
                        retval = NULL;
                        break;
                    }
                    retval = tmp;
                }
                memcpy(retval + (*decompressed_size - rc), buf, rc);
            }
        }
        ov_clear(&vf);
        return retval;
    }

    return NULL;
}
Ejemplo n.º 25
0
void	CSoundRender_Target::attach()
{
	VERIFY			(0==wave);
	VERIFY			(pEmitter);
	ov_callbacks ovc= {ov_read_func,ov_seek_func,ov_close_func,ov_tell_func};
	wave			= FS.r_open		(pEmitter->source->pname.c_str()); 
	R_ASSERT3		(wave&&wave->length(),"Can't open wave file:",pEmitter->source->pname.c_str());
 	ov_open_callbacks(wave,&ovf,NULL,0,ovc);
	VERIFY			(0!=wave);
}
Ejemplo n.º 26
0
int Cogg_file::get_c_channels()
{
	OggVorbis_File vf;
	seek(0);
	if (ov_open_callbacks(this, &vf, NULL, 0, cbs) < 0) 
		return 0;
	int r = ov_info(&vf, -1)->channels;
	ov_clear(&vf);
	return r;
}
Ejemplo n.º 27
0
int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  ov_callbacks callbacks = {
    (size_t (*)(void *, size_t, size_t, void *))  fread,
    (int (*)(void *, ogg_int64_t, int))              _fseek64_wrap,
    (int (*)(void *))                             fclose,
    (long (*)(void *))                            ftell
  };

  return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
}
Ejemplo n.º 28
0
int Cogg_file::get_c_samples()
{
	OggVorbis_File vf;
	seek(0);
	if (ov_open_callbacks(this, &vf, NULL, 0, cbs) < 0) 
		return 0;
	int r = ov_pcm_total(&vf, -1);
	ov_clear(&vf);
	return r;
}
Ejemplo n.º 29
0
int Cogg_file::get_samplerate()
{
	OggVorbis_File vf;
	seek(0);
	if (ov_open_callbacks(this, &vf, NULL, 0, cbs) < 0) 
		return 0;
	int r = ov_info(&vf, -1)->rate;
	ov_clear(&vf);
	return r;
}