2 * Copyright (c) 2018 AlaskanEmily
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 #include "cin_common.h"
9 #include "cin_loader.h"
10 #include "cin_driver.h"
14 #define CIN_COMMON_LOADER_ASSERT_ENUMS_EQUAL(WHAT)\
15 assert((int)Cin_eLoader ## WHAT == (int)Cin_eDriver ## WHAT)
17 CIN_PRIVATE(enum Cin_LoaderError) Cin_FormatCompatible(struct Cin_Driver *drv,
19 unsigned num_channels,
20 enum Cin_Format format){
22 CIN_COMMON_LOADER_ASSERT_ENUMS_EQUAL(UnsupportedFormat);
23 CIN_COMMON_LOADER_ASSERT_ENUMS_EQUAL(InvalidFormat);
24 CIN_COMMON_LOADER_ASSERT_ENUMS_EQUAL(UnsupportedNumChannels);
25 CIN_COMMON_LOADER_ASSERT_ENUMS_EQUAL(UnsupportedSampleRate);
28 const enum Cin_DriverError drv_err =
29 Cin_DriverSupportsFormat(drv, format, num_channels);
30 if(drv_err != Cin_eDriverSuccess){
31 assert(drv_err == Cin_eDriverUnsupportedFormat ||
32 drv_err == Cin_eDriverInvalidFormat ||
33 drv_err == Cin_eDriverUnsupportedNumChannels);
34 return (enum Cin_LoaderError)drv_err;
39 const enum Cin_DriverError drv_err =
40 Cin_DriverSupportsSampleRate(drv, sample_rate);
41 if(drv_err != Cin_eDriverSuccess){
42 assert(drv_err == Cin_eLoaderUnsupportedSampleRate);
43 return (enum Cin_LoaderError)drv_err;
47 return Cin_eLoaderSuccess;
50 CIN_PRIVATE_PURE(unsigned) Cin_BytesPerSample(enum Cin_Format format){
58 case Cin_eFormatFloat32:
60 case Cin_eFormatFloat64:
62 case Cin_eFormatULaw8: