'Decypher AIFF File Contents with Python, AIFC
I am trying to extract values of an AIFF sound file to do some processing (FFT, frequency content, filter modeling, etc.). I have used AIFC to extract the parameters and read some frames. I have not been able to find enough information to interpret the resulting frame data. Here is some Python code.
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information.
>>> import math as m
>>> import numpy as np
>>> import aifc as a
>>> obj = a.open('E:/Downloads/AudioFile1.aiff','r')
>>> print ( "parameters:",obj.getparams())
parameters: _aifc_params(nchannels=2, sampwidth=3, framerate=96000, nframes=6398031,
comptype=b'NONE', compname=b'not compressed')
>>> x = obj.readframes(1)
>>> x
b"\xff\xe8\xb8\x00'\x14"
>>> len(x)
6
>>> x2 = np.frombuffer(x, np.short).byteswap()
>>> x2
array([ -24, -18432, 10004], dtype=int16)
As can be seen, the audio data is 2 channels of 24 bits/sample, 96000 samples/sec.
It is at this point that I am unable to figure out how to proceed. I'm assuming that the 3 int16 values of x2 represent the 6 bytes I expected from the 3 bytes (24 bits) per sample * 2 channels of the first frame. Is this the case? Are the bits of the data found by concatenating the 3 ints and dividing them into x2[0:24] for channel 0 and x2[24:48] for channel 1? Or, are the channels interleaved bytewise? Also, I have read that AIFF data must be byte swapped to change the endian of the AIFF data. Is that correct? Are the binary representations of the ints in 2's complement form? In short, can somebody provide information on how to process the values I can extract from the file into integer values that can by processed in Python, Numpy?
Thanks,
Doug
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|