AeBookAsset.c++
2.01 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
/*****************************************************************************
* File: AeADPCMBookAsset.c++
*
* AeADPCMBookAsset Class Implementations
*
****************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "AeAsset.h"
#include "GList.h"
#include "AeErr.h"
AeADPCMBookAsset::AeADPCMBookAsset(const char * name,
int order,
int npredictors,
int vsize,
short * bookData)
: AeAsset (name, kADPCMBookType)
{
fNBookItems = 0;
fBookData = NULL;
SetBook (order, npredictors, vsize, bookData);
}
AeADPCMBookAsset::~AeADPCMBookAsset()
{
if(fBookData)
free (fBookData);
if (fParentList)
{
AeAsset * parent;
int i;
// nullify any references to this asset
fParentList->Start (i, kReverse);
while (fParentList->Prev (i, parent))
{
if (((AeADPCMWaveAsset *)parent)->GetBook () == this)
((AeADPCMWaveAsset *)parent)->SetBook (NULL);
}
}
}
void
AeADPCMBookAsset::SetBook(int order, int npredictors, int vsize, short * bookData)
{
int bookItems;
fOrder = order;
fNpredictors = npredictors;
fVSize = vsize;
bookItems = npredictors * order * vsize;
if (bookItems && bookData)
{
if (bookItems != fNBookItems)
{
if (fBookData)
free (fBookData);
fNBookItems = bookItems;
fBookData = (short *)malloc(bookItems * sizeof (short));
FailNIL (fBookData);
}
memcpy (fBookData, bookData, fNBookItems * sizeof (short));
}
}
int
AeADPCMBookAsset::GetOrderProc(AeAsset * asset)
{
assert (asset);
return ((AeADPCMBookAsset *)asset)->GetOrder ();
}
int
AeADPCMBookAsset::GetNPredictorsProc (AeAsset * asset)
{
assert (asset);
return ((AeADPCMBookAsset *)asset)->GetNPredictors ();
}
int
AeADPCMBookAsset::GetBookData (short * bookData)
{
if(!fBookData)
return 0;
assert (fNBookItems);
memcpy (bookData, fBookData, fNBookItems * sizeof(short));
return fNBookItems;
}