sip-lab 1.31.0 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/binding.gyp +1 -0
- package/index.js +4 -5
- package/package.json +1 -1
- package/prebuilds/linux-x64/node.abi102.node +0 -0
- package/prebuilds/linux-x64/node.abi108.node +0 -0
- package/prebuilds/linux-x64/node.abi111.node +0 -0
- package/prebuilds/linux-x64/node.abi115.node +0 -0
- package/prebuilds/linux-x64/node.abi120.node +0 -0
- package/prebuilds/linux-x64/node.abi88.node +0 -0
- package/prebuilds/linux-x64/node.abi93.node +0 -0
- package/samples/100_calls.js +7 -4
- package/samples/16_audio_streams.js +1 -0
- package/samples/183_session_progress.js +1 -0
- package/samples/custom_call_id.js +1 -0
- package/samples/delayed_media.js +1 -0
- package/samples/four_audio_streams_two_refused.js +1 -0
- package/samples/g729.js +1 -0
- package/samples/media_fields.js +1 -0
- package/samples/mrcp_and_audio.js +1 -0
- package/samples/mrcp_and_audio.simplified_media.js +1 -0
- package/samples/multiple_audio_streams.js +1 -0
- package/samples/options.js +1 -0
- package/samples/pcma.js +1 -0
- package/samples/play_wav_and_speech_recog.bad_transcript.pcmu8000.js +1 -0
- package/samples/refer.js +1 -0
- package/samples/refuse_telephone_event.js +1 -0
- package/samples/register_no_expires.js +1 -0
- package/samples/register_subscribe.js +1 -0
- package/samples/reinvite_and_dtmf.js +1 -0
- package/samples/reinvite_audio_audio.js +1 -0
- package/samples/reinvite_with_hold_unhold.js +1 -0
- package/samples/rtp_and_srtp.js +1 -0
- package/samples/rtp_and_srtp.rtp_refused.js +1 -0
- package/samples/rtp_and_srtp.unbalanced_sdp_answer.js.future +1 -0
- package/samples/{send_and_receive_bfsk.js.future → send_and_receive_bfsk.js} +25 -27
- package/samples/send_and_receive_fax.js +1 -0
- package/samples/session_expires.update.js.future +1 -0
- package/samples/session_expires.update.with_sipjs-lab.js +64 -47
- package/samples/simple.js +1 -0
- package/samples/sip_cancel.js +1 -0
- package/samples/speech_synth_and_recog.speex16000.js +1 -0
- package/samples/srtp.js +1 -0
- package/samples/start_play_wav_with_end_of_file_event.js +1 -0
- package/samples/start_play_wav_with_no_loop.js +1 -0
- package/samples/stop_with_cleanup.js +134 -0
- package/samples/tcp.js +1 -0
- package/samples/text_to_speech.js +1 -0
- package/samples/tls.js +1 -0
- package/samples/two_audio_streams.js +1 -0
- package/samples/two_audio_streams.port_zero.js +1 -0
- package/samples_extra/ws_speech_server.bfsk.js +1 -0
- package/samples_extra/ws_speech_server.dtmf.js +1 -0
- package/samples_extra/ws_speech_server.google.js +1 -0
- package/samples_extra/ws_speech_server.send_bfsk.js +1 -0
- package/samples_extra/{ws_speech_server.start_bfsk_detection.js.future → ws_speech_server.start_bfsk_detection.js} +1 -0
- package/src/addon.cpp +9 -1
- package/src/idmanager.cpp +4 -0
- package/src/idmanager.hpp +1 -0
- package/src/pjmedia/include/pjmedia/bfsk_det2.h +23 -0
- package/src/pjmedia/src/pjmedia/bfsk_det.c +124 -131
- package/src/pjmedia/src/pjmedia/bfsk_det2.c +226 -0
- package/src/pjmedia/src/pjmedia/ws_speech_port.cpp +16 -1
- package/src/sip.cpp +114 -108
- package/src/sip.hpp +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const sip = require ('../index.js')
|
|
2
|
+
const Zeq = require('@mayama/zeq')
|
|
3
|
+
const m = require('data-matching')
|
|
4
|
+
const sip_msg = require('sip-matching')
|
|
5
|
+
|
|
6
|
+
// here we create our Zeq instance
|
|
7
|
+
var z = new Zeq()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async function test() {
|
|
11
|
+
z.trap_events(sip.event_source, 'event', (evt) => {
|
|
12
|
+
var e = evt.args[0]
|
|
13
|
+
return e
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
console.log(sip.start((data) => { console.log(data)} ))
|
|
17
|
+
|
|
18
|
+
const t1 = sip.transport.create({address: "127.0.0.1"})
|
|
19
|
+
const t2 = sip.transport.create({address: "127.0.0.1"})
|
|
20
|
+
|
|
21
|
+
const oc = sip.call.create(t1.id, {
|
|
22
|
+
from_uri: 'sip:alice@test.com',
|
|
23
|
+
to_uri: `sip:bob@${t2.address}:${t2.port}`,
|
|
24
|
+
headers: {
|
|
25
|
+
'X-MyHeader1': 'abc',
|
|
26
|
+
'X-MyHeader2': 'def',
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
await z.wait([
|
|
31
|
+
{
|
|
32
|
+
event: "incoming_call",
|
|
33
|
+
call_id: m.collect("call_id"),
|
|
34
|
+
transport_id: t2.id,
|
|
35
|
+
msg: sip_msg({
|
|
36
|
+
$rU: 'bob',
|
|
37
|
+
$fU: 'alice',
|
|
38
|
+
$tU: 'bob',
|
|
39
|
+
$fd: 'test.com',
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
event: 'response',
|
|
44
|
+
call_id: oc.id,
|
|
45
|
+
method: 'INVITE',
|
|
46
|
+
msg: sip_msg({
|
|
47
|
+
$rs: '100',
|
|
48
|
+
$rr: 'Trying',
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
], 1000)
|
|
52
|
+
|
|
53
|
+
const ic = {
|
|
54
|
+
id: z.store.call_id,
|
|
55
|
+
sip_call_id: z.store.sip_call_id,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
sip.call.respond(ic.id, {
|
|
59
|
+
code: 200,
|
|
60
|
+
reason: 'OK',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await z.wait([
|
|
64
|
+
{
|
|
65
|
+
event: 'response',
|
|
66
|
+
call_id: oc.id,
|
|
67
|
+
method: 'INVITE',
|
|
68
|
+
msg: sip_msg({
|
|
69
|
+
$rs: '200',
|
|
70
|
+
$rr: 'OK',
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
event: 'media_update',
|
|
75
|
+
call_id: oc.id,
|
|
76
|
+
status: 'ok',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
event: 'media_update',
|
|
80
|
+
call_id: ic.id,
|
|
81
|
+
status: 'ok',
|
|
82
|
+
},
|
|
83
|
+
], 1000)
|
|
84
|
+
|
|
85
|
+
// Now force an error in the script.
|
|
86
|
+
// This will be catched by exception handler at the end of the script where
|
|
87
|
+
// sip.stop(true) will be called (true: terminate all remaining calls, registrations and subscriptions)
|
|
88
|
+
|
|
89
|
+
throw "SOME ERROR"
|
|
90
|
+
|
|
91
|
+
sip.call.terminate(oc.id)
|
|
92
|
+
|
|
93
|
+
// and wait for termination events
|
|
94
|
+
await z.wait([
|
|
95
|
+
{
|
|
96
|
+
event: 'response',
|
|
97
|
+
call_id: oc.id,
|
|
98
|
+
method: 'BYE',
|
|
99
|
+
msg: sip_msg({
|
|
100
|
+
$rs: '200',
|
|
101
|
+
$rr: 'OK',
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
event: 'call_ended',
|
|
106
|
+
call_id: oc.id,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
event: 'call_ended',
|
|
110
|
+
call_id: ic.id,
|
|
111
|
+
},
|
|
112
|
+
], 1000)
|
|
113
|
+
|
|
114
|
+
console.log("Success")
|
|
115
|
+
|
|
116
|
+
sip.stop()
|
|
117
|
+
process.exit(0)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
test()
|
|
122
|
+
.catch(e => {
|
|
123
|
+
console.error(e)
|
|
124
|
+
sip.stop(true)
|
|
125
|
+
|
|
126
|
+
if(e == "SOME ERROR") {
|
|
127
|
+
console.log("Expected error catched")
|
|
128
|
+
process.exit(0)
|
|
129
|
+
} else {
|
|
130
|
+
console.log("Unexpected error catched")
|
|
131
|
+
process.exit(1)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
package/samples/tcp.js
CHANGED
package/samples/tls.js
CHANGED
package/src/addon.cpp
CHANGED
|
@@ -1568,7 +1568,15 @@ Napi::Value do_poll(const Napi::CallbackInfo &info) {
|
|
|
1568
1568
|
Napi::Value shutdown_(const Napi::CallbackInfo &info) {
|
|
1569
1569
|
Napi::Env env = info.Env();
|
|
1570
1570
|
|
|
1571
|
-
|
|
1571
|
+
if (info.Length() != 1) {
|
|
1572
|
+
Napi::Error::New(
|
|
1573
|
+
env, "Wrong number of arguments. Expected: clean_up")
|
|
1574
|
+
.ThrowAsJavaScriptException();
|
|
1575
|
+
return env.Null();
|
|
1576
|
+
}
|
|
1577
|
+
int clean_up = info[0].As<Napi::Number>().Int32Value();
|
|
1578
|
+
|
|
1579
|
+
int res = __pjw_shutdown(clean_up);
|
|
1572
1580
|
|
|
1573
1581
|
if (res != 0) {
|
|
1574
1582
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
package/src/idmanager.cpp
CHANGED
package/src/idmanager.hpp
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#ifndef __PJMEDIA_BFSK_DET2_H__
|
|
2
|
+
#define __PJMEDIA_BFSK_DET2_H__
|
|
3
|
+
|
|
4
|
+
#include <pjmedia/port.h>
|
|
5
|
+
|
|
6
|
+
PJ_BEGIN_DECL
|
|
7
|
+
|
|
8
|
+
PJ_DEF(pj_status_t) pjmedia_bfsk_det2_create( pj_pool_t *pool,
|
|
9
|
+
unsigned clock_rate,
|
|
10
|
+
unsigned channel_count,
|
|
11
|
+
unsigned samples_per_frame,
|
|
12
|
+
unsigned bits_per_sample,
|
|
13
|
+
void (*cb)(pjmedia_port*,
|
|
14
|
+
void *user_data,
|
|
15
|
+
int bit),
|
|
16
|
+
void *user_data,
|
|
17
|
+
int freq_zero,
|
|
18
|
+
int freq_one,
|
|
19
|
+
pjmedia_port **p_port);
|
|
20
|
+
|
|
21
|
+
PJ_END_DECL
|
|
22
|
+
|
|
23
|
+
#endif /* __PJMEDIA_BFSK_DET2_H__ */
|
|
@@ -36,88 +36,106 @@
|
|
|
36
36
|
# define TRACE_(expr)
|
|
37
37
|
#endif
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
#include <math.h>
|
|
40
|
+
#include <stdio.h>
|
|
41
|
+
#include <stdlib.h>
|
|
42
|
+
#include <stdbool.h>
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
// Converted by ChatGPT from https://github.com/hackergrrl/goertzel/blob/master/index.js
|
|
42
45
|
|
|
43
46
|
typedef struct {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
double sine;
|
|
49
|
-
double cosine;
|
|
47
|
+
int freq;
|
|
48
|
+
int sampleRate;
|
|
49
|
+
int samplesPerFrame;
|
|
50
|
+
double targetMagnitude; // Store the precomputed magnitude
|
|
50
51
|
} goertzel_t;
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
int ONE_16 = 1 << 16;
|
|
53
|
+
#define CHUNK_SIZE 16
|
|
54
|
+
#define THRESHOLD 0.9
|
|
55
55
|
|
|
56
|
-
int
|
|
57
|
-
|
|
56
|
+
double precalcMagnitude(int freq, double rate) {
|
|
57
|
+
double t = 0.0;
|
|
58
|
+
double tstep = 1.0 / rate;
|
|
59
|
+
double samples[CHUNK_SIZE];
|
|
60
|
+
for (int i = 0; i < CHUNK_SIZE; i++) {
|
|
61
|
+
samples[i] = sin(2 * M_PI * freq * t);
|
|
62
|
+
t += tstep;
|
|
63
|
+
}
|
|
58
64
|
|
|
59
|
-
int
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
int k = (int)(0.5 + (CHUNK_SIZE * freq) / rate);
|
|
66
|
+
double w = (2 * M_PI / CHUNK_SIZE) * k;
|
|
67
|
+
double c = cos(w);
|
|
68
|
+
double s = sin(w);
|
|
69
|
+
double coeff = 2.0 * c;
|
|
70
|
+
|
|
71
|
+
double q0 = 0.0, q1 = 0.0, q2 = 0.0;
|
|
72
|
+
for (int i = 0; i < CHUNK_SIZE; i++) {
|
|
73
|
+
q0 = coeff * q1 - q2 + samples[i];
|
|
74
|
+
q2 = q1;
|
|
75
|
+
q1 = q0;
|
|
76
|
+
}
|
|
63
77
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
double real = q1 - q2 * c;
|
|
79
|
+
double imaginary = q2 * s;
|
|
80
|
+
double magSquared = real * real + imaginary * imaginary;
|
|
67
81
|
|
|
68
|
-
|
|
69
|
-
return fix >> FIXED_POINT;
|
|
82
|
+
return magSquared;
|
|
70
83
|
}
|
|
71
84
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
85
|
+
void goertzel_det_init(goertzel_t *g, int freq, int sample_rate) {
|
|
86
|
+
g->freq = freq;
|
|
87
|
+
g->sampleRate = sample_rate;
|
|
88
|
+
g->samplesPerFrame = CHUNK_SIZE;
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
void goertzel_det_init(goertzel_t *g, float frequency, float sampling_rate, int samples_per_frame)
|
|
86
|
-
{
|
|
87
|
-
int k;
|
|
88
|
-
double floatN;
|
|
89
|
-
double omega;
|
|
90
|
-
floatN = (double)samples_per_frame;
|
|
91
|
-
k = (int)(0.5 + ((floatN * frequency) / sampling_rate));
|
|
92
|
-
omega = (2.0 * PI * k) / floatN;
|
|
93
|
-
g->sine = sin(omega);
|
|
94
|
-
g->cosine = cos(omega);
|
|
95
|
-
g->coeff = 2.0 * g->cosine;
|
|
96
|
-
g->fix_coeff = toFix(g->coeff, ONE_30);
|
|
97
|
-
printf("For sampling_rate = %f", sampling_rate);
|
|
98
|
-
printf("samples_per_frame = %d", samples_per_frame);
|
|
99
|
-
printf(" and frequency = %f,\n", frequency);
|
|
100
|
-
printf("k = %d and coeff = %f\n\n", k, g->coeff);
|
|
101
|
-
goertzel_det_reset(g);
|
|
90
|
+
assert(g->sampleRate >= g->freq * 2);
|
|
91
|
+
|
|
92
|
+
g->samplesPerFrame = (int)floor(g->samplesPerFrame);
|
|
93
|
+
|
|
94
|
+
// Precompute the target magnitude and store it in the struct
|
|
95
|
+
g->targetMagnitude = precalcMagnitude(g->freq, g->sampleRate);
|
|
96
|
+
// printf("Target Magnitude: %f\n", g->targetMagnitude);
|
|
102
97
|
}
|
|
103
98
|
|
|
104
|
-
float goertzel_mag(goertzel_t *g,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
g->Q1 = Q0;
|
|
99
|
+
float goertzel_mag(goertzel_t *g, void *samples) {
|
|
100
|
+
// Allocate an array of floats to hold normalized samples
|
|
101
|
+
float float_samples[CHUNK_SIZE];
|
|
102
|
+
uint8_t *byteBuffer = (uint8_t *)samples; // Cast the void* to a byte array (uint8_t *)
|
|
103
|
+
for (int i = 0; i < CHUNK_SIZE ; i++) {
|
|
104
|
+
// Combine two consecutive bytes into a 16-bit signed integer (little-endian)
|
|
105
|
+
int16_t sample = byteBuffer[i * 2] | (byteBuffer[i * 2 + 1] << 8);
|
|
106
|
+
float_samples[i] = sample * 2.0f / 0x7FFF;
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
/*
|
|
110
|
+
for (int i = 0; i < CHUNK_SIZE; i++) {
|
|
111
|
+
printf("%f,", float_samples[i]);
|
|
112
|
+
}
|
|
113
|
+
printf("\n");
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
int k = (int)(0.5f + (CHUNK_SIZE * g->freq) / g->sampleRate);
|
|
118
|
+
float w = (2.0f * M_PI / CHUNK_SIZE) * k;
|
|
119
|
+
float c = cosf(w);
|
|
120
|
+
float s = sinf(w);
|
|
121
|
+
float coeff = 2.0f * c;
|
|
122
|
+
|
|
123
|
+
float q0 = 0.0f, q1 = 0.0f, q2 = 0.0f;
|
|
124
|
+
|
|
125
|
+
for (int i = 0; i < CHUNK_SIZE; i++) {
|
|
126
|
+
q0 = coeff * q1 - q2 + float_samples[i];
|
|
127
|
+
q2 = q1;
|
|
128
|
+
q1 = q0;
|
|
129
|
+
}
|
|
120
130
|
|
|
131
|
+
float real = q1 - q2 * c;
|
|
132
|
+
float imaginary = q2 * s;
|
|
133
|
+
float magSquared = real * real + imaginary * imaginary;
|
|
134
|
+
|
|
135
|
+
float per = magSquared / g->targetMagnitude;
|
|
136
|
+
//printf("(freq=%i) MagSquared=%f targetMagnitude=%f per=%f\n", g->freq, magSquared, g->targetMagnitude, per);
|
|
137
|
+
return per;
|
|
138
|
+
}
|
|
121
139
|
|
|
122
140
|
|
|
123
141
|
static pj_status_t bfsk_det_put_frame(pjmedia_port *this_port,
|
|
@@ -141,24 +159,6 @@ struct bfsk_det
|
|
|
141
159
|
void *bfsk_cb_user_data;
|
|
142
160
|
};
|
|
143
161
|
|
|
144
|
-
/*
|
|
145
|
-
static void bfsk_det_bit_callback(void *user_data, int bit)
|
|
146
|
-
{
|
|
147
|
-
printf("bfsk_det_bit_callback got bit=%i\n", bit);
|
|
148
|
-
if(bit != 0 && bit != 1) return;
|
|
149
|
-
|
|
150
|
-
struct bfsk_det *dport = (struct bfsk_det*)user_data;
|
|
151
|
-
|
|
152
|
-
TRACE_((THIS_FILE, "bfsk_det bit detected: %c", bit));
|
|
153
|
-
|
|
154
|
-
if(!dport->bfsk_cb) return;
|
|
155
|
-
|
|
156
|
-
dport->bfsk_cb((pjmedia_port*)dport,
|
|
157
|
-
dport->bfsk_cb_user_data,
|
|
158
|
-
bit);
|
|
159
|
-
}
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
162
|
PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
163
163
|
unsigned clock_rate,
|
|
164
164
|
unsigned channel_count,
|
|
@@ -172,10 +172,9 @@ PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
|
172
172
|
int freq_one,
|
|
173
173
|
pjmedia_port **p_port)
|
|
174
174
|
{
|
|
175
|
-
printf("pjmedia_bfsk_det_create\n");
|
|
175
|
+
//printf("pjmedia_bfsk_det_create\n");
|
|
176
176
|
struct bfsk_det *det;
|
|
177
177
|
|
|
178
|
-
printf("p1\n");
|
|
179
178
|
const pj_str_t name = pj_str("bfsk_det");
|
|
180
179
|
|
|
181
180
|
PJ_ASSERT_RETURN(pool && clock_rate && channel_count &&
|
|
@@ -184,11 +183,8 @@ PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
|
184
183
|
|
|
185
184
|
PJ_ASSERT_RETURN(pool && p_port, PJ_EINVAL);
|
|
186
185
|
|
|
187
|
-
printf("p2\n");
|
|
188
|
-
|
|
189
186
|
det = PJ_POOL_ZALLOC_T(pool, struct bfsk_det);
|
|
190
187
|
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
|
|
191
|
-
printf("p3\n");
|
|
192
188
|
|
|
193
189
|
pjmedia_port_info_init(&det->base.info, &name, SIGNATURE, clock_rate,
|
|
194
190
|
channel_count, bits_per_sample, samples_per_frame);
|
|
@@ -196,13 +192,9 @@ PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
|
196
192
|
det->base.put_frame = &bfsk_det_put_frame;
|
|
197
193
|
det->base.on_destroy = &bfsk_det_on_destroy;
|
|
198
194
|
|
|
199
|
-
printf("p5\n");
|
|
200
|
-
|
|
201
195
|
det->bfsk_cb = cb;
|
|
202
196
|
det->bfsk_cb_user_data = user_data;
|
|
203
197
|
|
|
204
|
-
printf("p6\n");
|
|
205
|
-
|
|
206
198
|
det->clock_rate = clock_rate;
|
|
207
199
|
det->freq_zero = freq_zero;
|
|
208
200
|
det->freq_one = freq_one;
|
|
@@ -217,15 +209,10 @@ PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
|
217
209
|
|
|
218
210
|
int sample_rate = clock_rate;
|
|
219
211
|
|
|
220
|
-
|
|
221
|
-
goertzel_det_init(det->goertzel_one, det->freq_one, sample_rate, samples_per_frame);
|
|
222
|
-
|
|
223
|
-
printf("p7\n");
|
|
224
|
-
|
|
225
|
-
TRACE_((THIS_FILE, "bfsk_det created: clock_rate=%u channel_count=%u samples_per_frame=%u bits_per_frame=%u", clock_rate,
|
|
226
|
-
channel_count, samples_per_frame, bits_per_sample));
|
|
212
|
+
//printf("bfsk_det: clock_rate=%u channel_count=%u samples_per_frame=%u bits_per_frame=%u", clock_rate, channel_count, samples_per_frame, bits_per_sample);
|
|
227
213
|
|
|
228
|
-
|
|
214
|
+
goertzel_det_init(det->goertzel_zero, det->freq_zero, sample_rate);
|
|
215
|
+
goertzel_det_init(det->goertzel_one, det->freq_one, sample_rate);
|
|
229
216
|
|
|
230
217
|
*p_port = &det->base;
|
|
231
218
|
return PJ_SUCCESS;
|
|
@@ -234,50 +221,56 @@ PJ_DEF(pj_status_t) pjmedia_bfsk_det_create( pj_pool_t *pool,
|
|
|
234
221
|
static pj_status_t bfsk_det_put_frame(pjmedia_port *this_port,
|
|
235
222
|
pjmedia_frame *frame)
|
|
236
223
|
{
|
|
237
|
-
printf("
|
|
224
|
+
//printf("bfsk_det put_frame\n");
|
|
238
225
|
if(frame->type != PJMEDIA_FRAME_TYPE_AUDIO) return PJ_SUCCESS;
|
|
239
226
|
|
|
240
227
|
struct bfsk_det *dport = (struct bfsk_det*) this_port;
|
|
241
228
|
|
|
242
|
-
int size =
|
|
229
|
+
int size = frame->size;
|
|
243
230
|
int bps = PJMEDIA_PIA_BITS(&dport->base.info);
|
|
244
231
|
|
|
245
|
-
printf("p=%x, size=%i clock_rate=%i bits_per_sample=%i\n", frame->buf, size, dport->clock_rate, bps);
|
|
232
|
+
//printf("p=%x, size=%i clock_rate=%i bits_per_sample=%i\n", frame->buf, size, dport->clock_rate, bps);
|
|
246
233
|
|
|
247
234
|
int16_t * samples = (int16_t*)frame->buf;
|
|
248
235
|
|
|
236
|
+
/*
|
|
249
237
|
printf("Buffer contents:\n");
|
|
250
238
|
for (int i = 0; i < size; i++) {
|
|
251
|
-
printf("%
|
|
239
|
+
printf("%02x", samples[i] & 0xFF);
|
|
240
|
+
printf("%02x", samples[i] >> 8 & 0xFF);
|
|
252
241
|
}
|
|
253
242
|
printf("\n");
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
dport->zero_in_progress
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
dport->one_in_progress
|
|
279
|
-
|
|
280
|
-
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
for(int i=0 ; i<size/2/CHUNK_SIZE; i++) {
|
|
246
|
+
double zero_power = goertzel_mag(dport->goertzel_zero, &frame->buf[i*2*CHUNK_SIZE]);
|
|
247
|
+
double one_power = goertzel_mag(dport->goertzel_one, &frame->buf[i*2*CHUNK_SIZE]);
|
|
248
|
+
|
|
249
|
+
int zero = zero_power > THRESHOLD;
|
|
250
|
+
int one = one_power > THRESHOLD;
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
printf("zero_power=%f zero_in_progress=%i zero=%i threshold=%f\n", zero_power, dport->zero_in_progress, zero, THRESHOLD);
|
|
254
|
+
printf(" one_power=%f one_in_progress=%i one=%i threshold=%f\n", one_power, dport->one_in_progress, one, THRESHOLD);
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
// Check for zero signal extinction
|
|
258
|
+
if(dport->zero_in_progress && zero == 0) {
|
|
259
|
+
printf("notifying bit=0\n");
|
|
260
|
+
dport->bfsk_cb((pjmedia_port*)dport, dport->bfsk_cb_user_data, 0);
|
|
261
|
+
dport->zero_in_progress = 0;
|
|
262
|
+
} else {
|
|
263
|
+
dport->zero_in_progress = zero;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Check for one signal extinction
|
|
267
|
+
if(dport->one_in_progress && one == 0) {
|
|
268
|
+
printf("notifying bit=1\n");
|
|
269
|
+
dport->bfsk_cb((pjmedia_port*)dport, dport->bfsk_cb_user_data, 1);
|
|
270
|
+
dport->one_in_progress = 0;
|
|
271
|
+
} else {
|
|
272
|
+
dport->one_in_progress = one;
|
|
273
|
+
}
|
|
281
274
|
}
|
|
282
275
|
|
|
283
276
|
return PJ_SUCCESS;
|