int WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine, int CmdShow)
{	
	HWND Window = GetWindow("nlife-class", "sound-server", 1920, 1080, WindowProc);

	win32_bitmap_buffer BitmapBuffer;
	Win32AllocBitmapBuffer(&BitmapBuffer, 1920, 1080);
	
	Speakers Speaker = {};		
	Speaker.SamplesPerSec = 48000;
	Speaker.BufferSize = (48000*4)/16;
	Speaker.Raw = (s8*)malloc(sizeof(s8)*Speaker.BufferSize);
	
	Microphone Mic = {};	
	Mic.SamplesPerSec = 48000;
	Mic.BufferSize = (48000*4)/16;
	Mic.Raw = (s8*)malloc(sizeof(s8)*Mic.BufferSize);
	
	InitDSoundSpeakers(Window, &Speaker);
	InitDSoundMic(&Mic);
	
	Record(&Mic);
	Play(&Speaker);
		
	MSG Message;
	AppRunning = true;
	   		
	while(AppRunning)
	{
		while(PeekMessage(&Message, 0, 0, 0, PM_REMOVE) > 0)
		{
			TranslateMessage(&Message);
			DispatchMessage(&Message);
		}

		Mic.RecordedSampleCount = 0;
		
		RecordMic(&Mic);
	    RenderSound(&Speaker, (s16*)Mic.Raw, Mic.RecordedSampleCount);
		
		DrawRect(&BitmapBuffer, 0, 0, BitmapBuffer.Width, BitmapBuffer.Height, 0, 0, 0); 
		RenderWave(&BitmapBuffer, (s16*)Mic.Raw, Mic.RecordedSampleCount*2, 10, 20,
				   BitmapBuffer.Height-200, 1.0f, 0.0f, 0.0f,
				   BitmapBuffer.Width, BitmapBuffer.Height);		
						
		HDC DeviceContext = GetDC(Window);
		{
			win32_window_dimension Dimension = Win32WindowDimension(Window);
			Win32BlitBitmap(DeviceContext, &BitmapBuffer, Dimension.Width, Dimension.Height);
		}	   
		ReleaseDC(Window, DeviceContext);				
	}

	WSACleanup();
	return 0;
}
Example #2
0
DWORD WINAPI InitGL(HWND hDlg) // Tarea de dibujado
{
    HDC hDC;
    HGLRC hglrc;

    hDC = GetDC(GetDlgItem(hDlg, ID_GRAFICO));

    PIXELFORMATDESCRIPTOR pfd = {
        sizeof (PIXELFORMATDESCRIPTOR), // size of this pfd
        1, // version number
        PFD_DRAW_TO_WINDOW | // support window
        PFD_SUPPORT_OPENGL, // support OpenGL
        PFD_TYPE_RGBA, // RGBA type
        32, // 24-bit color depth
        0, 0, 0, 0, 0, 0, // color bits ignored
        0, // no alpha buffer
        0, // shift bit ignored
        0, // no accumulation buffer
        0, 0, 0, 0, // accum bits ignored
        32, // 32-bit z-buffer
        0, // no stencil buffer
        0, // no auxiliary buffer
        PFD_MAIN_PLANE, // main layer
        0, // reserved
        0, 0, 0 // layer masks ignored
    };

    // get the device context's best, available pixel format match
    // make that match the device context's current pixel format
    SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);

    hglrc = wglCreateContext(hDC);
    // Select first Window as the rendering context and draw to it
    wglMakeCurrent(hDC, hglrc);

    sourceBitmap = (byte*) malloc(BLUR_TEXT_TAM * BLUR_TEXT_TAM);
    targetBitmap = (byte*) malloc(BLUR_TEXT_TAM * BLUR_TEXT_TAM);

    // ******  inicializar glew *******
    //glewExperimental = GL_TRUE;
    glewInit();

    // Configurar Blending y antialiasing
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Modos de Antialiasing (mejor calidad)
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

    // Activar Blending
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glShadeModel(GL_FLAT);

    // Color de fondo de pantalla
    glClearColor(0, 0.12f, 0, 0);

    // Crear una textura vacia para el blur
    GLuint blur_textura;
    glGenTextures(1, &blur_textura);
    glBindTexture(GL_TEXTURE_2D, blur_textura); //Activar textura
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BLUR_TEXT_TAM, BLUR_TEXT_TAM, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);

    // crear un framebuffer object
    GLuint mifbo;
    glGenFramebuffers(1, &mifbo);

    // enlazar la textura al color del FBO
    glBindFramebuffer(GL_FRAMEBUFFER, mifbo); //Activar framebuffer de usuario
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, blur_textura, 0);
    
    // acomodar la ventana la primera vez
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    OglFlag = OGL_DEFORMAR; 
    
    while (1) // loop de renderizado
    {
        switch (OglFlag)
        {
        case (OGL_DEFORMAR):
            InverseStretch(hDlg, ID_GRAFICO, 420, 128);
            OglFlag = OGL_RUN;
            break;

        case (OGL_STOP):
            wglMakeCurrent(NULL, NULL);
            ReleaseDC(hDlg, hDC);
            wglDeleteContext(hglrc);
            free(sourceBitmap);
            free(targetBitmap);
            return TRUE;
        }
        
        glBindFramebuffer(GL_FRAMEBUFFER, mifbo); //Activar framebuffer de usuario
        RenderWave();
        Sleep(10); // Throttle the loop. If we don't put a sleep here, the thread will use 100% cpu
    }
}