fast_osc 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_osc/fast_osc_wrapper.c +56 -29
- data/lib/fast_osc/version.rb +1 -1
- data/test/fast_osc_test.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508967c0e5e99fef79f7f3cc09bbe81fa82e0ee3
|
4
|
+
data.tar.gz: 281e6bae19a455de611780448a9238afde2f66d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc96c488b7ea7b0c7e357e692efdc16351c2596731307ea51bc57d4ea52b2369d0367102170a73ab2c57f8bce6fbf27485e6123b71ea99a3f4f8cd94b53b8c5b
|
7
|
+
data.tar.gz: f2b0e4f6104a27077c48dafe65584e42628c6ab88e6def545cc1f6bfdf2a46e50977df2acef945b7f5dae77503c2e8ad80cbd374c07e089ab50d7672971fba22
|
@@ -38,6 +38,35 @@ const char *rtosc_path(const char *msg)
|
|
38
38
|
return msg;
|
39
39
|
}
|
40
40
|
|
41
|
+
#define JAN_1970 2208988800.0 /* 2208988800 time from 1900 to 1970 in seconds */
|
42
|
+
|
43
|
+
uint64_t ruby_time_to_osc_timetag(VALUE rubytime) {
|
44
|
+
uint64_t timetag;
|
45
|
+
double floattime;
|
46
|
+
uint32_t sec;
|
47
|
+
uint32_t frac;
|
48
|
+
|
49
|
+
switch(TYPE(rubytime)) {
|
50
|
+
case T_NIL:
|
51
|
+
timetag = 1;
|
52
|
+
break;
|
53
|
+
default:
|
54
|
+
// convert Time object to ntp
|
55
|
+
floattime = JAN_1970 + NUM2DBL(rb_funcall(rubytime, rb_intern("to_f"), 0));
|
56
|
+
|
57
|
+
sec = floor(floattime);
|
58
|
+
frac = (uint32_t)(fmod(floattime, 1.0) * 4294967296); // * (2 ** 32)
|
59
|
+
// printf("\nsec: %04x\n", sec);
|
60
|
+
// printf("\nfrac: %04x\n", frac);
|
61
|
+
timetag = (uint64_t)((uint64_t)sec << 32 | (uint64_t)frac);
|
62
|
+
// printf("\ntimetag: %08llx\n", timetag);
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
|
66
|
+
return timetag;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
41
70
|
VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
|
42
71
|
rtosc_arg_itr_t itr;
|
43
72
|
char* data = StringValuePtr(msg);
|
@@ -49,6 +78,9 @@ VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
|
|
49
78
|
|
50
79
|
rtosc_arg_val_t next_val;
|
51
80
|
|
81
|
+
// for timestamp arg decoding
|
82
|
+
uint64_t tt, secs, frac;
|
83
|
+
|
52
84
|
while(!rtosc_itr_end(itr)) {
|
53
85
|
|
54
86
|
next_val = rtosc_itr_next(&itr);
|
@@ -73,7 +105,21 @@ VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
|
|
73
105
|
break;
|
74
106
|
case 't' :
|
75
107
|
// OSC time tag
|
76
|
-
//
|
108
|
+
// need to decode OSC (ntp style time) to unix timestamp
|
109
|
+
// then call Time.now with that
|
110
|
+
tt = next_val.val.t;
|
111
|
+
secs = (tt >> 32) - JAN_1970;
|
112
|
+
// taken from this SO post on how to convert NTP to Unix epoch
|
113
|
+
// http://stackoverflow.com/a/29138806
|
114
|
+
frac = ((tt & 0xFFFFFFFF) * 1000000) >> 32;
|
115
|
+
// example call from grpc ruby extension
|
116
|
+
// https://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/rb_grpc.c
|
117
|
+
// return rb_funcall(rb_cTime, id_at, 2, INT2NUM(real_time.tv_sec),
|
118
|
+
// INT2NUM(real_time.tv_nsec / 1000));
|
119
|
+
// printf("\noutsec: %08llx\n", secs);
|
120
|
+
// printf("\noutfrac: %08llx\n", frac);
|
121
|
+
// printf("\nouttimetag: %08llx\n", tt);
|
122
|
+
rb_ary_push(args_output, rb_funcall(rb_cTime, rb_intern("at"), 2, LONG2NUM(secs), LONG2NUM(frac)));
|
77
123
|
break;
|
78
124
|
case 'd' :
|
79
125
|
rb_ary_push(args_output, rb_float_new(next_val.val.d));
|
@@ -164,6 +210,15 @@ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self) {
|
|
164
210
|
rb_str_concat(tagstring, rb_str_new2("s"));
|
165
211
|
output_args[i].s = StringValueCStr(strval);
|
166
212
|
break;
|
213
|
+
case T_DATA:
|
214
|
+
if (CLASS_OF(current_arg) == rb_cTime) {
|
215
|
+
// at present I only care about the Time as an object arg
|
216
|
+
max_buffer_size += 8;
|
217
|
+
|
218
|
+
rb_str_concat(tagstring, rb_str_new2("t"));
|
219
|
+
output_args[i].t = ruby_time_to_osc_timetag(current_arg);
|
220
|
+
}
|
221
|
+
break;
|
167
222
|
}
|
168
223
|
}
|
169
224
|
|
@@ -194,34 +249,6 @@ VALUE method_fast_osc_encode_single_message(int argc, VALUE* argv, VALUE self) {
|
|
194
249
|
return output;
|
195
250
|
}
|
196
251
|
|
197
|
-
#define JAN_1970 2208988800.0 /* 2208988800 time from 1900 to 1970 in seconds */
|
198
|
-
|
199
|
-
uint64_t ruby_time_to_osc_timetag(VALUE rubytime) {
|
200
|
-
uint64_t timetag;
|
201
|
-
double floattime;
|
202
|
-
uint32_t sec;
|
203
|
-
uint32_t frac;
|
204
|
-
|
205
|
-
switch(TYPE(rubytime)) {
|
206
|
-
case T_NIL:
|
207
|
-
timetag = 1;
|
208
|
-
break;
|
209
|
-
default:
|
210
|
-
// convert Time object to ntp
|
211
|
-
floattime = JAN_1970 + NUM2DBL(rb_funcall(rubytime, rb_intern("to_f"), 0));
|
212
|
-
|
213
|
-
sec = floor(floattime);
|
214
|
-
frac = (uint32_t)(fmod(floattime, 1.0) * 4294967296); // * (2 ** 32)
|
215
|
-
/* printf("\nsec: %04x\n", sec); */
|
216
|
-
/* printf("\nfrac: %04x\n", frac); */
|
217
|
-
timetag = (uint64_t)((uint64_t)sec << 32 | (uint64_t)frac);
|
218
|
-
/* printf("\ntimetag: %08llx\n", timetag); */
|
219
|
-
break;
|
220
|
-
}
|
221
|
-
|
222
|
-
return timetag;
|
223
|
-
}
|
224
|
-
|
225
252
|
VALUE method_fast_osc_encode_single_bundle(int argc, VALUE* argv, VALUE self) {
|
226
253
|
VALUE timetag, path, args;
|
227
254
|
rb_scan_args(argc, argv, "21", &timetag, &path, &args);
|
data/lib/fast_osc/version.rb
CHANGED
data/test/fast_osc_test.rb
CHANGED
@@ -75,6 +75,16 @@ class FastOscTest < Minitest::Test
|
|
75
75
|
assert_equal args.map {|x| x.is_a?(Symbol) ? x.to_s : x}, outargs.map {|x| x.is_a?(Float) ? x.round(5) : x }
|
76
76
|
end
|
77
77
|
|
78
|
+
def test_that_it_encodes_and_decodes_messages_with_timestamps
|
79
|
+
path = "/s_new"
|
80
|
+
args = [Time.at(1463234577.488746)]
|
81
|
+
#args = [Time.at(1463234577.0)]
|
82
|
+
outpath, outargs = FastOsc.decode_single_message(FastOsc.encode_single_message(path, args))
|
83
|
+
|
84
|
+
assert_equal path, outpath
|
85
|
+
assert_equal args.first.to_f.round(5), outargs.first.to_f.round(5)
|
86
|
+
end
|
87
|
+
|
78
88
|
def test_that_encoded_timestamps_line_up
|
79
89
|
# this test is a bit convoluted but I found that fractional
|
80
90
|
# seconds weren't working when I plugged this into Sonic Pi
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_osc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
126
|
+
rubygems_version: 2.4.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Serialize and deserialize Open Sound Control messages
|