ComponentResult Reset (AudioUnitScope inScope, AudioUnitElement inElement)
    {
        if (! prepared)
            prepareToPlay();

        return JuceAUBaseClass::Reset (inScope, inElement);
    }
示例#2
0
pdsp::Sampler::Sampler(){

        addInput("trig", input_trig);
        addInput("pitch", input_pitch_mod);
        addInput("select", input_select);
        addInput("start", input_start);
        addInput("direction", input_direction);
        addOutput("signal", output);
        updateOutputNodes();  
        
        incBase = 1.0f / 11050.0f;
        sample = nullptr;
        readIndex = 0.0f;
        direction = 1.0f;
        
        positionMeter.store(0.0f);
        positionDivider = 0.000000000001f;

        input_pitch_mod.setDefaultValue(0.0f);
        input_select.setDefaultValue(0.0f);
        input_start.setDefaultValue(0.0f);
        input_direction.setDefaultValue(1.0f);
        //input_trigger_to_start.setDefaultValue(0.0f);


        interpolatorShell.changeInterpolator(Linear);

        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
void MediaPlayerPrivateAVFoundation::load(const String& url)
{
    LOG(Media, "MediaPlayerPrivateAVFoundation::load(%p)", this);

    if (m_networkState != MediaPlayer::Loading) {
        m_networkState = MediaPlayer::Loading;
        m_player->networkStateChanged();
    }
    if (m_readyState != MediaPlayer::HaveNothing) {
        m_readyState = MediaPlayer::HaveNothing;
        m_player->readyStateChanged();
    }

    m_videoFrameHasDrawn = false;
    m_assetURL = url;

    // Don't do any more work if the url is empty.
    if (!url.length())
        return;

    if (m_preload == MediaPlayer::None) {
        LOG(Media, "MediaPlayerPrivateAVFoundation::load(%p) - preload==none so returning", this);
        m_delayingLoad = true;
        return;
    }

    prepareToPlay();
}
示例#4
0
PitchedDelay::PitchedDelay(float samplerate)
	: pitch(1.f),
		sampleRate(samplerate),
		feedback(0.f),
		pingpong(false),
		preDelayPitch(false),
		enablePitch(false),
		latency(0),
		currentTime(2),
		delayL(MAXDELAYSECONDS),
		delayR(MAXDELAYSECONDS),
		sizeLastData(0)
{
#if ! _WIN64
	pitcher.addPitchProc(new PitchDiracLE(PitchDiracLE::kPreview));
	pitcher.addPitchProc(new PitchDiracLE(PitchDiracLE::kGood));
	pitcher.addPitchProc(new PitchDiracLE(PitchDiracLE::kBetter));
	pitcher.addPitchProc(new PitchDiracLE(PitchDiracLE::kBest));
#endif
	pitcher.addPitchProc(new Detune("Detune (low-latency)", 256));
	pitcher.addPitchProc(new Detune("Detune (compromise)", 1024));
	pitcher.addPitchProc(new Detune("Detune (best)", 4096));

	prepareToPlay(44100, 512);
}
示例#5
0
pdsp::BufferShell::BufferShell() {
    buffer = nullptr;
    overSample = 1;

    if(dynamicConstruction) {
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#6
0
pdsp::TriggerControl::TriggerControl(){
    
    addOutput("trig", output);
    updateOutputNodes();
    
    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }    
}
void MediaPlayerPrivateAVFoundation::resumeLoad()
{
    LOG(Media, "MediaPlayerPrivateAVFoundation::resumeLoad(%p)", this);

    ASSERT(m_delayingLoad);
    m_delayingLoad = false;

    if (m_assetURL.length())
        prepareToPlay();
}
示例#8
0
pdsp::Formula::Formula(){
        addInput("signal", input);
        addOutput("signal", output);
        updateOutputNodes();
        lastProcessedValue = 0.0f;
        input.setDefaultValue(0.0f);

        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
示例#9
0
pdsp::ExternalInput::ExternalInput() {
    buffer = nullptr;
    output.buffer = nullptr;
    output.state = AudioRate;
    addOutput("signal", output);
    updateOutputNodes();

    if(dynamicConstruction) {
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#10
0
void audio_StreamSource_play(audio_StreamSource *source) {
  switch(source->common.state) {
  case audio_SourceState_stopped:
    prepareToPlay(source);
    // Fall through
  case audio_SourceState_paused:
    audio_SourceCommon_play(&source->common);
    break;
  default:
    break;
  }
}
示例#11
0
void audio_StreamSource_rewind(audio_StreamSource *source) {
  // TODO Skip to end of current buffers if playing or paused
  audio_SourceState state = source->common.state;

  audio_StreamSource_stop(source);

  if(state == audio_SourceState_playing) {
    audio_StreamSource_play(source);
  } else {
    prepareToPlay(source);
    source->common.state = audio_SourceState_paused;
  }
}
示例#12
0
pdsp::Decimator::Decimator(){
    
    phase = 1.0f;
    addInput("signal", input_signal);
    addInput("freq", input_freq);
    addOutput("output", output);
    updateOutputNodes();

    input_freq.setDefaultValue(44100.0f);

    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#13
0
pdsp::TriggerGeiger::TriggerGeiger(){
    
    addInput("jitter",   in_jitter_ms );
    addInput("distance", in_distance_ms );
    addOutput("trig", output_trig);
    updateOutputNodes();
    
    in_distance_ms.setDefaultValue(200.0f);
    in_jitter_ms.setDefaultValue(0.0f);

    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#14
0
文件: Amp.cpp 项目: drakh/ofxPDSP
pdsp::Amp::Amp(){
        addInput("signal", input_signal);
        addInput("mod", input_mod);
        addOutput("signal", output);
        updateOutputNodes();
    
        input_mod.setDefaultValue(0.0f);
    
        meter.store(0.0f);
        meterOut.store(0.0f);
    
        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
示例#15
0
pdsp::ValueSequencer::ValueSequencer(){
        
    addOutput("signal", output);
    resetOutputToDefault();

    setSlewTime(0.0f);
    
    connectToSlewControl = false;

    messageBuffer = nullptr;
    slewControl = nullptr;

    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#16
0
pdsp::PRNoiseGen::PRNoiseGen(){

    addInput("clock", input_trig_clock);
    addInput("reseed", input_trig_seed);
    addOutput("signal", output);
    updateOutputNodes();

    seedMult = rand();
    //seed = seedMult * time(NULL);
    seed = randomInt();
    pnRegister = seed;

    if(dynamicConstruction){
            prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#17
0
ofxPDSPValue::ofxPDSPValue(){
    addOutput("signal", output);
    updateOutputNodes();
    slewInitValue = 0.0f;
    value = 0.0f;
    lastValue = numeric_limits<float>::infinity();
    this->deactivateSlew();
  
    parameter.addListener(this, &ofxPDSPValue::onSet);
    parameter_i.addListener(this, &ofxPDSPValue::onSetI);
    parameter.set( 0.0f );
    parameter_i.set( 0 );
    
    if(dynamicConstruction){
            prepareToPlay(globalBufferSize, globalSampleRate);
    }
    
}
示例#18
0
pdsp::GainComputer::GainComputer(){
    addInput("signal", input);
    addOutput("signal", output);
    addInput("threshold", in_thresh);
    addInput("ratio", input_ratio);
    addInput("knee", input_knee);
    updateOutputNodes();
    
    in_thresh.setDefaultValue(-20.0f);
    
    input_ratio.setDefaultValue(4.0f);
    CS = 1.0f-(1.0f/4.0f);
    
    input_knee.setDefaultValue(0.0f);
    
    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }    
}
Ebu128LoudnessMeter::Ebu128LoudnessMeter()
    : bufferForMeasurement(2, 2048), // Initialise the buffer with some common values.
    // Also initialise the two filters with the coefficients for a sample
    // rate of 44100 Hz. These values are given in the ITU-R BS.1770-2.
    preFilter(1.53512485958697,  // b0
              -2.69169618940638, // b1
              1.19839281085285,  // b2
              -1.69065929318241, // a1
              0.73248077421585), // a2
    revisedLowFrequencyBCurveFilter(1.0,               // b0
                                    -2.0,              // b1
                                    1.0,               // b2
                                    -1.99004745483398, // a1
                                    0.99007225036621), // a2
    numberOfBins (0),
    numberOfSamplesPerBin (0),
    numberOfSamplesInAllBins (0),
    numberOfBinsToCover400ms (0),
    numberOfSamplesIn400ms (0),
    numberOfBinsToCover100ms (0),
    numberOfBinsSinceLastGateMeasurementForI (0),
    millisecondsSinceLastGateMeasurementForLRA (0),
    numberOfBlocksToCalculateRelativeThreshold (0),
    sumOfAllBlocksToCalculateRelativeThreshold(0.0),
    relativeThreshold (absoluteThreshold),
    numberOfBlocksToCalculateRelativeThresholdLRA (0),
    sumOfAllBlocksToCalculateRelativeThresholdLRA (0.0),
    relativeThresholdLRA (absoluteThreshold),
    integratedLoudness (minimalReturnValue),
    loudnessRangeStart(minimalReturnValue),
    loudnessRangeEnd(minimalReturnValue)
{
    DBG ("The longest possible measurement until a bufferoverflow = "
        + String(INT_MAX / 10. / 3600. / 365.) + " years");
    
    // If this class is used without caution and processBlock
    // is called before prepareToPlay, divisions by zero
    // might occure. E.g. if numberOfSamplesInAllBins = 0.
    //
    // To prevent this, prepareToPlay is called here with
    // some arbitrary arguments.
    prepareToPlay(44100.0, 2, 512, 20);
}
示例#20
0
pdsp::EnvelopeFollower::EnvelopeFollower(){
    addInput("signal", input);
    addInput("attack", in_attack_ms);
    addInput("release", in_release_ms);
    addOutput("signal", output);
    updateOutputNodes();
    
    //TC = logf(0.368); //Analog
    TC = logf(0.01); //Digital
    envelopeOutput = 0.0f;
    in_attack_ms.setDefaultValue(20.0f);
    in_release_ms.setDefaultValue(50.0f);
    
    meter.store(0.0f);
    
    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#21
0
pdsp::ClockedPhazor::ClockedPhazor(){

        addInput("retrig", input_trig);
        addOutput("phase", output_phase);
        addOutput("trig", output_trig);
        addInput("phase start", input_phase);
        addInput("division", input_division);
        updateOutputNodes();
        
        input_division.setDefaultValue(4.0f);


        input_phase.setDefaultValue(0.0f);
        oversampleFactor = 1.0f;

        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
示例#22
0
pdsp::ScoreProcessor::ScoreProcessor(){
    
    //synchronizeClockable = true;
    tempo = 120.0;
    playHead = 0.0;
    playHeadEnd = 0.0;
    maxBars = 32000.0;
    
    clearToken = 0;
    
    playhead_meter.store(0.0f);
    
    sections.clear();
    setSections(1);
    
    playing.store(false);
    
    if(dynamicConstruction){
        prepareToPlay(globalBufferSize, globalSampleRate);
    }
}
示例#23
0
pdsp::GrainWindow::GrainWindow(){
    
        addInput("signal", input_signal);
        addInput("trig", input_trigger);
        addInput("length", input_length_ms);

        addOutput("signal", output);
        
        updateOutputNodes();

        //interpolatorShell.changeInterpolator(Linear);
        setWindowType(Triangular);
        
        input_length_ms.setDefaultValue(200.0f);

        windowMeter.store(0.0f);
        
        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
    //==============================================================================
    ComponentResult Initialize()
    {
#if ! JucePlugin_IsSynth
        const int numIns = GetInput(0) != 0 ? GetInput(0)->GetStreamFormat().mChannelsPerFrame : 0;
#endif
        const int numOuts = GetOutput(0) != 0 ? GetOutput(0)->GetStreamFormat().mChannelsPerFrame : 0;

        bool isValidChannelConfig = false;

        for (int i = 0; i < numChannelConfigs; ++i)
#if JucePlugin_IsSynth
            if (numOuts == channelConfigs[i][1])
#else
            if (numIns == channelConfigs[i][0] && numOuts == channelConfigs[i][1])
#endif
                isValidChannelConfig = true;

        if (! isValidChannelConfig)
            return kAudioUnitErr_FormatNotSupported;

        JuceAUBaseClass::Initialize();
        prepareToPlay();
        return noErr;
    }
void MediaPlayerPrivateAVFoundation::updateStates()
{
    if (m_ignoreLoadStateChanges)
        return;

    MediaPlayer::NetworkState newNetworkState = m_networkState;
    MediaPlayer::ReadyState newReadyState = m_readyState;

    if (m_loadingMetadata)
        newNetworkState = MediaPlayer::Loading;
    else {
        // -loadValuesAsynchronouslyForKeys:completionHandler: has invoked its handler; test status of keys and determine state.
        AssetStatus assetStatus = this->assetStatus();
        ItemStatus itemStatus = playerItemStatus();
        
        m_assetIsPlayable = (assetStatus == MediaPlayerAVAssetStatusPlayable);
        if (m_readyState < MediaPlayer::HaveMetadata && assetStatus > MediaPlayerAVAssetStatusLoading) {
            if (m_assetIsPlayable) {
                if (assetStatus >= MediaPlayerAVAssetStatusLoaded)
                    newReadyState = MediaPlayer::HaveMetadata;
                if (itemStatus <= MediaPlayerAVPlayerItemStatusUnknown) {
                    if (assetStatus == MediaPlayerAVAssetStatusFailed || m_preload > MediaPlayer::MetaData || isLiveStream()) {
                        // The asset is playable but doesn't support inspection prior to playback (eg. streaming files),
                        // or we are supposed to prepare for playback immediately, so create the player item now.
                        newNetworkState = MediaPlayer::Loading;
                        prepareToPlay();
                    } else
                        newNetworkState = MediaPlayer::Idle;
                }
            } else {
                // FIX ME: fetch the error associated with the @"playable" key to distinguish between format 
                // and network errors.
                newNetworkState = MediaPlayer::FormatError;
            }
        }
        
        if (assetStatus >= MediaPlayerAVAssetStatusLoaded && itemStatus > MediaPlayerAVPlayerItemStatusUnknown) {
            switch (itemStatus) {
            case MediaPlayerAVPlayerItemStatusDoesNotExist:
            case MediaPlayerAVPlayerItemStatusUnknown:
            case MediaPlayerAVPlayerItemStatusFailed:
                break;

            case MediaPlayerAVPlayerItemStatusPlaybackLikelyToKeepUp:
            case MediaPlayerAVPlayerItemStatusPlaybackBufferFull:
                // If the status becomes PlaybackBufferFull, loading stops and the status will not
                // progress to LikelyToKeepUp. Set the readyState to  HAVE_ENOUGH_DATA, on the
                // presumption that if the playback buffer is full, playback will probably not stall.
                newReadyState = MediaPlayer::HaveEnoughData;
                break;

            case MediaPlayerAVPlayerItemStatusReadyToPlay:
                if (m_readyState != MediaPlayer::HaveEnoughData && maxTimeLoaded() > currentMediaTime())
                    newReadyState = MediaPlayer::HaveFutureData;
                break;

            case MediaPlayerAVPlayerItemStatusPlaybackBufferEmpty:
                newReadyState = MediaPlayer::HaveCurrentData;
                break;
            }

            if (itemStatus == MediaPlayerAVPlayerItemStatusPlaybackBufferFull)
                newNetworkState = MediaPlayer::Idle;
            else if (itemStatus == MediaPlayerAVPlayerItemStatusFailed)
                newNetworkState = MediaPlayer::DecodeError;
            else if (itemStatus != MediaPlayerAVPlayerItemStatusPlaybackBufferFull && itemStatus >= MediaPlayerAVPlayerItemStatusReadyToPlay)
                newNetworkState = (maxTimeLoaded() == durationMediaTime()) ? MediaPlayer::Loaded : MediaPlayer::Loading;
        }
    }

    if (isReadyForVideoSetup() && currentRenderingMode() != preferredRenderingMode())
        setUpVideoRendering();

    if (!m_haveReportedFirstVideoFrame && m_cachedHasVideo && hasAvailableVideoFrame()) {
        if (m_readyState < MediaPlayer::HaveCurrentData)
            newReadyState = MediaPlayer::HaveCurrentData;
        m_haveReportedFirstVideoFrame = true;
        m_player->firstVideoFrameAvailable();
    }

#if !LOG_DISABLED
    if (m_networkState != newNetworkState || m_readyState != newReadyState) {
        LOG(Media, "MediaPlayerPrivateAVFoundation::updateStates(%p) - entered with networkState = %i, readyState = %i,  exiting with networkState = %i, readyState = %i",
            this, static_cast<int>(m_networkState), static_cast<int>(m_readyState), static_cast<int>(newNetworkState), static_cast<int>(newReadyState));
    }
#endif

    setNetworkState(newNetworkState);
    setReadyState(newReadyState);

    if (m_playWhenFramesAvailable && hasAvailableVideoFrame()) {
        m_playWhenFramesAvailable = false;
        platformPlay();
    }
}
示例#26
0
void LoopMachine::setPreset(const char* const presetFilename) {
//    std::cout << "MPD: CPP: LoopMachine::setPreset: setting looper preset to: " << presetFilename << std::endl;
    
    File presetFile(presetFilename);
    File presetDir = presetFile.getParentDirectory();
    var preset = JSON::parse(presetFile);
    
//    std::cout << "MPD: CPP: LoopMachine::setPreset: preset json: " << preset.toString() << std::endl;
    
    auto& obj = *preset.getDynamicObject();
	jassert(&obj != nullptr);
    
//    std::cout << "MPD: CPP: LoopMachine::setPreset: preset name: " << obj.getProperty("preset").toString()
//    << "; created by: " << obj.getProperty("createdBy").toString() << ", orig bpm: "
//    << obj.getProperty("origBpm").toString() << std::endl;
    
    fixedBpmTransport.setBpm(obj.getProperty("origBpm"));

    var groups = obj.getProperty("groups");
    
    for (int i = 0; i < groups.size(); i++) {
        var group = groups[i];
        auto& obj = *group.getDynamicObject();
        String groupName = obj.getProperty("name");
//        std::cout << "MPD: CPP: LoopMachine::setPreset: adding loops for " << groupName << std::endl;
		
        var loops = obj.getProperty("loops");
        for (int j = 0; j < loops.size(); j++) {
			var sampleInfoObj = loops[j];
			auto& sampleInfo = *sampleInfoObj.getDynamicObject();
			
			float gain = sampleInfo.getProperty("gain");
			String typeStr = sampleInfo.getProperty("type");
			LoopType type = typeStr == "one-shot" ? LoopType::ONE_SHOT : LoopType::LOOP;
			int length = type == LoopType::LOOP ? (int) sampleInfo.getProperty("length") : -1;
            File sample = presetDir.getChildFile(sampleInfo.getProperty("file").toString());
            
//            std::cout << "MPD: CPP: LoopMachine::setPreset: adding sample: "
//            << sample.getFullPathName() << std::endl;
            
            addLoop(groupName, sample, gain, type, length);
        }
    }
	
	var scenes = obj.getProperty("scenes");
	
	for (int i = 0; i < scenes.size(); i++) {
		var scene = scenes[i];
		auto& obj = *scene.getDynamicObject();
		
		String name = obj.getProperty("name");
		int sceneIx = addScene(name);
		
		var loops = obj.getProperty("loops");
		for (int j = 0; j < loops.size(); j++) {
			var obj2 = loops[j];
			auto& info = *obj2.getDynamicObject();
			
			String group = info.getProperty("group");
			int groupIx = groupNameToIx[group];
			int loopIx = info.getProperty("loopIx");
			
			addSceneLoop(sceneIx, groupIx, loopIx);
		}
		
	}
    
    prepareToPlay(expectedBufferSize, audioEngine.getTransport().getSampleRate());
}
void MediaPlayerPrivateAVFoundation::updateStates()
{
    MediaPlayer::NetworkState oldNetworkState = m_networkState;
    MediaPlayer::ReadyState oldReadyState = m_readyState;

    LOG(Media, "MediaPlayerPrivateAVFoundation::updateStates(%p) - entering with networkState = %i, readyState = %i", 
        this, static_cast<int>(m_networkState), static_cast<int>(m_readyState));

    if (m_loadingMetadata)
        m_networkState = MediaPlayer::Loading;
    else {
        // -loadValuesAsynchronouslyForKeys:completionHandler: has invoked its handler; test status of keys and determine state.
        AVAssetStatus avAssetStatus = assetStatus();
        ItemStatus itemStatus = playerItemStatus();
        
        m_assetIsPlayable = (avAssetStatus == MediaPlayerAVAssetStatusPlayable);
        if (m_readyState < MediaPlayer::HaveMetadata && avAssetStatus > MediaPlayerAVAssetStatusLoading) {
            if (m_assetIsPlayable) {
                if (itemStatus == MediaPlayerAVPlayerItemStatusUnknown) {
                    if (avAssetStatus == MediaPlayerAVAssetStatusFailed || m_preload > MediaPlayer::MetaData) {
                        // We may have a playable asset that doesn't support inspection prior to playback; go ahead 
                        // and create the AVPlayerItem now. When the AVPlayerItem becomes ready to play, we will 
                        // have access to its metadata. Or we may have been asked to become ready to play immediately.
                        m_networkState = MediaPlayer::Loading;
                        prepareToPlay();
                    } else
                        m_networkState = MediaPlayer::Idle;
                }
                if (avAssetStatus == MediaPlayerAVAssetStatusLoaded)
                    m_readyState = MediaPlayer::HaveMetadata;
            } else {
                // FIX ME: fetch the error associated with the @"playable" key to distinguish between format 
                // and network errors.
                m_networkState = MediaPlayer::FormatError;
            }
        }
        
        if (avAssetStatus >= MediaPlayerAVAssetStatusLoaded && itemStatus > MediaPlayerAVPlayerItemStatusUnknown) {
            if (seeking())
                m_readyState = m_readyState >= MediaPlayer::HaveMetadata ? MediaPlayer::HaveMetadata : MediaPlayer::HaveNothing;
            else {
                float maxLoaded = maxTimeLoaded();
                switch (itemStatus) {
                case MediaPlayerAVPlayerItemStatusUnknown:
                    break;
                case MediaPlayerAVPlayerItemStatusFailed:
                    m_networkState = MediaPlayer::DecodeError;
                    break;
                case MediaPlayerAVPlayerItemStatusPlaybackLikelyToKeepUp:
                    m_readyState = MediaPlayer::HaveEnoughData;
                    break;
                case MediaPlayerAVPlayerItemStatusReadyToPlay:
                case MediaPlayerAVPlayerItemStatusPlaybackBufferEmpty:
                case MediaPlayerAVPlayerItemStatusPlaybackBufferFull:
                    if (maxLoaded > currentTime())
                        m_readyState = MediaPlayer::HaveFutureData;
                    else
                        m_readyState = MediaPlayer::HaveCurrentData;
                    break;
                }

                if (itemStatus >= MediaPlayerAVPlayerItemStatusReadyToPlay)
                    m_networkState = (maxLoaded == duration()) ? MediaPlayer::Loaded : MediaPlayer::Loading;
            }
        }
    }

    if (isReadyForVideoSetup() && currentRenderingMode() != preferredRenderingMode())
        setUpVideoRendering();

    if (m_networkState != oldNetworkState)
        m_player->networkStateChanged();

    if (m_readyState != oldReadyState)
        m_player->readyStateChanged();

    LOG(Media, "MediaPlayerPrivateAVFoundation::updateStates(%p) - exiting with networkState = %i, readyState = %i", 
        this, static_cast<int>(m_networkState), static_cast<int>(m_readyState));
}
示例#28
0
void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
{
    prepareToPlay (device->getCurrentSampleRate(),
                   device->getCurrentBufferSizeSamples());
}
void MediaPlayerPrivateAVFoundation::updateStates()
{
    if (m_ignoreLoadStateChanges)
        return;

    MediaPlayer::NetworkState oldNetworkState = m_networkState;
    MediaPlayer::ReadyState oldReadyState = m_readyState;

    LOG(Media, "MediaPlayerPrivateAVFoundation::updateStates(%p) - entering with networkState = %i, readyState = %i", 
        this, static_cast<int>(m_networkState), static_cast<int>(m_readyState));

    if (m_loadingMetadata)
        m_networkState = MediaPlayer::Loading;
    else {
        // -loadValuesAsynchronouslyForKeys:completionHandler: has invoked its handler; test status of keys and determine state.
        AssetStatus assetStatus = this->assetStatus();
        ItemStatus itemStatus = playerItemStatus();
        
        m_assetIsPlayable = (assetStatus == MediaPlayerAVAssetStatusPlayable);
        if (m_readyState < MediaPlayer::HaveMetadata && assetStatus > MediaPlayerAVAssetStatusLoading) {
            if (m_assetIsPlayable) {
                if (assetStatus >= MediaPlayerAVAssetStatusLoaded)
                    m_readyState = MediaPlayer::HaveMetadata;
                if (itemStatus <= MediaPlayerAVPlayerItemStatusUnknown) {
                    if (assetStatus == MediaPlayerAVAssetStatusFailed || m_preload > MediaPlayer::MetaData || isLiveStream()) {
                        // The asset is playable but doesn't support inspection prior to playback (eg. streaming files),
                        // or we are supposed to prepare for playback immediately, so create the player item now.
                        m_networkState = MediaPlayer::Loading;
                        prepareToPlay();
                    } else
                        m_networkState = MediaPlayer::Idle;
                }
            } else {
                // FIX ME: fetch the error associated with the @"playable" key to distinguish between format 
                // and network errors.
                m_networkState = MediaPlayer::FormatError;
            }
        }
        
        if (assetStatus >= MediaPlayerAVAssetStatusLoaded && itemStatus > MediaPlayerAVPlayerItemStatusUnknown) {
            switch (itemStatus) {
            case MediaPlayerAVPlayerItemStatusDoesNotExist:
            case MediaPlayerAVPlayerItemStatusUnknown:
            case MediaPlayerAVPlayerItemStatusFailed:
                break;

            case MediaPlayerAVPlayerItemStatusPlaybackLikelyToKeepUp:
                m_readyState = MediaPlayer::HaveEnoughData;
                break;

            case MediaPlayerAVPlayerItemStatusPlaybackBufferFull:
            case MediaPlayerAVPlayerItemStatusReadyToPlay:
                // If the readyState is already HaveEnoughData, don't go lower because of this state change.
                if (m_readyState == MediaPlayer::HaveEnoughData)
                    break;

            case MediaPlayerAVPlayerItemStatusPlaybackBufferEmpty:
                if (maxTimeLoaded() > currentTime())
                    m_readyState = MediaPlayer::HaveFutureData;
                else
                    m_readyState = MediaPlayer::HaveCurrentData;
                break;
            }

            if (itemStatus == MediaPlayerAVPlayerItemStatusPlaybackBufferFull)
                m_networkState = MediaPlayer::Idle;
            else if (itemStatus == MediaPlayerAVPlayerItemStatusFailed)
                m_networkState = MediaPlayer::DecodeError;
            else if (itemStatus != MediaPlayerAVPlayerItemStatusPlaybackBufferFull && itemStatus >= MediaPlayerAVPlayerItemStatusReadyToPlay)
                m_networkState = (maxTimeLoaded() == duration()) ? MediaPlayer::Loaded : MediaPlayer::Loading;
        }
    }

    if (isReadyForVideoSetup() && currentRenderingMode() != preferredRenderingMode())
        setUpVideoRendering();

    if (!m_haveReportedFirstVideoFrame && m_cachedHasVideo && hasAvailableVideoFrame()) {
        if (m_readyState < MediaPlayer::HaveCurrentData)
            m_readyState = MediaPlayer::HaveCurrentData;
        m_haveReportedFirstVideoFrame = true;
        m_player->firstVideoFrameAvailable();
    }

    if (m_networkState != oldNetworkState)
        m_player->networkStateChanged();

    if (m_readyState != oldReadyState)
        m_player->readyStateChanged();

    if (m_playWhenFramesAvailable && hasAvailableVideoFrame()) {
        m_playWhenFramesAvailable = false;
        platformPlay();
    }

    LOG(Media, "MediaPlayerPrivateAVFoundation::updateStates(%p) - exiting with networkState = %i, readyState = %i", 
        this, static_cast<int>(m_networkState), static_cast<int>(m_readyState));
}