Skip to content

Instantly share code, notes, and snippets.

@benmargolin
benmargolin / gist:5089a37d3eaf4d5c1192e3ceb8d7500c
Created May 9, 2016 21:52
Take the average value of part of a ByteBuffer (that is actually 16 bit little endian) easily
// posBefore = where in the mBuffer the new data started (before put)
ShortBuffer avgBuf = ((ByteBuffer) mBuffer.duplicate().flip().position(posBefore))
.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
long total = 0;
while (avgBuf.remaining() > 0) {
total += avgBuf.get() & 0xffff; // Because unsigned.
}
sLastDataAverage = total / numOfBytes / 2 / 65535f;
Logger.v(TAG, "Analysis of audio data: avg = %f", sLastDataAverage);
@benmargolin
benmargolin / com.deluged.plist
Created April 25, 2014 06:46
deluged launchd plist (goes in /Library/LaunchDaemons, then launchctl load -w com.deluged.plist ; launchctl start com.deluged)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UserName</key>
<string>ben</string>
<key>Label</key>
<string>com.deluged</string>
<key>OnDemand</key>
<false/>
@benmargolin
benmargolin / com.couchpotato.plist
Created April 25, 2014 06:37
couchpotato launchd plist (goes in /Library/LaunchDaemons, then launchctl load -w com.couchpotato.plist ; launchctl start com.couchpotato)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UserName</key>
<string>ben</string>
<key>Label</key>
<string>com.couchpotato</string>
<key>OnDemand</key>
<false/>