This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
Hex Dumper | |
*/ | |
public struct HexDump { | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if we have a type param, can we get the bits we need out of it, | |
// like length? | |
let xtype = UInt16.self | |
// MemoryLayout<xtype> etc, no no no, so ... | |
func sizeof<T>(_ value: T.Type) -> Int { | |
MemoryLayout<T>.size | |
} | |
let sz = sizeof(xtype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hex bytes of swift int in memory order (LSB->MSB) | |
func memhex<T: BinaryInteger>(_ value: T) -> String { | |
var value = value | |
var hex = "" | |
withUnsafeBytes(of: &value) { bytes in | |
for byte in bytes { | |
hex += String(format:"%02x", byte) + " " | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
Generate the I and Q components for a local oscillator | |
*/ | |
public class IQ_Oscillator { | |
let tau = 2 * Double.pi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
Demo implementation of the famous Goertzel algorithm in Swift | |
NB it is not currently possible to make this generic without | |
also pulling in the Swift Numerics package. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// couple of useful functions for dealing with an AVCaptureSession | |
// chucked out there for posterity and search | |
// What led to me to do this : Set size of AVCaptureAudioDataOutput buffer | |
// What might also lead you here : Swift AudioValueTranslation | |
// PLEASE NOTE : There are no error checks in this code, demo purposes only. | |
import AVFoundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import CoreAudio | |
import OSLog | |
/* | |
So you want to get a list of audio input and output devices on macOS do you? | |
Should be easy right? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func reverse <T: FixedWidthInteger> ( word: T ) -> T { | |
var word = word | |
var rev : T = 0 | |
for _ in (0..<word.bitWidth) { | |
rev = (rev << 1) + (word & 0b1) | |
word >>= 1 | |
} | |
return rev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// so the main limitation of the previous efforts was that we couldn't do e.g. | |
// p { "here is " em { "some" } "emphasis" } | |
// without starting to write crazy amounts of buildBlock functions, so... | |
extension XMLNode { | |
func named(_ name: String) -> XMLNode { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension XMLNode { | |
func named(_ name: String) -> XMLNode { | |
self.name = name | |
return self | |
} |
NewerOlder