From: parking_turkeys Date: Sat, 8 Aug 2026 23:51:37 +0000 (-0400) Subject: it works??? lik it makes. a sound X-Git-Tag: horizons~9 X-Git-Url: http://git.parking-turkeys.net/?a=commitdiff_plain;h=5e493ab47b074911fa739a39d4f447c908b2c650;p=colon3wavtool.git it works??? lik it makes. a sound --- diff --git a/a.exe b/a.exe new file mode 100644 index 0000000..c771734 Binary files /dev/null and b/a.exe differ diff --git a/appendwave.c b/appendwave.c new file mode 100644 index 0000000..8918b09 --- /dev/null +++ b/appendwave.c @@ -0,0 +1,124 @@ +#include "wavtool.h" + +#define HEADERLENGTH 44 +#define FMTLENGTH 16 + +static int writeBlankHeader(char *filename); +static int addWaveToEnd(int16_t wave[], int wave_length, HANDLE fp); +static int editHeaderBecauseFileIsLongerUwU(HANDLE fp); + +int appendWave(int16_t wave[], int wave_length, char *filename) +{ + if (GetFileAttributes(filename) == 0xFFFFFFFF) { + //write header + writeBlankHeader(filename); + }; + HANDLE fp; + + fp = CreateFile( + filename, + GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + addWaveToEnd(wave, wave_length, fp); + editHeaderBecauseFileIsLongerUwU(fp); + + //idk GAY + + //etcetc + + return 1; + +}; + +int writeBlankHeader(char *filename) +{ + HANDLE fp; + long unsigned int bytes_written; + fp = CreateFile( + filename, + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + const char riff_id[4] = {'R', 'I', 'F', 'F' }; + WriteFile(fp, riff_id, 4, &bytes_written, NULL); + + const uint32_t riff_length = HEADERLENGTH - 8; + WriteFile(fp, &riff_length, 4, &bytes_written, NULL); + + const char wave_id[4] = {'W', 'A', 'V', 'E'}; + WriteFile(fp, wave_id, 4, &bytes_written, NULL); + + const char fmt_id[4] = {'f', 'm', 't', ' '}; + WriteFile(fp, fmt_id, 4, &bytes_written, NULL); + + const uint32_t fmt_length = FMTLENGTH; + WriteFile(fp, &fmt_length, 4, &bytes_written, NULL); + + const uint16_t format_tag = 1; //microsoft PCM i think?? + WriteFile(fp, &format_tag, 2, &bytes_written, NULL); + + const uint16_t channel_count = 1; //mono + WriteFile(fp, &channel_count, 2, &bytes_written, NULL); + + const uint32_t sampling_rate = 44100; + WriteFile(fp, &sampling_rate, 4, &bytes_written, NULL); + + const uint32_t bytes_per_second = 88200; + WriteFile(fp, &bytes_per_second, 4, &bytes_written, NULL); + + const uint16_t block_align = 2; //no idea what this means + WriteFile(fp, &block_align, 2, &bytes_written, NULL); + + const uint16_t bits_per_sample = 16; + WriteFile(fp, &bits_per_sample, 2, &bytes_written, NULL); + + const char data_id[4] = {'d', 'a', 't', 'a'}; + WriteFile(fp, data_id, 4, &bytes_written, NULL); + + const uint32_t data_size = 0; + WriteFile(fp, &data_size, 4, &bytes_written, NULL); + + CloseHandle(fp); + + return 1; +}; + +static int addWaveToEnd(int16_t w[], int w_l, HANDLE fp) +{ + SetFilePointer(fp, 0, NULL, FILE_END); + unsigned long int gay = 0; + + WriteFile(fp, w, w_l, &gay, NULL); + + return 1; + + + +}; + +static int editHeaderBecauseFileIsLongerUwU(HANDLE fp) +{ + unsigned long int gay = 0; + uint32_t filesize = GetFileSize(fp, NULL); + uint32_t riff_data_size = filesize - 8; + uint32_t wave_data_size = filesize - 44; + + SetFilePointer(fp, 4, NULL, FILE_BEGIN); //file size - 8 + WriteFile(fp, &riff_data_size, 4, &gay, NULL); + + SetFilePointer(fp, 40, NULL, FILE_BEGIN); //wave size + WriteFile(fp, &riff_data_size, 4, &gay, NULL); + + return 1; +}; diff --git a/main.c b/main.c index bfa6ff3..f4ead24 100644 --- a/main.c +++ b/main.c @@ -14,28 +14,48 @@ static int log_args(int argc, char *argv[]); int main(int argc, char *argv[]) { - int input_wave_length = 0; + int input_wave_length = 0; // in bytes int16_t *input_wave = NULL; + char *error_msg = "unknown error in main()"; //test ver: just like. log the arguments lol!! log_args(argc, argv); //ok. if (argc >= 3) { input_wave_length = readWave(argv[2], NULL); - } else { goto error; }; + } else { + error_msg = "not enough arguments"; + goto error; + }; if (input_wave_length > 0) { input_wave = GlobalAlloc(0, input_wave_length); - } else { goto error; } - + } else { + error_msg = "input wave error || input wave length is 0"; + goto error; + } + int errored = 0; if (input_wave != NULL) { - readWave(argv[2], input_wave); + errored = readWave(argv[2], input_wave); + } else { + error_msg = "[main()] GlobalAlloc() failed"; + goto error; + }; + + if (errored != -1) { + errored = appendWave(input_wave, input_wave_length, argv[1]); + } else { + error_msg = "[main()] error from readWave()"; + goto error; }; + GlobalFree(input_wave); + + return 0; error: - MessageBox(NULL, "Lmao error w", "colon3wavtool errored", MB_OK | MB_ICONWARNING); + MessageBoxA(NULL, error_msg, "colon3wavtool errored", MB_OK | MB_ICONWARNING); + GlobalFree(input_wave); - return 0; }; int log_args(int argc, char *argv[]) diff --git a/readwave.c b/readwave.c index 691a1d2..a90a2e2 100644 --- a/readwave.c +++ b/readwave.c @@ -6,6 +6,8 @@ int readWave(char *filename, int16_t buffer[]) //if buffer is NULL it only retur //ok so expect 16-bit samples, and also the length required should be in BYTES HANDLE fp; char *error_msg = "unknown error in reading wave file"; + printf("input file: %s \n", filename); + fp = CreateFileA( filename, GENERIC_READ, @@ -93,17 +95,26 @@ int readWave(char *filename, int16_t buffer[]) //if buffer is NULL it only retur error_msg = "input file does not have data chunk right after fmt chunk"; goto error; }; + uint32_t data_length; + ReadFile(fp, &data_length, 4, &bytes_read, NULL); + if (bytes_read != 4) { + error_msg = "input file ended unexpectedly in 'data' chunk"; + goto error; + }; + //NOW TO READ THE WAVE wwwwwwwwww + int sample_count = data_length/2; + if (buffer != NULL) { + ReadFile(fp, buffer, data_length, &bytes_read, NULL); + }; + CloseHandle(fp); - - - - - return 0; + return data_length; error: MessageBoxA(NULL, error_msg, "colon3wavtool error :(((", MB_OK | MB_ICONWARNING); + CloseHandle(fp); return -1; }; diff --git a/test.ust b/test.ust new file mode 100644 index 0000000..9175fd7 --- /dev/null +++ b/test.ust @@ -0,0 +1,75 @@ +[#VERSION] +UST Version1.2 +[#SETTING] +Tempo=120.00 +Tracks=1 +ProjectName=New Project +VoiceDir=%VOICE%d‰¹ƒeƒg‰¹ºƒ‰ƒCƒuƒ‰ƒŠ[ +OutFile= +CacheDir=test.cache +Tool1=D:\projects\colon3wavtool\a.exe +Tool2=resampler.exe +Mode2=True +[#0000] +Length=480 +Lyric=‚Ç +NoteNum=60 +Intensity=100 +Modulation=0 +[#0001] +Length=480 +Lyric=‚ê +NoteNum=62 +Intensity=100 +Modulation=0 +PBS=-43 +PBW=84 +[#0002] +Length=480 +Lyric=‚Ý +NoteNum=64 +Intensity=100 +Modulation=0 +PBS=-43 +PBW=84 +[#0003] +Length=480 +Lyric=‚Ó‚Ÿ +NoteNum=65 +Intensity=100 +Modulation=0 +PBS=-43 +PBW=84 +[#0004] +Length=480 +Lyric=‚» +NoteNum=67 +Intensity=100 +Modulation=0 +PBS=-45 +PBW=89 +[#0005] +Length=480 +Lyric=‚ç +NoteNum=69 +Intensity=100 +Modulation=0 +PBS=-45 +PBW=89 +[#0006] +Length=480 +Lyric=‚Ä‚¡ +NoteNum=71 +Intensity=100 +Modulation=0 +PBS=-45 +PBW=89 +[#0007] +Length=480 +Lyric=‚Ç +NoteNum=72 +Intensity=100 +Modulation=0 +PBS=-43 +PBW=84 +[#TRACKEND] diff --git a/wavtool.h b/wavtool.h index a56c134..7c010d0 100644 --- a/wavtool.h +++ b/wavtool.h @@ -19,3 +19,9 @@ struct riff_chunk { //ok so first read the whole file into a thingy int readWave(char *filename, int16_t buffer[]); + +//then edit the wave based on argv (do this later!!) +//int modifyWave(int16_t wave[], int argc, char *argv[]); + +//then append the new wave into the output file, creating it if it doesn't exist, and fixing the header! +int appendWave(int16_t wave[], int wave_length_bytes, char *output_filename);