LMMS
Loading...
Searching...
No Matches
wave.h
Go to the documentation of this file.
1/* Calf DSP Library
2 * Primitive interface to NAS WAV file operations.
3 * Not really useful for now, I've used it for testing previously.
4 *
5 * Copyright (C) 2007 Krzysztof Foltman
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <audio/wave.h>
24
25namespace dsp {
26
27template<class T>
28bool load_wave(dsp::dynamic_buffer<T> &dest, const char *file_name) {
29 WaveInfo *file = WaveOpenFileForReading(file_name);
30 typedef dsp::sample_traits<T> st;
31 if (file->channels == st::channels && file->bitsPerSample == st::bps) {
32 dest.resize(file->numSamples);
33 WaveReadFile((char *)dest.data(), dest.size()*sizeof(T), file);
34 WaveCloseFile(file);
35 return true;
36 }
37 WaveCloseFile(file);
38 fprintf(stderr, "Sorry, need a %d channels and %d bps, got %d channels and %d bps\n", st::channels, st::bps, file->channels, file->bitsPerSample);
39 return false;
40}
41
42template<class T>
44 T *data;
46 unsigned int size;
48public:
49 void set_wave(T *_data, int _size) {
50 data = _data;
51 size = _size;
52 is_active = false;
53 }
54 void get_wave(T *&_data, int &_size) {
55 _data = data;
56 _size = size;
57 }
58 void set_pos(wpos _pos) {
59 pos = _pos;
60 is_active = true;
61 }
63 return pos;
64 }
65 void set_rate(wpos _rate) {
66 rate = _rate;
67 }
68 template<class U>U get() {
69 U result;
70 if (!is_active) {
72 return result;
73 }
74 unsigned int ipos = pos.ipart();
75 if (ipos>=size) {
77 is_active = false;
78 return result;
79 }
80 result = pos.lerp_ptr_lookup_int<T, 12, int >(data);
81 pos += rate;
82 return result;
83 }
84 bool get_active() {
85 return is_active;
86 }
87};
88
89}
Definition buffer.h:115
void resize(int new_size, bool fill_with_zeros=false)
Definition buffer.h:132
T * data()
Definition buffer.h:129
int size()
Definition buffer.h:131
Definition wave.h:43
void set_pos(wpos _pos)
Definition wave.h:58
void set_wave(T *_data, int _size)
Definition wave.h:49
wpos get_pos()
Definition wave.h:62
T * data
Definition wave.h:44
U get()
Definition wave.h:68
wpos rate
Definition wave.h:47
bool is_active
Definition wave.h:45
void set_rate(wpos _rate)
Definition wave.h:65
wpos pos
Definition wave.h:47
bool get_active()
Definition wave.h:84
unsigned int size
Definition wave.h:46
void get_wave(T *&_data, int &_size)
Definition wave.h:54
#define U(x)
Definition fmopl.c:132
Definition audio_fx.h:36
void zero(float &v)
Set a float to zero.
Definition primitives.h:41
bool load_wave(dsp::dynamic_buffer< T > &dest, const char *file_name)
Definition wave.h:28
fixed_point< unsigned long long int, 24 > wpos
wave position (unsigned 64-bit int including 24-bit fractional part)
Definition fixed_point.h:264
Definition buffer.h:70
int result
Definition process.c:1455
struct zdirent * file
Definition win32.c:1500