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
|
#include "csound.h"
#include <stdio.h>
#include <CUnit/Basic.h>
int init_suite1(void)
{
return 0;
}
int clean_suite1(void)
{
return 0;
}
void test_dev_list(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
char *name, *type;
int n = 0;
// printf("Output ------------------------------\n");
while(!csoundGetModule(csound, n++, &name, &type)) {
if (strcmp(type, "midi") == 0) {
csoundSetMIDIModule(csound,name);
int i,ndevs = csoundGetMIDIDevList(csound,NULL,1);
CS_MIDIDEVICE *devs = (CS_MIDIDEVICE *) malloc(ndevs*sizeof(CS_MIDIDEVICE));
csoundGetMIDIDevList(csound,devs,1);
// printf("Module %d: %s (%s): %i devices\n", n, name, type, ndevs);
for(i=0; i < ndevs; i++) {
CU_ASSERT_PTR_NOT_NULL(devs[i].device_id);
CU_ASSERT_PTR_NOT_NULL(devs[i].device_name);
CU_ASSERT_STRING_EQUAL(devs[i].midi_module, name);
// printf(" %d: %s %s (%s)\n", i,
// devs[i].device_id, devs[i].device_name, devs[i].interface_name);
}
free(devs);
} else if (strcmp(type, "audio") == 0) {
csoundSetRTAudioModule(csound,name);
int i,ndevs = csoundGetAudioDevList(csound,NULL,1);
CS_AUDIODEVICE *devs = (CS_AUDIODEVICE *) malloc(ndevs*sizeof(CS_AUDIODEVICE));
csoundGetAudioDevList(csound,devs,1);
// printf("Module %d: %s (%s): %i devices\n", n, name, type, ndevs);
for(i=0; i < ndevs; i++) {
CU_ASSERT_PTR_NOT_NULL(devs[i].device_id);
CU_ASSERT_PTR_NOT_NULL(devs[i].device_name);
// CU_ASSERT_STRING_EQUAL(devs[i].rt_module, name);
// printf(" %d: %s (%s)\n", i, devs[i].device_id, devs[i].device_name);
}
free(devs);
}
}
printf("\nInput ------------------------------\n");
n = 0;
while(!csoundGetModule(csound, n++, &name, &type)) {
if (strcmp(type, "midi") == 0) {
csoundSetMIDIModule(csound,name);
int i,ndevs = csoundGetMIDIDevList(csound,NULL,0);
//printf("%d \n", ndevs);
CS_MIDIDEVICE *devs = (CS_MIDIDEVICE *) malloc(ndevs*sizeof(CS_MIDIDEVICE));
csoundGetMIDIDevList(csound,devs,0);
// printf("Module %d: %s (%s): %i devices\n", n, name, type, ndevs);
for(i=0; i < ndevs; i++) {
CU_ASSERT_PTR_NOT_NULL(devs[i].device_id);
CU_ASSERT_PTR_NOT_NULL(devs[i].device_name);
CU_ASSERT_STRING_EQUAL(devs[i].midi_module, name) ;
// printf(" %d: %s %s (%s)\n", i,
// devs[i].device_id, devs[i].device_name, devs[i].interface_name);
}
free(devs);
} else if (strcmp(type, "audio") == 0) {
csoundSetRTAudioModule(csound,name);
int i,ndevs = csoundGetAudioDevList(csound,NULL,0);
CS_AUDIODEVICE *devs = (CS_AUDIODEVICE *) malloc(ndevs*sizeof(CS_AUDIODEVICE));
csoundGetAudioDevList(csound,devs,0);
printf("Module %d: %s (%s): %i devices\n", n, name, type, ndevs);
for(i=0; i < ndevs; i++) {
CU_ASSERT_PTR_NOT_NULL(devs[i].device_id);
CU_ASSERT_PTR_NOT_NULL(devs[i].device_name);
// CU_ASSERT_STRING_EQUAL(devs[i].rt_module, name);
printf(" %d: %s (%s)\n", i, devs[i].device_id, devs[i].device_name);
}
free(devs);
}
}
csoundDestroy(csound);
}
int key_callback_evt(void *userData, void *p,
unsigned int type)
{
(void) type;
int *prev = (int *) userData;
*((int *) p) = *prev;
*prev += 1;
return CSOUND_SUCCESS;
}
int key_callback_txt(void *userData, void *p,
unsigned int type)
{
(void) type;
int *prev = (int *) userData;
*((int *) p) = *prev;
*prev += 1;
return CSOUND_SUCCESS;
}
void test_keyboard_io(void)
{
int ret, err, prev = 100;
CSOUND *csound;
csound = csoundCreate(NULL);
ret = csoundRegisterKeyboardCallback(csound, key_callback_evt, &prev, CSOUND_CALLBACK_KBD_EVENT);
CU_ASSERT(ret == CSOUND_SUCCESS);
ret = csoundRegisterKeyboardCallback(csound, key_callback_txt, &prev, CSOUND_CALLBACK_KBD_TEXT);
CU_ASSERT(ret == CSOUND_SUCCESS);
const char *instrument =
"chn_k \"key\", 2\n"
"instr 1 \n"
"kkey sensekey\n"
"chnset kkey, \"key\"\n"
"kkey2, kdown2 sensekey\n"
"chnset kkey2, \"key2\"\n"
"chnset kdown2, \"down2\"\n"
// "printk2 kkey2\n"
// "printk2 kdown2\n"
"endin \n";
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 1");
ret = csoundStart(csound);
CU_ASSERT(ret == CSOUND_SUCCESS);
ret = csoundPerformKsmps(csound);
CU_ASSERT(ret == CSOUND_SUCCESS);
MYFLT val = csoundGetControlChannel(csound, "key", &err);
// CU_ASSERT(err == CSOUND_SUCCESS);
CU_ASSERT_DOUBLE_EQUAL(val, 100.0, 0.001);
val = csoundGetControlChannel(csound, "key2", &err);
// CU_ASSERT(err == CSOUND_SUCCESS);
CU_ASSERT_DOUBLE_EQUAL(val, 101.0, 0.001);
val = csoundGetControlChannel(csound, "down2", &err);
// CU_ASSERT(err == CSOUND_SUCCESS);
CU_ASSERT_DOUBLE_EQUAL(val, 1.0, 0.001);
csoundDestroy(csound);
}
void test_audio_modules(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
char *name, *type;
int n = 0;
while(!csoundGetModule(csound, n++, &name, &type)) {
if (strcmp(type, "audio") == 0) {
const char *instrument =
"ksmps = 256\n"
"instr 1 \n"
"asig oscil 0dbfs/4, A4\n"
"out linen(asig,0.005,p3,0.05)\n"
"endin \n";
csoundSetOption(csound, "-B4096");
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 0.1\n e 0.2");
csoundSetRTAudioModule(csound, name);
csoundSetOutput(csound, "dac", NULL, NULL);
int ret = csoundStart(csound);
if (strcmp(name, "jack") != 0) { // Jack module would fail this test if jack is not running
CU_ASSERT(ret == 0);
}
if (ret == 0) {
ret = csoundPerform(csound);
CU_ASSERT(ret > 0);
}
csoundReset(csound);
}
}
}
void test_audio_hostbased(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
const char *instrument =
"ksmps = 256\n"
"instr 1 \n"
"asig oscil 0dbfs/4, A4\n"
"out linen(asig,0.005,p3,0.05)\n"
"endin \n";
csoundSetOption(csound, "-B4096");
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 0.1\n e 0.2");
// csoundSetRTAudioModule(csound, "hostbased");
csoundSetHostImplementedAudioIO(csound, 1, 256);
csoundSetOutput(csound, "dac", NULL, NULL);
int ret = csoundStart(csound);
CU_ASSERT(ret == 0);
ret = csoundPerform(csound);
CU_ASSERT(ret > 0);
csoundReset(csound);
}
void test_audio_realtime_mode(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
const char *instrument =
"ksmps = 256\n"
"instr 1 \n"
"asig oscil 0dbfs/4, A4\n"
"out linen(asig,0.005,p3,0.05)\n"
"endin \n";
csoundSetOption(csound, "-B256");
csoundSetOption(csound, "-b64");
csoundSetOption(csound, "--realtime");
csoundSetOption(csound, "-odac");
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 0.1\n e 0.2");
int ret = csoundStart(csound);
CU_ASSERT(ret == 0);
ret = csoundPerform(csound);
CU_ASSERT(ret > 0);
csoundReset(csound);
}
void test_midi_modules(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
char *name, *type;
int n = 0;
while(!csoundGetModule(csound, n++, &name, &type)) {
if (strcmp(type, "midi") == 0) {
const char *instrument =
"ksmps = 256\n"
"instr 1 \n"
"asig oscil 0dbfs/4, A4\n"
"out linen(asig,0.005,p3,0.05)\n"
"endin \n";
csoundSetOption(csound, "-B4096");
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 0.1\n e 0.2");
csoundSetMIDIModule(csound, name);
csoundSetOutput(csound, "dac", NULL, NULL);
int ret = csoundStart(csound);
CU_ASSERT(ret == 0);
ret = csoundPerform(csound);
CU_ASSERT(ret > 0);
csoundReset(csound);
}
}
}
void test_midi_hostbased(void)
{
CSOUND *csound;
csound = csoundCreate(NULL);
const char *instrument =
"ksmps = 256\n"
"instr 1 \n"
"asig oscil 0dbfs/4, A4\n"
"out linen(asig,0.005,p3,0.05)\n"
"endin \n";
csoundSetOption(csound, "-B4096");
csoundCompileOrc(csound, instrument);
csoundReadScore(csound, "i 1 0 0.1\n e 0.2");
// csoundSetMIDIModule(csound, "hostbased");
csoundSetHostImplementedMIDIIO(csound, 1);
csoundSetOutput(csound, "dac", NULL, NULL);
int ret = csoundStart(csound);
CU_ASSERT(ret == 0);
ret = csoundPerform(csound);
CU_ASSERT(ret > 0);
csoundReset(csound);
}
int main()
{
CU_pSuite pSuite = NULL;
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite("Message Buffer Tests", init_suite1, clean_suite1);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}
/* add the tests to the suite */
if ((NULL == CU_add_test(pSuite, "Device Listing", test_dev_list))
|| (NULL == CU_add_test(pSuite, "Keyboard IO\n", test_keyboard_io))
|| (NULL == CU_add_test(pSuite, "Audio Modules\n", test_audio_modules))
|| (NULL == CU_add_test(pSuite, "Audio Hostbased\n", test_audio_hostbased))
|| (NULL == CU_add_test(pSuite, "MIDI Modules\n", test_midi_modules))
|| (NULL == CU_add_test(pSuite, "MIDI Hostbased\n", test_midi_hostbased))
|| (NULL == CU_add_test(pSuite, "Audio realtime mode\n", test_audio_realtime_mode))
)
{
CU_cleanup_registry();
return CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}
|