1b815c7f3Sopenharmony_ci[+ AutoGen5 template c +] 2b815c7f3Sopenharmony_ci/* 3b815c7f3Sopenharmony_ci** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com> 4b815c7f3Sopenharmony_ci** 5b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify 6b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by 7b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2 of the License, or 8b815c7f3Sopenharmony_ci** (at your option) any later version. 9b815c7f3Sopenharmony_ci** 10b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful, 11b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of 12b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13b815c7f3Sopenharmony_ci** GNU General Public License for more details. 14b815c7f3Sopenharmony_ci** 15b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License 16b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software 17b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18b815c7f3Sopenharmony_ci*/ 19b815c7f3Sopenharmony_ci 20b815c7f3Sopenharmony_ci#include "sfconfig.h" 21b815c7f3Sopenharmony_ci 22b815c7f3Sopenharmony_ci#include <stdio.h> 23b815c7f3Sopenharmony_ci#include <stdlib.h> 24b815c7f3Sopenharmony_ci 25b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 26b815c7f3Sopenharmony_ci#include <unistd.h> 27b815c7f3Sopenharmony_ci#endif 28b815c7f3Sopenharmony_ci 29b815c7f3Sopenharmony_ci#if (HAVE_DECL_S_IRGRP == 0) 30b815c7f3Sopenharmony_ci#include <sf_unistd.h> 31b815c7f3Sopenharmony_ci#endif 32b815c7f3Sopenharmony_ci 33b815c7f3Sopenharmony_ci#include <string.h> 34b815c7f3Sopenharmony_ci#include <math.h> 35b815c7f3Sopenharmony_ci#include <time.h> 36b815c7f3Sopenharmony_ci#include <fcntl.h> 37b815c7f3Sopenharmony_ci#include <sys/stat.h> 38b815c7f3Sopenharmony_ci 39b815c7f3Sopenharmony_ci#include <sndfile.h> 40b815c7f3Sopenharmony_ci 41b815c7f3Sopenharmony_ci#ifndef M_PI 42b815c7f3Sopenharmony_ci#define M_PI 3.14159265358979323846264338 43b815c7f3Sopenharmony_ci#endif 44b815c7f3Sopenharmony_ci 45b815c7f3Sopenharmony_ci/* 46b815c7f3Sopenharmony_ci** Neat solution to the Win32/OS2 binary file flage requirement. 47b815c7f3Sopenharmony_ci** If O_BINARY isn't already defined by the inclusion of the system 48b815c7f3Sopenharmony_ci** headers, set it to zero. 49b815c7f3Sopenharmony_ci*/ 50b815c7f3Sopenharmony_ci#ifndef O_BINARY 51b815c7f3Sopenharmony_ci#define O_BINARY 0 52b815c7f3Sopenharmony_ci#endif 53b815c7f3Sopenharmony_ci 54b815c7f3Sopenharmony_ci#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY) 55b815c7f3Sopenharmony_ci#define READ_FLAGS (O_RDONLY | O_BINARY) 56b815c7f3Sopenharmony_ci 57b815c7f3Sopenharmony_ci#if (defined (WIN32) || defined (_WIN32) || defined (__OS2__)) 58b815c7f3Sopenharmony_ci #define WRITE_PERMS 0777 59b815c7f3Sopenharmony_ci#else 60b815c7f3Sopenharmony_ci #define WRITE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP) 61b815c7f3Sopenharmony_ci#endif 62b815c7f3Sopenharmony_ci 63b815c7f3Sopenharmony_ci#define BUFFER_SIZE (1 << 18) 64b815c7f3Sopenharmony_ci#define BLOCK_COUNT (30) 65b815c7f3Sopenharmony_ci#define TEST_DURATION (5) /* 5 Seconds. */ 66b815c7f3Sopenharmony_ci 67b815c7f3Sopenharmony_citypedef struct 68b815c7f3Sopenharmony_ci{ double write_rate ; 69b815c7f3Sopenharmony_ci double read_rate ; 70b815c7f3Sopenharmony_ci} PERF_STATS ; 71b815c7f3Sopenharmony_ci 72b815c7f3Sopenharmony_cistatic void *data = NULL ; 73b815c7f3Sopenharmony_ci 74b815c7f3Sopenharmony_cistatic void calc_raw_performance (PERF_STATS *stats) ; 75b815c7f3Sopenharmony_ci 76b815c7f3Sopenharmony_ci[+ FOR data_type 77b815c7f3Sopenharmony_ci+]static void calc_[+ (get "type_name") +]_performance (int format, double read_rate, double write_rate) ; 78b815c7f3Sopenharmony_ci[+ ENDFOR data_type 79b815c7f3Sopenharmony_ci+] 80b815c7f3Sopenharmony_ci 81b815c7f3Sopenharmony_cistatic int cpu_is_big_endian (void) ; 82b815c7f3Sopenharmony_ci 83b815c7f3Sopenharmony_cistatic const char* get_subtype_str (int subtype) ; 84b815c7f3Sopenharmony_ci 85b815c7f3Sopenharmony_ciint 86b815c7f3Sopenharmony_cimain (int argc, char *argv []) 87b815c7f3Sopenharmony_ci{ PERF_STATS stats ; 88b815c7f3Sopenharmony_ci char buffer [256] = "Benchmarking " ; 89b815c7f3Sopenharmony_ci int format_major ; 90b815c7f3Sopenharmony_ci 91b815c7f3Sopenharmony_ci if (! (data = malloc (BUFFER_SIZE * sizeof (double)))) 92b815c7f3Sopenharmony_ci { perror ("Error : malloc failed") ; 93b815c7f3Sopenharmony_ci exit (1) ; 94b815c7f3Sopenharmony_ci } ; 95b815c7f3Sopenharmony_ci 96b815c7f3Sopenharmony_ci sf_command (NULL, SFC_GET_LIB_VERSION, buffer + strlen (buffer), sizeof (buffer) - strlen (buffer)) ; 97b815c7f3Sopenharmony_ci 98b815c7f3Sopenharmony_ci puts (buffer) ; 99b815c7f3Sopenharmony_ci memset (buffer, '-', strlen (buffer)) ; 100b815c7f3Sopenharmony_ci puts (buffer) ; 101b815c7f3Sopenharmony_ci printf ("Each test takes a little over %d seconds.\n\n", TEST_DURATION) ; 102b815c7f3Sopenharmony_ci 103b815c7f3Sopenharmony_ci calc_raw_performance (&stats) ; 104b815c7f3Sopenharmony_ci 105b815c7f3Sopenharmony_ci if (argc < 2 || strcmp ("--native-only", argv [1]) == 0) 106b815c7f3Sopenharmony_ci { puts ("\nNative endian I/O :") ; 107b815c7f3Sopenharmony_ci format_major = cpu_is_big_endian () ? SF_FORMAT_AIFF : SF_FORMAT_WAV ; 108b815c7f3Sopenharmony_ci 109b815c7f3Sopenharmony_ci calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ; 110b815c7f3Sopenharmony_ci calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ; 111b815c7f3Sopenharmony_ci calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ; 112b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ; 113b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ; 114b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ; 115b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ; 116b815c7f3Sopenharmony_ci } ; 117b815c7f3Sopenharmony_ci 118b815c7f3Sopenharmony_ci if (argc < 2 || strcmp ("--swap-only", argv [1]) == 0) 119b815c7f3Sopenharmony_ci { puts ("\nEndian swapped I/O :") ; 120b815c7f3Sopenharmony_ci format_major = cpu_is_big_endian () ? SF_FORMAT_WAV : SF_FORMAT_AIFF ; 121b815c7f3Sopenharmony_ci 122b815c7f3Sopenharmony_ci calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ; 123b815c7f3Sopenharmony_ci calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ; 124b815c7f3Sopenharmony_ci calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ; 125b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ; 126b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ; 127b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ; 128b815c7f3Sopenharmony_ci calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ; 129b815c7f3Sopenharmony_ci } ; 130b815c7f3Sopenharmony_ci 131b815c7f3Sopenharmony_ci puts ("") ; 132b815c7f3Sopenharmony_ci 133b815c7f3Sopenharmony_ci free (data) ; 134b815c7f3Sopenharmony_ci 135b815c7f3Sopenharmony_ci return 0 ; 136b815c7f3Sopenharmony_ci} /* main */ 137b815c7f3Sopenharmony_ci 138b815c7f3Sopenharmony_ci/*============================================================================== 139b815c7f3Sopenharmony_ci*/ 140b815c7f3Sopenharmony_ci 141b815c7f3Sopenharmony_cistatic void 142b815c7f3Sopenharmony_cicalc_raw_performance (PERF_STATS *stats) 143b815c7f3Sopenharmony_ci{ clock_t start_clock, clock_time ; 144b815c7f3Sopenharmony_ci int fd, k, byte_count, retval, op_count ; 145b815c7f3Sopenharmony_ci const char *filename ; 146b815c7f3Sopenharmony_ci 147b815c7f3Sopenharmony_ci filename = "benchmark.dat" ; 148b815c7f3Sopenharmony_ci 149b815c7f3Sopenharmony_ci byte_count = BUFFER_SIZE * sizeof (short) ; 150b815c7f3Sopenharmony_ci 151b815c7f3Sopenharmony_ci /* Collect write stats */ 152b815c7f3Sopenharmony_ci printf (" Raw write PCM_16 : ") ; 153b815c7f3Sopenharmony_ci fflush (stdout) ; 154b815c7f3Sopenharmony_ci 155b815c7f3Sopenharmony_ci clock_time = 0 ; 156b815c7f3Sopenharmony_ci op_count = 0 ; 157b815c7f3Sopenharmony_ci start_clock = clock () ; 158b815c7f3Sopenharmony_ci 159b815c7f3Sopenharmony_ci while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) 160b815c7f3Sopenharmony_ci { if ((fd = open (filename, WRITE_FLAGS, WRITE_PERMS)) < 0) 161b815c7f3Sopenharmony_ci { printf ("Error : not able to open file : %s\n", filename) ; 162b815c7f3Sopenharmony_ci perror ("") ; 163b815c7f3Sopenharmony_ci exit (1) ; 164b815c7f3Sopenharmony_ci } ; 165b815c7f3Sopenharmony_ci 166b815c7f3Sopenharmony_ci for (k = 0 ; k < BLOCK_COUNT ; k++) 167b815c7f3Sopenharmony_ci { if ((retval = write (fd, data, byte_count)) != byte_count) 168b815c7f3Sopenharmony_ci { printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ; 169b815c7f3Sopenharmony_ci exit (1) ; 170b815c7f3Sopenharmony_ci } ; 171b815c7f3Sopenharmony_ci } ; 172b815c7f3Sopenharmony_ci 173b815c7f3Sopenharmony_ci close (fd) ; 174b815c7f3Sopenharmony_ci 175b815c7f3Sopenharmony_ci clock_time = clock () - start_clock ; 176b815c7f3Sopenharmony_ci op_count ++ ; 177b815c7f3Sopenharmony_ci } ; 178b815c7f3Sopenharmony_ci 179b815c7f3Sopenharmony_ci stats->write_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ; 180b815c7f3Sopenharmony_ci stats->write_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ; 181b815c7f3Sopenharmony_ci printf ("%10.0f samples per sec\n", stats->write_rate) ; 182b815c7f3Sopenharmony_ci 183b815c7f3Sopenharmony_ci /* Collect read stats */ 184b815c7f3Sopenharmony_ci printf (" Raw read PCM_16 : ") ; 185b815c7f3Sopenharmony_ci fflush (stdout) ; 186b815c7f3Sopenharmony_ci 187b815c7f3Sopenharmony_ci clock_time = 0 ; 188b815c7f3Sopenharmony_ci op_count = 0 ; 189b815c7f3Sopenharmony_ci start_clock = clock () ; 190b815c7f3Sopenharmony_ci 191b815c7f3Sopenharmony_ci while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) 192b815c7f3Sopenharmony_ci { if ((fd = open (filename, READ_FLAGS)) < 0) 193b815c7f3Sopenharmony_ci { printf ("Error : not able to open file : %s\n", filename) ; 194b815c7f3Sopenharmony_ci perror ("") ; 195b815c7f3Sopenharmony_ci exit (1) ; 196b815c7f3Sopenharmony_ci } ; 197b815c7f3Sopenharmony_ci 198b815c7f3Sopenharmony_ci for (k = 0 ; k < BLOCK_COUNT ; k++) 199b815c7f3Sopenharmony_ci { if ((retval = read (fd, data, byte_count)) != byte_count) 200b815c7f3Sopenharmony_ci { printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ; 201b815c7f3Sopenharmony_ci exit (1) ; 202b815c7f3Sopenharmony_ci } ; 203b815c7f3Sopenharmony_ci } ; 204b815c7f3Sopenharmony_ci 205b815c7f3Sopenharmony_ci close (fd) ; 206b815c7f3Sopenharmony_ci 207b815c7f3Sopenharmony_ci clock_time = clock () - start_clock ; 208b815c7f3Sopenharmony_ci op_count ++ ; 209b815c7f3Sopenharmony_ci } ; 210b815c7f3Sopenharmony_ci 211b815c7f3Sopenharmony_ci stats->read_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ; 212b815c7f3Sopenharmony_ci stats->read_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ; 213b815c7f3Sopenharmony_ci printf ("%10.0f samples per sec\n", stats->read_rate) ; 214b815c7f3Sopenharmony_ci 215b815c7f3Sopenharmony_ci unlink (filename) ; 216b815c7f3Sopenharmony_ci} /* calc_raw_performance */ 217b815c7f3Sopenharmony_ci 218b815c7f3Sopenharmony_ci/*------------------------------------------------------------------------------ 219b815c7f3Sopenharmony_ci*/ 220b815c7f3Sopenharmony_ci 221b815c7f3Sopenharmony_ci[+ FOR data_type 222b815c7f3Sopenharmony_ci+]static void 223b815c7f3Sopenharmony_cicalc_[+ (get "type_name") +]_performance (int format, double read_rate, double write_rate) 224b815c7f3Sopenharmony_ci{ SNDFILE *file ; 225b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 226b815c7f3Sopenharmony_ci clock_t start_clock, clock_time ; 227b815c7f3Sopenharmony_ci double performance ; 228b815c7f3Sopenharmony_ci int k, item_count, retval, op_count ; 229b815c7f3Sopenharmony_ci const char* subtype ; 230b815c7f3Sopenharmony_ci [+ (get "type_name") +] *[+ (get "type_name") +]_data ; 231b815c7f3Sopenharmony_ci const char *filename ; 232b815c7f3Sopenharmony_ci 233b815c7f3Sopenharmony_ci filename = "benchmark.dat" ; 234b815c7f3Sopenharmony_ci subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ; 235b815c7f3Sopenharmony_ci 236b815c7f3Sopenharmony_ci [+ (get "type_name") +]_data = data ; 237b815c7f3Sopenharmony_ci item_count = BUFFER_SIZE ; 238b815c7f3Sopenharmony_ci for (k = 0 ; k < item_count ; k++) 239b815c7f3Sopenharmony_ci [+ (get "type_name") +]_data [k] = [+ (get "multiplier") +] * sin (2 * M_PI * k / 32000.0) ; 240b815c7f3Sopenharmony_ci 241b815c7f3Sopenharmony_ci /* Collect write stats */ 242b815c7f3Sopenharmony_ci printf (" Write %-5s to %s : ", "[+ (get "type_name") +]", subtype) ; 243b815c7f3Sopenharmony_ci fflush (stdout) ; 244b815c7f3Sopenharmony_ci 245b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 246b815c7f3Sopenharmony_ci sfinfo.format = format ; 247b815c7f3Sopenharmony_ci sfinfo.frames = 1 ; 248b815c7f3Sopenharmony_ci sfinfo.samplerate = 32000 ; 249b815c7f3Sopenharmony_ci 250b815c7f3Sopenharmony_ci clock_time = 0 ; 251b815c7f3Sopenharmony_ci op_count = 0 ; 252b815c7f3Sopenharmony_ci start_clock = clock () ; 253b815c7f3Sopenharmony_ci 254b815c7f3Sopenharmony_ci while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) 255b815c7f3Sopenharmony_ci { if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) 256b815c7f3Sopenharmony_ci { printf ("Error : not able to open file : %s\n", filename) ; 257b815c7f3Sopenharmony_ci perror ("") ; 258b815c7f3Sopenharmony_ci exit (1) ; 259b815c7f3Sopenharmony_ci } ; 260b815c7f3Sopenharmony_ci 261b815c7f3Sopenharmony_ci /* Turn off the addition of a PEAK chunk. */ 262b815c7f3Sopenharmony_ci sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; 263b815c7f3Sopenharmony_ci 264b815c7f3Sopenharmony_ci for (k = 0 ; k < BLOCK_COUNT ; k++) 265b815c7f3Sopenharmony_ci { if ((retval = sf_write_[+ (get "type_name") +] (file, [+ (get "type_name") +]_data, item_count)) != item_count) 266b815c7f3Sopenharmony_ci { printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ; 267b815c7f3Sopenharmony_ci exit (1) ; 268b815c7f3Sopenharmony_ci } ; 269b815c7f3Sopenharmony_ci } ; 270b815c7f3Sopenharmony_ci 271b815c7f3Sopenharmony_ci sf_close (file) ; 272b815c7f3Sopenharmony_ci 273b815c7f3Sopenharmony_ci clock_time = clock () - start_clock ; 274b815c7f3Sopenharmony_ci op_count ++ ; 275b815c7f3Sopenharmony_ci } ; 276b815c7f3Sopenharmony_ci 277b815c7f3Sopenharmony_ci performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ; 278b815c7f3Sopenharmony_ci performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ; 279b815c7f3Sopenharmony_ci printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ; 280b815c7f3Sopenharmony_ci 281b815c7f3Sopenharmony_ci /* Collect read stats */ 282b815c7f3Sopenharmony_ci printf (" Read %-5s from %s : ", "[+ (get "type_name") +]", subtype) ; 283b815c7f3Sopenharmony_ci fflush (stdout) ; 284b815c7f3Sopenharmony_ci 285b815c7f3Sopenharmony_ci clock_time = 0 ; 286b815c7f3Sopenharmony_ci op_count = 0 ; 287b815c7f3Sopenharmony_ci start_clock = clock () ; 288b815c7f3Sopenharmony_ci 289b815c7f3Sopenharmony_ci while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) 290b815c7f3Sopenharmony_ci { if (! (file = sf_open (filename, SFM_READ, &sfinfo))) 291b815c7f3Sopenharmony_ci { printf ("Error : not able to open file : %s\n", filename) ; 292b815c7f3Sopenharmony_ci perror ("") ; 293b815c7f3Sopenharmony_ci exit (1) ; 294b815c7f3Sopenharmony_ci } ; 295b815c7f3Sopenharmony_ci 296b815c7f3Sopenharmony_ci for (k = 0 ; k < BLOCK_COUNT ; k++) 297b815c7f3Sopenharmony_ci { if ((retval = sf_read_[+ (get "type_name") +] (file, [+ (get "type_name") +]_data, item_count)) != item_count) 298b815c7f3Sopenharmony_ci { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ; 299b815c7f3Sopenharmony_ci exit (1) ; 300b815c7f3Sopenharmony_ci } ; 301b815c7f3Sopenharmony_ci } ; 302b815c7f3Sopenharmony_ci 303b815c7f3Sopenharmony_ci sf_close (file) ; 304b815c7f3Sopenharmony_ci 305b815c7f3Sopenharmony_ci clock_time = clock () - start_clock ; 306b815c7f3Sopenharmony_ci op_count ++ ; 307b815c7f3Sopenharmony_ci } ; 308b815c7f3Sopenharmony_ci 309b815c7f3Sopenharmony_ci performance = (1.0 * item_count) * BLOCK_COUNT * op_count ; 310b815c7f3Sopenharmony_ci performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ; 311b815c7f3Sopenharmony_ci printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ; 312b815c7f3Sopenharmony_ci 313b815c7f3Sopenharmony_ci unlink (filename) ; 314b815c7f3Sopenharmony_ci 315b815c7f3Sopenharmony_ci} /* calc_[+ (get "type_name") +]_performance */ 316b815c7f3Sopenharmony_ci[+ ENDFOR data_type 317b815c7f3Sopenharmony_ci+] 318b815c7f3Sopenharmony_ci 319b815c7f3Sopenharmony_ci/*============================================================================== 320b815c7f3Sopenharmony_ci*/ 321b815c7f3Sopenharmony_ci 322b815c7f3Sopenharmony_cistatic int 323b815c7f3Sopenharmony_cicpu_is_big_endian (void) 324b815c7f3Sopenharmony_ci{ unsigned char *cptr ; 325b815c7f3Sopenharmony_ci int endtest ; 326b815c7f3Sopenharmony_ci 327b815c7f3Sopenharmony_ci endtest = 0x12345678 ; 328b815c7f3Sopenharmony_ci 329b815c7f3Sopenharmony_ci cptr = (unsigned char*) (&endtest) ; 330b815c7f3Sopenharmony_ci 331b815c7f3Sopenharmony_ci if (cptr [0] == 0x12 && cptr [1] == 0x34 && cptr [3] == 0x78) 332b815c7f3Sopenharmony_ci return SF_TRUE ; 333b815c7f3Sopenharmony_ci 334b815c7f3Sopenharmony_ci return SF_FALSE ; 335b815c7f3Sopenharmony_ci} /* cpu_is_big_endian */ 336b815c7f3Sopenharmony_ci 337b815c7f3Sopenharmony_cistatic const char* 338b815c7f3Sopenharmony_ciget_subtype_str (int subtype) 339b815c7f3Sopenharmony_ci{ switch (subtype) 340b815c7f3Sopenharmony_ci { case SF_FORMAT_PCM_16 : 341b815c7f3Sopenharmony_ci return "PCM_16" ; 342b815c7f3Sopenharmony_ci 343b815c7f3Sopenharmony_ci case SF_FORMAT_PCM_24 : 344b815c7f3Sopenharmony_ci return "PCM_24" ; 345b815c7f3Sopenharmony_ci 346b815c7f3Sopenharmony_ci case SF_FORMAT_PCM_32 : 347b815c7f3Sopenharmony_ci return "PCM_32" ; 348b815c7f3Sopenharmony_ci 349b815c7f3Sopenharmony_ci case SF_FORMAT_FLOAT : 350b815c7f3Sopenharmony_ci return "FLOAT " ; 351b815c7f3Sopenharmony_ci 352b815c7f3Sopenharmony_ci case SF_FORMAT_DOUBLE : 353b815c7f3Sopenharmony_ci return "DOUBLE" ; 354b815c7f3Sopenharmony_ci 355b815c7f3Sopenharmony_ci default : break ; 356b815c7f3Sopenharmony_ci } ; 357b815c7f3Sopenharmony_ci 358b815c7f3Sopenharmony_ci return "UNKNOWN" ; 359b815c7f3Sopenharmony_ci} /* get_subtype_str */ 360b815c7f3Sopenharmony_ci 361