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 "NSVAACDecoder.h"
#include <assert.h>
#include "api.h"
#include "../nsv/nsvlib.h"
#include "api.h"
#include "../nsv/nsvlib.h"
#include "../nsv/dec_if.h"
#include <string.h>
#include <bfc/platform/export.h>
#include "NSVAACDecoder.h"
#include <bfc/error.h>
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
NSVAACDecoder *NSVAACDecoder::CreateDecoder()
{
NSVAACDecoder *decoder=0;
WASABI_API_MEMMGR->New(&decoder);
if (!decoder)
{
return 0;
}
decoder->Initialize();
return decoder;
}
NSVAACDecoder::NSVAACDecoder()
{
source_position=0;
out_left=0;
in_position=0;
}
NSVAACDecoder::~NSVAACDecoder()
{
}
void NSVAACDecoder::Initialize()
{
decoder.Open();
}
void NSVAACDecoder::flush()
{
decoder.Flush();
}
// returns -1 on error, 0 on success (done with data in 'in'), 1 on success
// but to pass 'in' again next time around.
int NSVAACDecoder::decode(void *in, int in_len, void *out, int *out_len, unsigned int out_fmt[8])
{
HRESULT hr;
size_t local_out_len = *out_len;
if (SUCCEEDED(decoder.Decode(out, &local_out_len, 16, false, 1.0))) {
*out_len = (int)local_out_len;
if (local_out_len) {
uint32_t local_sample_rate, local_channels;
if (SUCCEEDED(decoder.GetOutputProperties(&local_sample_rate, &local_channels))) {
out_fmt[0] = NSV_MAKETYPE('P', 'C', 'M', ' ');
out_fmt[1] = local_sample_rate;
out_fmt[2] = local_channels;
out_fmt[3] = 16;
}
return 1;
}
}
hr = decoder.Feed(in, in_len);
if (FAILED(hr)) {
hr=hr;
}
local_out_len = *out_len;
if (SUCCEEDED(decoder.Decode(out, &local_out_len, 16, false, 1.0))) {
*out_len = (int)local_out_len;
if (local_out_len) {
uint32_t local_sample_rate, local_channels;
if (SUCCEEDED(decoder.GetOutputProperties(&local_sample_rate, &local_channels))) {
out_fmt[0] = NSV_MAKETYPE('P', 'C', 'M', ' ');
out_fmt[1] = local_sample_rate;
out_fmt[2] = local_channels;
out_fmt[3] = 16;
}
}
} else {
*out_len = 0;
}
return 0;
}
IAudioDecoder *NSVDecoder::CreateAudioDecoder(FOURCC format, IAudioOutput **output)
{
switch (format)
{
case NSV_MAKETYPE('A', 'A', 'C', ' ') :
case NSV_MAKETYPE('A', 'A', 'C', 'P'):
case NSV_MAKETYPE('A', 'P', 'L', ' '):
{
NSVAACDecoder *dec = NSVAACDecoder::CreateDecoder();
return dec;
}
default:
return 0;
}
}
#define CBCLASS NSVDecoder
START_DISPATCH;
CB(SVC_NSVFACTORY_CREATEAUDIODECODER, CreateAudioDecoder)
END_DISPATCH;
#undef CBCLASS
|