Exemple #1
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
}
Exemple #2
0
int alogg_get_length_secs_ogg(ALOGG_OGG *ogg) {
#ifdef USE_TREMOR
  return (int)ov_time_total(&(ogg->vf), -1) * 1000;
#else
  return (int)ov_time_total(&(ogg->vf), -1);
#endif
}
Exemple #3
0
long ov_bitrate(OggVorbis_File *vf,int i){
  if(vf->ready_state<OPENED)return(OV_EINVAL);
  if(i>=vf->links)return(OV_EINVAL);
  if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  if(i<0){
    ogg_int64_t bits=0;
    int i;
    for(i=0;i<vf->links;i++)
      bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
    return(bits*1000/ov_time_total(vf,-1));
  }else{
    if(vf->seekable){
      /* return the actual bitrate */
      return((vf->offsets[i+1]-vf->dataoffsets[i])*8000/ov_time_total(vf,i));
    }else{
      /* return nominal if set */
      if(vf->vi[i].bitrate_nominal>0){
	return vf->vi[i].bitrate_nominal;
      }else{
	if(vf->vi[i].bitrate_upper>0){
	  if(vf->vi[i].bitrate_lower>0){
	    return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
	  }else{
	    return vf->vi[i].bitrate_upper;
	  }
	}
	return(OV_FALSE);
      }
    }
  }
}
Exemple #4
0
static double ogg_stream_get_length(ALLEGRO_AUDIO_STREAM *stream)
{
   AL_OV_DATA *extra = (AL_OV_DATA *) stream->extra;
#if !defined(ALLEGRO_GP2XWIZ) && !defined(ALLEGRO_IPHONE)
   double ret = ov_time_total(extra->vf, -1);
#else
   double ret = ov_time_total(extra->vf, -1)/1000.0;
#endif
   return ret;
}
int RageSoundReader_Vorbisfile::GetLength() const
{
#if defined(INTEGER_VORBIS)
	int len = ov_time_total(vf, -1);
#else
	int len = int(ov_time_total(vf, -1) * 1000);
#endif
	if( len == OV_EINVAL )
		RageException::Throw( "RageSoundReader_Vorbisfile::GetLength: ov_time_total returned OV_EINVAL." );

	return len; 
}
double COggVorbisFileHelper::ov_time_total_func( OggVorbis_File *vf,int i )
{
#ifdef _USELIBTREMOR
	ogg_int64_t tt = 0;
	tt = ov_time_total(vf,-1);
	return ((double)tt) / 1000;
#else
	double tt = 0;
	tt = ov_time_total(vf,-1);
	return tt;
#endif
}
	 static inline jlong wrapped_Java_com_badlogic_gdx_audio_io_VorbisDecoder_openFile
