X-Git-Url: http://git.tdb.fi/?p=libs%2Fal.git;a=blobdiff_plain;f=source%2Fformat.cpp;fp=source%2Fformat.cpp;h=1cb5b23e6ae921807b7c2a6b6c0acb1d4e9b38e1;hp=0000000000000000000000000000000000000000;hb=227da1e7a20432e056e7ab42444cb56f197c53d6;hpb=7961a6bc2a735d08a5d1ffeb6772ec3d545cb98c diff --git a/source/format.cpp b/source/format.cpp new file mode 100644 index 0000000..1cb5b23 --- /dev/null +++ b/source/format.cpp @@ -0,0 +1,59 @@ +#include +#include "format.h" + +using namespace std; + +namespace Msp { +namespace AL { + +Format create_format(unsigned sample_size, unsigned n_channels) +{ + if(n_channels==1) + { + if(sample_size==1) + return MONO8; + else if(sample_size==2) + return MONO16; + } + else if(n_channels==2) + { + if(sample_size==1) + return STEREO8; + else if(sample_size==2) + return STEREO16; + } + + throw invalid_argument("create_format"); +} + +unsigned get_sample_size(Format fmt) +{ + switch(fmt) + { + case MONO8: + case STEREO8: return 1; + case MONO16: + case STEREO16: return 2; + default: throw invalid_argument("get_sample_size"); + } +} + +unsigned get_n_channels(Format fmt) +{ + switch(fmt) + { + case MONO8: + case MONO16: return 1; + case STEREO8: + case STEREO16: return 2; + default: throw invalid_argument("get_n_channels"); + } +} + +unsigned get_unit_size(Format fmt) +{ + return get_sample_size(fmt)*get_n_channels(fmt); +} + +} // namespace AL +} // namespace Msp