Fix new assertions

pull/2/head
Stelios Bounanos 2007-12-09 18:27:33 +00:00
rodzic 80f6f30cc9
commit 38a677e798
5 zmienionych plików z 76 dodań i 62 usunięć

Wyświetl plik

@ -19,6 +19,7 @@
#include <config.h>
#include <cassert>
#include <new>
#include "fft.h"
@ -30,9 +31,9 @@ Cfft::Cfft(int n)
int tablesize = (int)(sqrt(n*1.0)+0.5) + 2;
fftlen = n;
fftsiz = 2 * n;
assert (ip = new int[tablesize]);
assert (w = new double[fftlen]);
assert (fftwin = new double[fftlen*2]);
assert (ip = new(std::nothrow) int[tablesize]);
assert (w = new(std::nothrow) double[fftlen]);
assert (fftwin = new(std::nothrow) double[fftlen*2]);
makewt();
makect();
wintype = FFT_NONE;
@ -52,11 +53,11 @@ void Cfft::resize(int n)
fftlen = n;
fftsiz = 2 * n;
if (ip) delete [] ip;
assert (ip = new int[tablesize]);
assert (ip = new(std::nothrow) int[tablesize]);
if (w) delete [] w;
assert (w = new double[fftlen]);
assert (w = new(std::nothrow) double[fftlen]);
if (fftwin) delete [] fftwin;
assert (fftwin = new double[fftlen*2]);
assert (fftwin = new(std::nothrow) double[fftlen*2]);
makewt();
makect();
wintype = FFT_NONE;

Wyświetl plik

