Exemplo n.º 1
0
bool loadOggSampleFromFile(const char *inFileURL, QuickVec<unsigned char> &outBuffer, int *channels, int *bitsPerSample, int* outSampleRate)
{
    FILE *f;

    //Read the file data
#ifdef ANDROID
    FileInfo info = AndroidGetAssetFD(inFileURL);
    f = fdopen(info.fd, "rb");
    fseek(f, info.offset, 0);
#else
    f = fopen(inFileURL, "rb");
#endif

    if (!f)
    {
        LOG_SOUND("FAILED to read sound file, file pointer as null?\n");
        return false;
    }

    OggVorbis_File oggFile;
    //Read the file data
#ifdef ANDROID
    ov_open(f, &oggFile, NULL, info.length);
#else
    ov_open(f, &oggFile, NULL, 0);
#endif

    return loadOggSample(oggFile, outBuffer, channels, bitsPerSample, outSampleRate);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
int LoadMusic(char *filename)
{
    FILE *f;

    /* First, open the file with the normal stdio interface. */

    if ((f = fopen(filename, "r")) ==  NULL)
    {
        printf("Unable to open music file %s.\n", filename);
        return -1;
    }

    /* Now pass it to libvorbis. */
    if (ov_open(f, &music_file, NULL, 0) < 0)
    {
        printf("Unable to attach libvorbis to %s.\n", filename);
        fclose(f);
        return -1;
    }

    /* Retrieve information about this stream. */
    music_info = ov_info(&music_file, -1);

    printf("Reading %li Hz, %i-channel music from %s.\n",
	   music_info->rate,
	   music_info->channels,
	   filename);
      
    music_file_loaded = 1;
	
    return 0;
}
Exemplo n.º 4
0
void oggLoad( SOggSound* o, const char* name )
{
  // file opening
  o->file = fopen( name, "rb");
  
  if( !o->file )
    {
      printf( "Sound error : %s !!!\n", name );
      return;
    }
  
  // with file, we open a ogg-vorbis stream
  if( ov_open( o->file, &o->stream, NULL, 0) )
    {
      printf( "Sound error : ogg stream error !!!\n" );
      return;
    }

  o->format = o->stream.vi->channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
  
  if( !alIsSource( o->source ) )
    {
      alGenSources( 1, &o->source );
      //printf( "create source.\n" );
    }
    
  soundCheckErrorAL( "load ogg" );
  soundCheckErrorALC( "load ogg" );
}
Exemplo n.º 5
0
bool WINCESdlMixerManager::checkOggHighSampleRate() {
	char trackFile[255];
	FILE *testFile;
	OggVorbis_File *test_ov_file = new OggVorbis_File;

	// FIXME: The following sprintf assumes that "path" is always
	// terminated by a path separator. This is *not* true in general.
	// This code really should check for the path separator, or even
	// better, use the FSNode API.
	sprintf(trackFile, "%sTrack1.ogg", ConfMan.get("path").c_str());
	// Check if we have an OGG audio track
	testFile = fopen(trackFile, "rb");
	if (testFile) {
		if (!ov_open(testFile, test_ov_file, NULL, 0)) {
			bool highSampleRate = (ov_info(test_ov_file, -1)->rate == 22050);
			ov_clear(test_ov_file);
			delete test_ov_file;
			return highSampleRate;
		}
	}

	// Do not test for OGG samples - too big and too slow anyway :)

	delete test_ov_file;
	return false;
}
Exemplo n.º 6
0
    void cOggStream::Open(const string_t& path)
    {
      LOG<<"cOggStream::Open "<<path<<std::endl;

      if(!(oggFile = fopen(breathe::string::ToUTF8(path).c_str(), "rb"))) LOG<<"cOggStream::Open Could not open Ogg file "<<path<<std::endl;

      int result = ov_open(oggFile, &oggStream, NULL, 0);
      if (result < 0) {
        fclose(oggFile);

        LOG<<"cOggStream::Open Could not open Ogg stream "<<path<<" result="<<result<<std::endl;
      }

      vorbisInfo = ov_info(&oggStream, -1);
      vorbisComment = ov_comment(&oggStream, -1);

      if (vorbisInfo->channels == 1) format = AL_FORMAT_MONO16;
      else format = AL_FORMAT_STEREO16;

      alGenBuffers(BUFFER_NUMBER, buffers);
      ReportError();
      alGenSources(1, &source);
      ReportError();

      alSource3f(source, AL_POSITION, 0.0, 0.0, 0.0);
      alSource3f(source, AL_VELOCITY, 0.0, 0.0, 0.0);
      alSource3f(source, AL_DIRECTION, 0.0, 0.0, 0.0);
      alSourcef(source, AL_ROLLOFF_FACTOR, 0.0);
      alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);

      LOG<<"cOggStream::Open "<<path<<" successfully opened, returning"<<std::endl;
    }