(JNIEnv* env, jclass clazz, jstring obj_filename, char* filename) {

//@line:125

		OggVorbis_File* ogg = new OggVorbis_File();
		FILE* file = fopen(filename, "rb" );
	
		if( file == 0 )
		{
			delete ogg;
			return 0;
		}
	
		if( ov_open( file, ogg, NULL, 0 ) != 0 )
		{
			fclose( file );
			delete ogg;
			return 0;
		}
	
		vorbis_info *info = ov_info( ogg, -1 );
		int channels = info->channels;
		int rate = info->rate;
		float length = (float)ov_time_total(ogg, -1 ) / 1000.0f;
	
		OggFile* oggFile = new OggFile();
		oggFile->ogg = ogg;
		oggFile->channels = channels;
		oggFile->rate = rate;
		oggFile->length = length;
	
		return (jlong)oggFile;	
	
}
Exemple #8
0
int vorbis_open(const char *file) {
	FILE *fp;
	vorbis_info *info;
	
	if (!file || !*file)
		return 0;

	if (!(fp = fopen(file, "rb")))
		return 0;

	if (ov_open(fp, &track, NULL, 0)) {
		fclose(fp);
		return 0;
	}

	parse_comments(ov_comment(&track, -1));
	
	info = ov_info(&track, -1);
	
	sample_rate = info->rate;
	channels = info->channels;
	duration = ov_time_total(&track, -1);
	bitrate = ov_bitrate(&track, -1);

	return 1;
}
Exemple #9
0
bool OGGMusic::Load(const char * filename)
{
	if (ov_fopen((char*)filename,&_ogg_file)!=0)
		return false;	

	_frequency = _ogg_file.vi->rate;
	_channels = _ogg_file.vi->channels;
	_total_time = ov_time_total(&_ogg_file,-1);

	if (_channels!=2 && _channels!=1)
		return false;

	//On alloue tout le temps pour 1sec de musique
	_stream_block_size = _frequency*2*_channels;
	
	_sound_data_size = _total_time*_frequency*2*_channels;

	_sound_data[0] = new char[_stream_block_size];
	_sound_data[1] = new char[_stream_block_size];

	alGenBuffers(2,_buffer);
	alGenSources(1,_source);

	CreateThread(NULL,NULL,_thread_play_pause_stop_wrapper,(void*)this,0,NULL);	

	return true;
}
Exemple #10
0
bool RealSoundOgg::OpenStream(void* pData, int nMaxSize)
{
	if (m_bOpened) Close();

	m_nOggMaxSize = nMaxSize;
	ov_callbacks callbacks = {ReadCallback, SeekCallback, CloseCallback, TellCallback};

	if (ov_open_callbacks(pData, &m_vf, NULL, 0, callbacks) < 0) 
	{
		m_nOggMaxSize = 0;
		return false;
	}

	m_nLength = (int)ov_time_total(&m_vf, -1) * 1000;

	if (!CreateSoundBuffer())
	{
		m_nOggMaxSize = 0;
		return false;
	}

	m_bOpened = true;

	return true;
}
Exemple #11
0
//=================================================================================================
int SoundFileOgg::size()
{
  if (!file)
    return 0;

  return (int)(ov_time_total( &vf, -1 ) + 0.5) * channels * freq * 2;
}
long VorbisDecoder::length() {
    if (!m_data->initialized) return -1;
    // -1 return total length of all bitstreams.
    // Should we take them one at a time instead?
    double ogglen = ov_time_total(m_data->vf,-1);
    return (long)(ogglen*1000.0);
}
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 );
}
Exemple #14
0
//Inspired from ogginfo.c
// part of the vorbis-tools package of the OGG Vorbis project
int OGG_length(const char *filename)
{
  FILE *fp;
  OggVorbis_File vf;
  int rc,i;
  double playtime;

  memset(&vf,0,sizeof(OggVorbis_File));

  fp = fopen(filename,"r");
  if (!fp) {
    fprintf(stderr,"Unable to open \"%s\n", filename);
  }

  rc = ov_open(fp,&vf,NULL,0);

  if (rc < 0) {
    fprintf(stderr,"Unable to understand \"%s\", errorcode=%d\n", filename, rc);
    return 0;
  }

  playtime = (double) ov_time_total(&vf,-1);

//  printf("length (seconds) =%f\n",playtime);
//  printf("length (samples) =%d\n",((int) (playtime * 75)));

  ov_clear(&vf);

  return (int) (playtime * 75.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;
}
Exemple #16
0
void OGGgetInfo(){
    //Estraggo le informazioni:
    OGG_info.fileType = OGG_TYPE;
    OGG_info.defaultCPUClock = OGG_defaultCPUClock;
    OGG_info.needsME = 0;

    vorbis_info *vi = ov_info(&OGG_VorbisFile, -1);
	OGG_info.kbit = vi->bitrate_nominal/1000;
    OGG_info.instantBitrate = vi->bitrate_nominal;
	OGG_info.hz = vi->rate;
	OGG_info.length = (long)ov_time_total(&OGG_VorbisFile, -1)/1000;
    if (vi->channels == 1)
        strcpy(OGG_info.mode, "single channel");
    else if (vi->channels == 2)
        strcpy(OGG_info.mode, "normal LR stereo");
    strcpy(OGG_info.emphasis, "no");

	int h = 0;
	int m = 0;
	int s = 0;
	long secs = OGG_info.length;
	h = secs / 3600;
	m = (secs - h * 3600) / 60;
	s = secs - h * 3600 - m * 60;
	snprintf(OGG_info.strLength, sizeof(OGG_info.strLength), "%2.2i:%2.2i:%2.2i", h, m, s);

    getOGGTagInfo(&OGG_VorbisFile, &OGG_info);
}
JNIEXPORT jlong JNICALL Java_com_badlogic_gdx_audio_io_VorbisDecoder_openFile(JNIEnv *env, jobject, jstring filename)
{
	char* fileString = (char*)env->GetStringUTFChars(filename, NULL);
	OggVorbis_File* ogg = new OggVorbis_File();
	FILE* file = fopen(fileString, "rb" );
	env->ReleaseStringUTFChars( filename, fileString );

	if( file == 0 )
	{
		delete ogg;
		return 0;
	}

	if( ov_open( file, ogg, NULL, 0 ) != 0 )
	{
		fclose( file );
		delete ogg;
		return 0;
	}

	vorbis_info *info = ov_info( ogg, -1 );
	int channels = info->channels;
	int rate = info->rate;
	float length = (float)ov_time_total(ogg, -1 ) / 1000.0f;

	OggFile* oggFile = new OggFile();
	oggFile->ogg = ogg;
	oggFile->channels = channels;
	oggFile->rate = rate;
	oggFile->length = length;

	return (jlong)oggFile;
}
Exemple #18
0
uint32 VorbisLMC::CalculateSongLength(const char *url)
{
    char            path[_MAX_PATH];
    uint32          len = _MAX_PATH;
    FILE           *fpFile;
    OggVorbis_File  vf;
    double          dur;

    URLToFilePath(url, path, &len);
    fpFile = fopen(path, "rb");
    if (fpFile == NULL)
       return 0;  

    memset(&vf, 0, sizeof(vf));
    if (ov_open(fpFile, &vf, NULL, 0) < 0)
    {
       fclose(fpFile);
       return 0; 
    }

    dur = ov_time_total(&vf, 0);

    ov_clear(&vf);

    return (int)dur;
}
Exemple #19
0
int Audio::loadFakeOgg(Path file){
	
	AudioSource* source=new AudioSource;

	source->filename=file;
	source->type=AUDIO_OGG;

	if(!(source->oggFile = fopen(file.getAbsolute().c_str(), "rb"))){
		console().write("audio error: i/o error, could not open off file '"+file.getRelative()+"'");
		return -1;
	}

	int result;

	if((result = ov_open(source->oggFile, &source->oggStream, NULL, 0)) < 0){
		fclose(source->oggFile);
        
		console().write("audio error: could not open ogg stream '"+file.getRelative()+"'");
		return -1;
	}

	source->fakeLen=ov_time_total(&source->oggStream,-1);

	sources.pushBack(source);
	source->sourceIndex=sources.size()-1;
	return sources.size()-1;

}
Exemple #20
0
int main(){
  OggVorbis_File ov;
  int i;

#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

  /* open the file/pipe on stdin */
  if(ov_open(stdin,&ov,NULL,-1)<0){
    printf("Could not open input as an OggVorbis file.\n\n");
    exit(1);
  }
  
  /* print details about each logical bitstream in the input */
  if(ov_seekable(&ov)){
    printf("Input bitstream contained %ld logical bitstream section(s).\n",
	   ov_streams(&ov));
    printf("Total bitstream samples: %ld\n\n",
	   (long)ov_pcm_total(&ov,-1));
    printf("Total bitstream playing time: %ld seconds\n\n",
	   (long)ov_time_total(&ov,-1));

  }else{
    printf("Standard input was not seekable.\n"
	   "First logical bitstream information:\n\n");
  }

  for(i=0;i<ov_streams(&ov);i++){
    vorbis_info *vi=ov_info(&ov,i);
    printf("\tlogical bitstream section %d information:\n",i+1);
    printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
	   vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
	   ov_serialnumber(&ov,i));
    printf("\t\theader length: %ld bytes\n",(long)
	   (ov.dataoffsets[i]-ov.offsets[i]));
    printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
    printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
  }

  ov_clear(&ov);
  return 0;
}
Exemple #21
0
void COggDec::SetMetaData(OggVorbis_File* vf, CAudioMetaData* m)
{
	/* Set Metadata */
	m->type = CAudioMetaData::OGG;
	m->bitrate = ov_info(vf,0)->bitrate_nominal;
	m->samplerate = ov_info(vf,0)->rate;
	if(mSeekable)
#ifdef USE_TREMOR
		m->total_time = (time_t) ov_time_total(vf, 0) / 1000;
#else
		m->total_time = (time_t) ov_time_total(vf, 0);
#endif
	std::stringstream ss;
	ss << "OGG V." << ov_info(vf,0)->version << " / " <<  ov_info(vf,0)->channels << "channel(s)";
	m->type_info = ss.str();
	ParseUserComments(ov_comment(vf, 0), m);
	m->changed=true;
}
Exemple #22
0
 int AudioStream_Ogg::getLength(const std::string &path) {
      
      if (openal_is_shutdown) return 0;
      
      int result;
      mPath = std::string(path.c_str());
      mIsValid = true;
      
      #ifdef ANDROID
      
      mInfo = AndroidGetAssetFD(path.c_str());
      oggFile = fdopen(mInfo.fd, "rb");
      fseek(oggFile, mInfo.offset, 0);
      
      ov_callbacks callbacks;
      callbacks.read_func = &nme::AudioStream_Ogg::read_func;
      callbacks.seek_func = &nme::AudioStream_Ogg::seek_func;
      callbacks.close_func = &nme::AudioStream_Ogg::close_func;
      callbacks.tell_func = &nme::AudioStream_Ogg::tell_func;
      
      #else
      
      oggFile = fopen(path.c_str(), "rb");
      
      #endif
      
      if(!oggFile) {
          //throw std::string("Could not open Ogg file.");
          LOG_SOUND("Could not open Ogg file.");
          mIsValid = false;
          return 0;
      }
      
      oggStream = new OggVorbis_File();
      
      #ifdef ANDROID
      result = ov_open_callbacks(this, oggStream, NULL, 0, callbacks);
      #else
      result = ov_open(oggFile, oggStream, NULL, 0);
      #endif
      
      if(result < 0) {
       
          fclose(oggFile);
          oggFile = 0;
       
          //throw std::string("Could not open Ogg stream. ") + errorString(result);
          LOG_SOUND("Could not open Ogg stream.");
          //LOG_SOUND(errorString(result).c_str());
          mIsValid = false;
          return 0;
      }
      
      return ov_time_total(oggStream, -1);
 }
