Blog Archive

Friday, October 14, 2016

sox cannot play files with a-law encoding

sox cannot play files with a-law encoding - Stack Overflow:



Question:

sox cannot play files with a-law encoding



I am in linux mint 14 and trying to play a .sph file using sox with play foo.sph and got the following error: play FAIL formats: can't open input file 'foo.sph': sph: unsupported coding 'alaw'



Doesn't sox support alaw encoding? What can I do to play this file? Note that it can successfully play ulaw. Thanks!



Solution:

Here is the relevant SoX source code (from sox-14.4.2/src/sphere.c, starting at line 79):
(the source code can be downloaded from: https://sourceforge.net/projects/sox/files/sox/14.4.2/sox-14.4.2.tar.gz/download)
if (!strcasecmp(fldsval, "ulaw") || !strcasecmp(fldsval, "mu-law"))
  encoding = SOX_ENCODING_ULAW;
else if (!strcasecmp(fldsval, "pcm"))
  encoding = SOX_ENCODING_SIGN2;
else {
  lsx_fail_errno(ft, SOX_EFMT, "sph: unsupported coding `%s'", fldsval);
  /* ... */
}
As you can see, the format handler only knows about µ-law and PCM encodings, nothing else. As you say, SoX does have decoding routines for A-law; therefore, it would suffice to add these lines:
else if (!strcasecmp(fldsval, "alaw"))
  encoding = SOX_ENCODING_ALAW;
Obviously, this is only going to help you if you can compile SoX yourself from source with this addition.

A probably simpler way is to use the libsndfile driver, which is supposed to support A-law encoding in Sphere files: play -t sndfile foo.sph


Reference:

http://stackoverflow.com/questions/18169817/sox-cannot-play-files-with-a-law-encoding

'via Blog this'

No comments:

Post a Comment