4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 // An object which contains samples
39 // Allocate number of samples
40 Samples::Samples(int samples)
46 Samples::Samples(Samples *src)
49 share(src->get_shmid());
50 set_allocated(src->get_allocated());
51 set_offset(src->get_offset());
68 void Samples::clear_objects()
83 void Samples::share(int shmid)
94 data = (double*)shmat(shmid, NULL, 0);
99 void Samples::allocate(int samples, int use_shm)
102 this->allocated >= samples &&
103 this->use_shm == use_shm) return;
113 this->use_shm = use_shm;
117 shmid = shmget(IPC_PRIVATE,
118 (samples + 1) * sizeof(double),
120 data = (double*)shmat(shmid, NULL, 0);
121 // This causes it to automatically delete when the program exits.
122 shmctl(shmid, IPC_RMID, 0);
127 data = new double[samples];
131 this->allocated = samples;
139 double* Samples::get_data()
141 return data + offset;
144 // Get number of samples allocated
145 int Samples::get_allocated()
150 // Set number of samples allocated
151 void Samples::set_allocated(int allocated)
153 this->allocated = allocated;
156 int Samples::get_shmid()
161 void Samples::set_offset(int offset)
163 this->offset = offset;
166 int Samples::get_offset()