Skip to content

Instantly share code, notes, and snippets.

View bczhc's full-sized avatar
🌴

Zhai Can bczhc

🌴
  • Jiangsu, China
  • 09:43 (UTC +08:00)
  • X @bczhc0
View GitHub Profile
@bczhc
bczhc / a.rs
Last active December 29, 2025 14:40
Huffman编码文件解压缩器 #huffman
/// 没有支持流式压缩/解压缩
///
/// 手动实现,未使用bitvec bitstream-io 等库,练习作品,还有很多优化空间、、
#![feature(file_buffered)]
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
use clap::Parser;
use std::cmp::{Ordering, Reverse};
use std::collections::{BinaryHeap, HashMap};
@bczhc
bczhc / a.cc
Last active December 28, 2025 09:54
Huffman编码实现 #huffman
#include <iostream>
#include <optional>
#include <vector>
using namespace std;
using Symbol = string;
class Node {
public:
@bczhc
bczhc / a.md
Created December 27, 2025 05:04
频域操作实验

使用Rust写如下程序,用到主要crate有realfft、hound。

读入音频/home/bczhc/Music/2.wav,其总采样点数为N。对左右声道分别实数dft,fft点数为N。

对输出的结果进行降采样,设置一个缩放系数,比如为2.0,那就分配一个新的频域采样数组长度为N/2.0,然后把原fft结果降采样映射到新数组,不能有truncate,也就是新数组第一个元素是旧数组第一个元素,新数组最后一个元素就是旧的最后一个。

把新数组idft成新的音频,输出到/home/bczhc/out.wav,idft点数为新数组的长度。

左右声道的处理部分抽取成函数。缩放系数置为常量。

@bczhc
bczhc / a.rs
Created December 26, 2025 14:50
对音频dft小玩具 #dft #fft #audio
//! Mainly wrote by Gemini.
use anyhow::{Context, Result};
use clap::Parser;
use hound::{SampleFormat, WavReader, WavSpec, WavWriter};
use num_complex::Complex64;
use rustfft::FftPlanner;
use std::env;
use std::f64::consts::TAU;
use std::path::PathBuf;
@bczhc
bczhc / a.rs
Created December 26, 2025 07:12
chatgpt使用macroquad写的李萨如图小玩具 #vibecoding #macroquad #cg
// [dependencies]
// macroquad = "0.4.14"
// palette = "0.7.6"
use macroquad::hash;
use macroquad::prelude::*;
use macroquad::ui::{root_ui, widgets};
use palette::{FromColor, Hsl, Srgb};
fn window_conf() -> Conf {
@bczhc
bczhc / 3.wgsl
Last active December 25, 2025 14:47
wgpu绘制李萨如动画 #cg #wgpu
struct VertexInput {
@location(0) pos: vec2<f32>,
};
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
};
@vertex
fn vs_main(model: VertexInput) -> VertexOutput {
@bczhc
bczhc / a.html
Last active December 25, 2025 14:47
Gemini thinking 写的李萨如曲线全面进化版 #cg
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>利萨茹艺术生成器 - https://github.com/bczhc/Lissajous-curves/blob/master/a.htm 进化版</title>
<style>
:root {
--bg-color: #0a0a0c;
--panel-bg: rgba(255, 255, 255, 0.05);
@bczhc
bczhc / 1.html
Last active December 25, 2025 14:47
WebGPU/wgpu学习 #cg #webgpu #wgpu
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas width="500px" height="500px"></canvas>
<script>
async function loadShader(url) {
@bczhc
bczhc / 1.svg
Last active December 20, 2025 10:24
Inkscape masking bug
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bczhc
bczhc / ev100.rs
Last active December 11, 2025 08:14
高性能快速输出图片ev100值 #photography #image
#!/bin/env rust-script
//! ```cargo
//! [dependencies]
//! rexif = "0.7.5"
//! serde_json = "1.0.145"
//! ```
use std::env;
use rexif::{ExifTag, TagValue};
fn main() {