JNIEXPORT void JNICALL Java_com_jme3_audio_plugins_NativeVorbisFile_open
(JNIEnv *env, jobject nvf, jint fd, jlong off, jlong len)
{
    LOGI("open: fd = %d, off = %lld, len = %lld", fd, off, len);

    OggVorbis_File* ovf = (OggVorbis_File*) malloc(sizeof(OggVorbis_File));

    FileDescWrapper* wrapper = (FileDescWrapper*) malloc(sizeof(FileDescWrapper));
    wrapper->fd = fd;
    wrapper->env = env; // NOTE: every java call has to update this
    wrapper->start = off;
    wrapper->current = off;
    wrapper->end = off + len;

    int result = ov_open_callbacks((void*)wrapper, ovf, NULL, 0, FileDescCallbacks);

    if (result != 0)
    {
        LOGI("ov_open fail");

        free(ovf);
        free(wrapper);

        char err[512];
        sprintf(err, "ov_open failed: %d", result);
        throwIOException(env, err);

        return;
    }

    LOGI("ov_open OK");
    jobject ovfBuf = (*env)->NewDirectByteBuffer(env, ovf, sizeof(OggVorbis_File));

    vorbis_info* info = ov_info(ovf, -1);

    // total # of bytes = total samples * bytes per sample * channels
    int total_samples = ov_pcm_total(ovf, -1);
    jint total_bytes = total_samples * 2 * info->channels;

    jboolean seekable = ov_seekable(ovf) != 0;

    // duration = millis / 1000
    long timeMillis = ov_time_total(ovf, -1);
    double timeSeconds = ((double)timeMillis) / 1000.0;
    jfloat duration = (jfloat) timeSeconds;

    (*env)->SetObjectField(env, nvf, nvf_field_ovf, ovfBuf);
    (*env)->SetBooleanField(env, nvf, nvf_field_seekable, seekable);
    (*env)->SetIntField(env, nvf, nvf_field_channels, info->channels);
    (*env)->SetIntField(env, nvf, nvf_field_sampleRate, info->rate);
    (*env)->SetIntField(env, nvf, nvf_field_bitRate, info->bitrate_nominal);
    (*env)->SetIntField(env, nvf, nvf_field_totalBytes, total_bytes);
    (*env)->SetFloatField(env, nvf, nvf_field_duration, duration);
}
/** 
 * Reads the header information of an ogg vorbis file
 * 
 * @param	Resource		Info about vorbis data
 */
