Example #1
0
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
AsioSample::AsioSample (LPUNKNOWN pUnk, HRESULT *phr)
	: CUnknown("ASIOSAMPLE", pUnk, phr)

//------------------------------------------------------------------------------------------

#else

// when not on windows, we derive from AsioDriver
AsioSample::AsioSample () : AsioDriver ()

#endif
{
	long i;

	blockFrames = kBlockFrames;
	inputLatency = blockFrames;		// typically
	outputLatency = blockFrames * 2;
	// typically blockFrames * 2; try to get 1 by offering direct buffer
	// access, and using asioPostOutput for lower latency
	samplePosition = 0;
	sampleRate = 44100.;
	milliSeconds = (long)((double)(kBlockFrames * 1000) / sampleRate);
	active = false;
	started = false;
	timeInfoMode = false;
	tcRead = false;
	for (i = 0; i < kNumInputs; i++)
	{
		inputBuffers[i] = 0;
		inMap[i] = 0;
	}
#if TESTWAVES
	sawTooth = sineWave = 0;
#endif
	for (i = 0; i < kNumOutputs; i++)
	{
		outputBuffers[i] = 0;
		outMap[i] = 0;
	}
	callbacks = 0;
	activeInputs = activeOutputs = 0;
	toggle = 0;
}

//------------------------------------------------------------------------------------------
AsioSample::~AsioSample ()
{
	stop ();
	outputClose ();
	inputClose ();
	disposeBuffers ();
}