Exemplo n.º 7
0
bool OggAudioSource::init(const RString& path, bool loadIntoMemory)
{
	if(mLoadedInMemory && loadIntoMemory)
		return true;

	mPath = path;
	mInFile = fopen(mPath.c_str(), "rb");

	if(mInFile == NULL)
	{
		std::cerr << "Cannot open " << mPath.c_str() << " for reading..." << std::endl;
		return false;
	}

	// Try opening the given file
	if(ov_open(mInFile, &mOggFile, NULL, 0) != 0)
	{
		std::cerr << "Error opening " << mPath.c_str() << " for decoding..." << std::endl;
		return false;
	}

	// Get some information about the OGG file
	mpOggInfo = ov_info(&mOggFile, -1);

	return BufferedAudioSource::init(path, loadIntoMemory);
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
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;
}
	 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;	
	
}
Exemplo n.º 11
0
QString getMusStr(const char *fileE, int type, QPixmap &pix)
{
	QString musStr;
	pix = NULL;
	if ( type == 0 )
	{
		if ( tag_editor )
		{
			musStr = tag_editor->getData( fileE, NULL );
			if ( !musStr.isEmpty() )
				musStr = "\n"+musStr;
			return musStr;
		}
		OggVorbis_File mus;
		FILE *fil = NULL;
		fil = qmp_fopen(fileE,"rb");
		if ( ov_open(fil,&mus,NULL,0) )
		{
			if (fil)
				fclose(fil);
			return "";
		}

		getMusInfo( mus, NULL, NULL, NULL, NULL, &musStr );
		musStr = "\n" + musStr;

		ov_clear(&mus);
	}
	return musStr;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
bool AudioStreamOGG::openFile(const io::stringc &Filename)
{
    closeFile();
    
    s32 Result = 0;
    
    /* Open file */
    if ( !( OggFile_ = fopen(Filename.c_str(), "rb") ) )
    {
        io::Log::error("Could not open 'Ogg Vorbis' file");
        return false;
    }
    
    /* Open ogg vorbis file stream */
    if ( ( Result = ov_open(OggFile_, &OggStream_, 0, 0) ) < 0 )
    {
        fclose(OggFile_);
        io::Log::error("Could not open 'Ogg Vorbis' stream (" + AudioStreamOGG::getErrorString(Result) + ")");
        return false;
    }
    
    /* Get stream information */
    VorbisInfo_ = ov_info(&OggStream_, -1);
    VorbisComment_ = ov_comment(&OggStream_, -1);
    
    if (VorbisInfo_->channels == 1)
        Format_ = WAVECHANNEL_MONO16;
    else
        Format_ = WAVECHANNEL_STEREO16;
    
    return true;
}
Exemplo n.º 14
0
void infoWindow( QWidget *w, const char *fileE, int type )
{
	if ( type != 0 )
		return;

	if ( tag_editor )
	{
		tag_editor->openWindow( fileE, w, false, false );
		return;
	}

	OggVorbis_File mus;

	FILE *fil = qmp_fopen( fileE, "rb" );
	if ( ov_open(fil,&mus,NULL,0) )
	{
		if (fil)
			fclose(fil);
		ov_clear(&mus);
		return;
	}

	QString txt;
	getMusInfo( mus, NULL, NULL, NULL, NULL, &txt );
	txt = "\n\n" + txt;

	ov_clear(&mus);

	QMessageBox::information( w, PlugInfoStr, "File path: \"" + QString( fileE ) + "\"" + txt);
}
Exemplo n.º 15
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;

}
Exemplo n.º 16
0
int SoundManager::LoadOGG(WAVEFORMATEX* fformat, unsigned char** sample_data, size_t* size_data, char* ogg_path)
{
  FILE *fs;
  if(!(fs=fopen(ogg_path,"rb"))) return 0;

  OggVorbis_File vf;
  if(ov_open(fs,&vf,NULL,0)) return 0;
  vorbis_info* vi=ov_info(&vf,-1);

  int data_len=(int)ov_pcm_total(&vf,-1);
  int start_pos=(int)ov_pcm_tell(&vf);

  int BPS=vi->channels==1?2:4;
  *size_data=(data_len-start_pos)*BPS;

  *sample_data=new unsigned char[*size_data];

  size_t decoded=0;

  while (decoded < *size_data) {
    int curr;
    decoded += ov_read(&vf,(char*)(*sample_data)+decoded,(*size_data)-decoded,0,2,1,&curr);
  }

  fformat->wFormatTag=WAVE_FORMAT_PCM;
  fformat->nChannels=vi->channels;
  fformat->nSamplesPerSec=vi->rate;
  fformat->wBitsPerSample=16;
  fformat->nBlockAlign=vi->channels*fformat->wBitsPerSample/8;
  fformat->nAvgBytesPerSec=fformat->nBlockAlign*vi->rate;
  fformat->cbSize=0;

  return 1;
}
Exemplo n.º 17
0
int FileVorbis::check_sig(Asset *asset)
{
// FILEVORBIS DECODING IS DISABLED
	return 0;
	FILE *fd = fopen(asset->path, "rb");
	OggVorbis_File vf;

// Test for Quicktime since OGG misinterprets it
	fseek(fd, 4, SEEK_SET);
	char data[4];
	fread(data, 4, 1, fd);
	if(data[0] == 'm' &&
		data[1] == 'd' &&
		data[2] == 'a' &&
		data[3] == 't')
	{
		fclose(fd);
		return 0;
	}
	
	fseek(fd, 0, SEEK_SET);

	if(ov_open(fd, &vf, NULL, 0) < 0)
	{
// OGG failed.  Close file handle manually.
		ov_clear(&vf);
		if(fd) fclose(fd);
		return 0;
	}
	else
	{
		ov_clear(&vf);
		return 1;
	}
}
Exemplo n.º 18
0
void Stream::loadOgg(const char *filename)
{
   sound = filename;

   file = fopen(filename, "rb");
   if (!file)
      throw RubyException(rb_eRuntimeError, "Cannot open the stream file.");
   ov_open(file, &stream, NULL, 0);

   info = ov_info(&stream, -1);
   comment = ov_comment(&stream, -1);

   format = SAMPLES_FORMAT;
   
   alGenBuffers(2, buffers);
   if (alGetError() != AL_NO_ERROR)
      throw RubyException(rb_eRuntimeError, "Cannot generate the buffer.");

   generateSource();
   if (alGetError() != AL_NO_ERROR)
     throw RubyException(rb_eRuntimeError, "Cannot generate sources.");

   setPos(0.f, 0.f, 0.f);
   setVelocity(0.f, 0.f, 0.f);
   setDirection(0.f, 0.f, 0.f);

   setPitch(1.f);
   setGain(1.f);
}
Exemplo n.º 19
0
/* Load an OGG stream from the given file */
OGG_music *OGG_new(const char *file)
{
	OGG_music *music;
	FILE *fp;

	music = (OGG_music *)malloc(sizeof *music);
	if ( music ) {
		/* Initialize the music structure */
		memset(music, 0, (sizeof *music));
		OGG_stop(music);
		OGG_setvolume(music, MIX_MAX_VOLUME);
		music->section = -1;

		fp = fopen(file, "rb");
		if ( fp == NULL ) {
			SDL_SetError("Couldn't open %s", file);
			free(music);
			return(NULL);
		}
		if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) {
			SDL_SetError("Not an Ogg Vorbis audio stream");
			free(music);
			fclose(fp);
			return(NULL);
		}
	} else {
		SDL_SetError("Out of memory");
	}
	return(music);
}
Exemplo n.º 20
0
Arquivo: snd_ogg.c Projeto: ZwS/qudos
/*
==========
OGG_Open

Play Ogg Vorbis file (with absolute or relative index).
==========
*/
qboolean OGG_Open(ogg_seek_t type, int offset)
{
	int		 size;		/* File size. */
	int		 pos;		/* Absolute position. */
	int		 res;		/* Error indicator. */

	pos = -1;

	switch (type) {
	case ABS:
		/* Absolute index. */
		if (offset < 0 || offset >= ogg_numfiles) {
			Com_Printf("OGG_Open: %d out of range.\n", offset+1);
			return (false);
		} else
			pos = offset;
		break;
	case REL:
		/* Simulate a loopback. */
		if (ogg_curfile == -1 && offset < 0)
			offset++;
		while (ogg_curfile + offset < 0)
			offset += ogg_numfiles;
		while (ogg_curfile + offset >= ogg_numfiles)
			offset -= ogg_numfiles;
		pos = ogg_curfile + offset;
		break;
	}

	/* Check running music. */
	if (ogg_status == PLAY) {
		if (ogg_curfile == pos)
			return (true);
		else
			OGG_Stop();
	}

	/* Find file. */
	if ((size = FS_LoadFile(ogg_filelist[pos], (void **)&ogg_buffer)) == -1) {
		Com_Printf("OGG_Open: could not open %d (%s): %s.\n", pos, ogg_filelist[pos], strerror(errno));
		return (false);
	}

	/* Open ogg vorbis file. */
	if ((res = ov_open(NULL, &ovFile, (char *)ogg_buffer, size)) < 0) {
		Com_Printf("OGG_Open: '%s' is not a valid Ogg Vorbis file (error %i).\n", ogg_filelist[pos], res);
		FS_FreeFile(ogg_buffer);
		return (false);
	}

	/* Play file. */
	ovSection = 0;
	ogg_curfile = pos;
	ogg_status = PLAY;

	Com_Printf("Playing file %d '%s'\n", pos, ogg_filelist[pos]);

	return (true);
}
Exemplo n.º 21
0
int ov_fopen(char *path,OggVorbis_File *vf)
{
	int result;
    FILE *fp = fopen(path, "rb");
	if((result = ov_open(fp, vf, NULL, 0)) < 0)
		fclose(fp);
	return result;
}
Exemplo n.º 22
0
 OggVorbisReader(FILE *fp)
 {
  fseek(fp, 0, SEEK_SET);
  lseek(fileno(fp), 0, SEEK_SET);

  if(ov_open(fp, &ovfile, NULL, 0))
   throw(0);
 }
