comparison data/fileio/WavFileWriter.cpp @ 929:59e7fe1b1003 warnfix_no_size_t

Unsigned removals and warning fixes in data/
author Chris Cannam
date Tue, 17 Jun 2014 14:33:42 +0100
parents e802e550a1f2
children cc27f35aa75c
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
23 #include <QFileInfo> 23 #include <QFileInfo>
24 24
25 #include <iostream> 25 #include <iostream>
26 26
27 WavFileWriter::WavFileWriter(QString path, 27 WavFileWriter::WavFileWriter(QString path,
28 size_t sampleRate, 28 int sampleRate,
29 size_t channels, 29 int channels,
30 FileWriteMode mode) : 30 FileWriteMode mode) :
31 m_path(path), 31 m_path(path),
32 m_sampleRate(sampleRate), 32 m_sampleRate(sampleRate),
33 m_channels(channels), 33 m_channels(channels),
34 m_temp(0), 34 m_temp(0),
118 selection->setSelection(Selection(source->getStartFrame(), 118 selection->setSelection(Selection(source->getStartFrame(),
119 source->getEndFrame())); 119 source->getEndFrame()));
120 ownSelection = true; 120 ownSelection = true;
121 } 121 }
122 122
123 size_t bs = 2048; 123 int bs = 2048;
124 float *ub = new float[bs]; // uninterleaved buffer (one channel) 124 float *ub = new float[bs]; // uninterleaved buffer (one channel)
125 float *ib = new float[bs * m_channels]; // interleaved buffer 125 float *ib = new float[bs * m_channels]; // interleaved buffer
126 126
127 for (MultiSelection::SelectionList::iterator i = 127 for (MultiSelection::SelectionList::iterator i =
128 selection->getSelections().begin(); 128 selection->getSelections().begin();
129 i != selection->getSelections().end(); ++i) { 129 i != selection->getSelections().end(); ++i) {
130 130
131 size_t f0(i->getStartFrame()), f1(i->getEndFrame()); 131 int f0(i->getStartFrame()), f1(i->getEndFrame());
132 132
133 for (size_t f = f0; f < f1; f += bs) { 133 for (int f = f0; f < f1; f += bs) {
134 134
135 size_t n = std::min(bs, f1 - f); 135 int n = std::min(bs, f1 - f);
136 136
137 for (int c = 0; c < int(m_channels); ++c) { 137 for (int c = 0; c < int(m_channels); ++c) {
138 source->getData(c, f, n, ub); 138 source->getData(c, f, n, ub);
139 for (size_t i = 0; i < n; ++i) { 139 for (int i = 0; i < n; ++i) {
140 ib[i * m_channels + c] = ub[i]; 140 ib[i * m_channels + c] = ub[i];
141 } 141 }
142 } 142 }
143 143
144 sf_count_t written = sf_writef_float(m_file, ib, n); 144 sf_count_t written = sf_writef_float(m_file, ib, n);
157 157
158 return isOK(); 158 return isOK();
159 } 159 }
160 160
161 bool 161 bool
162 WavFileWriter::writeSamples(float **samples, size_t count) 162 WavFileWriter::writeSamples(float **samples, int count)
163 { 163 {
164 if (!m_file) { 164 if (!m_file) {
165 m_error = QString("Failed to write model to audio file '%1': File not open") 165 m_error = QString("Failed to write model to audio file '%1': File not open")
166 .arg(getWriteFilename()); 166 .arg(getWriteFilename());
167 return false; 167 return false;
168 } 168 }
169 169
170 float *b = new float[count * m_channels]; 170 float *b = new float[count * m_channels];
171 for (size_t i = 0; i < count; ++i) { 171 for (int i = 0; i < int(count); ++i) {
172 for (size_t c = 0; c < m_channels; ++c) { 172 for (int c = 0; c < int(m_channels); ++c) {
173 b[i * m_channels + c] = samples[c][i]; 173 b[i * m_channels + c] = samples[c][i];
174 } 174 }
175 } 175 }
176 176
177 sf_count_t written = sf_writef_float(m_file, b, count); 177 sf_count_t written = sf_writef_float(m_file, b, count);
178 178
179 delete[] b; 179 delete[] b;
180 180
181 if (written < count) { 181 if (written < int(count)) {
182 m_error = QString("Only wrote %1 of %2 frames") 182 m_error = QString("Only wrote %1 of %2 frames")
183 .arg(written).arg(count); 183 .arg(written).arg(count);
184 } 184 }
185 185
186 return isOK(); 186 return isOK();