Skip to content

Instantly share code, notes, and snippets.

View standinga's full-sized avatar

standinga

View GitHub Profile
@standinga
standinga / AudioReverse.swift
Created July 28, 2021 01:19
Reverse audio file in Swift using Accelerate framework (this is fast)
import Accelerate
import AVFoundation
func reverse(fromUrl: URL) -> URL? {
do {
let input = try AVAudioFile(forReading: fromUrl)
let format = input.processingFormat
let frameCount = AVAudioFrameCount(input.length)
let outSettings = [AVNumberOfChannelsKey: format.channelCount,
@standinga
standinga / UIFont+Monospace.swift
Created September 28, 2019 22:46
UIFont extension for monospaced font.
import UIKit
extension UIFont {
static func monospacedFont(at size: CGFloat) -> UIFont{
let bodyFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFont.TextStyle.body)
let bodyMonospacedNumbersFontDescriptor = bodyFontDescriptor.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings: [
@standinga
standinga / Browser.swift
Created November 30, 2020 08:57
IOS/OSX Networking updated browser
//
// Client.swift
// MultiConnect
//
// Created by michal on 29/11/2020.
//
import Foundation
import Network
@standinga
standinga / Swift Playground Audio playing audio files with AVAudioPlayerNode on top of AVPlayer or on top of another AVAudioPlayerNode.swift
Last active October 31, 2023 07:33
Swift Playground Audio playing audio files with AVAudioPlayerNode on top of AVPlayer or on top of another AVAudioPlayerNode
import AVFoundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class AudioPlayer {
var topAudioFiles: [AVAudioFile] = []
var engine:AVAudioEngine
var backgroundAudioNode: AVAudioPlayerNode
var backgroundAudioFile: AVAudioFile
@standinga
standinga / sh
Created July 20, 2023 21:46
Stream mac camera using ffmpeg
# stream facetime camera (0)
ffmpeg -f avfoundation -framerate 30 -i "0" -video_size 1024x720 -vcodec libx264 -preset ultrafast -f flv "rtmp://127.0.0.1/live"
# framerate needs to be set before the "-i" (input)
# list available devices:
ffmpeg -f avfoundation -list_devices true -i ""
@standinga
standinga / AudioPlayground.swift
Last active March 22, 2023 14:06
Swift Playground shows how to play multiple wav files on top of background audio file, using AVAudioPlayerNode, AVAudioMixerNode, AVAudioEngine
import AVFoundation
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class AudioPlayer {
var backgroundAudioFile:AVAudioFile
var topAudioFiles: [AVAudioFile] = []
@standinga
standinga / UserDefaults+Swizzle.swift
Created August 18, 2022 15:25
Swizzle UserDefaults set(object: forKey:) in objc and swift
/// ObjC
@implementation NSUserDefaults(Tracking)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(setObject:forKey:);
@standinga
standinga / ViewController.swift
Last active June 10, 2021 18:00
connectAudioUnitWithPlayer() connecting host view controller with audio unit plugin
private func connectAudioUnitWithPlayer() {
var componentDescription = AudioComponentDescription()
componentDescription.componentType = kAudioUnitType_Effect
// used https://codebeautify.org/string-hex-converter to convert strings to fourCC hex
componentDescription.componentSubType = 0x44656d6f // "Demo"
componentDescription.componentManufacturer = 0x44656d6f // "Demo"
componentDescription.componentFlags = 0
componentDescription.componentFlagsMask = 0
AUAudioUnit.registerSubclass(VolumePluginAudioUnit.self, as: componentDescription, name: "demo: VolumePlugin", version: UInt32.max)
@standinga
standinga / CustomView.swift
Created May 30, 2019 23:00
CustomView.swift for medium post about UICollectionView inside UIView
import UIKit
@IBDesignable
class CustomView: UIView {
@IBOutlet var contentView: UIView!
@IBOutlet weak var collectionView: UICollectionView!
override init(frame: CGRect) {
super.init(frame: frame)
@standinga
standinga / main.swift
Created November 18, 2018 00:16
Read MJPEG int CGImage using Swift4, URLSession, OSX
//
// main.swift
// MJPEGreader
//
// Created by michal on 17/11/2017.
// Copyright © 2018 michal. All rights reserved.
//
import Foundation