Pārlūkot izejas kodu

cmDspStore.h/c: Initial commit.

cmDspCtx.h, cmDspNet.h/c, cmDspSys.c, Makefile.am: Added cmDspStore.
master
kevin 11 gadus atpakaļ
vecāks
revīzija
d7b64b882b
7 mainītis faili ar 229 papildinājumiem un 2 dzēšanām
  1. 2
    2
      Makefile.am
  2. 5
    0
      dsp/cmDspCtx.h
  3. 1
    0
      dsp/cmDspNet.c
  4. 1
    0
      dsp/cmDspNet.h
  5. 179
    0
      dsp/cmDspStore.c
  6. 30
    0
      dsp/cmDspStore.h
  7. 11
    0
      dsp/cmDspSys.c

+ 2
- 2
Makefile.am Parādīt failu

@@ -39,8 +39,8 @@ cmHDR += src/libcm/cmGr.h src/libcm/cmGrDevCtx.h src/libcm/cmGrPage.h src/libcm/
39 39
 cmHDR +=  src/libcm/dsp/cmDspSys.h src/libcm/dsp/cmDspClass.h src/libcm/dsp/cmDspValue.h src/libcm/dsp/cmDspUi.h src/libcm/dsp/cmDspPreset.h src/libcm/dsp/cmDspNet.h
40 40
 cmSRC +=  src/libcm/dsp/cmDspSys.c src/libcm/dsp/cmDspClass.c src/libcm/dsp/cmDspValue.c src/libcm/dsp/cmDspUi.c src/libcm/dsp/cmDspPreset.c src/libcm/dsp/cmDspNet.c
41 41
 
42
-cmHDR += src/libcm/dsp/cmDspBuiltIn.h  src/libcm/dsp/cmDspFx.h 
43
-cmSRC += src/libcm/dsp/cmDspBuiltIn.c  src/libcm/dsp/cmDspFx.c 
42
+cmHDR += src/libcm/dsp/cmDspStore.h src/libcm/dsp/cmDspBuiltIn.h  src/libcm/dsp/cmDspFx.h 
43
+cmSRC += src/libcm/dsp/cmDspStore.c src/libcm/dsp/cmDspBuiltIn.c  src/libcm/dsp/cmDspFx.c 
44 44
 
45 45
 cmHDR += src/libcm/dsp/cmDspPgm.h src/libcm/dsp/cmDspPgmPP.h src/libcm/dsp/cmDspPgmPPMain.h
46 46
 cmSRC += src/libcm/dsp/cmDspPgm.c src/libcm/dsp/cmDspPgmPP.c src/libcm/dsp/cmDspPgmPPMain.c

+ 5
- 0
dsp/cmDspCtx.h Parādīt failu

