Ejemplo n.º 1
0
void OpenALPlayer::Notify()
{
	ALsizei newplayed;
	alGetSourcei(source, AL_BUFFERS_PROCESSED, &newplayed);

	LOG_D("player/audio/openal") << "buffers_played=" << buffers_played << " newplayed=" << newplayed;

	if (newplayed > 0) {
		// Reclaim buffers
		ALuint bufs[num_buffers];
		for (ALsizei i = 0; i < newplayed; ++i) {
			bufs[i] = buffers[buf_first_queued];
			buf_first_queued = (buf_first_queued + 1) % num_buffers;
		}
		alSourceUnqueueBuffers(source, newplayed, bufs);
		buffers_free += newplayed;

		// Update
		buffers_played += newplayed;
		playback_segment_timer.Start();

		// Fill more buffers
		FillBuffers(newplayed);
	}

	LOG_D("player/audio/openal") << "frames played=" << (buffers_played - num_buffers) * decode_buffer.size() / bpf << " num frames=" << end_frame - start_frame;
	// Check that all of the selected audio plus one full set of buffers has been queued
	if ((buffers_played - num_buffers) * (int64_t)decode_buffer.size() > (end_frame - start_frame) * bpf) {
		Stop();
	}
}
Ejemplo n.º 2
0
void AudioDeck::ResetDeck()
{
    if (cs->IsOpen())
        cs->Close();

    int ss = 1;
    if (decodeData->bit==16) ss = 2;
    this->sampsize = ss * decodeData->ch;

    this->currentPosition = 0;
    this->totsamps = 0;
    this->failed = false;

    this->playStarted = false;
    this->pause = false;

    this->decodeData->outOfData = false;

    this->isFinished = false;

    vc.Clean();
    vc.Reset();
    this->vizlast = 0;

    this->bufferCountdown = NUM_BUFFERS;
    cs->Open(decodeData->ch, decodeData->bit, decodeData->samplerate);
    FillBuffers();

    cs->SetVolume(volume);
    cs->SetPitch(pitchBend);
    cs->SetPan(pan);
    //memset(&this->fades,0,sizeof(AudioFades));
}
Ejemplo n.º 3
0
void OpenALPlayer::Play(int64_t start, int64_t count)
{
	if (playing) {
		// Quick reset
		playing = false;
		alSourceStop(source);
		alSourcei(source, AL_BUFFER, 0);
	}

	// Set params
	start_frame = start;
	cur_frame = start;
	end_frame = start + count;
	playing = true;

	// Prepare buffers
	buffers_free = num_buffers;
	buffers_played = 0;
	buf_first_free = 0;
	buf_first_queued = 0;
	FillBuffers(num_buffers);

	// And go!
	alSourcePlay(source);
	wxTimer::Start(100);
	playback_segment_timer.Start();
}
Ejemplo n.º 4
0
void AudioIO::OnTimer()
{
   if (!mProject)
      return;
   
   FillBuffers();
   
   if (mT1!=mT0 && mT >= mT1 && GetIndicator() >= mT1)
      Stop();
}
Ejemplo n.º 5
0
POSITION CFileEditCtrl::GetStartPosition()
{
	// if the window is active, fills the buffers with the text in the window.
	// returns a pointer to the buffer, type-casted as an MFC POSITION structure
	if (IsWindow(this) && m_bTextChanged)
	{
		FillBuffers();
		m_bTextChanged = FALSE;
	}
	return (POSITION)m_lpstrFiles;
}
Ejemplo n.º 6
0
bool AudioIO::Start()
{
   mT = mT0;
   mOutID = 1;
   mInID = 1;
   mBufferSize = 4096;
   mInUnderruns = 0;
   mRepeats = 0;

   unsigned int i;

   if (mNumInChannels > 0) {
      mInBuffer = new AudioIOBuffer[mMaxBuffers];
      for(i=0; i<mMaxBuffers; i++) {
         mInBuffer[i].ID = 0;   // means it's empty
         mInBuffer[i].len = 0;
         mInBuffer[i].data = NewSamples(mBufferSize * mNumInChannels,
                                        mFormat);
      }
   }
   else
      mInBuffer = NULL;

   if (mNumOutChannels > 0) {
      mOutBuffer = new AudioIOBuffer[mMaxBuffers];
      for(i=0; i<mMaxBuffers; i++) {
         mOutBuffer[i].ID = 0;   // means it's empty
         mOutBuffer[i].len = 0;
         mOutBuffer[i].data = NewSamples(mBufferSize * mNumOutChannels,
                                         mFormat);
      }
   }
   else
      mOutBuffer = NULL;
   
   FillBuffers();

   if (!OpenDevice()) {
      wxMessageBox(_("Error opening audio device.\n"
                     "(Change the device in the Preferences dialog.)"));

      return false;
   }

   PaError error = Pa_StartStream(mPortStream);

   mProject->SetStop(false);
   mProject->ReReadSettings();
   mProject->HandleResize();

   return (error == paNoError);
}
Ejemplo n.º 7
0
void CDX10Core::RenderMeshObject(CMeshObject *pObj, float dt)
{
	static float timeSpent = 0;
	timeSpent+= dt;
	if(!pObj || !pObj->m_pMesh || !pObj->m_pMesh->m_numVertices)
		return;

	FillBuffers(pObj);	

	D3DXMATRIX rotMatY, rotMatX, translate;
	D3DXMatrixRotationY(&rotMatY, 0.01f * 3.1416f * timeSpent);
	D3DXMatrixRotationX(&rotMatX,  0.3416f );
	D3DXMatrixTranslation(&translate, 0, 0, 80);
	m_matWorld = D3DXMATRIX((float *)pObj->m_matGlobal) * rotMatX * rotMatY * translate ;	

	m_pWorldMatrixEffectVariable->SetMatrix(m_matWorld);
	m_pViewMatrixEffectVariable->SetMatrix(m_matView);
	m_pProjectionMatrixEffectVariable->SetMatrix(m_matProjection);

	// Set the input layout
	m_pDevice->IASetInputLayout( m_pVertexLayout );

	ID3D10Buffer * pVBs[]={ m_pVertexBuffers[VBT_POSITION0], m_pVertexBuffers[VBT_COLOR0], m_pVertexBuffers[VBT_NORMAL0]};
	UINT strides[] = {sizeof(D3DXVECTOR3), sizeof(D3DXVECTOR4), sizeof(D3DXVECTOR3)};
	UINT offsets[] = {0, 0, 0};
	m_pDevice->IASetVertexBuffers( 0, 3, pVBs, strides, offsets );

	// Set index buffer	
	m_pDevice->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

	// Set primitive topology 
	m_pDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );	


	//get technique desc
	D3D10_TECHNIQUE_DESC techDesc;
	m_pBasicTechnique->GetDesc( &techDesc );

	for( UINT p = 0; p < techDesc.Passes; ++p )
	{
		//apply technique
		m_pBasicTechnique->GetPassByIndex( p )->Apply( 0 );

		//draw
		m_pDevice->DrawIndexed( pObj->m_pMesh->m_numIndices, 0, 0 );
	}	
}
    void AudioOutputDeviceCoreAudio::CreateAndStartAudioQueue() throw(Exception) {
        OSStatus res = AudioQueueNewOutput (
            &aqPlayerState.mDataFormat,
            HandleOutputBuffer,
            &aqPlayerState,
            CFRunLoopGetCurrent(),
            kCFRunLoopCommonModes,
            0,
            &aqPlayerState.mQueue
        );

        if(res) {
            String s = String("AudioQueueNewOutput: Error ") + ToString(res);
            throw Exception(s);
        }

        CFStringRef devUID = CFStringCreateWithCString (
            NULL, CurrentDevice.GetUID().c_str(), kCFStringEncodingASCII
        );
        res = AudioQueueSetProperty (
            aqPlayerState.mQueue,
            kAudioQueueProperty_CurrentDevice,
            &devUID, sizeof(CFStringRef)
        );
        CFRelease(devUID);

        if(res) {
            String s = String("Failed to set audio device: ") + ToString(res);
            throw Exception(s);
        }

        for (int i = 0; i < uiBufferNumber; ++i) {
            res = AudioQueueAllocateBuffer (
                aqPlayerState.mQueue,
                aqPlayerState.bufferByteSize,
                &aqPlayerState.mBuffers[i]
            );

            if(res) {
                String s = String("AudioQueueAllocateBuffer: Error ");
                throw Exception(s + ToString(res));
            }
        }

        res = AudioQueueAddPropertyListener (
            aqPlayerState.mQueue,
            kAudioQueueProperty_CurrentDevice,
            AudioQueueListener,
            NULL
        );
        if(res) std::cerr << "Failed to register device change listener: " << res << std::endl;

        res = AudioQueueAddPropertyListener (
            aqPlayerState.mQueue,
            kAudioQueueProperty_IsRunning,
            AudioQueueListener,
            NULL
        );
        if(res) std::cerr << "Failed to register running listener: " << res << std::endl;

        Float32 gain = 1.0;

        res = AudioQueueSetParameter (
            aqPlayerState.mQueue,
            kAudioQueueParam_Volume,
            gain
        );

        if(res) std::cerr << "AudioQueueSetParameter: Error " << res << std::endl;

        atomic_set(&(aqPlayerState.mIsRunning), 1);
        FillBuffers();
        PrimeAudioQueue();

        res = AudioQueueStart(aqPlayerState.mQueue, NULL);
        if(res) {
            String s = String("AudioQueueStart: Error ") + ToString(res);
            throw Exception(s);
        }
    }