Exemplo n.º 23
0
void InstallSoundExp(void)
{
 FILE *fp=fopen("test.ogg","rb");

 ov_open(fp,&cursong,NULL,0);
 FCEUGameInfo->soundrate=44100;
 FCEUGameInfo->soundchan=2;
}
Exemplo n.º 24
0
int SoundSourceOggVorbis::open()
{
    QByteArray qBAFilename = m_qFilename.toLocal8Bit();
#ifdef __WINDOWS__
    if(ov_fopen(qBAFilename.constData(), &vf) < 0) {
        qDebug() << "oggvorbis: Input does not appear to be an Ogg bitstream.";
        filelength = 0;
        return ERR;
    }
#else
    FILE *vorbisfile =  fopen(qBAFilename.constData(), "r");

    if (!vorbisfile) {
        qDebug() << "oggvorbis: cannot open" << m_qFilename;
        return ERR;
    }

    if(ov_open(vorbisfile, &vf, NULL, 0) < 0) {
        qDebug() << "oggvorbis: Input does not appear to be an Ogg bitstream.";
        filelength = 0;
        return ERR;
    }
#endif

    // lookup the ogg's channels and samplerate
    vorbis_info * vi = ov_info(&vf, -1);

    channels = vi->channels;
    m_iSampleRate = vi->rate;

    if(channels > 2){
        qDebug() << "oggvorbis: No support for more than 2 channels!";
        ov_clear(&vf);
        filelength = 0;
        return ERR;
    }

    // ov_pcm_total returns the total number of frames in the ogg file. The
    // frame is the channel-independent measure of samples. The total samples in
    // the file is channels * ov_pcm_total. rryan 7/2009 I verified this by
    // hand. a 30 second long 48khz mono ogg and a 48khz stereo ogg both report
    // 1440000 for ov_pcm_total.
    ogg_int64_t ret = ov_pcm_total(&vf, -1);

    if (ret >= 0) {
        // We pretend that the file is stereo to the rest of the world.
        filelength = ret * 2;
    }
    else //error
    {
      if (ret == OV_EINVAL) {
          //The file is not seekable. Not sure if any action is needed.
          qDebug() << "oggvorbis: file is not seekable " << m_qFilename;
      }
    }

    return OK;
}
void music_track::resolve()
{
	if (id_.empty()) {
		LOG_AUDIO << "empty track filename specified for track identification\n";
		return;
	}

	file_path_ = get_binary_file_location("music", id_);

	if (file_path_.empty()) {
		LOG_AUDIO << "could not find track '" << id_ << "' for track identification\n";
		return;
	}


#if !defined(_WIN32) && !defined(__APPLE__) && !defined(PANDORA)
	if (title_.empty()) {
		FILE* f;
		f = fopen(file_path_.c_str(), "r");
		if (f == NULL) {
			LOG_AUDIO << "Error opening file '" << file_path_
					<< "' for track identification\n";
			return;
		}

		OggVorbis_File vf;
		if(ov_open(f, &vf, NULL, 0) < 0) {
			LOG_AUDIO << "track does not appear to be an Ogg file '"
					<< id_ << "', cannot be identified\n";
			ov_clear(&vf);
			return;
		}

		vorbis_comment* comments = ov_comment(&vf, -1);
		char** user_comments = comments->user_comments;

		bool found = false;
		for (int i=0; i< comments->comments; i++) {
			const std::string comment_string(user_comments[i]);
			const std::vector<std::string> comment_list = utils::split(comment_string, '=');

			if (comment_list[0] == "TITLE" || comment_list[0] == "title") {
				title_ = comment_list[1];
				found = true;
			}
		}
		if (!found) {
			LOG_AUDIO << "No title for music track '" << id_ << "'\n";
		}

	ov_clear(&vf);
	}
#endif

	LOG_AUDIO << "resolved music track '" << id_ << "' into '" << file_path_ << "'\n";
}
Exemplo n.º 26
0
/* Same as sndoggvorbis_start, but takes an already-opened file. Once a file is
   passed into this function, we assume that _we_ own it. */
