Skip to content

Instantly share code, notes, and snippets.

View csukuangfj's full-sized avatar
👀
I may be slow to respond.

Fangjun Kuang csukuangfj

👀
I may be slow to respond.
  • Xiaomi Corporation
  • Peking
View GitHub Profile
@csukuangfj
csukuangfj / cpp-create-wav.cc
Created April 22, 2019 11:14
create wav file using c++
// author: fangjun kuang <csukuangfj at gmail dot com>
// date: Apr. 22, 2019
// refer to http://www.topherlee.com/software/pcm-tut-wavformat.html
#include <fstream>
#include <iostream>
typedef struct WAV_HEADER {
/* RIFF Chunk Descriptor */
@csukuangfj
csukuangfj / gist:24f04f881c61ff5a79d7b13d8f011cce
Created September 19, 2023 14:19 — forked from Jackarain/gist:ecc6594ef6930db7fa7f
Linking libstdc++ statically
Linking libstdc++ statically
Christopher Baus writes about his problems linking libstdc++ statically. Yes, making C++ binaries that will work properly in different Linux distributions is somewhat painful. The problem is not so much linking libstdc++ statically – it is just a library, after all – but the runtime support required by C++ code in general, to enable features like RTTI and exception handling.
The runtime support code used by different parts of a C++ application needs to be compatible. If one part of the program needs to dynamic_cast or catch objects provided by another, both parts must agree on certain implementation details: how to find vtables, how to unwind the stack, and so on.
For C++ and a few other GCC-supported languages with similar features, such details are specified by a C++ ABI. Whenever the ABI used by GCC changes you'll end up with incompatible libraries produced by the different GCC versions. The same is true for plain C, but the C ABI is much simpler and has been around a lot lon
@csukuangfj
csukuangfj / opencl-opencv-first-example.cpp
Last active September 14, 2023 05:33
First example of using OpenCL in OpenCV 3.x
// This example shows how to create
// a context from a specified device type
// using OpenCL wrappers provided by OpenCV 3.x
//
// The default platform is the zero-th platform
// returned by clGetPlatformIDs.
//
// To compile it on Mac OS X, add `-framework opencl`
// to CXX_FLAGS
@csukuangfj
csukuangfj / QGraphicsSceneTest.cpp
Last active June 23, 2023 19:30 — forked from benjbaron/QGraphicsSceneTest.cpp
Qt QGraphicsScene click, select, move, resize, delete QGraphicsItems
// Copyright 2017. All Rights Reserved.
// Author: csukuangfj@gmail.com (Fangjun Kuang)
#include <QtGui>
#include <QGraphicsRectItem>
#include <QGraphicsView>
#include <QApplication>
#include <QGraphicsSceneMouseEvent>
class CustomItem : public QGraphicsEllipseItem

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@csukuangfj
csukuangfj / ffmpeg.md
Created April 7, 2023 03:14 — forked from whizkydee/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@csukuangfj
csukuangfj / default-linker-script.txt
Last active February 13, 2023 18:50
This file shows the default linker script of `ld`, use `ld --verbose` to show it.
GNU ld (GNU Binutils for Ubuntu) 2.25.1
Supported emulations:
elf_x86_64
elf32_x86_64
elf_i386
i386linux
elf_l1om
elf_k1om
i386pep
i386pe
#!/usr/bin/env python3
# Copyright (c) 2021 Xiaomi Corporation (authors: Fangjun Kuang)
from snowfall.training.ctc_graph import build_ctc_topo2
from speechbrain.pretrained import EncoderDecoderASR
import k2
import torch
@csukuangfj
csukuangfj / arm-notes.md
Last active February 12, 2022 13:24
arm notes

Deep Learning

  • https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/NN/Include/arm_nnfunctions.h
  • a paper [CMSIS-NN: Efficient Neural Network Kernels for Arm Cortex-M CPUs][1], google scolar of the author [Liangzhen Lai][2]
  • a paper [Fixed point quantization of deep convolutional networks][3]
  • a paper [Deep Convolutional Neural Network Inference with Floating-point Weights and Fixed-point Activations][4]
  • a blog [Why GEMM is at the heart of deep learning][5]
  • a paper [cuDNN: Efficient Primitives for Deep Learning][6]