//------------------------------------------------------------------------------------------
void AsioSample::getDriverName (char *name)
{
	strcpy (name, "Sample ASIO");
}
Example #2
0
//------------------------------------------------------------------------------------------
KXAsio::~KXAsio ()
{
//  timeEndPeriod(1);

    debug("kxasio: destructor\n");

    stop ();
    disposeBuffers ();

    if(ikx)
    {
     ikx->asio_close();
     ikx->close();
     delete ikx;
     ikx=NULL;
    }
}
Example #3
0
//-----------------------------------------------------------------------------
//! Deletes the entire uniform grid data
void SLUniformGrid::deleteAll()
{
    if (_vox)
    {   for (SLuint i=0; i<_voxCnt; ++i) 
        {   if (_vox[i])
            {   _vox[i]->clear();
                delete _vox[i];
            }
        }
        delete[] _vox;
    }

    _vox         = 0;
    _voxCnt      = 0;
    _voxCntEmpty = 0;
    _voxMaxTria  = 0;
    _voxAvgTria  = 0;
    
    disposeBuffers();
}
Example #4
0
//------------------------------------------------------------------------------------------
ASIOError KXAsio::createBuffers (ASIOBufferInfo *bufferInfos, long numChannels,
    long bufferSize, ASIOCallbacks *callbacks)
{
    ASIOBufferInfo *info = bufferInfos;
    long i;
    bool notEnoughMem = false;

    activeInputs = 0;
    activeOutputs = 0;
    blockFrames = bufferSize;

    for (i = 0; i < numChannels; i++, info++)
    {
        if (info->isInput)
        {
            if (info->channelNum < 0 || info->channelNum >= (num_inputs))
                goto error;
            inMap[activeInputs] = info->channelNum;

            int ret;
AGAIN1:
            int cnt;
            for(cnt=0;cnt<3;cnt++)
            {
                ret=ikx->asio_alloc(ASIO_INPUT,info->channelNum,(void **)&inputBuffers[activeInputs],blockFrames * 2 * bps / 8,(int)sampleRate,bps);

                if (inputBuffers[activeInputs] && ret==0)
                {
                    info->buffers[0] = inputBuffers[activeInputs];
                    info->buffers[1] = (void *)((uintptr_t)inputBuffers[activeInputs] + (uintptr_t)(blockFrames*bps/8));
                    inputBufferSizes[activeInputs]=blockFrames * 2 * bps / 8;
                    memset(info->buffers[0],0,(blockFrames*bps/8));
                    memset(info->buffers[1],0,(blockFrames*bps/8));
                    break;
                }
                debug("!! kxasio: asio_alloc failed: input #%d [size=%d] ret=%d -- extending pool by %d bytes; GetLastError()=%x\n",
                  activeInputs,blockFrames*2*bps/8,ret,blockFrames*2*2*bps/8,GetLastError());
                if(ret==E_INVALIDARG)
                {
                 set_config(KXASIO_LATENCY,1024);
                 break;
                }
                extend_memory(blockFrames * 2 * 2 * bps / 8);
            }
            if(ret || (inputBuffers[activeInputs]==0))
            {
                char name[256];
                sprintf(name,"Error creating input buffer #%d: error = %d [size=%d]\nGetLastError()=%x\n\n%s\n\nRetry?",
                  activeInputs,ret,blockFrames*2*bps/8,GetLastError(),get_asio_error_string(ret));
                if(MessageBox(NULL,name,"kX ASIO",((ret==E_INVALIDARG)?MB_OK:MB_YESNO)|MB_ICONSTOP)==IDYES)
                 goto AGAIN1;
                info->buffers[0] = info->buffers[1] = 0;
                notEnoughMem = true;

                set_defaults(1);
                break;
            }
            activeInputs++;
            if (activeInputs > num_inputs)
            {
error:
                disposeBuffers();
                return ASE_InvalidParameter;
            }
        }
        else    // output           
        {
            if (info->channelNum < 0 || info->channelNum >= num_outputs)
                goto error;
            outMap[activeOutputs] = info->channelNum;
AGAIN2:
            int ret;
            for(int cnt=0;cnt<3;cnt++)
            {
                ret=ikx->asio_alloc(ASIO_OUTPUT,info->channelNum,(void **)&outputBuffers[activeOutputs],blockFrames * 2 * bps/8,(int)sampleRate,bps);

                if (outputBuffers[activeOutputs] && ret==0)
                {
                    info->buffers[0] = outputBuffers[activeOutputs];
                    info->buffers[1] = (void *)((uintptr_t)outputBuffers[activeOutputs] + (uintptr_t)blockFrames*bps/8);
                    outputBufferSizes[activeOutputs]=blockFrames * 2 * bps / 8;

                    memset(info->buffers[0],0,(blockFrames*bps/8));
                    memset(info->buffers[1],0,(blockFrames*bps/8));
                    break;
                }
                debug("kxasio: asio_alloc failed: output #%d [size=%d] ret=%d -- extending pool by %d bytes; GetLastError()=%x\n",
                  activeOutputs,blockFrames*2*bps/8,ret,blockFrames*2*2*bps/8,GetLastError());
                if(ret==E_INVALIDARG)
                {
                 set_config(KXASIO_LATENCY,1024);
                 break;
                }
                extend_memory(blockFrames * 2 * 2 * bps/8);
            }
            if(ret || (outputBuffers[activeOutputs]==0))
            {
                char name[256];
                sprintf(name,"Error creating output buffer #%d: error = %d [size=%d]\nGetLastError()=%x\n\n%s\n\nRetry?",
                  activeOutputs,ret,blockFrames*2*bps/8,GetLastError(),get_asio_error_string(ret));
                if(MessageBox(NULL,name,"kX ASIO",((ret==E_INVALIDARG)?MB_OK:MB_YESNO)|MB_ICONSTOP)==IDYES)
                 goto AGAIN2;
                info->buffers[0] = info->buffers[1] = 0;
                notEnoughMem = true;

                set_config(KXASIO_LATENCY,1024);
                set_config(KXASIO_BPS,16);

                int freq=48000; ikx->get_clock(&freq);

                set_config(KXASIO_FREQ,freq);
                set_config(KXASIO_N_PB_CHN,16);
                set_config(KXASIO_N_REC_CHN,16);
                break;
            }
            activeOutputs++;
            if (activeOutputs > num_outputs)
            {
                activeOutputs--;
                disposeBuffers();
                return ASE_InvalidParameter;
            }
        }
    }       
    if (notEnoughMem)
    {
        strcpy (errorMessage,"not enough virtual memory");
        disposeBuffers();
                debug("kxasio: alloc(): not enough memory\n");
        return ASE_NoMemory;
    }

    this->callbacks = callbacks;

    if(callbacks && callbacks->asioMessage && (callbacks->asioMessage(kAsioSupportsTimeInfo, 0, 0, 0)))
    {
        timeInfoMode = true;
        asioTime.timeInfo.speed = 1.;
        asioTime.timeInfo.systemTime.hi = asioTime.timeInfo.systemTime.lo = 0;
        asioTime.timeInfo.samplePosition.hi = asioTime.timeInfo.samplePosition.lo = 0;
        asioTime.timeInfo.sampleRate = sampleRate;
        asioTime.timeInfo.flags = kSystemTimeValid | kSamplePositionValid | kSampleRateValid;

        asioTime.timeCode.speed = 1.;
        asioTime.timeCode.timeCodeSamples.lo = asioTime.timeCode.timeCodeSamples.hi = 0;

        if(tcRead)
          asioTime.timeCode.flags = kTcValid | kTcRunning;
        else
          asioTime.timeCode.flags = 0;
    }
    else
    {
        timeInfoMode = false;   
        memset(&asioTime,0,sizeof(asioTime));
    }
    return ASE_OK;
}
Example #5
0
int main() {
    std::string dataRoot;
#ifdef DATA_ROOT
    dataRoot = DATA_ROOT;
#else
    std::cerr << "No DATA_ROOT path found" << std::endl;
    return -1;
#endif

    GLFWwindow *window = nullptr;

    if (initWindow(window)) {
        return -1;
    }

    Shader shader(dataRoot + "/data/shaders/shader.vert", dataRoot + "/data/shaders/shader.frag");

    Texture textures(dataRoot + "/data/assets/textures.png");
    Texture normals(dataRoot + "/data/assets/normals.png");

    std::vector<GLfloat> vertices;
    std::vector<GLuint> indices;

    std::vector<Quad> quads;

    Map map(10, 10);
    for (int x = 0; x < map.getWidth(); ++x) {
        for (int y = 0; y < map.getHeight(); ++y) {
            if (map.isPassable(x, y)) {
                quads.push_back(Quad(glm::vec3(x, 0, -y), glm::vec3(0, 0, -1), glm::vec3(1, 0, 0), 0.5f, 0.0f));
                quads.push_back(Quad(glm::vec3(x, 1, -y), glm::vec3(1, 0, 0), glm::vec3(0, 0, -1), 0.0f, 0.5f));
            }
            for (int direction = 0; direction < 4; ++direction) {
                int cx = x + dx[direction];
                int cy = y + dy[direction];
                if (map.isPassable(x, y) && !map.isPassable(cx, cy)) {
                    quads.push_back(Quad(
                            glm::vec3(x, 0, -y) + WALL_SHIFT[direction],
                            glm::vec3(0, 1, 0),
                            WALL_DIRECTION[direction],
                            0.0f,
                            0.0f
                    ));
                }
            }
        }
    }

    for (int index = 0; index < quads.size(); ++index) {
        Quad quad = quads[index];
        quad.update(vertices);

        indices.push_back(GLuint(4 * index + 0));
        indices.push_back(GLuint(4 * index + 1));
        indices.push_back(GLuint(4 * index + 2));

        indices.push_back(GLuint(4 * index + 2));
        indices.push_back(GLuint(4 * index + 3));
        indices.push_back(GLuint(4 * index + 0));
    }

    GLuint VBO, VAO, EBO;
    createBuffers(VBO, VAO, EBO, vertices, indices);

    glm::mat4 projection = glm::perspective(45.0f, WIDTH / (float) HEIGHT, 0.1f, 100.0f);
    glm::vec3 lamp(map.getWidth() / 2, 0.9f, -map.getHeight() / 2);

    float time = (float) glfwGetTime();

    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();

        float cTime = (float) glfwGetTime();
        float delta = cTime - time;
        time = cTime;

        update(map, delta);

        glClearColor(117 / 255.0f, 187 / 255.0f, 253 / 255.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        shader.use();

        GLint textureLocation = glGetUniformLocation(shader.get(), "textureSampler");
        glUniform1i(textureLocation, 0);

        GLint normalLocation = glGetUniformLocation(shader.get(), "normalSampler");
        glUniform1i(normalLocation, 1);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textures.get());

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, normals.get());

        GLfloat timeValue = (GLfloat) glfwGetTime();

        GLfloat xValue = (GLfloat) (sin(timeValue) / 4) + 0.25f;
        GLint xValueLocation = glGetUniformLocation(shader.get(), "xValue");
        glUniform1f(xValueLocation, xValue);

        GLfloat yValue = (GLfloat) (cos(timeValue + 0.2) / 4) + 0.25f;
        GLint yValueLocation = glGetUniformLocation(shader.get(), "yValue");
        glUniform1f(yValueLocation, yValue);

        glm::mat4 model;
        model = glm::rotate(model, rotation, glm::vec3(0.0f, 1.0f, 0.0f));
        model = glm::translate(model, -cameraPos);

        GLint modelLocation = glGetUniformLocation(shader.get(), "model");
        glUniformMatrix4fv(modelLocation, 1, GL_FALSE, glm::value_ptr(model));

        glm::mat4 view;
        glm::vec3 eye(0.0f, 0.5f, 0.0f);
        view = glm::lookAt(eye, eye + cameraFront, cameraUp);

        GLint viewLocation = glGetUniformLocation(shader.get(), "view");
        glUniformMatrix4fv(viewLocation, 1, GL_FALSE, glm::value_ptr(view));

        GLint projectionLocation = glGetUniformLocation(shader.get(), "projection");
        glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, glm::value_ptr(projection));

        GLint lightSourceLocation = glGetUniformLocation(shader.get(), "lightSource");
        if (spotlight) {
            glUniform3f(lightSourceLocation, cameraPos.x, cameraPos.y + 0.5f, cameraPos.z);
        } else {
            glUniform3f(lightSourceLocation, lamp.x, lamp.y, lamp.z);
        }

        glm::vec3 lookDirection = glm::normalize(glm::rotate(cameraFront, -rotation, cameraUp));
        GLint lookDirectionLocation = glGetUniformLocation(shader.get(), "lookDirection");
        glUniform3f(lookDirectionLocation, lookDirection.x, lookDirection.y, lookDirection.z);

        GLint spotlightLocation = glGetUniformLocation(shader.get(), "spotlight");
        glUniform1i(spotlightLocation, spotlight);

        glBindVertexArray(VAO);
        glDrawElements(GL_TRIANGLES, (GLuint) indices.size(), GL_UNSIGNED_INT, 0);
        glBindVertexArray(0);

        glfwSwapBuffers(window);
    }

    disposeBuffers(VBO, VAO, EBO);

    glfwTerminate();
    return 0;
}
Example #6
0
//------------------------------------------------------------------------------------------
ASIOError AsioSample::createBuffers (ASIOBufferInfo *bufferInfos, long numChannels,
	long bufferSize, ASIOCallbacks *callbacks)
{
	ASIOBufferInfo *info = bufferInfos;
	long i;
	bool notEnoughMem = false;

	activeInputs = 0;
	activeOutputs = 0;
	blockFrames = bufferSize;
	for (i = 0; i < numChannels; i++, info++)
	{
		if (info->isInput)
		{
			if (info->channelNum < 0 || info->channelNum >= kNumInputs)
				goto error;
			inMap[activeInputs] = info->channelNum;
			inputBuffers[activeInputs] = new short[blockFrames * 2];	// double buffer
			if (inputBuffers[activeInputs])
			{
				info->buffers[0] = inputBuffers[activeInputs];
				info->buffers[1] = inputBuffers[activeInputs] + blockFrames;
			}
			else
			{
				info->buffers[0] = info->buffers[1] = 0;
				notEnoughMem = true;
			}
			activeInputs++;
			if (activeInputs > kNumInputs)
			{
error:
				disposeBuffers();
				return ASE_InvalidParameter;
			}
		}
		else	// output			
		{
			if (info->channelNum < 0 || info->channelNum >= kNumOutputs)
				goto error;
			outMap[activeOutputs] = info->channelNum;
			outputBuffers[activeOutputs] = new short[blockFrames * 2];	// double buffer
			if (outputBuffers[activeOutputs])
			{
				info->buffers[0] = outputBuffers[activeOutputs];
				info->buffers[1] = outputBuffers[activeOutputs] + blockFrames;
			}
			else
			{
				info->buffers[0] = info->buffers[1] = 0;
				notEnoughMem = true;
			}
			activeOutputs++;
			if (activeOutputs > kNumOutputs)
			{
				activeOutputs--;
				disposeBuffers();
				return ASE_InvalidParameter;
			}
		}
	}		
	if (notEnoughMem)
	{
		disposeBuffers();
		return ASE_NoMemory;
	}

	this->callbacks = callbacks;
	if (callbacks->asioMessage (kAsioSupportsTimeInfo, 0, 0, 0))
	{
		timeInfoMode = true;
		asioTime.timeInfo.speed = 1.;
		asioTime.timeInfo.systemTime.hi = asioTime.timeInfo.systemTime.lo = 0;
		asioTime.timeInfo.samplePosition.hi = asioTime.timeInfo.samplePosition.lo = 0;
		asioTime.timeInfo.sampleRate = sampleRate;
		asioTime.timeInfo.flags = kSystemTimeValid | kSamplePositionValid | kSampleRateValid;

		asioTime.timeCode.speed = 1.;
		asioTime.timeCode.timeCodeSamples.lo = asioTime.timeCode.timeCodeSamples.hi = 0;
		asioTime.timeCode.flags = kTcValid | kTcRunning ;
	}
	else
		timeInfoMode = false;	
	return ASE_OK;
}