void ofSoundPlayerExtended::readFile(string fileName, vector<short> & buffer){
    if(ofFilePath::getFileExt(fileName)!="mp3" && ofFilePath::getFileExt(fileName)!="MP3"){
        if(!sfReadFile(fileName,buffer,fftAuxBuffer)) return;
    }else{
#ifdef OF_USING_MPG123
        if(!mpg123ReadFile(fileName,buffer,fftAuxBuffer)) return;
#else
        if(!decoderReadFile(fileName,buffer,fftAuxBuffer)) return;
#endif
    }
    
    int numFrames = buffer.size()/channels;
    
}
void ofOpenALSoundPlayer::readFile(string fileName, vector<short> & buffer){
#ifdef OF_USING_MPG123
	if(ofFileUtils::getFileExt(fileName)!="mp3" && ofFileUtils::getFileExt(fileName)!="MP3"){
		if(!sfReadFile(fileName,buffer,fftAuxBuffer)) return;
	}else{
		if(!mpg123ReadFile(fileName,buffer,fftAuxBuffer)) return;
	}
#else
	if(!sfReadFile(fileName,buffer,fftAuxBuffer)) return;
#endif
	fftBuffers.resize(channels);
	int numFrames = buffer.size()/channels;

	for(int i=0;i<channels;i++){
		fftBuffers[i].resize(numFrames);
		for(int j=0;j<numFrames;j++){
			fftBuffers[i][j] = fftAuxBuffer[j*channels+i];
		}
	}
}
Exemplo n.º 3
0
//--------------------------------------------------------------
bool ofxSoundFile::readTo(ofSoundBuffer & buffer, unsigned int _samples){
	buffer.setNumChannels(channels);
	buffer.setSampleRate(samplerate);
	if(_samples!=0){
		// will read the requested number of samples
		// clamp to the number of samples we actually have
		_samples = min(_samples,samples);
		buffer.resize(_samples*channels);
	}
#ifdef OF_USING_SNDFILE
	else if (sndFile){
		// will read entire file
		buffer.resize(samples);
	}
#endif
#ifdef OF_USING_LAD
	else if (audioDecoder) {
		// will read entire file
		buffer.resize(samples);
	}
#endif
#ifdef OF_USING_MPG123
	else if(mp3File){
		buffer.clear();
	}
#endif
	
#ifdef OF_USING_SNDFILE
	if(sndFile) return sfReadFile(buffer);
#elif defined( OF_USING_MPG123 )
	if(mp3File) return mpg123ReadFile(buffer);
#elif defined( OF_USING_LAD )
	if(audioDecoder) return ladReadFile(buffer);
#endif
	return false;
}