The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.
Dependencies: GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom
Fork of GR-PEACH_Audio_Playback_Sample by
alloc.h
00001 /* alloc - Convenience routines for safely allocating memory 00002 * Copyright (C) 2007-2009 Josh Coalson 00003 * Copyright (C) 2011-2014 Xiph.Org Foundation 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 00012 * - Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 00016 * - Neither the name of the Xiph.org Foundation nor the names of its 00017 * contributors may be used to endorse or promote products derived from 00018 * this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 00024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #ifndef FLAC__SHARE__ALLOC_H 00034 #define FLAC__SHARE__ALLOC_H 00035 00036 #ifdef HAVE_CONFIG_H 00037 # include <config.h> 00038 #endif 00039 00040 /* WATCHOUT: for c++ you may have to #define __STDC_LIMIT_MACROS 1 real early 00041 * before #including this file, otherwise SIZE_MAX might not be defined 00042 */ 00043 00044 #include <limits.h> /* for SIZE_MAX */ 00045 #if HAVE_STDINT_H 00046 #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */ 00047 #endif 00048 #include <stdlib.h> /* for size_t, malloc(), etc */ 00049 #include "share/compat.h" 00050 00051 #ifndef SIZE_MAX 00052 # ifndef SIZE_T_MAX 00053 # ifdef _MSC_VER 00054 # ifdef _WIN64 00055 # define SIZE_T_MAX 0xffffffffffffffffui64 00056 # else 00057 # define SIZE_T_MAX 0xffffffff 00058 # endif 00059 # else 00060 # error 00061 # endif 00062 # endif 00063 # define SIZE_MAX SIZE_T_MAX 00064 #endif 00065 00066 /* avoid malloc()ing 0 bytes, see: 00067 * https://www.securecoding.cert.org/confluence/display/seccode/MEM04-A.+Do+not+make+assumptions+about+the+result+of+allocating+0+bytes?focusedCommentId=5407003 00068 */ 00069 static inline void *safe_malloc_(size_t size) 00070 { 00071 /* malloc(0) is undefined; FLAC src convention is to always allocate */ 00072 if(!size) 00073 size++; 00074 return malloc(size); 00075 } 00076 00077 static inline void *safe_calloc_(size_t nmemb, size_t size) 00078 { 00079 if(!nmemb || !size) 00080 return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ 00081 return calloc(nmemb, size); 00082 } 00083 00084 /*@@@@ there's probably a better way to prevent overflows when allocating untrusted sums but this works for now */ 00085 00086 static inline void *safe_malloc_add_2op_(size_t size1, size_t size2) 00087 { 00088 size2 += size1; 00089 if(size2 < size1) 00090 return 0; 00091 return safe_malloc_(size2); 00092 } 00093 00094 static inline void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3) 00095 { 00096 size2 += size1; 00097 if(size2 < size1) 00098 return 0; 00099 size3 += size2; 00100 if(size3 < size2) 00101 return 0; 00102 return safe_malloc_(size3); 00103 } 00104 00105 static inline void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4) 00106 { 00107 size2 += size1; 00108 if(size2 < size1) 00109 return 0; 00110 size3 += size2; 00111 if(size3 < size2) 00112 return 0; 00113 size4 += size3; 00114 if(size4 < size3) 00115 return 0; 00116 return safe_malloc_(size4); 00117 } 00118 00119 void *safe_malloc_mul_2op_(size_t size1, size_t size2) ; 00120 00121 static inline void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3) 00122 { 00123 if(!size1 || !size2 || !size3) 00124 return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ 00125 if(size1 > SIZE_MAX / size2) 00126 return 0; 00127 size1 *= size2; 00128 if(size1 > SIZE_MAX / size3) 00129 return 0; 00130 return malloc(size1*size3); 00131 } 00132 00133 /* size1*size2 + size3 */ 00134 static inline void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3) 00135 { 00136 if(!size1 || !size2) 00137 return safe_malloc_(size3); 00138 if(size1 > SIZE_MAX / size2) 00139 return 0; 00140 return safe_malloc_add_2op_(size1*size2, size3); 00141 } 00142 00143 /* size1 * (size2 + size3) */ 00144 static inline void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3) 00145 { 00146 if(!size1 || (!size2 && !size3)) 00147 return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ 00148 size2 += size3; 00149 if(size2 < size3) 00150 return 0; 00151 if(size1 > SIZE_MAX / size2) 00152 return 0; 00153 return malloc(size1*size2); 00154 } 00155 00156 static inline void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2) 00157 { 00158 size2 += size1; 00159 if(size2 < size1) 00160 return 0; 00161 return realloc(ptr, size2); 00162 } 00163 00164 static inline void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3) 00165 { 00166 size2 += size1; 00167 if(size2 < size1) 00168 return 0; 00169 size3 += size2; 00170 if(size3 < size2) 00171 return 0; 00172 return realloc(ptr, size3); 00173 } 00174 00175 static inline void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4) 00176 { 00177 size2 += size1; 00178 if(size2 < size1) 00179 return 0; 00180 size3 += size2; 00181 if(size3 < size2) 00182 return 0; 00183 size4 += size3; 00184 if(size4 < size3) 00185 return 0; 00186 return realloc(ptr, size4); 00187 } 00188 00189 static inline void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2) 00190 { 00191 if(!size1 || !size2) 00192 return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ 00193 if(size1 > SIZE_MAX / size2) 00194 return 0; 00195 return realloc(ptr, size1*size2); 00196 } 00197 00198 /* size1 * (size2 + size3) */ 00199 static inline void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3) 00200 { 00201 if(!size1 || (!size2 && !size3)) 00202 return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ 00203 size2 += size3; 00204 if(size2 < size3) 00205 return 0; 00206 return safe_realloc_mul_2op_(ptr, size1, size2); 00207 } 00208 00209 #endif
Generated on Tue Jul 12 2022 19:32:28 by 1.7.2