2 Copyright (C) 2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "JackResampler.h"
25 JackResampler::JackResampler():fNum(1),fDenom(1)
27 fRingBuffer
= jack_ringbuffer_create(sizeof(float) * DEFAULT_RB_SIZE
);
28 jack_ringbuffer_read_advance(fRingBuffer
, (sizeof(float) * DEFAULT_RB_SIZE
) / 2);
31 JackResampler::~JackResampler()
34 jack_ringbuffer_free(fRingBuffer
);
37 void JackResampler::Reset()
39 jack_ringbuffer_read_advance(fRingBuffer
, (sizeof(float) * DEFAULT_RB_SIZE
) / 2);
42 unsigned int JackResampler::ReadSpace()
44 return (jack_ringbuffer_read_space(fRingBuffer
) / sizeof(float));
47 unsigned int JackResampler::WriteSpace()
49 return (jack_ringbuffer_write_space(fRingBuffer
) / sizeof(float));
52 unsigned int JackResampler::Read(float* buffer
, unsigned int frames
)
54 size_t len
= jack_ringbuffer_read_space(fRingBuffer
);
55 jack_log("JackResampler::Read input available = %ld", len
/ sizeof(float));
57 if (len
< frames
* sizeof(float)) {
58 jack_error("JackResampler::Read : producer too slow, missing frames = %d", frames
);
61 jack_ringbuffer_read(fRingBuffer
, (char*)buffer
, frames
* sizeof(float));
66 unsigned int JackResampler::Write(float* buffer
, unsigned int frames
)
68 size_t len
= jack_ringbuffer_write_space(fRingBuffer
);
69 jack_log("JackResampler::Write output available = %ld", len
/ sizeof(float));
71 if (len
< frames
* sizeof(float)) {
72 jack_error("JackResampler::Write : consumer too slow, skip frames = %d", frames
);
75 jack_ringbuffer_write(fRingBuffer
, (char*)buffer
, frames
* sizeof(float));
80 unsigned int JackResampler::ReadResample(float* buffer
, unsigned int frames
)
82 return Read(buffer
, frames
);
85 unsigned int JackResampler::WriteResample(float* buffer
, unsigned int frames
)
87 return Write(buffer
, frames
);