Skip to content

Commit 756e321

Browse files
committed
audio/utils: Add endianity swap
1 parent 52da6b5 commit 756e321

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/audio/utils.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,18 @@ const char *audio_desc_to_cstring(struct audio_desc desc) {
655655
return str.c_str();
656656
}
657657

658+
void swap_endianity(char *buf, int bps, unsigned sample_count) {
659+
const int swap_count = bps / 2;
660+
for(unsigned i = 0; i < sample_count; i++){
661+
for(int j = 0; j < swap_count; j++){
662+
unsigned char tmp = buf[j];
663+
buf[j] = buf[bps - j - 1];
664+
buf[bps - j - 1] = tmp;;
665+
}
666+
buf += bps;
667+
}
668+
}
669+
658670
/**
659671
* Parses configuration string for audio format.
660672
*

src/audio/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ const char *audio_desc_to_cstring(struct audio_desc desc);
146146
#define STORE_I32_SAMPLE(ptr, val, out_bps) memcpy((ptr), &(val), (out_bps))
147147
#endif
148148

149+
void swap_endianity(char *buf, int bps, unsigned sample_count);
150+
149151
/**
150152
* Appends data to audio frame
151153
*

0 commit comments

Comments
 (0)