summaryrefslogtreecommitdiff
path: root/util/spkmodem_recv
AgeCommit message (Collapse)Author
15 hoursutil/spkmodem-recv: extensive commentingLeah Rowe
and with this, i'm now pretty much done modifying grub's crappy code. this experiment started in 2023 has now pretty much concluded. the original GNU code was poorly written, hardcoded everywhere, and not documented or commented at all. i had to learn what the code is doing through inference instead, and i'm pretty sure that these explanations cover everything. i hope? maybe the frenchman can explain anything i missed. haha. Signed-off-by: Leah Rowe <leah@libreboot.org>
15 hoursutil/spkmodem: explain what the defines areLeah Rowe
and calculate some of them instead of hard coding Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursuseful commentsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-recv: also cache sep_pos in decodeLeah Rowe
yet another optimisation for weaker compilers - but some modern compilers may not optimise well for this code either. this reduces the amount of references to the struct, which is very expensive (48000 times per second) on very old CPUs. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-recv: optimise decode_pulseLeah Rowe
the frame[] array is never actually used meaningfully. that setting of frame[ringpos] on the decode_state is only set here, but then the value isn't really used at all. the entire size of the annay is used for sizeof in print_stats, but then we can just declare that manually. since we also know that this value never changes, we can use a global define for the sizeof entry in print_stats, thereby simplifying operation further Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-recv: clean up decode_pulseLeah Rowe
make it easier to read by clearer variable naming. this change also reduces memory accesses (fewer struct dereferences - see: struct decoder_state), when using much weaker/older compilers that don't optimise properly. this, in the most active part of the code, which is called.... 48000 times a second. peanuts on modern CPUs, but on old (early 90s) CPUs it makes a big difference. Signed-off-by: Leah Rowe <leah@libreboot.org>
16 hoursutil/spkmodem-recv: byte swap on big endian CPULeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/spkmodem-recv: remove errno defineLeah Rowe
may break on modern systems (macro) Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursadd endianness check to spkmodem-recvLeah Rowe
a bit dirty. should handle this at runtime. Signed-off-by: Leah Rowe <leah@libreboot.org>
17 hoursutil/spkmodem-recv: properly handle stdin errLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
28 hoursutil/spkmodem-recv: code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: optimise pulse checkLeah Rowe
the last change was good, but this code, again, has to do these calculations 48,000 times a second. trivial on new computers. but now try it on a computer from 1992. we should try to make this as fast as possible :) older compilers especially don't optimise these checks. this patch shifts it to one subtraction and one unsigned comparison, rather than checking less than or greater than both. often used in... literally exactly this type of program. on a good compiler this will compile to an add, cmp and conditional jump. less readable, but the results (set 1 or 0) make it pretty obvious what it does, after a few seconds. Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: clearer pulse decodingLeah Rowe
i turned this into abs() call earlier, but this isn't obviously readable by some people. make it absolutely clear what this does. also reduces use of syscalls. Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: say what freq_sep/data areLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: add a usage functionLeah Rowe
replace the err call in getopt Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: tidy up the getopt loopLeah Rowe
more knf-compliant Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: allow short sample readsLeah Rowe
fread() may return short reads, whereas the current code assumes either EOF or a full read. change if to a while. really, it's that simple. just loop until it's done. i probably b0rked this myself when refactoring the GNU code. Signed-off-by: Leah Rowe <leah@libreboot.org>
30 hoursutil/spkmodem-recv: don't exit in print_statsLeah Rowe
i treated ftell errors as fatal, but if fttell fails with ESPIPE, and someone's using -d, the program may exit immediately, even though there's no problem. instead, skip printing the offset (basically no debug). this fixes a bug that i introduced myself, when i forked this code, because i added that error check; the GNU code didn't have any check whatsoever. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: buffer calls to fread()Leah Rowe
we currently read small amounts of data with fread, repeatedly, which is quite taxing on the CPU, on very old systems. 48khz audio. 48000 calls to fread() per second? yeah. let's optimise this. performance now should be roughly O(1) in practise. this and the other recent changes means no modulo or division, reduced branching, memory memory roads, and lots of buffering. the buffering here is quite conservative, so the human won't notice any difference. we're cutting the number of times we call fread by a factor of several thousand, but you'll still see text scrolling down pretty quick, with minimal lag. the old GNU code i forked was terrible at this. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: make new pulse calculation clearerLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: tidy up pulse decodingLeah Rowe
make it clearer about next/old, in the loop. this also improves performance on older systems (cache the values first, don't re-calculate) again, this is GNU code. but you wouldn't know it, in my current version. i forked this from GRUB several years ago and started cleaning it for fun. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: split up handle_audio()Leah Rowe
the signal check should be its own function, for clearer understanding Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: tidy up handle_audioLeah Rowe
frame handling, error checks, pulse decoding and character decoding are all jumbled up. this patch separates them a bit, making it clearer. should also help codegen. this tool is dealing with high bandwidth text, which on slower computers may be cumbersome. every optimisation counts. not really relevant on newer systems. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: optimise ring buffer pos calcLeah Rowe
instead of computing next every time, just advance two indexes. another performance optimisation on older machines, especially old compilers, because it reduces the amount of logical branching. the old code was pretty much just advancing two indexes in lockstep, when getting the next pulse, but recalculating one of them based on the other, each time. this is yet another hangover from the old GNU code that i forked three years ago. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: don't use modulus on decodeLeah Rowe
it's slow on older compilers/systems that don't optimise. instead, we branch (cheaper) and just do an above or equal comparison), resetting appropriately or subtracting. should yield an actually useful performance gain, on older systems. a bit theoretical on modern systems, which optimise well (modern compilers will produce assembly code much like what the new C code is doing) Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursspkmodemrecv makefile: add -c to installLeah Rowe
a bit pedantic. but that's my intention. for backwards compatibility with older systems. this flag means: create the directory. on modern versions on all systems, it's the default behaviour. Signed-off-by: Leah Rowe <leah@libreboot.org>
31 hoursutil/spkmodem-recv: further portability / cleanupLeah Rowe
i used a bunch of global variables. that's gone. added proper externs, including for errno. lots of old unix systems require this. this version should be perfectly polished and portable now. all status is now handled in a struct, making the code a bit easier to understand, because the variables now are clearly pertinent to the state of the decoder, rather than being seemingly random. some indentation reduced. also cleaned up ftell/feof usage again. the new code is a bit more robust when dealing with piped input(which is literally what this program takes, exclusively) i started my cleanup of this tool from GNU GRUB in 2023. i finished it today. also the Openbsd pledge is more portable now (code made to compile on pre-pledge openbsd as well) Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursutil/nvmutil: further clean up decode_pulse()Leah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursutil/spkmodem-recv: tidy up frame decodingLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursutil/spkmodem-recv: handle fread errorsLeah Rowe
also handle EOF condition and exit cleanly. don't use dirty feof. Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursutil/spkmodem-recv: fix getopt prototypeLeah Rowe
i use -pedantic and std=c90 also add the define Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursremoved some unnecessary thingsLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hoursanother fixLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
36 hourstiny fixLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
37 hoursutil/spkmodem-recv: portability and code cleanupLeah Rowe
borrowing recent improvements from nvmutil Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-02-19util/spkmodem_recv: general code cleanupLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-03util/spkmodem-recv: More correct MakefileLeah Rowe
Set up the DESTDIR variable properly. Otherwise, this is just style changes. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-10-17util/spkmodem-recv: detailed copyright historyLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-09-25util/: use SPDX license and copyright headersLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-14util/spkmodem-recv: rename function for clarityLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: remove unnecessary error checkLeah Rowe
the loop in main() already checks EOF, and errno is properly handled at the end of main() we only need to call ferror(), to check error state this fixes a bogus error message when pressing ctrl+D to terminate the program, *which is the intended way to terminate this program* (that, or EOF is reached in any other another way) do not treat intended behaviour as an error condition! Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: say cc, not gcc, in commentLeah Rowe
i've build-tested this code with clang and that also works. in practise, a user is going to have clang or gcc Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: fix bad commentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: remove unnecessary assignmentLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: simplify getopt handlingLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13util/spkmodem-recv: cleaner ring buffer handlingLeah Rowe
make it more obvious that this *is* a ring buffer being handled, and make it more obvious when checking a pulse in the next frame Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-13remove errant fileLeah Rowe
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-12util/spkmodem-recv: re-add full license headerLeah Rowe
i forked spkmodem-recv from coreboot, who forked it from gnu grub. gnu grub's version has the full header, with copyright declared as belonging to the fsf coreboot made changes after forking it, and later replaced the license declaration with an equivalent SPDX header, but they also removed the FSF's copyright declaration, which by itself does not void the declaration anyway, i just feel better re-adding the full declaration. make it so! Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-08util/spkmodem-recv: fix regressionLeah Rowe
The last bit wasn't being handled, *and* ascii_bit wasn't being reduced at all. Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-06-05util/spkmodem-recv: make ringpos a global variableLeah Rowe
there's no point passing it as argument to a function. it's used across more than one function, so make it global Signed-off-by: Leah Rowe <leah@libreboot.org>