-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdecoder.cpp
More file actions
128 lines (115 loc) · 4.39 KB
/
Copy pathdecoder.cpp
File metadata and controls
128 lines (115 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// #include "decoder.h"
// #include "portaudio.h"
// #include <stdio.h>
// //https://github.com/Streampunk/naudiodon -- perhaps should just use this?
// #define SAMPLE_RATE (44100)
// #define FRAMES_PER_BUFFER (512)
// #define PA_SAMPLE_TYPE paFloat32
// typedef float SAMPLE;
// #define SAMPLE_SILENCE (0.0f)
// #define PRINTF_S_FORMAT "%.8f"
// using namespace Napi;
// Decoder::Decoder(const Napi::CallbackInfo & info): ObjectWrap(info) {
// //Napi::Env env = info.Env();
// PaError err;
// //suppress output from pa_initialize
// fclose(stderr);
// err = Pa_Initialize();
// freopen("CON", "w", stderr);
// if (err != paNoError) {
// printf("ERROR: Pa_Initialize returned 0x%x\n", err);
// }
// }
// Napi::Value Decoder::Close(const Napi::CallbackInfo & info) {
// Napi::Env env = info.Env();
// int retcode = 0;
// Pa_Terminate();
// return Napi::Number::New(env, retcode);
// }
// Napi::Value Decoder::ListDevices(const Napi::CallbackInfo & info) {
// Napi::Env env = info.Env();
// int numDevices;
// const PaDeviceInfo * deviceInfo;
// numDevices = Pa_GetDeviceCount();
// Napi::Array arrDevices = Napi::Array::New(env);
// for (int i = 0; i < numDevices; i++) {
// deviceInfo = Pa_GetDeviceInfo(i);
// printf("Source: %s -- inputs: %i outputs: %i\n", deviceInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
// arrDevices.Set(i, Napi::String::New(env, deviceInfo -> name));
// }
// return arrDevices;
// }
// static int recordCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
// {
// (void)outputBuffer;
// const float *finput = static_cast<const float *>(inputBuffer);
// printf("callback called! float: %.8f : frames: %i\n", finput, framesPerBuffer);
// Decoder *decoder = static_cast<Decoder *>(userData);
// return paContinue;
// }
// Napi::Value Decoder::SetInputDevice(const Napi::CallbackInfo &info)
// {
// Napi::Env env = info.Env();
// if (!info[0].IsNumber())
// {
// Napi::TypeError::New(env, "Device number must be an integer").ThrowAsJavaScriptException();
// return env.Null();
// }
// // begin test
// inputParameters.device = info[0].As<Napi::Number>().Int32Value();
// inputParameters.channelCount = 1;
// inputParameters.sampleFormat = PA_SAMPLE_TYPE;
// inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
// inputParameters.hostApiSpecificStreamInfo = NULL;
// return Napi::Number::New(env, 0);
// }
// Napi::Value Decoder::SetOutputDevice(const Napi::CallbackInfo &info)
// {
// Napi::Env env = info.Env();
// if (!info[0].IsNumber())
// {
// Napi::TypeError::New(env, "Device number must be an integer").ThrowAsJavaScriptException();
// return env.Null();
// }
// outputParameters.device = info[0].As<Napi::Number>().Int32Value();
// outputParameters.channelCount = 1;
// outputParameters.sampleFormat = PA_SAMPLE_TYPE;
// outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowInputLatency;
// outputParameters.hostApiSpecificStreamInfo = NULL;
// return Napi::Number::New(env, 0);
// }
// Napi::Value Decoder::Open(const Napi::CallbackInfo &info)
// {
// Napi::Env env = info.Env();
// PaError err = paNoError;
// err = Pa_OpenStream(
// &stream,
// &inputParameters,
// &outputParameters,
// SAMPLE_RATE,
// FRAMES_PER_BUFFER,
// paClipOff, /* we won't output out of range samples so don't bother clipping them */
// recordCallback,
// static_cast<void *>(this));
// if (err != paNoError)
// {
// Napi::TypeError::New(env, "Unable to open input!").ThrowAsJavaScriptException();
// return env.Null();
// }
// else
// {
// err = Pa_StartStream(stream);
// return Napi::Number::New(env, 0);
// }
// }
// Napi::Function Decoder::GetClass(Napi::Env env) {
// return DefineClass(
// env,
// "Decoder", {
// Decoder::InstanceMethod("close", & Decoder::Close),
// Decoder::InstanceMethod("listDevices", & Decoder::ListDevices),
// Decoder::InstanceMethod("setInputDevice", & Decoder::SetInputDevice),
// Decoder::InstanceMethod("setOutputDevice", & Decoder::SetOutputDevice),
// Decoder::InstanceMethod("open", & Decoder::Open)
// });
// }