Why do I get different values ​​when reading bytes from NSData depending on the order in which I get the bytes?

Well, it's rather "What the hell is going on?" than the real problem. But, given my relative inexperience with C, he could laugh at big problems.

Basically, I parse the header of the wav file and extract the values. In my header file, I defined class variables:

short channels;
int sampleRate;
int bytesPerSecond;
short bytesPerSample;
short bitsPerSample;
unsigned int size;  

And the class function to get these values:

NSData * fileData = [[NSData alloc] initWithContentsOfFile:filePath];
[fileData getBytes:&channels range:CHANNELS_R];
[fileData getBytes:&sampleRate range:SAMPLES_R];
[fileData getBytes:&bytesPerSecond range:BYTES_PER_SEC_R];
[fileData getBytes:&bytesPerSample range:BYTES_PER_SAMPLE_R];
[fileData getBytes:&bitsPerSample range:BITS_PER_SAMPLE_R];
[fileData getBytes:&size range:LENGTH_R];

Ranges defined previously:

const NSRange CHANNELS_R = {22,23};
const NSRange SAMPLES_R = {24,27};
const NSRange BYTES_PER_SEC_R = {28,31};
const NSRange BYTES_PER_SAMPLE_R = {32,33};
const NSRange BITS_PER_SAMPLE_R = {34,35};
const NSRange LENGTH_R = {40,43};

, , , , . wav, , 8000. . , , 524288000. . , , , , , . , , .

- , ?

+3
1
const NSRange CHANNELS_R = {22,23};
const NSRange SAMPLES_R = {24,27};
const NSRange BYTES_PER_SEC_R = {28,31};
const NSRange BYTES_PER_SAMPLE_R = {32,33};
const NSRange BITS_PER_SAMPLE_R = {34,35};
const NSRange LENGTH_R = {40,43};

, NSRange . NSRange

typedef struct _NSRange {
   NSUInteger location;
   NSUInteger length;
} NSRange;

, , . , 23 short ( ).

const NSRange CHANNELS_R = {22,2};
const NSRange SAMPLES_R = {24,4};
const NSRange BYTES_PER_SEC_R = {28,4};
const NSRange BYTES_PER_SAMPLE_R = {32,2};
const NSRange BITS_PER_SAMPLE_R = {34,2};
const NSRange LENGTH_R = {40,4};

.

+6

Source: https://habr.com/ru/post/1733880/


All Articles