diff options
Diffstat (limited to 'gnuradio-core/src/lib/io/gri_wavfile.cc')
-rw-r--r-- | gnuradio-core/src/lib/io/gri_wavfile.cc | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 8f1c6a2bb8..e316a08254 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -142,7 +142,7 @@ gri_wavheader_parse(FILE *fp, { // _o variables take return values char str_buf[8] = {0}; - + uint32_t file_size; uint32_t fmt_hdr_skip; uint16_t compression_type; @@ -152,52 +152,52 @@ gri_wavheader_parse(FILE *fp, uint16_t block_align; uint16_t bits_per_sample; uint32_t chunk_size; - + size_t fresult; fresult = fread(str_buf, 1, 4, fp); if (fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { return false; } - + fresult = fread(&file_size, 1, 4, fp); - + fresult = fread(str_buf, 1, 8, fp); if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { return false; } - + fresult = fread(&fmt_hdr_skip, 1, 4, fp); - + fresult = fread(&compression_type, 1, 2, fp); if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { return false; } - + fresult = fread(&nchans, 1, 2, fp); fresult = fread(&sample_rate, 1, 4, fp); fresult = fread(&avg_bytes_per_sec, 1, 4, fp); fresult = fread(&block_align, 1, 2, fp); fresult = fread(&bits_per_sample, 1, 2, fp); - + if (ferror(fp)) { return false; } - + fmt_hdr_skip = wav_to_host(fmt_hdr_skip); nchans = wav_to_host(nchans); sample_rate = wav_to_host(sample_rate); bits_per_sample = wav_to_host(bits_per_sample); - + if (bits_per_sample != 8 && bits_per_sample != 16) { return false; } - + fmt_hdr_skip -= 16; if (fmt_hdr_skip) { fseek(fp, fmt_hdr_skip, SEEK_CUR); } - + // data chunk fresult = fread(str_buf, 1, 4, fp); if (strncmp(str_buf, "data", 4)) { @@ -208,10 +208,10 @@ gri_wavheader_parse(FILE *fp, if (ferror(fp)) { return false; } - + // More byte swapping chunk_size = wav_to_host(chunk_size); - + // Output values sample_rate_o = (unsigned) sample_rate; nchans_o = (int) nchans; @@ -229,7 +229,7 @@ gri_wav_read_sample(FILE *fp, int bytes_per_sample) size_t fresult; fresult = fread(&buf, bytes_per_sample, 1, fp); - + return (short) wav_to_host(buf); } @@ -247,13 +247,13 @@ gri_wavheader_write(FILE *fp, uint16_t block_align = bytes_per_sample * nchans; uint32_t avg_bytes = sample_rate * block_align; uint16_t bits_per_sample = bytes_per_sample * 8; - + nchans_f = host_to_wav(nchans_f); sample_rate_f = host_to_wav(sample_rate_f); block_align = host_to_wav(block_align); avg_bytes = host_to_wav(avg_bytes); bits_per_sample = host_to_wav(bits_per_sample); - + wav_hdr[16] = 0x10; // no extra bytes wav_hdr[20] = 0x01; // no compression memcpy((void *) (wav_hdr + 22), (void *) &nchans_f, 2); @@ -261,12 +261,12 @@ gri_wavheader_write(FILE *fp, memcpy((void *) (wav_hdr + 28), (void *) &avg_bytes, 4); memcpy((void *) (wav_hdr + 32), (void *) &block_align, 2); memcpy((void *) (wav_hdr + 34), (void *) &bits_per_sample, 2); - + fwrite(&wav_hdr, 1, header_len, fp); if (ferror(fp)) { return false; } - + return true; } @@ -277,7 +277,7 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) void *data_ptr; unsigned char buf_8bit; int16_t buf_16bit; - + if (bytes_per_sample == 1) { buf_8bit = (unsigned char) sample; data_ptr = (void *) &buf_8bit; @@ -285,7 +285,7 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) buf_16bit = host_to_wav((int16_t) sample); data_ptr = (void *) &buf_16bit; } - + fwrite(data_ptr, 1, bytes_per_sample, fp); } @@ -295,19 +295,19 @@ gri_wavheader_complete(FILE *fp, unsigned int byte_count) { uint32_t chunk_size = (uint32_t) byte_count; chunk_size = host_to_wav(chunk_size); - + fseek(fp, 40, SEEK_SET); fwrite(&chunk_size, 1, 4, fp); - + chunk_size = (uint32_t) byte_count + 36; // fmt chunk and data header chunk_size = host_to_wav(chunk_size); fseek(fp, 4, SEEK_SET); - + fwrite(&chunk_size, 1, 4, fp); - + if (ferror(fp)) { return false; } - + return true; } |