summaryrefslogtreecommitdiff
path: root/audio_codec/libcook/ra_buffers.c (plain)
blob: 28aea79cd635e68fc2a48a636609e2e44dd4d778
1/* ***** BEGIN LICENSE BLOCK *****
2 * Source last modified: $Id: buffers.c,v 1.2 2005/04/27 19:20:50 hubbe Exp $
3 *
4 * REALNETWORKS CONFIDENTIAL--NOT FOR DISTRIBUTION IN SOURCE CODE FORM
5 * Portions Copyright (c) 1995-2002 RealNetworks, Inc.
6 * All Rights Reserved.
7 *
8 * The contents of this file, and the files included with this file,
9 * are subject to the current version of the Real Format Source Code
10 * Porting and Optimization License, available at
11 * https://helixcommunity.org/2005/license/realformatsource (unless
12 * RealNetworks otherwise expressly agrees in writing that you are
13 * subject to a different license). You may also obtain the license
14 * terms directly from RealNetworks. You may not use this file except
15 * in compliance with the Real Format Source Code Porting and
16 * Optimization License. There are no redistribution rights for the
17 * source code of this file. Please see the Real Format Source Code
18 * Porting and Optimization License for the rights, obligations and
19 * limitations governing use of the contents of the file.
20 *
21 * RealNetworks is the developer of the Original Code and owns the
22 * copyrights in the portions it created.
23 *
24 * This file, and the files included with this file, is distributed and
25 * made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND,
26 * EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL
27 * SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT
29 * OR NON-INFRINGEMENT.
30 *
31 * Technology Compatibility Kit Test Suite(s) Location:
32 * https://rarvcode-tck.helixcommunity.org
33 *
34 * Contributor(s):
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/**************************************************************************************
39 * Fixed-point RealAudio 8 decoder
40 * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
41 * October 2003
42 *
43 * buffers.c - allocation and freeing of internal RA8 decoder buffers
44 *
45 * All memory allocation for the codec is done in this file, so if you want
46 * to use something other the default malloc() and free() this is the only file
47 * you'll need to change.
48 **************************************************************************************/
49
50//#include "includes.h"
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54#include <fcntl.h>
55#include "coder.h"
56
57/**************************************************************************************
58 * Function: ClearBuffer
59 *
60 * Description: fill buffer with 0's
61 *
62 * Inputs: pointer to buffer
63 * number of bytes to fill with 0
64 *
65 * Outputs: cleared buffer
66 *
67 * Return: none
68 *
69 * Notes: slow, platform-independent equivalent to memset(buf, 0, nBytes)
70 **************************************************************************************/
71static void ClearBuffer(void *buf, int nBytes)
72{
73 int i;
74 unsigned char *cbuf = (unsigned char *)buf;
75
76 //for (i = 0; i < nBytes; i++)
77 // cbuf[i] = 0;
78 memset(cbuf, 0, nBytes);
79 return;
80}
81
82/**************************************************************************************
83 * Function: AllocateBuffers
84 *
85 * Description: allocate all the memory needed for the RA8 decoder
86 *
87 * Inputs: none
88 *
89 * Outputs: none
90 *
91 * Return: pointer to Gecko2Info structure, set to all 0's
92 **************************************************************************************/
93Gecko2Info *AllocateBuffers(void)
94{
95 Gecko2Info *gi;
96
97 /* create new Gecko2Info structure */
98 gi = (Gecko2Info *)malloc(sizeof(Gecko2Info));
99 if (!gi) {
100 return 0;
101 }
102 ClearBuffer(gi, sizeof(Gecko2Info));
103
104 return gi;
105}
106
107#define SAFE_FREE(x) {if (x) free(x); (x) = 0;} /* helper macro */
108
109/**************************************************************************************
110 * Function: FreeBuffers
111 *
112 * Description: free all the memory used by the RA8 decoder
113 *
114 * Inputs: pointer to initialized Gecko2Info structure
115 *
116 * Outputs: none
117 *
118 * Return: none
119 **************************************************************************************/
120void FreeBuffers(Gecko2Info *gi)
121{
122 if (!gi) {
123 return;
124 }
125
126 SAFE_FREE(gi);
127}
128