|
@@ -6,7 +6,7 @@ extern "C" {
|
6
|
6
|
#endif
|
7
|
7
|
|
8
|
8
|
/*
|
9
|
|
- The data for this object is stored in a CSV file with the following column syntax.
|
|
9
|
+ The CSV file used to initialize a SDB object has the following column syntax.
|
10
|
10
|
|
11
|
11
|
Column Name Type Description
|
12
|
12
|
------ -------- ----- -----------------------------------------------------
|
|
@@ -46,17 +46,26 @@ extern "C" {
|
46
|
46
|
kOkSdbRC,
|
47
|
47
|
kLHeapFailSdbRC,
|
48
|
48
|
kCsvFailSdbRC,
|
|
49
|
+ kFileSysFailSdbRC,
|
|
50
|
+ kAudioFileFailSdbRC,
|
49
|
51
|
kSyntaxErrSdbRC,
|
50
|
52
|
kInvalidRspIdxSdbRC,
|
51
|
|
- kChPairNotFoundSdbRC
|
|
53
|
+ kInvalidSeqIdxSdbRC,
|
|
54
|
+ kChPairNotFoundSdbRC,
|
|
55
|
+ kRspEvtNotFoundSdbRC,
|
|
56
|
+ kAssertFailSdbRC,
|
|
57
|
+ kInvalidArgSdbRC
|
52
|
58
|
};
|
53
|
59
|
|
54
|
60
|
typedef cmHandle_t cmSdbH_t;
|
55
|
61
|
typedef cmHandle_t cmSdbResponseH_t;
|
|
62
|
+ typedef cmHandle_t cmSdbSeqH_t;
|
56
|
63
|
|
57
|
64
|
typedef cmRC_t cmSdbRC_t;
|
58
|
|
- extern cmSdbH_t cmSdbNullHandle_t;
|
59
|
|
- extern cmSdbResponseH_t cmSdbResponseNullHandle_t;
|
|
65
|
+
|
|
66
|
+ extern cmSdbH_t cmSdbNullHandle;
|
|
67
|
+ extern cmSdbResponseH_t cmSdbResponseNullHandle;
|
|
68
|
+ extern cmSdbSeqH_t cmSdbSeqNullHandle;
|
60
|
69
|
|
61
|
70
|
typedef struct
|
62
|
71
|
{
|
|
@@ -77,12 +86,29 @@ extern "C" {
|
77
|
86
|
} cmSdbEvent_t;
|
78
|
87
|
|
79
|
88
|
|
80
|
|
- cmSdbRC_t cmSdbCreate( cmCtx_t* ctx, cmSdbH_t* hp, const cmChar_t* audioDir, const cmChar_t* csvFn );
|
|
89
|
+ // Create an SDB object. If 'csvFn' is non-NULL then an internal call is made to cmSdbLoad().
|
|
90
|
+ cmSdbRC_t cmSdbCreate( cmCtx_t* ctx, cmSdbH_t* hp, const cmChar_t* csvFn, const cmChar_t* audioDir );
|
|
91
|
+
|
|
92
|
+ // Release an SDB object previously created via cmSdbCreate().
|
81
|
93
|
cmSdbRC_t cmSdbDestroy( cmSdbH_t* hp );
|
82
|
94
|
|
83
|
95
|
bool cmSdbIsValid( cmSdbH_t h );
|
84
|
96
|
|
85
|
|
- cmSdbRC_t cmSdbLoad( cmSdbH_t h, const cmChar_t* csvFn );
|
|
97
|
+ // Iinitialze the internal database from the CSV file 'csvFn'.
|
|
98
|
+ cmSdbRC_t cmSdbLoad( cmSdbH_t h, const cmChar_t* csvFn, const cmChar_t* audioDir );
|
|
99
|
+
|
|
100
|
+ // Time align all channel pairs by setting the onset times to
|
|
101
|
+ // the minimum time among all the pairs and the offset times to
|
|
102
|
+ // the maximum among all the pairs. This function is applied to all
|
|
103
|
+ // the events contained in the sample database.
|
|
104
|
+ cmSdbRC_t cmSdbSyncChPairs( cmSdbH_t h );
|
|
105
|
+
|
|
106
|
+ // Given a sample event unique id return a pointer to the associated record.
|
|
107
|
+ const cmSdbEvent_t* cmSdbEvent( cmSdbH_t h, unsigned uuid );
|
|
108
|
+
|
|
109
|
+ //================================================================================================
|
|
110
|
+ // Query Related functions
|
|
111
|
+ //
|
86
|
112
|
|
87
|
113
|
// Select a set of events from the sample database.
|
88
|
114
|
//
|
|
@@ -122,15 +148,23 @@ extern "C" {
|
122
|
148
|
// which case a match will be triggered by fields where
|
123
|
149
|
// the key text is not a substring of the field text.
|
124
|
150
|
//
|
125
|
|
- // All query response handles returned from this function
|
126
|
|
- // should eventualy be released by the application via a call to
|
127
|
|
- // cmSdbResponseFree().
|
|
151
|
+ // pitchV[] contains an array of pitch values to match.
|
|
152
|
+ // The last value in pitchV[] must be kInvalidMidiPitch.
|
|
153
|
+ // If pitchV == NULL then all pitches match. Note that
|
|
154
|
+ // to match non-pitched instruments set set one element
|
|
155
|
+ // of pitchV[] to -1.
|
|
156
|
+ //
|
|
157
|
+ // The application should release all query response handles
|
|
158
|
+ // returned from this function via a call to cmSdbResponseFree().
|
|
159
|
+ // cmSdbDestroy() will automatically release any response
|
|
160
|
+ // handles not previously release by cmSdbReponseFree().
|
128
|
161
|
cmSdbRC_t cmSdbSelect(
|
129
|
162
|
cmSdbH_t h,
|
130
|
163
|
double srate, // event sample rate or 0 to ignore
|
131
|
164
|
const cmChar_t** instrV, // array of instrument labels to match
|
132
|
165
|
const cmChar_t** srcV, // array of 'src' labels to match
|
133
|
166
|
const cmChar_t** notesV, // array of text 'notes' to match
|
|
167
|
+ const unsigned* pitchV, // array of pitches terminated w/ kInvalidMidiPitch
|
134
|
168
|
double minDurSec, // min event duration
|
135
|
169
|
double maxDurSec, // max event duration or 0 to ignore
|
136
|
170
|
unsigned minChCnt, // min ch cnt or 0 to ignore
|
|
@@ -155,10 +189,106 @@ extern "C" {
|
155
|
189
|
cmSdbRC_t cmSdbResponseFree( cmSdbResponseH_t* rhp );
|
156
|
190
|
void cmSdbResponsePrint( cmSdbResponseH_t rh, cmRpt_t* rpt );
|
157
|
191
|
|
158
|
|
- // Time align all channel pairs by setting the onset times to
|
159
|
|
- // the minimum time among all the pairs and the offset times to
|
160
|
|
- // the maximum among all the pairs.
|
161
|
|
- cmSdbRC_t cmSdbSyncChPairs( cmSdbH_t h );
|
|
192
|
+ //================================================================================================
|
|
193
|
+ // Sequence Related functions
|
|
194
|
+ //
|
|
195
|
+ typedef struct
|
|
196
|
+ {
|
|
197
|
+ unsigned uuid; // uuid of sample data base envent.
|
|
198
|
+ double begSec; // Event start time in seconds.
|
|
199
|
+ double durSec; // Event duration in seconds.
|
|
200
|
+ double gain; // Event amplitude scaling factor.
|
|
201
|
+ unsigned outChIdx; // Output channel index.
|
|
202
|
+ } cmSdbSeqEvent_t;
|
|
203
|
+
|
|
204
|
+ // Generate a random sequence of events with a programmable
|
|
205
|
+ // density of events per second.
|
|
206
|
+ //
|
|
207
|
+ // 'minEvtPerSec' and 'maxEvtPerSec' specify the min and max count of events
|
|
208
|
+ // which may be initiated per second.
|
|
209
|
+ //
|
|
210
|
+ // The application should release all sequence handles
|
|
211
|
+ // returned from this function via a call to cmSdbSeqFree().
|
|
212
|
+ // cmSdbDestroy() will automatically release any sequence
|
|
213
|
+ // handles not previously release by cmSdbSeqFree().
|
|
214
|
+ //
|
|
215
|
+ // Note that the event selection is done with replacement.
|
|
216
|
+ // The same event may therefore be selected more than
|
|
217
|
+ // once.
|
|
218
|
+ cmSdbRC_t cmSdbSeqRand(
|
|
219
|
+ cmSdbResponseH_t rh,
|
|
220
|
+ unsigned seqDurSecs,
|
|
221
|
+ unsigned seqChCnt,
|
|
222
|
+ unsigned minEvtPerSec,
|
|
223
|
+ unsigned maxEvtPerSec,
|
|
224
|
+ cmSdbSeqH_t* shp );
|
|
225
|
+
|
|
226
|
+ // Generate a sequence of serial events w/ gapSec seconds
|
|
227
|
+ // between each event. Events longer than 'maxEvtDurSec'
|
|
228
|
+ // seconds are truncated to 'maxEvtDurSec'.
|
|
229
|
+ cmSdbRC_t cmSdbSeqSerial(
|
|
230
|
+ cmSdbResponseH_t rh,
|
|
231
|
+ unsigned seqChCnt,
|
|
232
|
+ double gapSec,
|
|
233
|
+ double maxEvtDurSec,
|
|
234
|
+ cmSdbSeqH_t* shp );
|
|
235
|
+
|
|
236
|
+ // Generate a chord sequence by randomly selecting one event
|
|
237
|
+ // from each response handle.
|
|
238
|
+ cmSdbRC_t cmSdbSeqChord(
|
|
239
|
+ cmSdbResponseH_t* rhp, // one rhp[rn] query resonse per chord note
|
|
240
|
+ unsigned rn, // count of response handles in rhp[].
|
|
241
|
+ unsigned seqChCnt, // output sequence channel count
|
|
242
|
+ unsigned maxEvtDurSec, // maximum event duration or 0 to prevent truncation
|
|
243
|
+ cmSdbSeqH_t* shp );
|
|
244
|
+
|
|
245
|
+ // Release a sequence.
|
|
246
|
+ cmSdbRC_t cmSdbSeqFree( cmSdbSeqH_t* shp );
|
|
247
|
+
|
|
248
|
+ // Return the count of sequence events.
|
|
249
|
+ unsigned cmSdbSeqCount( cmSdbSeqH_t sh );
|
|
250
|
+
|
|
251
|
+ // Return a pointer to a specified cmSdbSeqEvent_t record.
|
|
252
|
+ // where 0 <= index < cmSdbSeqCount(sh)
|
|
253
|
+ const cmSdbSeqEvent_t* cmSdbSeqEvent( cmSdbSeqH_t sh, unsigned index );
|
|
254
|
+
|
|
255
|
+ // Given a seqence index return the associate cmSdbEvent_t.
|
|
256
|
+ const cmSdbEvent_t* cmSdbSeqSdbEvent( cmSdbSeqH_t sh, unsigned index );
|
|
257
|
+
|
|
258
|
+ // Return the total duration of the sequence in seconds.
|
|
259
|
+ double cmSdbSeqDurSeconds( cmSdbSeqH_t sh );
|
|
260
|
+
|
|
261
|
+ // Return the sample rate of the first event in the sequence that
|
|
262
|
+ // has a non-zero sample rate. There is no guarantee that all
|
|
263
|
+ // of the other events in the sequence have the same sample rate
|
|
264
|
+ // unless this was enforced by the query response that the
|
|
265
|
+ // sequence was generated from.
|
|
266
|
+ double cmSdbSeqSampleRate( cmSdbSeqH_t sh );
|
|
267
|
+
|
|
268
|
+ // Generate an audio from a sequence and return it in
|
|
269
|
+ // a signal vector.
|
|
270
|
+ cmSdbRC_t cmSdbSeqToAudio(
|
|
271
|
+ cmSdbSeqH_t sh,
|
|
272
|
+ unsigned decayMs, // decay rate for truncated events
|
|
273
|
+ double noiseDb, // (-70.0) pad signal with white noise to avoid digital silence
|
|
274
|
+ double evtNormFact, // normalize each sample event by normFact / abs(max(x[])) or 0 to skip normalization
|
|
275
|
+ cmSample_t** signalRef, // *signalRef[*sigSmpCntRef * sh.chCnt] returned audio signal
|
|
276
|
+ unsigned* sigSmpCntRef ); // count of frames in *signalRef
|
|
277
|
+
|
|
278
|
+ // Generate an audio file from a sequence vector.
|
|
279
|
+ cmSdbRC_t cmSdbSeqToAudioFn(
|
|
280
|
+ cmSdbSeqH_t sh,
|
|
281
|
+ unsigned decayMs, // decay rate for truncated events
|
|
282
|
+ double noiseDb, // (-70.0) pad signal with white noise to avoid digital silence
|
|
283
|
+ double evtNormFact, // normalize each sample event by normFact / abs(max(x[])) or 0 to skip normalization
|
|
284
|
+ double normFact, // total signal norm factor or 0.0 to skip normalization
|
|
285
|
+ const cmChar_t* fn, // write the output signal to this audio file
|
|
286
|
+ unsigned bitsPerSample // audio file bits per sample
|
|
287
|
+ );
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+ // Print a sequence event listing.
|
|
291
|
+ void cmSdbSeqPrint( cmSdbSeqH_t sh, cmRpt_t* rpt );
|
162
|
292
|
|
163
|
293
|
cmSdbRC_t cmSdbTest( cmCtx_t* ctx );
|
164
|
294
|
|