1 // -----------------------------------------------------------------------------
2 //
3 //  Copyright (C) 2006-2018 Fons Adriaensen <fons@linuxaudio.org>
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 //
18 // -----------------------------------------------------------------------------
19 
20 
21 #ifndef __IMPDATA_H
22 #define __IMPDATA_H
23 
24 
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <sndfile.h>
28 
29 
30 class Impdata
31 {
32 public:
33 
34     enum
35     {
36         TYPE_RAW     = 0x00010000,
37 	TYPE_SWEEP   = 0x00020002,
38 	TYPE_LR      = 0x00030002,
39 	TYPE_MS      = 0x00040002,
40         TYPE_AMB_A   = 0x00050004,
41         TYPE_AMB_B3  = 0x00060003,
42         TYPE_AMB_B4  = 0x00070004,
43 	TYPE_LA_OCT  = 0x0008000C,
44 	TYPE__CHAN   = 0x0000ffff,
45 	TYPE__TYPE   = 0xffff0000
46     };
47 
48     enum
49     {
50         ERR_NONE    = 0,
51 	ERR_MODE    = -1,
52 	ERR_DATA    = -2,
53 	ERR_OPEN    = -3,
54 	ERR_FORM    = -4,
55 	ERR_SEEK    = -5,
56 	ERR_READ    = -6,
57 	ERR_WRITE   = -7
58     };
59 
60     enum
61     {
62         MODE_NONE   = 0,
63 	MODE_READ   = 1,
64 	MODE_WRITE  = 2
65     };
66 
67     Impdata (void);
68     ~Impdata (void);
69 
mode(void)70     uint32_t mode (void) const { return _mode; }
vers(void)71     uint32_t vers (void) const { return _vers; }
type(void)72     uint32_t type (void) const { return _type; }
rate_n(void)73     uint32_t rate_n (void) const { return _rate_n; }
rate_d(void)74     uint32_t rate_d (void) const { return _rate_d; }
n_chan(void)75     uint32_t n_chan (void) const { return _type & TYPE__CHAN; }
n_fram(void)76     uint32_t n_fram (void) const { return _n_fram; }
n_sect(void)77     uint32_t n_sect (void) const { return _n_sect; }
i_fram(void)78     uint32_t i_fram (void) const { return _i_fram; }
i_sect(void)79     uint32_t i_sect (void) const { return _i_sect; }
tref_i(void)80     int32_t  tref_i (void) const { return _tref_i; }
tref_n(void)81     uint32_t tref_n (void) const { return _tref_n; }
tref_d(void)82     uint32_t tref_d (void) const { return _tref_d; }
83 
84     int  set_type (uint32_t type);
85     int  set_n_fram (uint32_t n_fram);
86     int  set_n_sect (uint32_t n_sect);
87     void set_rate (uint32_t rate_n, uint32_t rate_d = 1) { _rate_n = rate_n; _rate_d = rate_d; }
88     void set_tref (int32_t i, uint32_t n = 0, uint32_t d = 1) { _tref_i = i; _tref_n = n; _tref_d = d; }
set_bits(uint32_t bits)89     void set_bits (uint32_t bits) { _bits = bits; }
90 
drate(void)91     double drate (void) const { return (double) _rate_n / (double) _rate_d; }
dtref(void)92     double dtref (void) const { return (double) _tref_n / (double) _tref_d + _tref_i; }
93 
data(int c)94     float *data (int c) const { return _data  ? (_data + c) : 0; }
95 
96     int alloc (void);
97     int deall (void);
98     int clear (void);
99 
100     int open_read (const char *name);
101     int open_write (const char *name);
102     int sf_open_read (const char *name);
103     int sf_open_write (const char *name);
104     int close (void);
105 
106     int read_sect  (uint32_t i_sect);
107     int write_sect (uint32_t i_sect);
108     int seek_sect (uint32_t i_sect);
109 
110     int read_ext  (uint32_t k, float *p);
111     int write_ext (uint32_t k, float *p);
112     int seek_ext (uint32_t k);
113 
locate(uint32_t i_sect)114     int locate (uint32_t i_sect) { return seek_sect (i_sect); }
115 
116     static void checkext (char *name);
117     static const char *channame (uint32_t type, uint32_t chan);
118 
119 private:
120 
121     uint32_t       _vers;
122     uint32_t       _type;
123     uint32_t       _rate_n;
124     uint32_t       _rate_d;
125     uint32_t       _n_fram;
126     uint32_t       _n_sect;
127     int32_t        _tref_i;
128     uint32_t       _tref_n;
129     uint32_t       _tref_d;
130     uint32_t       _bits;
131 
132     uint32_t       _i_fram;
133     uint32_t       _i_sect;
134     uint32_t       _mode;
135     uint32_t       _size;
136     float         *_data;
137     FILE          *_aldfile;
138     SNDFILE       *_sndfile;
139 
140     static uint32_t mapvers1 (uint32_t type);
141 
142     static char _suffix [12];
143     static const char *_suffix2 [2];
144     static const char *_suffix3 [2];
145     static const char *_suffix4 [2];
146     static const char *_suffix5 [4];
147     static const char *_suffix7 [4];
148     static const char *_suffix8 [12];
149 };
150 
151 
152 #endif
153 
154