Hacked node-speaker exports and other imports here to get examples working
Please note I changed package.json to refer to my fork of node-speaker also.
As a newb to the TypeScript ecosystem I don't know if my export/import changes are correct/modern/acceptable, but I got the examples working.
There is still a bug (in usb?) where fm_tone doesn't exit on a ^C interrupt. Have to ^Z and kill it.
welcome! I don't quite understand some of the changes you're proposing, I'll add comments
Mainly just things to get it compiling. I tried under VSCode, then command line, just saying "tsc" at the top level.
- tsconfig.json compiles things in examples
- examples import from ../lib, where the code is
- usb updated to a version that works
- speaker updates to a version that exports itself in a way that works (I understand there are two kinds of export):
https://github.com/cjheath/node-speaker/commit/09377c3544742a32afaa4e8aeff8a6ada33f0205
Also I've just done this:
- const carrierFrequency = 98.8e6
+ let carrierFrequency : number = 104.9e6
const carrierDeviation = 75e3
+ if (process.argv.length >= 3)
+ carrierFrequency = (+process.argv[2])*1.0e6;
There is still a bug (in usb?) where fm_tone doesn't exit on a ^C interrupt. Have to ^Z and kill it.
I'm just speculating, but that happened to me too, and it seems to be a loop starvation issue somewhere in my code or usb, which prevents the ^C event from being dispatched. if it happens on fm_tone, your cpu is probably not fast enough to run the code (keep in mind examples aren't optimized in any way)
I'd be very surprised if my CPU isn't fast enough. 2yo i7 MacBook Pro...
BTW, I've developed a new version of HackRF, updating to still-available components. and adding robust protection to the antenna port. It's about to go to batch manufacturing and will be available for purchase on aliexpress (no cash to me, just development sample units)
that looks nice :blue_heart: let me know when it's available :)
by the way, I don't know enough TypeScript to understand why speaker works for me, but not for you :thinking:
in any case, according to the documentation, import Speaker = require('speaker') syntax should be used, so I'll do that
I've added npm run build-examples, instructions, and proposed proper fixes to speaker
I've fetched your latest. npm run build-examples fails for me. The Speaker one is not a concern, but failing to import from .. is:
> [email protected] build-examples /Users/cjh/work/electronics/SDR/node/hackrf.js-upstream
> cd examples && tsc
fm_receiver.ts:9:22 - error TS2307: Cannot find module '..' or its corresponding type declarations.
9 import { open } from '..'
~~~~
fm_receiver.ts:26:22 - error TS2351: This expression is not constructable.
Type 'typeof import("/Users/cjh/work/electronics/SDR/node/hackrf.js-upstream/node_modules/speaker/index")' has no construct signatures.
26 const speaker = new Speaker({ sampleRate: 48000, channels: 1, bitDepth: 16 })
~~~~~~~
fm_receiver.ts:53:23 - error TS7006: Parameter 'array' implicitly has an 'any' type.
53 await device.receive(array => {
~~~~~
fm_tone.ts:5:22 - error TS2307: Cannot find module '..' or its corresponding type declarations.
5 import { open } from '..'
~~~~
fm_tone.ts:27:24 - error TS7006: Parameter 'array' implicitly has an 'any' type.
27 await device.transmit(array => {
~~~~~
Found 5 errors.
have you run npm install again? do you have compiled files in dist? (also, does dist/index.js exist?)
Ahh, apologies, that fixed it, or would have, if `speaker`` had been fixed already
perfect! now I just have to fix the loop starvation bug