Python Forum

Full Version: rf64 audio files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I got tons of rf64 audio files.
I try to parse the meaning of each field from the header with not much success.

here is the header of such file:
Quote: struct FormatChunk5 // declare FormatChunk structure
{
char chunkId[4]; // 'fmt '
unsigned int32 chunkSize; // 4 byte size of the 'fmt ' chunk
unsigned int16 formatType; // WAVE_FORMAT_PCM = 0x0001, etc.
unsigned int16 channelCount; // 1 = mono, 2 = stereo, etc.
unsigned int32 sampleRate; // 32000, 44100, 48000, etc.
unsigned int32 bytesPerSecond; // only important for compressed formats
unsigned int16 blockAlignment; // container size (in bytes) of one set of samples
unsigned int16 bitsPerSample; // valid bits per sample 16, 20 or 24
unsigned int16 cbSize; // extra information (after cbSize) to store
char extraData[22]; // extra data of WAVE_FORMAT_EXTENSIBLE when necessary
};

and a comparison to a regular wav:

[Image: rf64-vs-wav.png]

And this is how I tried to extract for instance the sample rate:

import struct

audio_file = open("audio.aac", 'rb')
wavHeader = audio_file.read(38)

HeaderFields = {
                'chunkId': 0,
                'sampleRate': 0
                }

HeaderFields['sampleRate'] = struct.unpack('<i', wavHeader[13:17])

print(wavHeader)
print(HeaderFields)

audio_file.close()
My output is on a sample wav:
Quote:b'\xff\xf9`@\x1f\x7f\xfc\x01.5\xa0\xd6Dq5\n\x01oQ?\x7f\xe2\x7f\xb7\xf5\xdc\xa4\x08\x10A\x02\x008\xbb\xc3\x8a/J'
{'chunkId': 0, 'sampleRate': (17446257,)}

The documentation says that the sampleRate is an integer, which is 4 bytes, that's why I count from 13-17.
I tried mapping different fields, but it never gives me back a normal sample rate.

DO you guys have any working solution to parse these new type of wav's header?

Thanks
could it be possible due to using struct.unpack()?

from the docs:
Quote:struct.unpack(format, buffer)

Unpack from the buffer buffer (presumably packed by pack(format, ...)) according to the format string format. The result is a tuple even if it contains exactly one item. The buffer’s size in bytes must match the size required by the format, as reflected by calcsize().

That's exactly what you get - single element tuple, so this should return just the first element
struct.unpack('<i', wavHeader[13:17])[0]
ok, but it's not what I expect when I return the first element:
IN: struct.unpack('<i', wavHeader[13:17])[0]
OUT: 'sampleRate': 17446257}

It is supposed to be 44100, 32000, 22100 etc
the output from struct.unpack() is tuple. If you don't get the correct/expected value I would guess you don't parse the correct chunk of data
Yes, But I scanned through segment of the 38 byte chunk, and never came out a human readable data...

I guess there is a problem with endiannes and the integer sizes
(May-14-2019, 11:50 AM)kerzol81 Wrote: [ -> ]I guess there is a problem with endiannes and the integer sizes
yes, maybe that's another possibility - wrong format string in the unpack()
Do you think that the sample rate starts at the 13th byte?
Sorry, I am not familiar with the format