@ -15,6 +15,7 @@
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <new>
#include "fftfilt.h"
@ -22,12 +23,12 @@
fftfilt::fftfilt(double f1, double f2, int len)
{
filterlen = len;
assert (fft = new Cfft(filterlen));
assert (ift = new Cfft(filterlen));
assert (fft = new(std::nothrow) Cfft(filterlen));
assert (ift = new(std::nothrow) Cfft(filterlen));
assert (ovlbuf = new complex[filterlen/2]);
assert (filter = new complex[filterlen]);
assert (filtdata = new complex[filterlen]);
assert (ovlbuf = new(std::nothrow) complex[filterlen/2]);
assert (filter = new(std::nothrow) complex[filterlen]);
assert (filtdata = new(std::nothrow) complex[filterlen]);
for (int i = 0; i < filterlen; i++)
filter[i].re = filter[i].im =
@ -55,7 +56,7 @@ void fftfilt::create_filter(double f1, double f2)
int len = filterlen / 2 + 1;
double t, h, x, it;
Cfft *tmpfft;
assert (tmpfft = new Cfft(filterlen));
assert (tmpfft = new(std::nothrow) Cfft(filterlen));
// initialize the filter to zero
for (int i = 0; i < filterlen; i++)

Wyświetl plik

@ -75,11 +75,11 @@ void C_FIR_filter::init(int len, int dec, double *itaps, double *qtaps) {
ibuffer[i] = qbuffer[i] = 0.0;
if (itaps) {
assert (ifilter = new double[len]);
assert (ifilter = new(std::nothrow) double[len]);
for (int i = 0; i < len; i++) ifilter[i] = itaps[i];
}
if (qtaps) {
assert (qfilter = new double[len]);
assert (qfilter = new(std::nothrow) double[len]);
for (int i = 0; i < len; i++) qfilter[i] = qtaps[i];
}
@ -98,7 +98,7 @@ double * C_FIR_filter::bp_FIR(int len, int hilbert, double f1, double f2)
double *fir;
double t, h, x;
assert (fir = new double[len]);
assert (fir = new(std::nothrow) double[len]);
for (int i = 0; i < len; i++) {
t = i - (len - 1.0) / 2.0;
@ -264,7 +264,7 @@ int C_FIR_filter::Qrun (double &in, double &out) {
Cmovavg::Cmovavg (int filtlen)
{
len = filtlen;
assert (in = new double[len]);
assert (in = new(std::nothrow) double[len]);
empty = true;
}
@ -297,7 +297,7 @@ void Cmovavg::setLength(int filtlen)
{
if (filtlen > len) {
if (in) delete [] in;
assert (in = new double[filtlen]);
assert (in = new(std::nothrow) double[filtlen]);
}
len = filtlen;
empty = true;
@ -405,9 +405,9 @@ void Cmovavg::reset()
sfft::sfft(int len, int _first, int _last)
{
assert (vrot = new complex[len]);
assert (delay = new complex[len]);
assert (bins = new complex[len]);
assert (vrot = new(std::nothrow) complex[len]);
assert (delay = new(std::nothrow) complex[len]);
assert (bins = new(std::nothrow) complex[len]);
fftlen = len;
first = _first;
last = _last;

Wyświetl plik

@ -29,6 +29,7 @@
#include <string.h>
#include <limits.h>
#include <cassert>
#include <new>
#include "viterbi.h"
#include "misc.h"
@ -41,7 +42,7 @@ viterbi::viterbi(int k, int poly1, int poly2)
_chunksize = 8;
nstates = 1 << (k - 1);
assert (output = new int[outsize]);
assert (output = new(std::nothrow) int[outsize]);
for (int i = 0; i < outsize; i++) {
output[i] = parity(poly1 & i) | (parity(poly2 & i) << 1);
@ -50,8 +51,8 @@ viterbi::viterbi(int k, int poly1, int poly2)
// printf("\n");
for (int i = 0; i < PATHMEM; i++) {
assert (metrics[i] = new int[nstates]);
assert (history[i] = new int[nstates]);
assert (metrics[i] = new(std::nothrow) int[nstates]);
assert (history[i] = new(std::nothrow) int[nstates]);
sequence[i] = 0;
for (int j = 0; j < nstates; j++)
metrics[i][j] = history[i][j] = 0;
@ -206,7 +207,7 @@ encoder::encoder(int k, int poly1, int poly2)
{
int size = 1 << k; /* size of the output table */
assert (output = new int[size]);
assert (output = new(std::nothrow) int[size]);
// output contains 2 bits in positions 0 and 1 describing the state machine
// for each bit delay, ie: for k = 7 there are 128 possible state pairs.
// the modulo-2 addition for polynomial 1 is in bit 0

Wyświetl plik

@ -260,43 +260,45 @@ cSoundOSS::cSoundOSS(const char *dev ) {
std::cout << e.what()
<< " <" << device.c_str()
<< ">" << std::endl;
}
}
int err;
try {
int err;
snd_buffer = new float [2*SND_BUF_LEN];
src_buffer = new float [2*SND_BUF_LEN];
cbuff = new unsigned char [4 * SND_BUF_LEN];
if (!snd_buffer || !src_buffer || !cbuff)
throw "Cannot create libsamplerate buffers";
for (int i = 0; i < 2*SND_BUF_LEN; i++)
snd_buffer[i] = src_buffer[i] = 0.0;
for (int i = 0; i < 4 * SND_BUF_LEN; i++)
cbuff[i] = 0;
cbuff = new unsigned char [4 * SND_BUF_LEN];
}
catch (const std::bad_alloc& e) {
cerr << "Cannot allocate libsamplerate buffers\n";
throw;
}
for (int i = 0; i < 2*SND_BUF_LEN; i++)
snd_buffer[i] = src_buffer[i] = 0.0;
for (int i = 0; i < 4 * SND_BUF_LEN; i++)
cbuff[i] = 0;
try {
tx_src_data = new SRC_DATA;
rx_src_data = new SRC_DATA;
if (!tx_src_data || !rx_src_data)
throw "Cannot create libsamplerate data structures";
rx_src_state = src_new(SRC_SINC_FASTEST, 2, &err);
if (rx_src_state == 0)
throw src_strerror(err);
tx_src_state = src_new(SRC_SINC_FASTEST, 2, &err);
if (tx_src_state == 0)
throw src_strerror(err);
rx_src_data->src_ratio = 1.0/(1.0 + rxppm/1e6);
src_set_ratio ( rx_src_state, 1.0/(1.0 + rxppm/1e6));
tx_src_data->src_ratio = 1.0 + txppm/1e6;
src_set_ratio ( tx_src_state, 1.0 + txppm/1e6);
}
catch (SndException){
exit(1);
};
catch (const std::bad_alloc& e) {
cerr << "Cannot create libsamplerate data structures\n";
throw;
}
rx_src_state = src_new(SRC_SINC_FASTEST, 2, &err);
if (rx_src_state == 0)
throw SndException(src_strerror(err));
tx_src_state = src_new(SRC_SINC_FASTEST, 2, &err);
if (tx_src_state == 0)
throw SndException(src_strerror(err));
rx_src_data->src_ratio = 1.0/(1.0 + rxppm/1e6);
src_set_ratio ( rx_src_state, 1.0/(1.0 + rxppm/1e6));
tx_src_data->src_ratio = 1.0 + txppm/1e6;
src_set_ratio ( tx_src_state, 1.0 + txppm/1e6);
}
cSoundOSS::~cSoundOSS()
@ -319,7 +321,7 @@ void cSoundOSS::setfragsize()
sndparam |= 0x00040000;
if (ioctl(device_fd, SNDCTL_DSP_SETFRAGMENT, &sndparam) < 0)
throw errno;
throw SndException(errno);
}
int cSoundOSS::Open(int md, int freq)
@ -652,16 +654,25 @@ cSoundPA::cSoundPA(const char *dev)
frames_per_buffer(paFramesPerBufferUnspecified), req_sample_rate(0),
dev_sample_rate(0), fbuf(0)
{
rx_src_data = new SRC_DATA;
tx_src_data = new SRC_DATA;
if (!rx_src_data || !tx_src_data)
throw SndException("Cannot create libsamplerate data structures");
try {
rx_src_data = new SRC_DATA;
tx_src_data = new SRC_DATA;
}
catch (const std::bad_alloc& e) {
cerr << "Cannot create libsamplerate data structures\n";
throw;
}
try {
snd_buffer = new float[2 * SND_BUF_LEN];
src_buffer = new float[2 * SND_BUF_LEN];
fbuf = new float[2 * SND_BUF_LEN];
}
catch (const std::bad_alloc& e) {
cerr << "Cannot allocate libsamplerate buffers\n";
throw;
}
snd_buffer = new float[2 * SND_BUF_LEN];
src_buffer = new float[2 * SND_BUF_LEN];
fbuf = new float[2 * SND_BUF_LEN];
if (!snd_buffer || !src_buffer || !fbuf)
throw SndException("Cannot allocate libsamplerate buffers");
memset(snd_buffer, 0, 2 * SND_BUF_LEN);
memset(src_buffer, 0, 2 * SND_BUF_LEN);
memset(fbuf, 0, 2 * SND_BUF_LEN);