コード例 #1
0
	S32 PCMAudioManager::loadSound(const char *assetName) {
		Property *prop = btGetContext()->appProperties->get("debug_sounds");
		BOOL32 debugSounds = FALSE;
		if (prop) {
			debugSounds = prop->getBoolValue();
		}
        if (isSoundLoaded(assetName)) {
            return getSoundId(assetName);
        }
		int assetSize = 0;
		unsigned char *fileData = _platform_load_asset(assetName, &assetSize);
		S32 sndId = -1;
		if (fileData) {
			signed short *decoded;
			int channels, len;
			unsigned int sampleRate = 0;
			len = stb_vorbis_decode_memory(fileData, assetSize, &channels, &sampleRate, &decoded);
			if (debugSounds) {
				char buf[1024];
				sprintf(buf, "Loaded %s: (%i enc bytes) length=%i channels=%i rate=%i", assetName, assetSize, len, channels, sampleRate);
				logmsg(buf);
			}
			sndId = loadSound(decoded, len * channels, sampleRate, channels, assetName);
		}
		_platform_free_asset(fileData);
		return sndId;
	}
コード例 #2
0
void ofxTLAudioTrack::playbackLooped(ofxTLPlaybackEventArgs& args){
	if(isSoundLoaded() && this != timeline->getTimecontrolTrack()){
		if(!player.getIsPlaying()){
			player.play();
		}
		player.setPosition( positionForSecond(timeline->getCurrentTime()) );
	}
}
コード例 #3
0
ファイル: sound.cpp プロジェクト: AlbanBedel/scummvm
void Sound::playSoundSegment(uint32 start, uint32 end) {
	if (!isSoundLoaded())
		return;

	stopSound();

	Audio::AudioStream *subStream = new Audio::SubSeekableAudioStream(_stream, Audio::Timestamp(0, start, 600), Audio::Timestamp(0, end, 600), DisposeAfterUse::NO);

	g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, subStream, -1, _volume, 0, DisposeAfterUse::YES);
}
コード例 #4
0
void ofxTLAudioTrack::playbackStarted(ofxTLPlaybackEventArgs& args){
	ofxTLTrack::playbackStarted(args);
	if(isSoundLoaded() && this != timeline->getTimecontrolTrack()){
		//player.setPosition(timeline->getPercentComplete());
		float position = positionForSecond(timeline->getCurrentTime());
		if(position < 1.0){
			player.play();
		}
		player.setPosition( position );
	}
}
コード例 #5
0
vector<float>& ofxTLAudioTrack::getFFTSpectrum(int numBins){
	float fftPosition = player.getPosition();
	if(isSoundLoaded() && lastFFTPosition != fftPosition){
		if(defaultFFTBins != numBins){
			maxBinReceived = 0;
			defaultFFTBins = numBins;
		}
		lastFFTPosition = fftPosition;
		fftBins = player.getSpectrum(defaultFFTBins);
	}
	return fftBins;
}
コード例 #6
0
ファイル: sound.cpp プロジェクト: AlbanBedel/scummvm
void Sound::playSound() {
	if (!isSoundLoaded())
		return;

	stopSound();

	// Make sure the sound is back at the beginning before we play it
	_stream->rewind();

	if (_fader)
		setVolume(_fader->getFaderValue());

	g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, _stream, -1, _volume, 0, DisposeAfterUse::NO);
}
コード例 #7
0
ファイル: sound.cpp プロジェクト: AlbanBedel/scummvm
void Sound::loopSound() {
	if (!isSoundLoaded())
		return;

	stopSound();

	// Create a looping stream
	Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_stream, 0, DisposeAfterUse::NO);

	// Assume that if there is a fader, we're going to fade the sound in.
	if (_fader)
		setVolume(0);

	g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, loopStream, -1, _volume, 0, DisposeAfterUse::YES);
}
コード例 #8
0
//envelope and dampening approach from Marius Watz
//http://workshop.evolutionzone.com/2012/08/30/workshops-sept-89-sound-responsive-visuals-3d-printing-and-parametric-modeling/
vector<float>& ofxTLAudioTrack::getFFT(){
	float fftPosition = player.getPosition();
	if(isSoundLoaded() && lastFFTPosition != fftPosition){

        vector<float>& fftAverages = player.getAverages();
        averageSize = fftAverages.size();
        if(envelope.size() != averageSize){
            generateEnvelope(averageSize);
        }
        
        if(dampened.size() != averageSize){
            dampened.clear();
            dampened.resize(averageSize);
        }

        if(getUseFFTEnvelope()){
            for(int i = 0; i < fftAverages.size(); i++){
                fftAverages[i] *= envelope[i];
            }
        }
        
        float max = 0;
        for(int i = 0; i < fftAverages.size(); i++){
            max = MAX(max, fftAverages[i]);
        }
        if(max != 0){
            for(int i = 0; i < fftAverages.size(); i++){
                fftAverages[i] = ofMap(fftAverages[i],0, max, 0, 1.0);
            }
        }
 
        for(int i = 0; i < averageSize; i++) {
            dampened[i] = (fftAverages[i] * dampening) + dampened[i]*(1-dampening);
        }
        
        //normalizer hack
        lastFFTPosition = fftPosition;
	}
    
	return dampened;
}
コード例 #9
0
ファイル: sound.cpp プロジェクト: AlbanBedel/scummvm
bool Sound::isPlaying() {
	return isSoundLoaded() && g_system->getMixer()->isSoundHandleActive(_handle);
}
コード例 #10
0
void ofxTLAudioTrack::playbackEnded(ofxTLPlaybackEventArgs& args){
	if(isSoundLoaded() && this != timeline->getTimecontrolTrack()){
		player.stop();
	}
}
コード例 #11
0
float ofxTLAudioTrack::positionForSecond(float second){
	if(isSoundLoaded()){
		return ofMap(second, 0, player.getDuration(), 0, 1.0, true);
	}
	return 0;
}
コード例 #12
0
void ofxTLAudioTrack::setFFTLogAverages(int minBandwidth, int bandsPerOctave){
    if(isSoundLoaded()){
        player.setLogAverages(minBandwidth, bandsPerOctave);
    }
}