File: perfthread_test.cpp

package info (click to toggle)
csound 1%3A6.18.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,416 kB
  • sloc: ansic: 192,636; cpp: 14,151; javascript: 9,654; objc: 9,181; java: 3,337; python: 3,333; sh: 1,783; yacc: 1,255; xml: 985; perl: 635; lisp: 411; tcl: 341; lex: 217; makefile: 126
file content (121 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download | duplicates (3)
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
#include "csound.hpp"
#include "csPerfThread.hpp"
#include <stdio.h>
#include <CUnit/Basic.h>

int init_suite1(void)
{
    return 0;
}

int clean_suite1(void)
{
    return 0;
}

#if defined(__WINNT__)
    #include <Windows.h>
#else
    #include "unistd.h"
#endif

void test_perfthread(void)
{
    const char  *instrument =
            "instr 1 \n"
            "k1 expon p4, p3, p4*0.001 \n"
            "a1 randi  k1, p5   \n"
            "out  a1   \n"
            "endin \n";

    Csound csound;
    csound.SetOption((char*)"-odac");
    csound.CompileOrc(instrument);
    csound.ReadScore((char*)"i 1 0  3 10000 5000\n");
    csound.Start();
    CsoundPerformanceThread performanceThread1(csound.GetCsound());
    performanceThread1.Play();
    performanceThread1.Join();
    csound.Cleanup();
    csound.Reset();
    CsoundPerformanceThread performanceThread2(csound.GetCsound());
    csound.SetOption((char*)"-odac");
    csound.CompileOrc(instrument);
    csound.ReadScore((char*)"i 1 0  3 10000 5000\n");
    csound.Start();
    performanceThread2.Play();
    performanceThread2.Join();
    csound.Cleanup();
    csound.Reset();
}

void test_record(void)
{
    const char  *instrument =
            "0dbfs = 1.0\n"
            "ksmps = 64\n"
            "instr 1 \n"
            "a1 line 0, p3, 0.5   \n"
            "out  a1   \n"
            "endin \n";

    Csound csound;
    CsoundPerformanceThread performanceThread1(csound.GetCsound());
    csound.SetOption((char*)"-otestplay.wav");
    csound.SetOption((char*)"-W");
    csound.CompileOrc(instrument);
    csound.ReadScore((char*)"i 1 0  3 0.5 5000\n");
    csound.Start();
    performanceThread1.Play();
    //performanceThread1.Record("testrec.wav");
#if !defined(__WINNT__)
    sleep(1);
#else
    Sleep(1000);
#endif
    //performanceThread1.StopRecord();
    performanceThread1.Join();
    csound.Cleanup();
    csound.Reset();
}

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("perfthread 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, "Test Record", test_record))
            || (NULL == CU_add_test(pSuite, "Test Performance Thread", test_perfthread))
        )
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* add the tests to the suite */
    if ((NULL == CU_add_test(pSuite, "Test Performance Thread second run", test_perfthread))
//            || (NULL == CU_add_test(pSuite, "Test reuse", test_reuse))
        )
    {
        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();
}