Got a listen loop set up for the mic
This commit is contained in:
parent
26caed68a4
commit
9d1809b5e2
|
@ -9,11 +9,6 @@
|
||||||
// - need to request opening a network port and getting messages from it pumped into CustomUpdate
|
// - need to request opening a network port and getting messages from it pumped into CustomUpdate
|
||||||
//
|
//
|
||||||
|
|
||||||
struct foo_
|
|
||||||
{
|
|
||||||
u32 Heyo;
|
|
||||||
};
|
|
||||||
|
|
||||||
internal gs_data
|
internal gs_data
|
||||||
BlumenLumen_CustomInit(app_state* State, context Context)
|
BlumenLumen_CustomInit(app_state* State, context Context)
|
||||||
{
|
{
|
||||||
|
@ -23,9 +18,10 @@ BlumenLumen_CustomInit(app_state* State, context Context)
|
||||||
// the sculpture's CustomUpdate function;
|
// the sculpture's CustomUpdate function;
|
||||||
gs_data Result = {};
|
gs_data Result = {};
|
||||||
|
|
||||||
Result = PushSizeToData(&State->Permanent, sizeof(foo_));
|
Result = PushSizeToData(&State->Permanent, sizeof(blumen_lumen_state));
|
||||||
foo_* MyFoo = (foo_*)Result.Memory;
|
|
||||||
MyFoo->Heyo = 5;
|
blumen_lumen_state* BLState = (blumen_lumen_state*)Result.Memory;
|
||||||
|
BLState->JobReq.Memory = (u8*)&BLState->MicPacketBuffer;
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
|
gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
|
||||||
|
@ -41,7 +37,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
|
||||||
Anim0.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
|
Anim0.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
|
||||||
Animation_AddLayer(&Anim0, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
|
Animation_AddLayer(&Anim0, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
|
||||||
|
|
||||||
Animation_AddBlock(&Anim0, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(5), 0);
|
Animation_AddBlock(&Anim0, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(11), 0);
|
||||||
|
|
||||||
AnimationArray_Push(&State->AnimationSystem.Animations, Anim0);
|
AnimationArray_Push(&State->AnimationSystem.Animations, Anim0);
|
||||||
|
|
||||||
|
@ -53,10 +49,22 @@ BlumenLumen_CustomInit(app_state* State, context Context)
|
||||||
Anim1.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
|
Anim1.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
|
||||||
Animation_AddLayer(&Anim1, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
|
Animation_AddLayer(&Anim1, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
|
||||||
|
|
||||||
Animation_AddBlock(&Anim1, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(5), 0);
|
Animation_AddBlock(&Anim1, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(12), 0);
|
||||||
|
|
||||||
AnimationArray_Push(&State->AnimationSystem.Animations, Anim1);
|
AnimationArray_Push(&State->AnimationSystem.Animations, Anim1);
|
||||||
|
|
||||||
|
animation Anim2 = {0};
|
||||||
|
Anim2.Name = PushStringF(&State->Permanent, 256, "i_love_you");
|
||||||
|
Anim2.Layers = AnimLayerArray_Create(State->AnimationSystem.Storage, 8);
|
||||||
|
Anim2.Blocks_ = AnimBlockArray_Create(State->AnimationSystem.Storage, 8);
|
||||||
|
Anim2.PlayableRange.Min = 0;
|
||||||
|
Anim2.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
|
||||||
|
Animation_AddLayer(&Anim2, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
|
||||||
|
|
||||||
|
Animation_AddBlock(&Anim2, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(10), 0);
|
||||||
|
|
||||||
|
AnimationArray_Push(&State->AnimationSystem.Animations, Anim2);
|
||||||
|
|
||||||
State->AnimationSystem.TimelineShouldAdvance = true;
|
State->AnimationSystem.TimelineShouldAdvance = true;
|
||||||
} // End Animation Playground
|
} // End Animation Playground
|
||||||
|
|
||||||
|
@ -66,8 +74,42 @@ BlumenLumen_CustomInit(app_state* State, context Context)
|
||||||
internal void
|
internal void
|
||||||
BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
||||||
{
|
{
|
||||||
foo_* MyFoo = (foo_*)UserData.Memory;
|
blumen_lumen_state* BLState = (blumen_lumen_state*)UserData.Memory;
|
||||||
Assert(MyFoo->Heyo == 5);
|
|
||||||
|
gs_string BlueString = MakeString("blue");
|
||||||
|
gs_string GreenString = MakeString("green");
|
||||||
|
gs_string ILoveYouString = MakeString("i_love_you");
|
||||||
|
|
||||||
|
while (BLState->MicPacketBuffer.ReadHead != BLState->MicPacketBuffer.WriteHead)
|
||||||
|
{
|
||||||
|
gs_data PacketData = BLState->MicPacketBuffer.Values[BLState->MicPacketBuffer.ReadHead++];
|
||||||
|
microphone_packet Packet = *(microphone_packet*)PacketData.Memory;
|
||||||
|
|
||||||
|
u32 NameLen = CStringLength(Packet.AnimationFileName);
|
||||||
|
if (StringEqualsCharArray(BlueString.ConstString, Packet.AnimationFileName, NameLen))
|
||||||
|
{
|
||||||
|
State->AnimationSystem.ActiveAnimationIndex = 0;
|
||||||
|
}
|
||||||
|
else if (StringEqualsCharArray(GreenString.ConstString, Packet.AnimationFileName, NameLen))
|
||||||
|
{
|
||||||
|
State->AnimationSystem.ActiveAnimationIndex = 1;
|
||||||
|
}
|
||||||
|
else if (StringEqualsCharArray(ILoveYouString.ConstString, Packet.AnimationFileName, NameLen))
|
||||||
|
{
|
||||||
|
State->AnimationSystem.ActiveAnimationIndex = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
gs_string TempString = PushStringF(State->Transient, 256, "%.*s", 32, Packet.AnimationFileName);
|
||||||
|
NullTerminate(&TempString);
|
||||||
|
|
||||||
|
OutputDebugStringA("Received\n");
|
||||||
|
OutputDebugStringA(TempString.Str);
|
||||||
|
|
||||||
|
if (BLState->MicPacketBuffer.ReadHead >= PACKETS_MAX)
|
||||||
|
{
|
||||||
|
BLState->MicPacketBuffer.ReadHead = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,26 @@ typedef struct motor_packet
|
||||||
u8 FlowerPositions[3];
|
u8 FlowerPositions[3];
|
||||||
} motor_packet;
|
} motor_packet;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
struct microphone_packet
|
||||||
|
{
|
||||||
|
b8 ChangeAnimation;
|
||||||
|
char AnimationFileName[32];
|
||||||
|
b8 SetLayer;
|
||||||
|
char LayerName[32];
|
||||||
|
r32 LayerOpacity;
|
||||||
|
b8 SetLayerParamColor;
|
||||||
|
char LayerParamColor[7];
|
||||||
|
r32 OverrideDuration;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct blumen_lumen_state
|
||||||
|
{
|
||||||
|
packet_ringbuffer MicPacketBuffer;
|
||||||
|
temp_job_req JobReq;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#define BLUMEN_LUMEN_H
|
#define BLUMEN_LUMEN_H
|
||||||
#endif // BLUMEN_LUMEN_H
|
#endif // BLUMEN_LUMEN_H
|
|
@ -27,6 +27,8 @@ ClearAndPushPatterns(animation_pattern_array* Patterns)
|
||||||
Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow);
|
Patterns_PushPattern(Patterns, Pattern_SmoothGrowRainbow);
|
||||||
Patterns_PushPattern(Patterns, Pattern_GrowAndFade);
|
Patterns_PushPattern(Patterns, Pattern_GrowAndFade);
|
||||||
Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
|
Patterns_PushPattern(Patterns, Pattern_ColorToWhite);
|
||||||
|
Patterns_PushPattern(Patterns, Pattern_Blue);
|
||||||
|
Patterns_PushPattern(Patterns, Pattern_Green);
|
||||||
}
|
}
|
||||||
|
|
||||||
RELOAD_STATIC_DATA(ReloadStaticData)
|
RELOAD_STATIC_DATA(ReloadStaticData)
|
||||||
|
@ -93,6 +95,10 @@ INITIALIZE_APPLICATION(InitializeApplication)
|
||||||
State->AnimationSystem = AnimationSystem_Init(AnimSysDesc);
|
State->AnimationSystem = AnimationSystem_Init(AnimSysDesc);
|
||||||
|
|
||||||
State->UserData = BlumenLumen_CustomInit(State, Context);
|
State->UserData = BlumenLumen_CustomInit(State, Context);
|
||||||
|
|
||||||
|
// TEMP
|
||||||
|
blumen_lumen_state* BLState = (blumen_lumen_state*)State->UserData.Memory;
|
||||||
|
return (temp_job_req*)&BLState->JobReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
UPDATE_AND_RENDER(UpdateAndRender)
|
UPDATE_AND_RENDER(UpdateAndRender)
|
||||||
|
|
|
@ -41,6 +41,8 @@ typedef struct panel panel;
|
||||||
#include "engine/animation/foldhaus_animation_serializer.cpp"
|
#include "engine/animation/foldhaus_animation_serializer.cpp"
|
||||||
#include "engine/animation/foldhaus_animation_renderer.cpp"
|
#include "engine/animation/foldhaus_animation_renderer.cpp"
|
||||||
|
|
||||||
|
#include "blumen_lumen.h"
|
||||||
|
|
||||||
struct app_state
|
struct app_state
|
||||||
{
|
{
|
||||||
gs_memory_arena Permanent;
|
gs_memory_arena Permanent;
|
||||||
|
|
|
@ -50,7 +50,23 @@ typedef struct context context;
|
||||||
|
|
||||||
// Application Functions
|
// Application Functions
|
||||||
|
|
||||||
#define INITIALIZE_APPLICATION(name) void name(context Context)
|
// TODO(pjs): TEMP
|
||||||
|
typedef void temp_job_req_proc(gs_thread_context* Ctx, u8* Memory);
|
||||||
|
struct temp_job_req
|
||||||
|
{
|
||||||
|
temp_job_req_proc* Proc;
|
||||||
|
u8* Memory;
|
||||||
|
};
|
||||||
|
// This isn't necessarily temp but I'm not sure it goes here
|
||||||
|
#define PACKETS_MAX 32
|
||||||
|
struct packet_ringbuffer
|
||||||
|
{
|
||||||
|
gs_data Values[PACKETS_MAX];
|
||||||
|
u32 ReadHead;
|
||||||
|
u32 WriteHead;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define INITIALIZE_APPLICATION(name) temp_job_req* name(context Context)
|
||||||
typedef INITIALIZE_APPLICATION(initialize_application);
|
typedef INITIALIZE_APPLICATION(initialize_application);
|
||||||
|
|
||||||
#define UPDATE_AND_RENDER(name) void name(context* Context, input_queue InputQueue, render_command_buffer* RenderBuffer, addressed_data_buffer_list* OutputData)
|
#define UPDATE_AND_RENDER(name) void name(context* Context, input_queue InputQueue, render_command_buffer* RenderBuffer, addressed_data_buffer_list* OutputData)
|
||||||
|
@ -200,6 +216,5 @@ struct context
|
||||||
platform_get_socket_handle* PlatformGetSocketHandle;
|
platform_get_socket_handle* PlatformGetSocketHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define FOLDHAUS_PLATFORM_H
|
#define FOLDHAUS_PLATFORM_H
|
||||||
#endif // FOLDHAUS_PLATFORM_H
|
#endif // FOLDHAUS_PLATFORM_H
|
|
@ -5,6 +5,29 @@
|
||||||
//
|
//
|
||||||
#ifndef BLUMEN_PATTERNS_H
|
#ifndef BLUMEN_PATTERNS_H
|
||||||
|
|
||||||
|
internal void
|
||||||
|
SolidColorPattern(led_buffer* Leds, pixel Color)
|
||||||
|
{
|
||||||
|
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
|
||||||
|
{
|
||||||
|
Leds->Colors[LedIndex] = Color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
Pattern_Blue(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
|
||||||
|
{
|
||||||
|
pixel Blue = pixel{0, 0, 255};
|
||||||
|
SolidColorPattern(Leds, Blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
Pattern_Green(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
|
||||||
|
{
|
||||||
|
pixel Green = pixel{0, 255, 0};
|
||||||
|
SolidColorPattern(Leds, Green);
|
||||||
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
|
TestPatternOne(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include "../foldhaus_renderer.cpp"
|
#include "../foldhaus_renderer.cpp"
|
||||||
|
|
||||||
|
#include "win32_test_code.cpp"
|
||||||
|
|
||||||
global b32 Running = false;
|
global b32 Running = false;
|
||||||
global b32 WindowIsActive = false;
|
global b32 WindowIsActive = false;
|
||||||
|
|
||||||
|
@ -423,26 +425,6 @@ Win32_SendAddressedDataBuffer_Job(gs_thread_context Context, gs_data Arg)
|
||||||
Win32_SendAddressedDataBuffer(Context, OutputData);
|
Win32_SendAddressedDataBuffer(Context, OutputData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
struct test_microphone_packet
|
|
||||||
{
|
|
||||||
b8 ChangeAnimation;
|
|
||||||
char AnimationFileName[32];
|
|
||||||
b8 SetLayer;
|
|
||||||
char LayerName[32];
|
|
||||||
r32 LayerOpacity;
|
|
||||||
b8 SetLayerParamColor;
|
|
||||||
char LayerParamColor[7];
|
|
||||||
r32 OverrideDuration;
|
|
||||||
};
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
inline u32
|
|
||||||
UpackB4(const u8* ptr)
|
|
||||||
{
|
|
||||||
return (u32)(ptr[3] | (ptr[2] << 8) | (ptr[1] << 16) | (ptr[0] << 24));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal bool
|
internal bool
|
||||||
ReloadAndLinkDLL(win32_dll_refresh* DLL, context* Context, gs_work_queue* WorkQueue, bool ShouldError)
|
ReloadAndLinkDLL(win32_dll_refresh* DLL, context* Context, gs_work_queue* WorkQueue, bool ShouldError)
|
||||||
{
|
{
|
||||||
|
@ -524,7 +506,9 @@ WinMain (
|
||||||
|
|
||||||
addressed_data_buffer_list OutputData = AddressedDataBufferList_Create(ThreadContext);
|
addressed_data_buffer_list OutputData = AddressedDataBufferList_Create(ThreadContext);
|
||||||
|
|
||||||
Context.InitializeApplication(Context);
|
temp_job_req* Req = Context.InitializeApplication(Context);
|
||||||
|
Req->Proc = BlumenLumen_MicListenJob;
|
||||||
|
Win32_TestCode_SocketReading(ThreadContext, Req);
|
||||||
|
|
||||||
Running = true;
|
Running = true;
|
||||||
Context.WindowIsVisible = true;
|
Context.WindowIsVisible = true;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
//
|
//
|
||||||
#ifndef WIN32_TEST_CODE_CPP
|
#ifndef WIN32_TEST_CODE_CPP
|
||||||
|
|
||||||
|
#if 0
|
||||||
internal void
|
internal void
|
||||||
Win32_TestCode_UART(gs_thread_context ThreadContext)
|
Win32_TestCode_UART(gs_thread_context ThreadContext)
|
||||||
{
|
{
|
||||||
|
@ -31,21 +32,45 @@ Win32_TestCode_UART(gs_thread_context ThreadContext)
|
||||||
uart_footer* Footer = PushStructOnCursor(WriteCursor, uart_footer);
|
uart_footer* Footer = PushStructOnCursor(WriteCursor, uart_footer);
|
||||||
UART_FillFooter(Footer, (u8*)Header);
|
UART_FillFooter(Footer, (u8*)Header);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
internal void
|
win32_socket ListenSocket;
|
||||||
Win32_TestCode_SocketReading(gs_thread_context ThreadContext)
|
|
||||||
|
DWORD WINAPI
|
||||||
|
Win32_TestCode_ListenThreadProc(LPVOID ThreadData)
|
||||||
{
|
{
|
||||||
win32_socket TestSocket = Win32Socket_ConnectToAddress("127.0.0.1", "20185");
|
gs_thread_context Ctx = Win32CreateThreadContext();
|
||||||
test_microphone_packet* Recv = 0;
|
|
||||||
|
temp_job_req* Req = (temp_job_req*)ThreadData;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
gs_data Data = Win32Socket_Receive(&TestSocket, ThreadContext.Transient);
|
Req->Proc(&Ctx, Req->Memory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
Win32_TestCode_SocketReading(gs_thread_context ThreadContext, temp_job_req* Req)
|
||||||
|
{
|
||||||
|
ListenSocket = Win32Socket_ConnectToAddress("127.0.0.1", "20185");
|
||||||
|
u8* Arg = (u8*)Req;
|
||||||
|
HANDLE Handle = CreateThread(0, 0, &Win32_TestCode_ListenThreadProc, Arg, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
|
||||||
|
{
|
||||||
|
packet_ringbuffer* MicPacketBuffer = (packet_ringbuffer*)UserData;
|
||||||
|
|
||||||
|
gs_data Data = Win32Socket_Receive(&ListenSocket, Ctx->Transient);
|
||||||
if (Data.Size > 0)
|
if (Data.Size > 0)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("Received\n");
|
OutputDebugStringA("Listened");
|
||||||
Recv = (test_microphone_packet*)Data.Memory;
|
MicPacketBuffer->Values[MicPacketBuffer->WriteHead++] = Data;
|
||||||
|
if (MicPacketBuffer->WriteHead >= PACKETS_MAX)
|
||||||
|
{
|
||||||
|
MicPacketBuffer->WriteHead = 0;
|
||||||
}
|
}
|
||||||
ClearArena(ThreadContext.Transient);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue