Sunday, 12 January 2025

svelte HMR

https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state says:

On the contrary, if you keep the default preserveLocalState to false, you can enable preservation of all the local state of a given component by adding the following comment: // @hmr:keep-all. You can also preserve only the state of some specific variables, by annotating them with: // @hmr:keep.

How to decide which systems to reboot when code changes? Developing gets waitsy when everything has to complicatedly clunk.

If I change code in audio.svelte.ts,

The reload happens to Call.svelte, which includes it via Peering via Party.


The later "hot updated" messages are for the nearest Component, though nothing seems to mention the test.js location of the change...

That first one though we have hooked in before with the following code, as vite suggested, but it doesn't seem to all be there:

// < HMR can sort-of be listened for
$effect(() => {
if (import.meta.hot) {
import.meta.hot.accept((mod) => {
let of = {
// always rather opaque
mod,
// always Call.svelte?t=...
url:import.meta.url,
// empty, guesses from AI at what it would expect to be here?
hot:import.meta.hot,
id:import.meta.hot.id,
}
console.log("Codechange!", of)
})
// if you write these as import.meta.hot.accept(
// it compiles in a ['default'] as a first argument
// and an error about our strings being a callback occurs elsewhere
// so svelte must be obscuring vite's advertised feature of thus:
let imh = import.meta.hot
// none of these work?
imh.accept('/src/lib/kolektiva/Party.svelte', (newFoo) => {
console.log("Party Codechange!", {url:import.meta.url,newFoo})
})
imh.accept('kolektiva/Party.svelte', (newFoo) => {
console.log("Party short Codechange!", {url:import.meta.url,newFoo})
})
imh.accept('./kolektiva/Party.svelte', (newFoo) => {
console.log("Party ./short Codechange!", {url:import.meta.url,newFoo})
})
}
else {
throw "never here"
}
})

Probably because svelte is between us and vite, doing something I can't find info about - the discord wants me to click squirrels.

And so,

Just separate what should reload into a component! Yay.

I guess this means my UI, which is a list of participants (Y axis) and their features (X axis), may want to be a multi-table join sort of thing.

Which means I'm writing a table class with synthesized absolute positioning! It also seems like the Basket grouper|compressor I built before...

Monday, 6 January 2025

On Trans

Trans people are great and you totally want to be in a world that is safe for them. That's my main angle. And I must reiterate that they are awesome, uncompromising and so forth. It's a messy universe and people have feelings. Lots of people get thrown across the gender divide for various reasons, eg Bob from Fight Club had some med shit and somehow a rather gender-definitive body panel of his popped up... The less uptight cultures have had them for ages, eg that ladyman in Little Big Man. Heaps of spectrums of stuff going on.

Believe it or not, a woman is something people want to be. Etc.
It's just weird that teens are ideally supposed to deeply figure out who they are before their natural hormones drag them one way or the other from the undifferentiated pudge that kids are made of. I think that's a source of tension. We don't do great with most people's development so it's weird having such an early deadline emerge.

I think most of its exposure is due to being interesting to write about. I mean would you look at all this...

Most of what people buy into is trash, is being trans the same? Probably not.
Another thing, men think like dicks and women think like vaginas. So there's a clue. Here's a fairly female sentence: Let us not scrutinise everyone to smithereens tho, for we are humans.

Sunday, 5 January 2025

linux high resolution audio

So, you can use all 24 bits and 96kHz of your soundcard, if you want:

 vi ~/.config/pipewire/pipewire.conf.d/99-sample-rate.conf

And specify:

context.properties = {
    default.clock.rate = 96000
    default.clock.allowed-rates = [ 44100 48000 88200 96000 ]
    default.clock.quantum = 1024
    default.clock.min-quantum = 32
    default.clock.max-quantum = 8192
}

Then:

pactl info

Should say:

Default Sample Specification: float32le 2ch 96000Hz

And yay, it sounds great, just look at all this music: 
There must be some upscaling going on somewhere...
I've seen easyeffects using 60% cpu, but restarting sound calmed it right down. On ubuntu 24:

systemctl --user restart pipewire pipewire-pulse

It seems like 16bit samples could become 24bit just by adding zeroes at the little end, and 48kHz can simply repeat each sample... What do we do when it's 44100 Hz? Hmmm

Claude AI

