-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVoice.cpp
More file actions
108 lines (91 loc) · 3.34 KB
/
Copy pathVoice.cpp
File metadata and controls
108 lines (91 loc) · 3.34 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
// Copyright (C) 2022-2024 Theo Niessink <theo@taletn.com>
// This work is free. You can redistribute it and/or modify it under the
// terms of the Do What The Fuck You Want To Public License, Version 2,
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#include "Voice.h"
namespace TG101 {
char* RightTrim(char* const str, int len)
{
assert(len >= 0);
while (len-- && str[(unsigned int)len] == ' ');
str[(unsigned int)++len] = 0;
return str;
}
void VoiceCommon::Init()
{
static const unsigned char tbl[60] =
{
// VoiceCommon
0x00, // SetVoiceMode(kVoiceSingle);
0x7F, // SetLevel(kVoiceElement1, 127);
0x7F, // SetLevel(kVoiceElement2, 127);
0x40, // SetDetune(kVoiceElement1, 64);
0x40, // SetDetune(kVoiceElement2, 64);
0x01, // SetPortamentoTime(1);
0x0F, // SetModLFOPitchDepth(15);
0x00, // DontCare();
0x00, // SetAftertouchLFOPitchDepth(0);
0x00, // DontCare();
0x00, // SetPitchRateScale(kVoiceElement1, kPitchRateScale100);
0x3C, // SetPitchRateScaleCenterNote(kVoiceElement1, kNoteMiddleC);
0x40, // SetNoteShift(kVoiceElement1, 64);
0x40, // SetNoteShift(kVoiceElement2, 64);
0x00, // SetPitchRateScale(kVoiceElement2, kPitchRateScale100);
0x3C, // SetPitchRateScaleCenterNote(kVoiceElement2, kNoteMiddleC);
// SetName(NULL);
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
// VoiceElement
0x00, 0x00, // SetWaveNo(kWaveNoSine);
0x40, // SetEGAttackRate(64);
0x40, // SetEGReleaseRate(64);
0x40, // SetLevelScaleBreakPoint(0, 64);
0x40, // SetLevelScaleBreakPoint(1, 64);
0x40, // SetLevelScaleBreakPoint(2, 64);
0x40, // SetLevelScaleBreakPoint(3, 64);
0x08, 0x00, // SetLevelScaleOffset(0, 128);
0x08, 0x00, // SetLevelScaleOffset(1, 128);
0x08, 0x00, // SetLevelScaleOffset(2, 128);
0x08, 0x00, // SetLevelScaleOffset(3, 128);
0x00, // SetPan(kPanCenter);
0x04, // SetLFOSpeed(4);
0x00, // SetLFODelay(0);
0x00, // DontCare();
0x00, // SetLFOPitchModDepth(0);
0x00, // SetLFOAmpModDepth(0);
0x00, // SetPitchLFOWave(kPitchLFOTriangle);
0x01, // SetPitchEGRange(kPitchEGRange1);
0x01, // SetPitchEGVelocitySwitch(true);
0x00, // SetPitchEGRateScale(0);
0x3F, // SetPitchEGRate(kPitchEGRateAttack, 63);
0x3F, // SetPitchEGRate(kPitchEGRateDecay1, 63);
0x3F, // SetPitchEGRate(kPitchEGRateDecay2, 63);
0x3F, // SetPitchEGRate(kPitchEGRateRelease, 63);
0x40, // SetPitchEGLevel(kPitchEGLevelInit, 64)
0x40, // SetPitchEGLevel(kPitchEGLevelAttack, 64)
0x40, // SetPitchEGLevel(kPitchEGLevelDecay1, 64)
0x40, // SetPitchEGLevel(kPitchEGLevelDecay2, 64)
0x40, // SetPitchEGLevel(kPitchEGLevelRelease, 64)
0x00 // SetVelocityCurve(0);
};
memcpy(mBuf, tbl, 60);
memcpy(&mBuf[60], &tbl[24], 36);
}
char* VoiceCommon::GetName(char buf[9]) const
{
memcpy(buf, &mBuf[16], 8);
return RightTrim(buf, 8);
}
void VoiceCommon::SetName(const char* const name)
{
unsigned char* const buf = &mBuf[16];
memset(buf, ' ', 8);
if (!name) return;
for (int i = 0; i < 8; ++i)
{
const int c = (signed char)name[i];
if (!c) break;
assert(c >= ' ' && c <= 127);
buf[i] = wdl_max(c, ' ');
}
}
} // namespace TG101