FastLED 3.9.15
Loading...
Searching...
No Matches
buffers.hpp
Go to the documentation of this file.
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: RCSL 1.0/RPSL 1.0
3 *
4 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
5 *
6 * The contents of this file, and the files included with this file, are
7 * subject to the current version of the RealNetworks Public Source License
8 * Version 1.0 (the "RPSL") available at
9 * http://www.helixcommunity.org/content/rpsl unless you have licensed
10 * the file under the RealNetworks Community Source License Version 1.0
11 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
12 * in which case the RCSL will apply. You may also obtain the license terms
13 * directly from RealNetworks. You may not use this file except in
14 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
15 * applicable to this file, the RCSL. Please see the applicable RPSL or
16 * RCSL for the rights, obligations and limitations governing use of the
17 * contents of the file.
18 *
19 * This file is part of the Helix DNA Technology. RealNetworks is the
20 * developer of the Original Code and owns the copyrights in the portions
21 * it created.
22 *
23 * This file, and the files included with this file, is distributed and made
24 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
26 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
27 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
28 *
29 * Technology Compatibility Kit Test Suite(s) Location:
30 * http://www.helixcommunity.org/content/tck
31 *
32 * Contributor(s):
33 *
34 * ***** END LICENSE BLOCK ***** */
35
36/**************************************************************************************
37 * Fixed-point MP3 decoder
38 * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
39 * June 2003
40 *
41 * buffers.c - allocation and freeing of internal MP3 decoder buffers
42 *
43 * All memory allocation for the codec is done in this file, so if you don't want
44 * to use other the default system malloc() and free() for heap management this is
45 * the only file you'll need to change.
46 **************************************************************************************/
47
48//#include "hlxclib/stdlib.h" /* for malloc, free */
49#include <stdlib.h>
50#include "fl/stl/string.h"
51#include "coder.h"
52#include "fl/stl/noexcept.h"
53#include "fl/stl/stdint.h"
54
55namespace fl {
56namespace third_party {
57
58/**************************************************************************************
59 * Function: ClearBuffer
60 *
61 * Description: fill buffer with 0's
62 *
63 * Inputs: pointer to buffer
64 * number of bytes to fill with 0
65 *
66 * Outputs: cleared buffer
67 *
68 * Return: none
69 *
70 * Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
71 **************************************************************************************/
72static void ClearBuffer(void *buf, int nBytes) FL_NOEXCEPT
73{
74 int i;
75 unsigned char *cbuf = (unsigned char *)buf;
76
77 for (i = 0; i < nBytes; i++)
78 cbuf[i] = 0;
79
80 return;
81}
82
83/**************************************************************************************
84 * Function: AllocateBuffers
85 *
86 * Description: allocate all the memory needed for the MP3 decoder
87 *
88 * Inputs: none
89 *
90 * Outputs: none
91 *
92 * Return: pointer to MP3DecInfo structure (initialized with pointers to all
93 * the internal buffers needed for decoding, all other members of
94 * MP3DecInfo structure set to 0)
95 *
96 * Notes: if one or more mallocs fail, function frees any buffers already
97 * allocated before returning
98 **************************************************************************************/
100{
101 MP3DecInfo *mp3DecInfo;
102 FrameHeader *fh;
103 SideInfo *si;
104 ScaleFactorInfo *sfi;
105 HuffmanInfo *hi;
106 DequantInfo *di;
107 IMDCTInfo *mi;
108 SubbandInfo *sbi;
109
110 mp3DecInfo = (MP3DecInfo *)malloc(sizeof(MP3DecInfo));
111 if (!mp3DecInfo)
112 return 0;
113 ClearBuffer(mp3DecInfo, sizeof(MP3DecInfo));
114
115 fh = (FrameHeader *) malloc(sizeof(FrameHeader));
116 si = (SideInfo *) malloc(sizeof(SideInfo));
117 sfi = (ScaleFactorInfo *) malloc(sizeof(ScaleFactorInfo));
118 hi = (HuffmanInfo *) malloc(sizeof(HuffmanInfo));
119 di = (DequantInfo *) malloc(sizeof(DequantInfo));
120 mi = (IMDCTInfo *) malloc(sizeof(IMDCTInfo));
121 sbi = (SubbandInfo *) malloc(sizeof(SubbandInfo));
122
123 mp3DecInfo->FrameHeaderPS = (void *)fh;
124 mp3DecInfo->SideInfoPS = (void *)si;
125 mp3DecInfo->ScaleFactorInfoPS = (void *)sfi;
126 mp3DecInfo->HuffmanInfoPS = (void *)hi;
127 mp3DecInfo->DequantInfoPS = (void *)di;
128 mp3DecInfo->IMDCTInfoPS = (void *)mi;
129 mp3DecInfo->SubbandInfoPS = (void *)sbi;
130
131 if (!fh || !si || !sfi || !hi || !di || !mi || !sbi) {
132 FreeBuffers(mp3DecInfo); /* safe to call - only frees memory that was successfully allocated */
133 return 0;
134 }
135
136 /* important to do this - DSP primitives assume a bunch of state variables are 0 on first use */
137 ClearBuffer(fh, sizeof(FrameHeader));
138 ClearBuffer(si, sizeof(SideInfo));
139 ClearBuffer(sfi, sizeof(ScaleFactorInfo));
140 ClearBuffer(hi, sizeof(HuffmanInfo));
141 ClearBuffer(di, sizeof(DequantInfo));
142 ClearBuffer(mi, sizeof(IMDCTInfo));
143 ClearBuffer(sbi, sizeof(SubbandInfo));
144
145 return mp3DecInfo;
146}
147
148#define SAFE_FREE(x) {if (x) fl::free(x); (x) = 0;} /* helper macro */
149
150/**************************************************************************************
151 * Function: FreeBuffers
152 *
153 * Description: frees all the memory used by the MP3 decoder
154 *
155 * Inputs: pointer to initialized MP3DecInfo structure
156 *
157 * Outputs: none
158 *
159 * Return: none
160 *
161 * Notes: safe to call even if some buffers were not allocated (uses SAFE_FREE)
162 **************************************************************************************/
164{
165 if (!mp3DecInfo)
166 return;
167
168 SAFE_FREE(mp3DecInfo->FrameHeaderPS);
169 SAFE_FREE(mp3DecInfo->SideInfoPS);
170 SAFE_FREE(mp3DecInfo->ScaleFactorInfoPS);
171 SAFE_FREE(mp3DecInfo->HuffmanInfoPS);
172 SAFE_FREE(mp3DecInfo->DequantInfoPS);
173 SAFE_FREE(mp3DecInfo->IMDCTInfoPS);
174 SAFE_FREE(mp3DecInfo->SubbandInfoPS);
175
176 SAFE_FREE(mp3DecInfo);
177}
178
179} // namespace third_party
180} // namespace fl
#define SAFE_FREE(x)
Definition buffers.hpp:148
struct _MP3DecInfo MP3DecInfo
void * IMDCTInfoPS
Definition mp3common.h:73
void * FrameHeaderPS
Definition mp3common.h:68
void * DequantInfoPS
Definition mp3common.h:72
void * ScaleFactorInfoPS
Definition mp3common.h:70
void * SideInfoPS
Definition mp3common.h:69
void * HuffmanInfoPS
Definition mp3common.h:71
void * SubbandInfoPS
Definition mp3common.h:74
struct fl::third_party::_IMDCTInfo IMDCTInfo
struct fl::third_party::_DequantInfo DequantInfo
struct fl::third_party::_HuffmanInfo HuffmanInfo
struct fl::third_party::_SubbandInfo SubbandInfo
struct fl::third_party::_FrameHeader FrameHeader
struct fl::third_party::_SideInfo SideInfo
void FreeBuffers(MP3DecInfo *mp3DecInfo) FL_NOEXCEPT
Definition buffers.hpp:163
struct fl::third_party::_ScaleFactorInfo ScaleFactorInfo
MP3DecInfo * AllocateBuffers(void) FL_NOEXCEPT
Definition buffers.hpp:99
static void ClearBuffer(void *buf, int nBytes) FL_NOEXCEPT
Definition buffers.hpp:72
void * malloc(size_t size)
Definition malloc.cpp.hpp:9
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT