Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Commit

Permalink
use versioning to send 16bit data
Browse files Browse the repository at this point in the history
  • Loading branch information
blandinw committed Oct 3, 2014
1 parent e2e1279 commit 179bbf5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions app/microphone.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VERSION = "0.7.0"

navigator.getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
Expand Down Expand Up @@ -154,7 +156,11 @@ states =
conn = new WebSocket(WEBSOCKET_HOST)
conn.onopen = (e) =>
log "connection opened", e
conn.send(JSON.stringify(["auth", token]))
opts =
token: token
bps: 16
encoding: 'signed-integer'
conn.send(JSON.stringify(["auth", opts]))
conn.onclose = (e) =>
@fsm('socket_closed')
conn.onmessage = (e) =>
Expand All @@ -181,16 +187,18 @@ states =
# we want 16bps, 16khz, mono
n_samples = float32s.length

# let's convert these 32bits samples into 16bits samples
int16s = new Int16Array(float32s.buffer)
# let's convert these 32bits samples into 16bits samples
int16s = new Int16Array(n_samples)
for i in [0..n_samples]
x = float32s[i]
y = if x < 0
x * 0x8000
else
x * 0x7fff

# log "[audiobuffer] rate=#{buffer.sampleRate}, samples=#{n_samples}, bytes=#{int16s.byteLength}"
int16s[i] = y

log "[audiobuffer] rate=#{buffer.sampleRate}, samples=#{n_samples}, bytes=#{int16s.byteLength}"

@conn.send(int16s)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wit-microphone",
"version": "0.6.0",
"version": "0.7.0",
"dependencies": {
},
"devDependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

set -x -e

VER=$(cat bower.json | jq --raw-output '.version')
VER=$(head -n1 app/microphone.coffee | sed '/VERSION/s/VERSION = "\(.*\)"/\1/g')
DIR=release/microphone-$VER
TAR=microphone-$VER.tar.gz

Expand Down

0 comments on commit 179bbf5

Please sign in to comment.