Download code/engine/physics/broadcast.h from HDTenEightyP/SeafarerEngine: direct link, hf CLI and curl.
- Browser
- Download file 7.1 kB
-
https://huggingface.co/HDTenEightyP/SeafarerEngine/resolve/main/code/engine/physics/broadcast.h
- Command line
-
hf download hf://HDTenEightyP/SeafarerEngine/code/engine/physics/broadcast.h
-
curl -L -o broadcast.h https://huggingface.co/HDTenEightyP/SeafarerEngine/resolve/main/code/engine/physics/broadcast.h
7.1 kB
| /* | |
| Copyright (c) 2026 Ethan Mortonson. | |
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| */ | |
| // --- Configuration Constants --- | |
| // WAV File Constants | |
| // Signal Constants (Highly Simplified NTSC Emulation) | |
| // This is the FIXED FREQUENCY used by the encoder (the "broadcast channel"). | |
| // Encoding Adjustment | |
| // Phase of the color burst in the encoder. Changing this is the primary way to fix hue shifts. | |
| // Decoding Adjustments | |
| // Factors used to scale the recovered U/V components independently to adjust color balance. | |
| // Filter Constants | |
| // PLL Constants | |
| // Line Timing (in samples @ 44.1kHz) | |
| // Analog Voltage Mapping (from 0-100 IRE units, mapped to -1.0 to 1.0 amplitude) | |
| // --- Structs for File Headers --- | |
| // BMP File Header (14 bytes) | |
| typedef struct { | |
| unsigned short signature; // 'BM' | |
| unsigned int fileSize; | |
| unsigned short reserved1; | |
| unsigned short reserved2; | |
| unsigned int dataOffset; | |
| } BMPFileHeader; | |
| // BMP Info Header (40 bytes) | |
| typedef struct { | |
| unsigned int headerSize; | |
| int width; | |
| int height; | |
| unsigned short planes; | |
| unsigned short bitCount; // 24 | |
| unsigned int compression; // 0 | |
| unsigned int imageSize; | |
| int xPelsPerMeter; | |
| int yPelsPerMeter; | |
| unsigned int colorsUsed; | |
| unsigned int colorsImportant; | |
| } BMPInfoHeader; | |
| // WAV File Header (44 bytes) | |
| typedef struct { | |
| char chunkID[4]; | |
| unsigned int chunkSize; | |
| char format[4]; | |
| char subchunk1ID[4]; | |
| unsigned int subchunk1Size; | |
| unsigned short audioFormat; | |
| unsigned short numChannels; | |
| unsigned int sampleRate; | |
| unsigned int byteRate; | |
| unsigned short blockAlign; | |
| unsigned short bitsPerSample; | |
| char subchunk2ID[4]; | |
| unsigned int subchunk2Size; | |
| } WAVHeader; | |
| // --- Color Space Conversion (Simplified YUV/YIQ Approximation) --- | |
| typedef struct { | |
| double Y, U, V; | |
| } YUV; | |
| void RGBtoYUV(unsigned char R, unsigned char G, unsigned char B, YUV *yuv); | |
| void YUVtoRGB(YUV yuv, unsigned char *R, unsigned char *G, unsigned char *B); | |
| unsigned char* read_bmp(const char* filename); | |
| // Function to write a fixed-size 24-bit BMP (64x48) | |
| int write_bmp(const char* filename, unsigned char* data); | |
| // --- WAV File I/O --- | |
| // Function to write the WAV header | |
| void write_wav_header(FILE* fp, unsigned int totalSamples); | |
| // --- NTSC Encoding and Decoding --- | |
| // 1. BMP -> WAV Encoding | |
| void encode_ntsc(unsigned char* bmp_data, short* wav_samples); | |
| /** | |
| * @brief Applies a simple 5-tap moving average filter (LPF) to the input signal. | |
| * @param input_samples The raw 16-bit WAV samples. | |
| * @param luma_output The array to store the filtered, normalized (double) signal. | |
| * @param num_samples The total number of samples. | |
| */ | |
| void apply_lpf_filter(const short* input_samples, double* luma_output, int num_samples); | |
| // 2. WAV -> BMP Decoding | |
| // Now accepts the desired demodulation frequency as an argument. | |
| void decode_ntsc(short* wav_samples, unsigned char* decoded_bmp_data, double demod_freq, double Amplitude, int Interference); | |
| // --- Main Program --- | |
| float Calculate_Inverse_Square_Law(float Source_Strength, float Distance_In_Meters); | |
| struct _Broadcaster | |
| { | |
| struct _Image* Image; | |
| struct _Image* No_Signal; | |
| struct _Model* Screen; | |
| float Frequency; | |
| float Gain; | |
| bool Signal_Received; | |
| short *wav_samples; | |
| unsigned char *decoded_bmp_data; | |
| unsigned char *original_bmp_data; | |
| GLuint fboId; // The Framebuffer Object | |
| GLuint textureId; // The texture object to render into | |
| GLuint rboId; // The Renderbuffer Object (for depth) | |
| }; | |
| struct _Broadcaster* Create_Broadcaster(); | |
| void Encode_Image(struct _Broadcaster* Broadcaster,GLuint textureID,float Frequency, float Broadcast_Strength); | |
| void Receive_Image(struct _Broadcaster* Broadcaster, float Frequency, float Broadcast_Strength, double Amplitude, int Interference); | |
| void initFBO(struct _Broadcaster* Broadcaster); | |
| void setupFBO(struct _Engine* Engine); | |
| void Draw_Camera_Scene(struct _Engine* Engine); | |
| void Render_Screen_Model(struct _SE3_Model* Model, GLuint textureId, float x, float y, float z, float x_Rotation, float y_Rotation, float z_Rotation, bool Vertex_Coloring, float R, float G, float B); | |
| void Draw_TV_Vertices(GLuint Texture_ID, double x1, double y1, double z1,double x2, double y2, double z2,double x3, double y3, double z3,double x4, double y4, double z4); | |