Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rf64 audio files
#1
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
Reply
#2
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]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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
Reply
#6
(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()
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Do you think that the sample rate starts at the 13th byte?
Reply
#8
Sorry, I am not familiar with the format
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Other modules for reading audio files? jedzz 0 1,569 Mar-25-2020, 11:07 PM
Last Post: jedzz
  Computing correlation in audio files ryanblumenow 0 2,723 Jan-15-2020, 06:11 PM
Last Post: ryanblumenow
  Analyse audio files, not sure where to start floatingshed 1 2,174 Jun-29-2018, 02:58 PM
Last Post: floatingshed

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020