Example #1
0
static void plugin_seek(struct playerHandles *ph, int modtime){
	int newtime;
	int seconds;
	struct vorbisHandles *h;

	if(ph->dechandle==NULL)
		return;

	h=(struct vorbisHandles *)ph->dechandle;
	if(modtime==0){
		ov_time_seek(h->vf,0);
		*h->total=0;
		snd_clear(ph);
		return;
	}

	seconds=(*h->total)/((h->rate)*(h->sizemod));
	seconds+=modtime;

	if(ov_time_seek(h->vf,seconds)!=0)
		return;
	newtime=seconds*((h->rate)*(h->sizemod));

	if(newtime<0)
		newtime=0;

	*h->total=newtime;
	snd_clear(ph);
}
Example #2
0
void alogg_seek_abs_secs_ogg(ALOGG_OGG *ogg, int sec) {
#ifdef USE_TREMOR
  ov_time_seek(&(ogg->vf), sec * 1000);
#else
  ov_time_seek(&(ogg->vf), sec);
#endif
}
Example #3
0
int COggVorbisFileHelper::ov_time_seek_func( OggVorbis_File *vf,double pos )
{
#ifdef _USELIBTREMOR
	ogg_int64_t ipos = 0;
	ipos = ((ogg_int64_t)pos) * 1000; 
	return ov_time_seek(vf,ipos)/1000;
#else
	return ov_time_seek(vf,pos);
#endif
}
Example #4
0
void alogg_seek_abs_msecs_ogg(ALOGG_OGG *ogg, int msec) {
#ifdef USE_TREMOR
  ov_time_seek(&(ogg->vf), msec);
#else
  /* convert msec to pcm sample position */
  double s = msec;
  s /= 1000;

  ov_time_seek(&(ogg->vf), s);
#endif
}
Example #5
0
void alogg_seek_rel_secs_ogg(ALOGG_OGG *ogg, int sec) {
#ifdef USE_TREMOR
  ogg_int64_t _msec = sec * 1000;
  _msec += ov_time_tell(&(ogg->vf));
  ov_time_seek(&(ogg->vf), _msec);
#else
  double s = sec;
  s += ov_time_tell(&(ogg->vf));
  ov_time_seek(&(ogg->vf), s);
#endif
}
Example #6
0
uint32_t AudioSourceOGG::Read(short* buffer, size_t count)
{
    size_t size;
    size_t read = 0;
    int sect;

    if (!mIsValid)
        return 0;

    size = count*sizeof(short);

    if (mSeekTime >= 0)
    {
        mIsDataLeft = true;
        ov_time_seek(&mOggFile, mSeekTime);
        mSeekTime = -1;
    }

    /* read from ogg vorbis file */
    size_t res = 1;
    while (read < size)
    {
        res = ov_read(&mOggFile, (char*)buffer + read, size - read, 0, 2, 1, &sect);

        if (res > 0)
            read += res;

        else if (res == 0)
        {
            if (mSourceLoop)
            {
                ov_time_seek(&mOggFile, 0);
            }
            else
            {
                mIsDataLeft = false;
                return 0;
            }
        }
        else
        {
            Log::Printf("AudioSourceOGG: Error while reading OGG source (%d)\n", res);
            mIsDataLeft = false;
            return 0;
        }
    }

    return read / sizeof(short);
}
Example #7
0
   bool AudioStream_Ogg::stream( ALuint buffer ) {
      
       if (openal_is_shutdown) return false;
       
       if (mSuspend) return true;
       //LOG_SOUND("STREAM\n");
       char pcm[STREAM_BUFFER_SIZE];
       int  size = 0;
       int  section;
       int  result;
       
       while (size < STREAM_BUFFER_SIZE) {
           result = ov_read(oggStream, pcm + size, STREAM_BUFFER_SIZE - size, 0, 2, 1, &section);
           if(result > 0)
               size += result;
           else
               if(result < 0) {

                  if ( mLoops > 0 ) {
                     mLoops --;
                     ov_time_seek(oggStream, 0);
                  }else{
                   break;
                  }
                   //LOG_SOUND ("Result is less than 0");
                   //throw errorString(result);
               }
               else
                   break;
       }
       if(size <= 0) {
         if ( mLoops > 0 ) {
            mLoops --;
            ov_time_seek(oggStream, 0);
            return stream( buffer );
         }else{
            alSourceStop(source);
            return false;
         }
           
           
      }
      
       alBufferData(buffer, format, pcm, size, vorbisInfo->rate);
       check();
       return true;

   } //stream