bool FVorbisAudioInfo::ReadCompressedInfo( const uint8* InSrcBufferData, uint32 InSrcBufferDataSize, FSoundQualityInfo* QualityInfo )
{
	SCOPE_CYCLE_COUNTER( STAT_VorbisPrepareDecompressionTime );

	FScopeLock ScopeLock(&VorbisCriticalSection);

	if (!VFWrapper)
	{
		return false;
	}

	ov_callbacks Callbacks;

	SrcBufferData = InSrcBufferData;
	SrcBufferDataSize = InSrcBufferDataSize;
	BufferOffset = 0;

	Callbacks.read_func = OggRead;
	Callbacks.seek_func = OggSeek;
	Callbacks.close_func = OggClose;
	Callbacks.tell_func = OggTell;

	// Set up the read from memory variables
	int Result = ov_open_callbacks(this, &VFWrapper->vf, NULL, 0, Callbacks);
	if (Result < 0)
	{
		UE_LOG(LogAudio, Error, TEXT("FVorbisAudioInfo::ReadCompressedInfo, ov_open_callbacks error code: %d"), Result);
		return false;
	}

	if( QualityInfo )
	{
		// The compression could have resampled the source to make loopable
		vorbis_info* vi = ov_info( &VFWrapper->vf, -1 );
		QualityInfo->SampleRate = vi->rate;
		QualityInfo->NumChannels = vi->channels;
		ogg_int64_t PCMTotal = ov_pcm_total( &VFWrapper->vf, -1 );
		if (PCMTotal >= 0)
		{
			QualityInfo->SampleDataSize = PCMTotal * QualityInfo->NumChannels * sizeof( int16 );
			QualityInfo->Duration = ( float )ov_time_total( &VFWrapper->vf, -1 );
		}
		else if (PCMTotal == OV_EINVAL)
		{
			// indicates an error or that the bitstream is non-seekable
			QualityInfo->SampleDataSize = 0;
			QualityInfo->Duration = 0.0f;
		}
	}

	return( true );
}
Exemple #25
0
/* returns: total milliseconds of content if i==-1
            seconds in that logical bitstream for i==0 to n
	    OV_EINVAL if the stream is not seekable (we can't know the
	    length) or only partially open 
*/
ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){
  if(vf->ready_state<OPENED)return(OV_EINVAL);
  if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  if(i<0){
    ogg_int64_t acc=0;
    int i;
    for(i=0;i<vf->links;i++)
      acc+=ov_time_total(vf,i);
    return(acc);
  }else{
    return(((ogg_int64_t)vf->pcmlengths[i])*1000/vf->vi[i].rate);
  }
}
bool OggFile::Initialize()
{
    _initialized = false;

    // Windows requires a special loading method in order load ogg files
    // properly when dynamically linking vorbis libs. The workaround is
    // to use the ov_open_callbacks function
#ifdef _WIN32
    // Callbacks struct defining the open, closing, seeking and location behaviors.
    ov_callbacks callbacks =  {
        (size_t ( *)(void *, size_t, size_t, void *)) fread,
        (int ( *)(void *, ogg_int64_t, int)) _FileSeekWrapper,
        (int ( *)(void *)) fclose,
        (long( *)(void *)) ftell
    };

    FILE *file = fopen(_filename.c_str(), "rb");

    if (!file)
        return false;

    if(ov_open_callbacks(file, &_vorbis_file, nullptr, 0, callbacks) < 0) {
        fclose(file);
        IF_PRINT_WARNING(AUDIO_DEBUG) << "input file does not appear to be an Ogg bitstream: " << _filename << std::endl;
        return false;
    }
#else
    // File loading code for non Win32 platforms.  Much simpler.
    FILE *file = fopen(_filename.c_str(), "rb");

    if (!file)
        return false;

    if(ov_open(file, &_vorbis_file, nullptr, 0) < 0) {
        fclose(file);
        IF_PRINT_WARNING(AUDIO_DEBUG) << "input file does not appear to be an Ogg bitstream: " << _filename << std::endl;
        return false;
    }
#endif

    _number_channels = _vorbis_file.vi->channels;
    _samples_per_second = _vorbis_file.vi->rate;
    _bits_per_sample = 16;
    _total_number_samples = static_cast<uint32_t>(ov_pcm_total(&_vorbis_file, -1));
    _play_time = static_cast<float>(ov_time_total(&_vorbis_file, -1));
    _sample_size = _number_channels * _bits_per_sample / 8;
    _data_size = _total_number_samples * _sample_size;

    _initialized = true;
    return true;
} // bool OggFile::Initialize()
Exemple #27
0
/* Fill info structure with data from ogg comments */
static void vorbis_tags (const char *file_name, struct file_tags *info,
		const int tags_sel)
{
	OggVorbis_File vf;
	FILE *file;
	int err_code;

	if (!(file = fopen (file_name, "r"))) {
		logit ("Can't open an OGG file: %s", strerror(errno));
		return;
	}

	/* ov_test() is faster than ov_open(), but we can't read file time
	 * with it. */
	if (tags_sel & TAGS_TIME) {
		if ((err_code = ov_open(file, &vf, NULL, 0)) < 0) {
			char *vorbis_err = vorbis_strerror (err_code);

			logit ("Can't open %s: %s", file_name, vorbis_err);
			free (vorbis_err);
			fclose (file);

			return;
		}
	}
	else {
		if ((err_code = ov_test(file, &vf, NULL, 0)) < 0) {
			char *vorbis_err = vorbis_strerror (err_code);

			logit ("Can't open %s: %s", file_name, vorbis_err);
			free (vorbis_err);
			fclose (file);

			return;
		}
	}

	if (tags_sel & TAGS_COMMENTS)
		get_comment_tags (&vf, info);

	if (tags_sel & TAGS_TIME) {
		int64_t vorbis_time;

		vorbis_time = ov_time_total (&vf, -1);
		if (vorbis_time >= 0)
			info->time = vorbis_time / time_scaler;
	}

	ov_clear (&vf);
}
Exemple #28
0
	//-------------------------------------------------------------------------------------------------------
	//
	void ogg_reader::open(const std::wstring& fileName) {
		FILE * fp = NULL;
		_wfopen_s(&fp, fileName.c_str(), L"rb");
		if (fp == NULL) {
			fclose(fp);
		}
		NYX_ASSERT(fp != NULL);
		if (ov_open(fp, &vorbisFile_, NULL, NULL) < 0) {
			fclose(fp);
		}
		vorbisInfo_ = *ov_info(&vorbisFile_, -1);

		auto timeLength = ov_time_total(&vorbisFile_, -1);
		fileSize_ = static_cast<uint64_t>(timeLength * (vorbisInfo_.rate * 2 * 2));
	}