Ejemplo n.º 9
0
void AudioDeck::Update()
{
    // If we're asking for a pause, let's pause!
    if (this->pause) {
        if (cs->IsPlaying())
            cs->Pause(); // Double check and make sure we're paused

        // Let the visualization know we're to be clear
        if (this->vis) this->vis->bClear = true;
        return;
    }
    else
    {
        // Not paused...
        if (this->playStarted && !cs->IsPlaying())
            cs->Resume(); // resume please
    }

    /**
    // Check to see if we need to seek...
    if (decodeData->seekOffset != -1 && 0)
    {
        cs->Close();
        delete cs;
        cs = new ChannelStream();
        cs->Open(decodeData->ch, decodeData->bit, decodeData->samplerate);

    	cs->SetPan(this->pan);
    	cs->SetVolume(this->volume);

        if (this->pitchBend != 1.0f)
    	{
    		cs->SetPitch(this->pitchBend);
    		if (this->vis) this->vis->bDisabled = 1;
    	}
    	else if (this->vis) this->vis->bDisabled = 0;

    	if (this->lastSeekPos >= 0){
            vc.Clean();
            vc.Reset();

    		this->writtenpos = this->lastSeekPos;
    		writtenpos = (this->lastSeekPos/1000)*decodeData->samplerate*sampsize;
    		//od->writtenpos = (totsamps*1000)/(oc->samples*sampsize);
    		cs->SetPlayOffset(this->lastSeekPos);
    		this->currentPosition = this->lastSeekPos;
    	}
    	else
    	{
    		this->lastSeekPos = 0;
    		this->writtenpos = 0;
    		//if (od->vis) od->vis->bClear = true;
    	}
    }
     **/

    if (decodeData->seekOffset != -1) {
        long seekTo = decodeData->seekOffset;
        bool repause = this->pause;
        ResetDeck();
        lastSeekPos = seekTo;
        if (!repause) cs->Play();
        this->pause = repause;
    }

    if (UpdateFades()) {
        // We stop here?
    }

    FillBuffers();
}