Example #8
0
	void oggStreamCallback(void* userData, u32 requestedChunkSize, u8* chunkData)
	{
		LOCK();

		s32 totalSize = 0;
		while (totalSize < (s32)requestedChunkSize)
		{
			s32 bitStream = 0;
			s32 soundSize = ov_read(&s_oggFile, (char*)&chunkData[totalSize], requestedChunkSize-totalSize, 0, 2, 1, &bitStream);

			//theoretically the sampling rate can change throughout the song...
			//however this is not supported by the XL Engine currently (it would require more work in the sound layer).

			//we've finished the loop, start the song all over again.
			if (soundSize == 0)
			{
				ov_time_seek(&s_oggFile, 0.0);
				soundSize = ov_read(&s_oggFile, (char*)&chunkData[totalSize], requestedChunkSize-totalSize, 0, 2, 1, &bitStream);
			}
			else if (soundSize < 0)	//error in the bit stream.
			{
				LOG( LOG_ERROR, "ogg streaming error: %d", soundSize );
				soundSize = 0;
				break;
			}

			totalSize += soundSize;
		};

		UNLOCK();
	}
Example #9
0
	/*/////////////////////////////////////////////////////////////////*/
	void OgreOggStreamSound::_updatePlayPosition()
	{
		if ( mSource==AL_NONE || !mSeekable ) 
			return;

		bool paused = isPaused();
		bool playing = isPlaying();

		// Seek...
		pause();
		ov_time_seek(&mOggStream, mPlayPos);

		// Unqueue all buffers
		_dequeue();

		// Fill buffers
		_prebuffer();

		// Reset state..
		if		( playing ) play();
		else if ( paused ) pause();

		// Set flag
		mStreamEOF=false;
		mPlayPosChanged = false;
		mLastOffset = mPlayPos;
	}			   
Example #10
0
File: ov.c Project: zhangsu/seal
seal_err_t
_seal_rewind_ov_stream(seal_stream_t* stream)
{
    if (ov_time_seek(stream->id, 0) != 0)
        return SEAL_CANNOT_REWIND_OV;
    return SEAL_OK;
}
Example #11
0
void alogg_seek_abs_msecs_ogg(ALOGG_OGG *ogg, int msec) {
  /* convert msec to pcm sample position */
  double s = msec;
  s /= 1000;

  ov_time_seek(&(ogg->vf), s);
}
void FVorbisAudioInfo::SeekToTime( const float SeekTime )
{
	FScopeLock ScopeLock(&VorbisCriticalSection);

	const float TargetTime = FMath::Min(SeekTime, ( float )ov_time_total( &VFWrapper->vf, -1 ));
	ov_time_seek( &VFWrapper->vf, TargetTime );
}
Example #13
0
void alogg_seek_rel_msecs_ogg(ALOGG_OGG *ogg, int msec) {
  double s = msec;
  s /= 1000;
  s += ov_time_tell(&(ogg->vf));

  ov_time_seek(&(ogg->vf), s);
}
Example #14
0
//=================================================================================================
void SoundFileOgg::seek( double time )
{
  if (!file)
    return;

  ov_time_seek( &vf, time );
}
Example #15
0
    bool cOggDecoder::seek(float seconds, bool relative)
    {
		if(Valid)
		{
			if(ov_seekable(&oggStream))
			{
				if(relative)
				{
					float curtime = ov_time_tell(&oggStream);
					return (ov_time_seek(&oggStream,curtime+seconds)==0);
				}
				else
					return (ov_time_seek(&oggStream,seconds)==0);
			}
		}
        return false;
    }
