1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* PROJECT:         ReactOS sndrec32
 * LICENSE:         GPL - See COPYING in the top level directory
 * FILE:            base/applications/sndrec32/audio_format.hpp
 * PURPOSE:         Audio format abstraction
 * PROGRAMMERS:     Marco Pagliaricci (irc: rendar)
 */

#ifndef _AUDIOFORMAT__H_
#define _AUDIOFORMAT__H_

#include "audio_def.hpp"

_AUDIO_NAMESPACE_START_

class audio_format
{
    protected:
        unsigned int samples_psec;
        unsigned short int bits_psample;
        unsigned short int chan;
    public:
        /* Ctors */
        audio_format(unsigned int samples_per_second,
                     unsigned short int bits_per_sample,
                     unsigned short int channels) : samples_psec(samples_per_second),
                                                    bits_psample(bits_per_sample),
                                                    chan(channels)
        {
        }

        /* Dtor */
        virtual ~audio_format(void)
        {
        }

        /* Operators */
        bool operator==(audio_format & eq) const<--- Parameter 'eq' can be declared with const
        {
            /* The same audio format is when samples per second,
               bit per sample, and channels mono/stereo are equal */
            return ((samples_psec == eq.samples_psec) &&
                    (bits_psample == eq.bits_psample) &&
                    (chan == eq.chan));
        }

        /* Public Functions */

        unsigned int sample_rate(void) const
        {
            return samples_psec;
        }

        unsigned short int bits(void) const
        {
            return bits_psample;
        }

        unsigned short int channels(void) const
        {
            return chan;
        }

        unsigned int byte_rate(void) const
        {
            return (samples_psec * chan * (bits_psample / 8));
        }

        unsigned int block_align(void) const
        {
            return (chan * (bits_psample / 8));
        }

        unsigned int samples_in_seconds(float seconds) const
        {
            return (unsigned int)(((float)samples_psec * (float) chan) * seconds);
        }

        unsigned int samples_in_bytes(unsigned int bytes) const
        {
            return (bytes / ((bits_psample / 8) * chan));
        }

        unsigned int bytes_in_samples(unsigned int samples) const
        {
            return (samples * ((bits_psample / 8) * chan));
        }
};

extern audio_format UNKNOWN_FORMAT;
extern audio_format A44100_16BIT_STEREO;
extern audio_format A44100_16BIT_MONO;

_AUDIO_NAMESPACE_END_

#endif /* _AUDIOFORMAT__H_ */