Fix internal bug and change the design of ico-app-samplenavi
[profile/ivi/ico-uxf-homescreen-sample-apps.git] / src / soundsample_yswavfile.h
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   Sound Sample APP
11  *          Test use with which sound is sounded
12  *
13  * @date    Mar-04-2013
14  */
15
16 #ifndef YSWAVFILE_IS_INCLUDED
17 #define YSWAVFILE_IS_INCLUDED
18 /* { */
19
20 #ifndef YSRESULT_IS_DEFINED
21 #define YSRESULT_IS_DEFINED
22 /*! Enum for processing result. */
23 typedef enum
24 {
25     YSERR,                      /*!< There were error(s). */
26     YSOK                        /*!< The process was successful. */
27 } YSRESULT;
28 #endif
29
30 #ifndef YSBOOL_IS_DEFINED
31 #define YSBOOL_IS_DEFINED
32 /*! Enum for boolearn. */
33 typedef enum
34 {
35     YSFALSE,                    /*!< False */
36     YSTRUE,                     /*!< True */
37     YSTFUNKNOWN                 /*!< Unable to tell true or false. */
38 } YSBOOL;
39 #endif
40
41 class YsWavFile
42 {
43   private:
44     YSBOOL stereo;
45     unsigned int bit;
46     unsigned int rate;
47     unsigned int sizeInBytes;
48
49     YSBOOL isSigned;
50     unsigned char *dat;
51
52   public:
53          YsWavFile();
54         ~YsWavFile();
55
56     void Initialize(void);
57
58     unsigned int NTimeStep(void) const;
59
60     YSBOOL Stereo(void) const;
61     unsigned int BytePerTimeStep(void) const;
62     unsigned int BitPerSample(void) const;
63     unsigned int BytePerSample(void) const;
64     unsigned int PlayBackRate(void) const;
65     unsigned int SizeInByte(void) const;
66     YSBOOL IsSigned(void) const;
67     const unsigned char *DataPointer(void) const;
68     const unsigned char *DataPointerAtTimeStep(unsigned int ts) const;
69
70     YSRESULT LoadWav(const char fn[]);
71     YSRESULT ConvertTo16Bit(void);
72     YSRESULT ConvertTo8Bit(void);
73     YSRESULT ConvertToStereo(void);
74     YSRESULT ConvertToMono(void);
75 //  YSRESULT Resample(int newRate);
76     YSRESULT Resample(unsigned int newRate);
77
78     YSRESULT ConvertToSigned(void);
79     YSRESULT ConvertToUnsigned(void);
80
81   private:
82     int GetNumChannel(void) const;
83     int GetNumSample(void) const;
84     int GetNumSamplePerChannel(void) const;
85     size_t GetUnitSize(void) const;
86     size_t GetSamplePosition(int atIndex) const;
87     int GetSignedValue(int atTimeStep, int channel) const;
88     void SetSignedValue(unsigned char *savePtr, int rawSignedValue);
89 };
90
91
92 /* } */
93 #endif