int sndoggvorbis_start_fd(FILE * fd, int loop)
{
	vorbis_comment *vc;

	/* If we are already playing or just loading a new file
	 * we can't start another one !
	 */
	if (sndoggvorbis_status != STATUS_READY)
	{
		fclose(fd);
		return -1;
	}

	/* Initialize liboggvorbis. Try to open file and grab the headers
	 * from the bitstream
	 */

	printf("oggthread: initializing and parsing ogg\n");

	if(ov_open(fd, &vf, NULL, 0) < 0) {
		printf("sndoggvorbis: input does not appear to be an Ogg bitstream\n");
		fclose(fd);
		return -1;
	}

	sndoggvorbis_loop = loop;
	strcpy(sndoggvorbis_lastfilename, "<stream>");

	if (sndoggvorbis_queue_enabled)
		sndoggvorbis_status = STATUS_QUEUEING;
	else
		sndoggvorbis_status = STATUS_STARTING;
	sem_signal(sndoggvorbis_halt_sem);

	/* Grab all standard comments from the file
	 * (based on v-comment.html found in OggVorbis source packages
	 */
	vc = ov_comment(&vf, -1);
	if (vc == NULL) {
		dbglog(DBG_WARNING, "sndoggvorbis: can't obtain bitstream comments\n");
		sndoggvorbis_clear_comments();
	} else {
		sndoggvorbis_info.artist = vc_get_comment(vc, "artist");
		sndoggvorbis_info.title = vc_get_comment(vc, "title");
		sndoggvorbis_info.version = vc_get_comment(vc, "version");
		sndoggvorbis_info.album = vc_get_comment(vc, "album");
		sndoggvorbis_info.tracknumber = vc_get_comment(vc, "tracknumber");
		sndoggvorbis_info.organization = vc_get_comment(vc, "organization");
		sndoggvorbis_info.description = vc_get_comment(vc, "description");
		sndoggvorbis_info.genre = vc_get_comment(vc, "genre");
		sndoggvorbis_info.date = vc_get_comment(vc, "date");
		sndoggvorbis_info.filename = sndoggvorbis_lastfilename;
	}

	return 0;
}
Exemplo n.º 27
0
BOOL ovd_get_comment_from_file(LPCTSTR pszFile, ovd_comment* comment)
{
	if (!ovd_test_file(pszFile))
		return FALSE;

	FILE* fp = _tfopen(pszFile, _T("rb"));
	if (!fp)
		return FALSE;

	OggVorbis_File	vf;
	if (ov_open(fp, &vf, NULL, 0) < 0)
	{
		fclose(fp);
		return FALSE;
	}

	memset(comment, 0, sizeof(ovd_comment));
	vorbis_comment* p = ov_comment(&vf, -1);
	for (int i = 0; i < p->comments; i++)
	{
		LPTSTR psz = NULL;
		char* s = strchr(p->user_comments[i], '=');
		if (s)
		{
			*s = NULL;
			ovd_strupr(p->user_comments[i]);
			if (strcmp(p->user_comments[i], OVD_COMMENT_DATE) == 0)
				psz = comment->szDate;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_TRACKNUM) == 0)
				psz = comment->szTrackNum;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_TITLE) == 0)
				psz = comment->szTitle;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_ARTIST) == 0)
				psz = comment->szArtist;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_ALBUM) == 0)
				psz = comment->szAlbum;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_GENRE) == 0)
				psz = comment->szGenre;
			else if (strcmp(p->user_comments[i], OVD_COMMENT_COMMENT) == 0)
				psz = comment->szComment;

			if (psz)
			{
#ifdef _UNICODE
				UTF8toUCS2(s + 1, psz, OVD_COMMENT_LEN);
#else
				WCHAR sz[OVD_COMMENT_LEN];
				UTF8toUCS2(s + 1, sz, OVD_COMMENT_LEN);
				WideCharToMultiByte(CP_ACP, 0, sz, -1, psz, OVD_COMMENT_LEN, 0, 0);
#endif	
			}
		}
	}
	fclose(fp);
	return TRUE;
}
Exemplo n.º 28
0
oggDecoder::oggDecoder(FILE* File, QObject *parent)
 : fileDecoder(File, parent )
{
	decoder = new OggVorbis_File;
	if(ov_open( File, decoder, NULL, 0) != 0 )
	{
		throw( new decoderException("OGGDecoder", tr("error opening File")) );
	}
	sampleRate = decoder->vi->rate;
}
Exemplo n.º 29
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);
 }
Exemplo n.º 30
0
	/*
	==================
	Sound::Init

	Initiates the file handles, sources and buffers.
	==================
	*/
	bool Sound::Init(string file) {
		Clear();

		if (pbMethod == PLAYBACK_STREAM) {
			if (!(oggFile = fopen(file.c_str(), "rb"))) {
				return false;
			}
			
			/* Attempt to read from the file as an Ogg-file */
			oggStream = new OggVorbis_File;
			
			int result;
			if ((result = ov_open(oggFile, oggStream, NULL, 0)) < 0) {
				fclose(oggFile);
				
				delete oggStream;
				oggStream = NULL;
				
				return false;
			}
			
			/* Read format data from the file */
			vorbisInfo = ov_info(oggStream, -1);

			if (vorbisInfo->channels == 1) {
				audioData.format = AL_FORMAT_MONO16;
			} else {
				audioData.format = AL_FORMAT_STEREO16;
			}
			
			audioData.frequency = vorbisInfo->rate;
		} else if (pbMethod == PLAYBACK_CACHE) {
			cacheBuffer = AudioManager::GetSingleton()->GetCacheBytes(file);
			PimAssert(cacheBuffer != NULL, "Failed to retrieve cache buffer");
			
			audioData = AudioManager::GetSingleton()->GetCacheData(file);
			PimAssert(audioData.format != 0, "Failed to retrieve cache format");
			PimAssert(audioData.frequency != 0, "Failed to retrieve cache frequency");
		} else {
			PimAssert(0, "Init called on PLAYBACK_UNDEFINED Sound object");
			return false;
		}

		alGenBuffers(2, buffers);
		alGenSources(1, &source);

		alSource3f(source, AL_POSITION,			0.f, 0.f, 0.f);
		alSource3f(source, AL_VELOCITY,			0.f, 0.f, 0.f);
		alSource3f(source, AL_DIRECTION,		0.f, 0.f, 0.f);
		alSourcef (source, AL_ROLLOFF_FACTOR,	0.f			 );
		alSourcei (source, AL_SOURCE_RELATIVE,	AL_TRUE		 );
		
		return true;
	}