Let me help clarify how audio sample rate and bit depth conversion actually works:

  1. Bit Depth Conversion (16-bit to 24/32-bit):
  • It's not just adding zeros at the end
  • The conversion involves scaling the values to maintain the same relative amplitude
  • 16-bit values (-32,768 to +32,767) are scaled to fit the 24-bit range (-8,388,608 to +8,388,607)
  • This preserves the original signal's dynamic range while providing headroom for processing
  1. Sample Rate Conversion (44.1kHz to 96kHz):
  • It doesn't simply repeat samples - that would create artifacts
  • Instead, it uses interpolation algorithms to calculate new samples between the existing ones
  • Common methods include:
    • Linear interpolation (basic, can cause artifacts)
    • Sinc interpolation (more accurate but CPU intensive)
    • Polynomial interpolation (good balance of quality and performance)

The tricky part with 44.1kHz to 96kHz conversion is that it's not a simple multiple (like 48kHz to 96kHz). The resampler needs to generate roughly 2.18 new samples for each original sample (96000/44100 ≈ 2.18). This requires more complex mathematics to maintain audio quality and prevent artifacts.

What's interesting though is that 44.1kHz was chosen as the CD standard because it's just over twice the human hearing range (roughly 20kHz), allowing for the Nyquist frequency to capture all audible frequencies. The 96kHz sampling rate is just over twice 44.1kHz, giving us another doubling that provides even more headroom for audio processing and ultrasonic frequencies.

Let me clarify these audio fundamentals:

Sample Rate determines the highest frequency that can be captured/reproduced (Nyquist frequency = sample rate/2). So:

  • 44.1kHz can theoretically capture up to 22.05kHz
  • 96kHz can theoretically capture up to 48kHz

Ultrasonic frequencies (>20kHz):

  1. Are often filtered out, yes, because:
    • Most people can't hear them
    • They can cause intermodulation distortion
    • They can waste amplifier power
  2. Arguments for keeping them:
    • Some argue they affect the audible frequencies' timing/phase relationships
    • Could affect perception of transients (very fast changes in sound)
    • May preserve more natural decay characteristics of instruments
    • Some claim they have subtle psychoacoustic effects

Bit depth is actually about dynamic range and noise floor, not wave location precision:

  • Each bit represents 6dB of dynamic range
  • 16-bit = ~96dB range
  • 24-bit = ~144dB range
  • Allows for quieter sounds to be captured without noise
  • Gives more headroom for audio processing
Sound-space is logarithmic:

  1. We perceive volume logarithmically, not linearly:

  • Each doubling of sound pressure (6dB) feels like a similar step in loudness
  • That's why each bit in digital audio represents 6dB
  • Going from 1 to 2 bits feels like the same increase as 15 to 16 bits
  1. So the bits aren't about "resolution" in the visual sense:
  • They're not like pixels that divide the wave into finer slices
  • Instead, they give us more "floors" in the dynamic range "building"
  • Each additional bit doubles the number of possible volume levels
  • But these levels are spaced logarithmically to match how we hear
  1. Sample rate, on the other hand, IS more like visual resolution:
  • Higher sample rates let us capture higher frequencies
  • It's about how finely we can slice time
  • This directly affects the highest frequency we can represent

It's a common misconception about bit depth because we tend to think in visual/linear terms, but our ears work differently from our eyes! Audio processing has to account for this logarithmic nature of human hearing.

Conclusion

It doesn't use much CPU to do this, might as well switch it on.

Especially for capturing high quality audio you intend to work on, you want all that sound-space to avoid squishing your delicious waves before you can get your compressor etc on it.

If you want to burn CPU and|or decrease latency, pipewire apparently calls that option the quantum.

Have fun!


Thursday, 2 January 2025

recipe for making PCM-15, a phase change material with a melting point of approximately 18°C

Just jotting this down for later. Is AI writing up this rad video:

https://youtu.be/Nqxjfp4Gi0k




The recipe for making PCM-15, a phase change material with a melting point of approximately 18°C (65°F), is as follows:

  1. Ingredients:
    • 5 cups (1.2 L) of water
    • 1 cup (240 mL) of sodium sulfate
    • 1/4 cup (60 mL) of table salt (sodium chloride)
    • 4 teaspoons (20 mL) of xanthan gum (optional, for thickening)
  2. Instructions:
    • Add 5 cups of water to a pot and heat it on the stove
    • Add 1 cup of sodium sulfate and 1/4 cup of table salt to the water
    • Stir the mixture until it begins to slightly boil
    • Continue stirring until the salts are mostly dissolved. It's okay if some remain undissolved
    • If desired, add 4 teaspoons of xanthan gum and simmer for a few more minutes to thicken the mixture.
    • For a more gel-like consistency, continue boiling for about 30 minutes
This PCM mixture will have a melting point of about 18°C (65°F) and can provide significant cooling effects. The recipe does not require precise measurements, making it easy to prepare with basic kitchen tools