Exemple #29
0
// display Ogg info and comments
void COggStream::DisplayInfo()
{
	LOG("version:           %d", vorbisInfo->version);
	LOG("channels:          %d", vorbisInfo->channels);
	LOG("time (sec):        %lf", ov_time_total(&oggStream,-1));
	LOG("rate (Hz):         %ld", vorbisInfo->rate);
	LOG("bitrate (upper):   %ld", vorbisInfo->bitrate_upper);
	LOG("bitrate (nominal): %ld", vorbisInfo->bitrate_nominal);
	LOG("bitrate (lower):   %ld", vorbisInfo->bitrate_lower);
	LOG("bitrate (window):  %ld", vorbisInfo->bitrate_window);
	LOG("vendor:            %s", vendor.c_str());

	for (TagVector::const_iterator it = vorbisTags.begin(); it != vorbisTags.end(); ++it) {
		LOG("%s", it->c_str());
	}
}
Exemple #30
0
void OGGUpdate()
{
	Artist = "";
	Title = "";
	title = "";

	getMusInfo( musicfile, &title, &Title, &Artist, Internet ? NULL : curF.toUtf8().data(), &vorbisInfoStr );

	if ( Internet )
	{
		QString header = getHeader( uF );
		char *a = NULL;
		if ( !header.isEmpty() )
		{
			a = getICYName( header.toAscii().data(), header.length() );
			if ( a && *a )
			{
				QLib->updateCurrPlistEntry( a );
				if ( title.isEmpty() )
					title = a;
			}
		}
		if ( !a )
			QLib->updateCurrPlistEntry( title );
		else
			free( a );
	}

	vorbis_info *vi = ov_info(&musicfile,0);

	rate = vi->rate;
	chn = vi->channels;

	updateF = true;

	plMaxtime = ov_time_total (&musicfile,0);
	NumPos = plMaxtime-1;

	getBR = QString::number( ov_bitrate(&musicfile,-1)/1000 ,10 )+"kbps";

	if (savsek != 0 )
	{
		seek( savsek );
		pltime = -1;
	}
	savsek = 0;
}