/* * Read up to len samples of type sox_sample_t from file into buf[]. * Return number of samples read. */ static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len) { priv_t * sf = (priv_t *)ft->priv; /* FIXME: We assume int == sox_sample_t here */ return (size_t)sf_read_int(sf->sf_file, (int *)buf, (sf_count_t)len); }
void WaveFile::read(ALuint bufferID) { int bytesRead = static_cast<int>(sf_read_int(mSoundFile, mBuffer.get(), mBUFFER_SIZE)); alBufferData(bufferID, mFormat, mBuffer.get(), bytesRead, mBUFFER_SIZE); }
/* Collect read stats */ printf (" Read %-5s from %s : ", "short", subtype) ; fflush (stdout) ; clock_time = 0 ; op_count = 0 ; start_clock = clock () ; while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) { if (! (file = sf_open (filename, SFM_READ, &sfinfo))) { printf ("Error : not able to open file : %s\n", filename) ; perror ("") ; exit (1) ; } ; for (k = 0 ; k < BLOCK_COUNT ; k++) { if ((retval = sf_read_short (file, short_data, item_count)) != item_count) { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ; exit (1) ; } ; } ; sf_close (file) ; clock_time = clock () - start_clock ; op_count ++ ; } ; performance = (1.0 * item_count) * BLOCK_COUNT * op_count ; performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ; printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ; unlink (filename) ; } /* calc_short_performance */ static void calc_int_performance (int format, double read_rate, double write_rate) { SNDFILE *file ; SF_INFO sfinfo ; clock_t start_clock, clock_time ; double performance ; int k, item_count, retval, op_count ; const char* subtype ; int *int_data ; char *filename ; filename = "benchmark.dat" ; subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ; int_data = data ; item_count = BUFFER_SIZE ; for (k = 0 ; k < item_count ; k++) int_data [k] = 32700.0 * (1<<16) * sin (2 * M_PI * k / 32000.0) ; /* Collect write stats */ printf (" Write %-5s to %s : ", "int", subtype) ; fflush (stdout) ; sfinfo.channels = 1 ; sfinfo.format = format ; sfinfo.frames = 1 ; sfinfo.samplerate = 32000 ; clock_time = 0 ; op_count = 0 ; start_clock = clock () ; while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) { if (! (file = sf_open (filename, SFM_WRITE, &sfinfo))) { printf ("Error : not able to open file : %s\n", filename) ; perror ("") ; exit (1) ; } ; /* Turn off the addition of a PEAK chunk. */ sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; for (k = 0 ; k < BLOCK_COUNT ; k++) { if ((retval = sf_write_int (file, int_data, item_count)) != item_count) { printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ; exit (1) ; } ; } ; sf_close (file) ; clock_time = clock () - start_clock ; op_count ++ ; } ; performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ; performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ; printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ; /* Collect read stats */ printf (" Read %-5s from %s : ", "int", subtype) ; fflush (stdout) ; clock_time = 0 ; op_count = 0 ; start_clock = clock () ; while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION)) { if (! (file = sf_open (filename, SFM_READ, &sfinfo))) { printf ("Error : not able to open file : %s\n", filename) ; perror ("") ; exit (1) ; } ; for (k = 0 ; k < BLOCK_COUNT ; k++) { if ((retval = sf_read_int (file, int_data, item_count)) != item_count) { printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ; exit (1) ; } ; } ; sf_close (file) ; clock_time = clock () - start_clock ; op_count ++ ; } ; performance = (1.0 * item_count) * BLOCK_COUNT * op_count ; performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ; printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ; unlink (filename) ; } /* calc_int_performance */