Use jack_client_open instead of old jack_client_new.
[jack2.git] / common / JackResampler.cpp
blobfb1793d4ed5b645eda41374c111a9016592c3416
1 /*
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"
21 #include <stdio.h>
23 namespace Jack
26 JackResampler::JackResampler()
27 :fRatio(1),fRingBufferSize(DEFAULT_RB_SIZE)
29 fRingBuffer = jack_ringbuffer_create(sizeof(float) * fRingBufferSize);
30 jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize) / 2);
33 JackResampler::~JackResampler()
35 if (fRingBuffer)
36 jack_ringbuffer_free(fRingBuffer);
39 void JackResampler::Reset(unsigned int new_size)
41 fRingBufferSize = new_size;
42 jack_ringbuffer_reset_size(fRingBuffer, sizeof(float) * fRingBufferSize);
43 jack_ringbuffer_read_advance(fRingBuffer, (sizeof(float) * fRingBufferSize / 2));
46 unsigned int JackResampler::ReadSpace()
48 return (jack_ringbuffer_read_space(fRingBuffer) / sizeof(float));
51 unsigned int JackResampler::WriteSpace()
53 return (jack_ringbuffer_write_space(fRingBuffer) / sizeof(float));
56 unsigned int JackResampler::Read(float* buffer, unsigned int frames)
58 size_t len = jack_ringbuffer_read_space(fRingBuffer);
59 jack_log("JackResampler::Read input available = %ld", len / sizeof(float));
61 if (len < frames * sizeof(float)) {
62 jack_error("JackResampler::Read : producer too slow, missing frames = %d", frames);
63 return 0;
64 } else {
65 jack_ringbuffer_read(fRingBuffer, (char*)buffer, frames * sizeof(float));
66 return frames;
70 unsigned int JackResampler::Write(float* buffer, unsigned int frames)
72 size_t len = jack_ringbuffer_write_space(fRingBuffer);
73 jack_log("JackResampler::Write output available = %ld", len / sizeof(float));
75 if (len < frames * sizeof(float)) {
76 jack_error("JackResampler::Write : consumer too slow, skip frames = %d", frames);
77 return 0;
78 } else {
79 jack_ringbuffer_write(fRingBuffer, (char*)buffer, frames * sizeof(float));
80 return frames;
84 unsigned int JackResampler::ReadResample(float* buffer, unsigned int frames)
86 return Read(buffer, frames);
89 unsigned int JackResampler::WriteResample(float* buffer, unsigned int frames)
91 return Write(buffer, frames);