-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaxDecoder.cpp
More file actions
332 lines (281 loc) · 11 KB
/
Copy pathWaxDecoder.cpp
File metadata and controls
332 lines (281 loc) · 11 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
//-----------------------------------------------------------------------------
//@file
// WaxDecoder.cpp
//
//@author
// Arnaud BEUROTTE aka 'naarud'
//
//@brief
// Implementation of the WaxDecoder class.
//
//@historic
// 2012/07/04
// first release, implement the timecoder used in v1.2 of xwax
// 2018/11/16
// updated to Usine SDK HH3-7.01.006
// based on xwax v1.7 sources
//
//@IMPORTANT
// All dependencies are under there own licence.
//
//@LICENCE
//
// Copyright (c) 2012, 2018 Arnaud BEUROTTE
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// includes
//-----------------------------------------------------------------------------
#include "WaxDecoder.h"
//-----------------------------------------------------------------------------
// create, general info and destroy methods
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CreateModule (void* &pModule, AnsiCharPtr optionalString, LongBool Flag, MasterInfo* pMasterInfo, AnsiCharPtr optionalContent)
{
pModule = new WaxDecoder();
}
//-----------------------------------------------------------------------------
void DestroyModule(void* pModule)
{
delete ((WaxDecoder*)pModule);
}
//-----------------------------------------------------------------------------
// module constants for browser info and module info
const AnsiCharPtr UserModuleBase::MODULE_NAME = "WaxDecoder";
const AnsiCharPtr UserModuleBase::MODULE_DESC = "Timecoded Vinyl/CD interpreter";
const AnsiCharPtr UserModuleBase::MODULE_VERSION = "20181116";
//-----------------------------------------------------------------------------
void GetBrowserInfo(ModuleInfo* pModuleInfo)
{
pModuleInfo->Name = UserModuleBase::MODULE_NAME;
pModuleInfo->Description = UserModuleBase::MODULE_DESC;
pModuleInfo->Version = UserModuleBase::MODULE_VERSION;
}
//-----------------------------------------------------------------------------
// module constructors/destructors and description
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
WaxDecoder::WaxDecoder()
{
usineBlockSize = 0;
usineSmplRate = 0;
target_position = TARGET_UNKNOWN;
pitch = 0.;
lbxTimecodes = 0;
lbxRpmSpeed = 0;
lbxSoftPA = 0;
};
//-----------------------------------------------------------------------------
WaxDecoder::~WaxDecoder()
{
if (pcm != NULL)
delete [] pcm;
}
//-----------------------------------------------------------------------------
void WaxDecoder::onGetModuleInfo (MasterInfo* pMasterInfo, ModuleInfo* pModuleInfo)
{
pModuleInfo->Name = MODULE_NAME;
pModuleInfo->Description = MODULE_DESC;
pModuleInfo->ModuleType = mtSimple;
pModuleInfo->BackColor = sdkGetUsineColor(clAudioModuleColor);
pModuleInfo->Version = MODULE_VERSION;
pModuleInfo->NumberOfParams = 4;
}
//-----------------------------------------------------------------------------
// query system and init methods
//-----------------------------------------------------------------------------
// query system not used
//-----------------------------------------------------------------------------
void WaxDecoder::onInitModule (MasterInfo* pMasterInfo, ModuleInfo* pModuleInfo) {
// init timecoder to 'serato_2a' timecode at 33 rpm without using a 'software' preamp
loadTimecoder(TC_NAMES[0], RPM_SPEED[0], SOFT_PREAMP[0]);
// usine block size
usineBlockSize = sdkGetBlocSize();
pcm = new signed short[usineBlockSize * 2];
}
//----------------------------------------------------------------------------
// parameters and process
//----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// parameters description
void WaxDecoder::onGetParamInfo (int ParamIndex, TParamInfo* pParamInfo)
{
switch (ParamIndex)
{
// audio in left
case 0:
pParamInfo->ParamType = ptAudio;
pParamInfo->Caption = "in L";
pParamInfo->IsInput = true;
pParamInfo->IsOutput = false;
pParamInfo->ReadOnly = false;
pParamInfo->EventPtr = &audioInputTab[0];
break;
// audio in right
case 1:
pParamInfo->ParamType = ptAudio;
pParamInfo->Caption = "in R";
pParamInfo->IsInput = true;
pParamInfo->IsOutput = false;
pParamInfo->ReadOnly = false;
pParamInfo->EventPtr = &audioInputTab[1];
break;
// position output
case 2:
pParamInfo->ParamType = ptDataField;
pParamInfo->Caption = "position";
pParamInfo->IsInput = false;
pParamInfo->IsOutput = true;
pParamInfo->MinValue = 0.0;
pParamInfo->MaxValue = 1200.0;
pParamInfo->DefaultValue = 0.0;
pParamInfo->Symbol = "s";
pParamInfo->Format = "%g";
pParamInfo->ReadOnly = true;
pParamInfo->EventPtr = &dtfPositionOut;
break;
// pitch output
case 3:
pParamInfo->ParamType = ptDataField;
pParamInfo->Caption = "pitch";
pParamInfo->IsInput = false;
pParamInfo->IsOutput = true;
pParamInfo->MinValue = -30.0;
pParamInfo->MaxValue = 30.0;
pParamInfo->DefaultValue = 0.0;
pParamInfo->Symbol = "";
pParamInfo->Format = "%g";
pParamInfo->ReadOnly = true;
pParamInfo->EventPtr = &dtfPitchOut;
break;
// default case
default:
break;
}
}
//-----------------------------------------------------------------------------
void WaxDecoder::onCallBack (UsineMessage *Message)
{
}
//-----------------------------------------------------------------------------
// populate properties tab with hardware settings (disc manufacturer, RPM speed and use of software phono preamp)
void WaxDecoder::onCreateSettings()
{
sdkAddSettingLineCaption(PROPERTIES_TAB_NAME, "hardware settings");
sdkAddSettingLineCombobox(PROPERTIES_TAB_NAME, &lbxTimecodes, "timecode", "\"serato_2a\",\"serato_2b\",\"serato_cd\",\"traktor_a\",\"traktor_b\",\"mixvibes_v2\",\"mixvibes_7inch\"");
sdkAddSettingLineCombobox(PROPERTIES_TAB_NAME, &lbxRpmSpeed, "rpm", "\"33\",\"45\"");
sdkAddSettingLineCombobox(PROPERTIES_TAB_NAME, &lbxSoftPA, "software phono preamp", "\"no\",\"yes\"");
}
//-----------------------------------------------------------------------------
void WaxDecoder::onSettingsHasChanged()
{
loadTimecoder(TC_NAMES[lbxTimecodes], RPM_SPEED[lbxRpmSpeed], SOFT_PREAMP[lbxSoftPA]);
}
//-----------------------------------------------------------------------------
void WaxDecoder::onBlocSizeChange (int BlocSize)
/* nothing to do ? Usine asks to reboot after a block size change.
* update the module even if Usine is not restarted */
{
usineBlockSize = BlocSize;
if (pcm != NULL)
delete[] pcm;
pcm = new signed short[usineBlockSize * 2];
}
//-----------------------------------------------------------------------------
void WaxDecoder::onSampleRateChange (double SampleRate)
{
loadTimecoder(TC_NAMES[lbxTimecodes], RPM_SPEED[lbxRpmSpeed], SOFT_PREAMP[lbxSoftPA]);
}
//-------------------------------------------------------------------------
void WaxDecoder::onProcess ()
{
outputTCoder();
}
//-------------------------------------------------------------------------
// private methods implementation
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------------
// init the timecoder (return -1 if fails, 0 otherwise)
int WaxDecoder::loadTimecoder(AnsiCharPtr tc_def, double speed, bool soft_pa)
{
TimecodeDefinition = timecoder_find_definition(tc_def);
if (TimecodeDefinition == NULL)
return -1;
usineSmplRate = sdkGetSampleRate();
timecoder_init(&TCoder, TimecodeDefinition, speed, usineSmplRate, soft_pa);
return 0;
}
//-----------------------------------------------------------------------------
// getting pitch and position from the decoder and writing to the module outputs
int WaxDecoder::exportPlaybackParameters()
{
/* FROM 'sync_to_timecode(struct player)' in player.c xwax sources */
/*******************************************************************/
double when, tcpos;
signed int timecode;
timecode = timecoder_get_position(&TCoder, &when);
/* Instruct the caller to disconnect the timecoder if the needle
* is outside the 'safe' zone of the record */
if (timecode != -1 && timecode > timecoder_get_safe(&TCoder))
return -1;
/* If the timecoder is alive, use the pitch from the sine wave */
pitch = timecoder_get_pitch(&TCoder);
/* If we can read an absolute time from the timecode, then use it */
if (timecode == -1)
target_position = TARGET_UNKNOWN;
else
{
tcpos = (double)timecode / timecoder_get_resolution(&TCoder);
target_position = tcpos + pitch * when;
}
/*******************************************************************/
// set outputs
sdkSetEvtData(dtfPositionOut, target_position);
sdkSetEvtData(dtfPitchOut, pitch);
return 0;
}
//-----------------------------------------------------------------------------
// pcm conversion from Usine stereo audio inputs to xwax decoder
void WaxDecoder::writeCompatibleAudio(signed short*& pcm)
{
int i;
for(i=0; i < usineBlockSize; ++i)
{
pcm[2*i] = 32768 * sdkGetEvtArrayData(audioInputTab[0], i);
pcm[2*i+1] = 32768 * sdkGetEvtArrayData(audioInputTab[1], i);
}
}
//-----------------------------------------------------------------------------
// main process
void WaxDecoder::outputTCoder()
{
// get 'xwax compatible' audio from inputs
writeCompatibleAudio(pcm);
// submit block to timecoder
timecoder_submit(&TCoder, pcm, usineBlockSize);
// decode and output playback infos
if (exportPlaybackParameters() == -1)
{
sdkSetEvtData(dtfPositionOut, TARGET_UNKNOWN);
sdkSetEvtData(dtfPitchOut, 0.);
}
}