@@ -6,8 +6,11 @@ extern "C" {
6 6
 #endif
7 7
 
8 8
   typedef cmHandle_t cmDspSysH_t;
9
+  typedef cmHandle_t cmDspStoreH_t;
10
+  
9 11
 
10 12
   struct cmAudioSysCtx_str;
13
+  struct cmDspGlobalVar_str;
11 14
 
12 15
   // DSP system context passed to many DSP instance functions
13 16
   typedef struct
@@ -20,9 +23,11 @@ extern "C" {
20 23
     cmLHeapH_t                lhH;
21 24
     cmJsonH_t                 jsH;
22 25
     cmSymTblH_t               stH;
26
+    cmDspStoreH_t             dsH;
23 27
     cmJsonH_t                 rsrcJsH;
24 28
     unsigned                  cycleCnt;  // count of DSP execution cycles (multiply by cmDspSamplesPerCycle() to get time since start of DSP system in samples)
25 29
 
30
+
26 31
     unsigned _disableSymId;
27 32
     unsigned _enableSymId;
28 33
 

+ 1
- 0
dsp/cmDspNet.c Parādīt failu

@@ -20,6 +20,7 @@
20 20
 #include "cmProcObj.h"
21 21
 #include "cmDspCtx.h"
22 22
 #include "cmDspClass.h"
23
+#include "cmDspStore.h"
23 24
 #include "cmDspSys.h"
24 25
 #include "cmDspPreset.h"
25 26
 #include "cmDspNet.h"

+ 1
- 0
dsp/cmDspNet.h Parādīt failu

@@ -62,6 +62,7 @@ extern "C" {
62 62
     cmDspCtx_t          ctx;
63 63
     cmLHeapH_t          lhH;      // DSP system lHeap used for system memory (DSP instance memory uses ctx->lhH so that it can be removed independent of the DSP system memory)
64 64
     cmSymTblH_t         stH;      // DSP system symbol table (holds class based symbols) (DSP instances use ctx->stH)
65
+    cmDspStoreH_t       dsH;      // DSP system global variable storate table
65 66
     cmJsonH_t           jsH;      // DSP json for use by the system 
66 67
     const cmChar_t*     rsrcFn;   // name of the JSON file containing resource specific resource      
67 68
     _cmDspClass_t*      classList;

+ 179
- 0
dsp/cmDspStore.c Parādīt failu

@@ -0,0 +1,179 @@
1
+#include "cmPrefix.h"
2
+#include "cmGlobal.h"
3
+#include "cmFloatTypes.h"
4
+#include "cmRpt.h"
5
+#include "cmErr.h"
6
+#include "cmCtx.h"
7
+#include "cmMem.h"
8
+#include "cmMallocDebug.h"
9
+#include "cmLinkedHeap.h"
10
+#include "cmSymTbl.h"
11
+#include "cmJson.h"
12
+#include "cmDspValue.h"
13
+#include "cmDspCtx.h"
14
+#include "cmDspClass.h"
15
+#include "cmDspStore.h"
16
+
17
+typedef struct
18
+{
19
+  unsigned     symId;
20
+  cmDspValue_t value;
21
+} cmDspStoreVar_t;
22
+
23
+typedef struct 
24
+{
25
+  cmErr_t          err;
26
+  cmDspStoreVar_t* array;
27
+  unsigned         allocCnt;
28
+  unsigned         growCnt;
29
+  unsigned         curCnt;
30
+} cmDspStore_t;
31
+
32
+
33
+cmDspStoreH_t cmDspStoreNullHandle = cmSTATIC_NULL_HANDLE;
34
+
35
+cmDspStore_t* _cmDspStoreHandleToPtr( cmDspStoreH_t h )
36
+{
37
+  cmDspStore_t* p = (cmDspStore_t*)h.h;
38
+  assert( p != NULL );
39
+  return p;
40
+}
41
+
42
+cmDspRC_t _cmDspStoreFree( cmDspStore_t* p )
43
+{
44
+  cmMemFree(p->array);
45
+  cmMemFree(p);
46
+  return kOkDspRC;
47
+}
48
+
49
+
50
+cmDspRC_t cmDspStoreAlloc( cmCtx_t* ctx, cmDspStoreH_t* hp, unsigned initStoreCnt, unsigned growStoreCnt )
51
+{
52
+  cmDspRC_t rc;
53
+  if((rc = cmDspStoreFree(hp)) != kOkDspRC )
54
+    return rc;
55
+
56
+  cmDspStore_t* p = cmMemAllocZ(cmDspStore_t,1);
57
+
58
+  cmErrSetup(&p->err,&ctx->rpt,"cmDspStore");
59
+
60
+  p->array    = cmMemAllocZ(cmDspStoreVar_t,initStoreCnt);
61
+  p->allocCnt = initStoreCnt;
62
+  p->curCnt   = 0;
63
+  p->growCnt  = growStoreCnt;
64
+
65
+  hp->h = p;
66
+
67
+  return rc;
68
+}
69
+  
70
+cmDspRC_t cmDspStoreFree( cmDspStoreH_t *hp )
71
+{
72
+  cmDspRC_t rc = kOkDspRC;
73
+  if(hp==NULL || cmDspStoreIsValid(*hp)==false )
74
+    return rc;
75
+
76
+  cmDspStore_t* p = _cmDspStoreHandleToPtr(*hp);
77
+
78
+  if((rc = _cmDspStoreFree(p)) != kOkDspRC )
79
+    return rc;
80
+
81
+  hp->h = NULL;
82
+
83
+  return rc;
84
+}
85
+
86
+bool      cmDspStoreIsValid( cmDspStoreH_t h )
87
+{ return h.h; }
88
+
89
+
90
+cmDspStoreVar_t*  _cmDspStoreSymToPtr( cmDspStore_t* p, unsigned symId )
91
+{
92
+  cmDspStoreVar_t* vp = p->array;
93
+  cmDspStoreVar_t* ep = p->array + p->curCnt;
94
+  for(; vp<ep; ++vp)
95
+    if( vp->symId == symId )
96
+      return vp;
97
+  return NULL;
98
+}
99
+
100
+cmDspStoreVar_t*  _cmDspStoreIdToPtr( cmDspStore_t* p, unsigned id )
101
+{
102
+  if( id < p->curCnt )
103
+    return p->array + id;
104
+ 
105
+  return NULL;
106
+}
107
+
108
+cmDspStoreVar_t* _cmDspStoreAppend( cmDspStore_t* p )
109
+{
110
+  cmDspStoreVar_t* vp = NULL;
111
+
112
+  if( p->curCnt >= p->allocCnt )
113
+  {
114
+    p->allocCnt += p->growCnt;
115
+    p->array = cmMemResizePZ(cmDspStoreVar_t,p->array,p->allocCnt);
116
+  }
117
+
118
+  vp = p->array + p->curCnt;
119
+
120
+  p->curCnt += 1;
121
+
122
+  return vp;
123
+}
124
+  
125
+unsigned  cmDspStoreSymToId( cmDspStoreH_t h, unsigned symId )
126
+{
127
+  cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
128
+  const cmDspStoreVar_t* vp;
129
+  if((vp = _cmDspStoreSymToPtr(p,symId)) == NULL )
130
+    return cmInvalidId;
131
+  return vp - p->array;
132
+}
133
+
134
+unsigned  cmDspStoreIdToSym( cmDspStoreH_t h, unsigned id )
135
+{
136
+  cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
137
+  const cmDspStoreVar_t* vp;
138
+  if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
139
+    return cmInvalidId;
140
+  return vp->symId;
141
+}
142
+
143
+const cmDspValue_t*  cmDspStoreIdToValue( cmDspStoreH_t h, unsigned id )
144
+{
145
+  cmDspStore_t* p = _cmDspStoreHandleToPtr(h);
146
+  const cmDspStoreVar_t* vp;
147
+  if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
148
+    return NULL;
149
+  return &vp->value;
150
+}
151
+
152
+cmDspRC_t cmDspStoreSetValueViaId(  cmDspStoreH_t h, unsigned id, const cmDspValue_t* val )
153
+{
154
+  cmDspRC_t rc = kOkDspRC;
155
+  cmDspStore_t*     p = _cmDspStoreHandleToPtr(h);
156
+  cmDspStoreVar_t* vp = NULL;
157
+
158
+  if((vp = _cmDspStoreIdToPtr(p,id)) == NULL )
159
+    return cmErrMsg(&p->err,kVarNotFoundDspRC,"There is not global variable at with id:%i\n",id);
160
+
161
+  cmDsvCopy(&vp->value,val);    
162
+  return rc;
163
+}
164
+
165
+unsigned cmDspStoreSetValueViaSym( cmDspStoreH_t h, unsigned symId, const cmDspValue_t* val )
166
+{
167
+  cmDspStore_t*     p = _cmDspStoreHandleToPtr(h);
168
+  cmDspStoreVar_t* vp = NULL;
169
+
170
+  if((vp = _cmDspStoreSymToPtr(p,symId)) == NULL )
171
+    vp = _cmDspStoreAppend(p);
172
+
173
+  assert(vp != NULL );
174
+
175
+  cmDsvCopy(&vp->value,val);    
176
+  vp->symId = symId;
177
+
178
+  return vp - p->array;
179
+}

+ 30
- 0
dsp/cmDspStore.h Parādīt failu

@@ -0,0 +1,30 @@
1
+#ifndef cmDspStore_h
2
+#define cmDspStore_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+  extern cmDspStoreH_t cmDspStoreNullHandle;
9
+
10
+  cmDspRC_t cmDspStoreAlloc( cmCtx_t* ctx, cmDspStoreH_t* hp, unsigned initStoreCnt, unsigned growStoreCnt );
11
+  
12
+  cmDspRC_t cmDspStoreFree( cmDspStoreH_t *hp );
13
+
14
+  bool      cmDspStoreIsValid( cmDspStoreH_t h );
15
+  
16
+  unsigned  cmDspStoreSymToId( cmDspStoreH_t h, unsigned symId );
17
+  unsigned  cmDspStoreIdToSym( cmDspStoreH_t h, unsigned id );
18
+  const cmDspValue_t*  cmDspStoreIdToValue( cmDspStoreH_t h, unsigned id );
19
+
20
+  cmDspRC_t cmDspStoreSetValueViaId(  cmDspStoreH_t h, unsigned id,    const cmDspValue_t* val );
21
+
22
+  // Sets the variable to the value (and creates it if it does not exist).
23
+  // Returns the 'id' of the variable.
24
+  unsigned cmDspStoreSetValueViaSym( cmDspStoreH_t h, unsigned symId, const cmDspValue_t* val );
25
+
26
+#ifdef __cplusplus
27
+  }
28
+#endif
29
+
30
+#endif

+ 11
- 0
dsp/cmDspSys.c Parādīt failu

@@ -21,6 +21,7 @@
21 21
 #include "cmProcObj.h"
22 22
 #include "cmDspCtx.h"
23 23
 #include "cmDspClass.h"
24
+#include "cmDspStore.h"
24 25
 #include "cmDspSys.h"
25 26
 #include "cmDspBuiltIn.h"
26 27
 #include "cmDspPgm.h"
@@ -140,6 +141,8 @@ cmDspRC_t _cmDspSysFinalize( cmDsp_t* p )
140 141
     if( cmCtxFree(&p->ctx.cmProcCtx) != cmOkRC )
141 142
       rc = cmErrMsg(&p->err,kProcFailDspRC,"The proc context finalizatoin failed.");
142 143
 
144
+  cmDspStoreFree(&p->dsH);
145
+
143 146
   if( cmSymTblIsValid(p->stH) ) 
144 147
     cmSymTblDestroy(&p->stH);
145 148
 
@@ -195,6 +198,13 @@ cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
195 198
     goto errLabel;
196 199
   }
197 200
 
201
+  // allocate the DSP system variable storage object
202
+  if( cmDspStoreAlloc(ctx,&p->dsH,10,10) != kOkDspRC )
203
+  {
204
+    rc = cmErrMsg(&p->err,kDspStoreFailDspRC,"DSP store allocation failed.");
205
+    goto errLabel;
206
+  }
207
+
198 208
   // initialize the proc context
199 209
   if( (p->ctx.cmProcCtx = cmCtxAlloc(NULL,&ctx->rpt,p->lhH,p->stH)) == NULL )
200 210
   {
@@ -214,6 +224,7 @@ cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
214 224
   p->ctx.lhH     = p->lhH;
215 225
   p->ctx.jsH     = p->jsH;
216 226
   p->ctx.stH     = p->stH;
227
+  p->ctx.dsH     = p->dsH;
217 228
   p->ctx.rsrcJsH = cmJsonNullHandle;
218 229
   p->ctx.rpt     = &ctx->rpt;
219 230
   p->ctx.cmCtx   = &p->cmCtx;

Notiek ielāde…
Atcelt
Saglabāt