Example #16
0
static int S_VORBIS_CodecRewindStream (snd_stream_t *stream)
{
    /* for libvorbisfile, the ov_time_seek() position argument
     * is seconds as doubles, whereas for Tremor libvorbisidec
     * it is milliseconds as 64 bit integers.
     */
    return ov_time_seek ((OggVorbis_File *)stream->priv, 0);
}
Example #17
0
static int OGG_seek(Sound_Sample *sample, uint32_t ms)
{
    Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
    OggVorbis_File *vf = (OggVorbis_File *) internal->decoder_private;
	/* Unlike Vorbis, Tremor uses integer milliseconds instead of double seconds. */
    BAIL_IF_MACRO(ov_time_seek(vf, (ogg_int64_t)ms) < 0, ERR_IO_ERROR, 0);
    return(1);
} /* OGG_seek */
Example #18
0
	/*/////////////////////////////////////////////////////////////////*/
	bool OgreOggStreamSound::_stream(ALuint buffer)
	{
		std::vector<char> audioData;
		char* data;
		int  section = 0;
		int  result = 0;

		// Create buffer
		data = OGRE_ALLOC_T(char, mBufferSize, Ogre::MEMCATEGORY_GENERAL);
		memset(data, 0, mBufferSize);
		
		// Read only what was asked for
		while( !mStreamEOF && (static_cast<int>(audioData.size()) < mBufferSize) )
		{
			int  bytes = 0;
			// Read up to a buffer's worth of data
			bytes = ov_read(&mOggStream, data, static_cast<int>(mBufferSize), 0, 2, 1, &section);
			// EOF check
			if (bytes == 0)
			{
				// If set to loop wrap to start of stream
				if ( mLoop && mSeekable )
				{
					if ( ov_time_seek(&mOggStream, 0 + mLoopOffset)!= 0 )
					{
						Ogre::LogManager::getSingleton().logMessage("***--- OgreOggStream::_stream() - ERROR looping stream, ogg file NOT seekable!");
						break;
					}
				}
				else
				{
					mStreamEOF=true;
					// Don't loop - finish.
					break;
				}
			}
			// Append to end of buffer
			audioData.insert(audioData.end(), data, data + bytes);
			// Keep track of read data
			result+=bytes;
		}

		// EOF
		if(result == 0)
		{
			OGRE_FREE(data, Ogre::MEMCATEGORY_GENERAL);
			return false;
		}

		alGetError();
		// Copy buffer data
		alBufferData(buffer, mFormat, &audioData[0], static_cast<ALsizei>(audioData.size()), mVorbisInfo->rate);

		// Cleanup
		OGRE_FREE(data, Ogre::MEMCATEGORY_GENERAL);

		return true;
	}
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 {
Example #20
0
//-----------------------------------------------------------------------------
void MusicOggStream::update()
{

    if (m_pausedMusic || m_soundSource == ALuint(-1))
    {
        // nothing todo
        return;
    }

    int processed= 0;
    bool active= true;

    alGetSourcei(m_soundSource, AL_BUFFERS_PROCESSED, &processed);

    while(processed--)
    {
        ALuint buffer;

        alSourceUnqueueBuffers(m_soundSource, 1, &buffer);
        if(!check("alSourceUnqueueBuffers")) return;

        active = streamIntoBuffer(buffer);
        if(!active)
        {
            // no more data. Seek to beginning (causes the sound to loop)
            ov_time_seek(&m_oggStream, 0);
            active = streamIntoBuffer(buffer);//now there really should be data
        }

        alSourceQueueBuffers(m_soundSource, 1, &buffer);
        if (!check("alSourceQueueBuffers")) return;
    }

    if (active)
    {
        // For debugging
        SFXManager::checkError("before source state");
        // we have data, so we should be playing...
        ALenum state;
        alGetSourcei(m_soundSource, AL_SOURCE_STATE, &state);
        if (state != AL_PLAYING)
        {
            // Prevent flooding
            static int count = 0;
            count++;
            if (count<10)
                Log::warn("MusicOgg", "Music not playing when it should be. "
                          "Source state: %d", state);
            alGetSourcei(m_soundSource, AL_BUFFERS_PROCESSED, &processed);
            alSourcePlay(m_soundSource);
        }
    }
    else
    {
        Log::warn("MusicOgg", "Attempt to stream music into buffer failed "
                              "twice in a row.");
    }
}   // update
Example #21
0
void alogg_seek_abs_msecs_ogg_ul(ALOGG_OGG *ogg, unsigned long msec) {
  /* convert msec to pcm sample position */
  double s = msec;
  s /= 1000;

  ov_time_seek(&(ogg->vf), s);
  if (ogg->time_stretch)
    rubberband_reset(ogg->time_stretch_state);
}
Example #22
0
	/* seek in  file */
static void oggread_seek(t_oggread *x, t_floatarg f)
{
	if(x->x_fd > 0)
		if(ov_time_seek(&x->x_ov, f) < 0)
		{
			post("oggread~: could not set playing position to %g seconds", f);
		}
		else post("oggread~: playing position set to %g seconds", f);
}
Example #23
0
 double AudioStream_Ogg::setPosition(const float &inFloat)
 {
    if (!mSuspend)
    {
       double seek = inFloat * 0.001;
       ov_time_seek(oggStream, seek);
    }
    return inFloat;
 }
Example #24
0
void SeekVorbisStream(MFAudioStream *pStream, float seconds)
{
	MFVorbisStream *pVS = (MFVorbisStream*)pStream->pStreamData;
#if defined(VORBIS_TREMOR)
	ov_pcm_seek(&pVS->vorbisFile, (ogg_int64_t)(seconds*(float)pVS->pInfo->rate));
#else
	ov_time_seek(&pVS->vorbisFile, seconds);
#endif
}
Example #25
0
int64_t Seek(void* context, int64_t time)
{
  VorbisContext* ctx = (VorbisContext*)context;

  if (ov_time_seek(&ctx->vorbisfile, ctx->timeoffset+(double)(time/1000.0f))!=0)
    return 0;

  return time;
}
Example #26
0
ALsizei
AudioManager::Player::FillBuffer()
{
    ALsizei read = 0;

    if(m_StreamFinished)
    {
        return read;
    }

    char *&buffer = AudioManager::getSingleton().m_Buffer;

    bool finished = false;
    do
    {
        long result = ov_read(&m_VorbisFile, buffer + read,
                              m_ChannelBufferSize - read, 0, 2, 1,
                              &m_VorbisSection);

        switch(result)
        {
            // error
            case OV_HOLE:
            case OV_EBADLINK:
            case OV_EINVAL:
            {
                finished = true;
            }
            break;

            // end of stream
            case 0:
            {
                // if there isn't loop point or can't seek
                if(m_Loop < 0.0f || ov_time_seek(&m_VorbisFile, m_Loop))
                {
                    finished = true;
                }
            }
            break;

            // readed "result" bytes
            default:
            {
                read += result;
                if(read == m_ChannelBufferSize)
                {
                    finished = true;
                }
            }
        }
    }
    while(finished == false);

    return read;
}
JNIEXPORT jint JNICALL Java_com_badlogic_gdx_audio_io_VorbisDecoder_timeSeek(JNIEnv* env, jclass clazz, jlong handle, jfloat time) {


//@line:225

		OggFile* file = (OggFile*)handle;
		return ov_time_seek (file->ogg, (ogg_int64_t)(time * 1000.f));
	

}
void QOggSimplePlayer::internalStop()
{
    needPlay=false;
    if(output==NULL)
        return;
    output->stop();
    buffer.clearData();
    current_section=0;
    ov_time_seek(&vf,0);
}
Example #29
0
static bool ogg_stream_seek(ALLEGRO_AUDIO_STREAM *stream, double time)
{
   AL_OV_DATA *extra = (AL_OV_DATA *) stream->extra;
   if (time >= extra->loop_end)
      return false;
#if !defined(ALLEGRO_GP2XWIZ) && !defined(ALLEGRO_IPHONE) 
   return (ov_time_seek_lap(extra->vf, time) != -1);
#else
   return ov_time_seek(extra->vf, time*1000) != -1;
#endif
}
int OggDecoder::Rewind()
{
	if(!file_fd)
		return -1;

	int ret = ov_time_seek(&ogg_file, 0);
	CurPos = 0;
	EndOfFile = false;

	return ret;
}