New vam thread connection

A new VAM (Virtual Audio Mixer) thread connection!

To establish a new VAM thread connection, you'll need to follow these steps:

  1. Create a new VAM instance: You can do this by calling the VAM_Create function, which returns a pointer to a VAM structure.
  2. Initialize the VAM: Call the VAM_Init function to initialize the VAM instance. This function takes a pointer to a VAM_CONFIG structure, which contains settings for the VAM.
  3. Create a new thread: Create a new thread using your preferred threading library (e.g., CreateThread on Windows or pthread_create on Linux).
  4. Pass the VAM instance to the thread: Pass the VAM pointer to the new thread using a thread-local storage mechanism (e.g., TlsAlloc on Windows or pthread_setspecific on Linux).
  5. Start the thread: Start the new thread using the CreateThread or pthread_create function.
  6. Connect the thread to the VAM: In the new thread, call the VAM_Connect function to connect the thread to the VAM instance. This function takes a pointer to the VAM structure and returns a VAM_THREAD handle.

Here's some sample code to illustrate these steps:

#include <vam.h>
#include <windows.h>

// VAM configuration structure
VAM_CONFIG vam_config = {
   .sample_rate = 44100,
   .buffer_size = 1024,
   .num_channels = 2
};

// Thread function
DWORD WINAPI thread_func(LPVOID lpParameter) {
    VAM* vam = (VAM*)lpParameter;
    VAM_THREAD thread = VAM_Connect(vam);
    // Process audio data in the thread
    return 0;
}

int main() {
    // Create a new VAM instance
    VAM* vam = VAM_Create();
    if (!vam) {
        return 1;
    }

    // Initialize the VAM
    VAM_Init(vam, &vam_config);

    // Create a new thread
    HANDLE hThread = CreateThread(NULL, 0, thread_func, vam, 0, NULL);
    if (hThread == NULL) {
        return 1;
    }

    // Wait for the thread to finish
    WaitForSingleObject(hThread, INFINITE);
    CloseHandle(hThread);

    // Clean up
    VAM_Destroy(vam);
    return 0;
}

Note that this is just a basic example, and you'll likely need to add error handling and other features depending on your specific use case.