MCPcopy Create free account
hub / github.com/audeering/opensmile / writeData

Method writeData

src/iocore/externalAudioSource.cpp:132–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132bool cExternalAudioSource::writeData(const void *data, int nBytes)
133{
134 if (!smileMutexLock(writeDataMtx_))
135 return false;
136 if (isAbort() || isPaused() || isEOI() || externalEOI_) {
137 smileMutexUnlock(writeDataMtx_);
138 return false;
139 }
140 if (!isFinalised()) {
141 SMILE_IERR(1, "cExternalAudioSource::writeData called before component was finalised.");
142 smileMutexUnlock(writeDataMtx_);
143 return false;
144 }
145 int nSamples = smilePcm_numberBytesToNumberSamples(nBytes, &pcmParam_);
146 // if the writer level has growDyn=1 set, nSamples is allowed to be larger than the blocksize
147 // thus this check is disabled for now
148 /*if (nSamples > blocksizeW_) {
149 SMILE_IERR(1, "cExternalAudioSource::writeData nSamples (%i) > max blocksize (%i). Write a smaller buffer or increase blocksize option in the configuration.",
150 nSamples, blocksizeW_);
151 smileMutexUnlock(writeDataMtx_);
152 return false;
153 }*/
154 if (!writer_->checkWrite(nSamples)) {
155 smileMutexUnlock(writeDataMtx_);
156 return false;
157 }
158
159 // allocate/resize data buffer
160 if (writtenDataBuffer_ == NULL) {
161 writtenDataBuffer_ = new cMatrix(channels_, nSamples, true);
162 } else if (writtenDataBuffer_->nT < nSamples) {
163 delete writtenDataBuffer_;
164 writtenDataBuffer_ = new cMatrix(channels_, nSamples, true);
165 }
166
167 if (nBits_ == 33) {
168 if (!smilePcm_convertFloatSamples(data, &pcmParam_, writtenDataBuffer_->data, channels_, nSamples, 0)) {
169 smileMutexUnlock(writeDataMtx_);
170 return false;
171 }
172 } else {
173 if (!smilePcm_convertSamples(data, &pcmParam_, writtenDataBuffer_->data, channels_, nSamples, 0)) {
174 smileMutexUnlock(writeDataMtx_);
175 return false;
176 }
177 }
178
179 // temporarily set the size of writtenDataBuffer_ to the current amount of data to write
180 long realBufferSize = writtenDataBuffer_->nT;
181 writtenDataBuffer_->nT = nSamples;
182 // save to data memory
183 int ret = writer_->setNextMatrix(writtenDataBuffer_);
184 // restore size of writtenDataBuffer_
185 writtenDataBuffer_->nT = realBufferSize;
186
187 if (!ret) {
188 smileMutexUnlock(writeDataMtx_);
189 return false;

Callers

nothing calls this directly

Calls 7

smileMutexLockFunction · 0.85
smileMutexUnlockFunction · 0.85
smilePcm_convertSamplesFunction · 0.85
setNextMatrixMethod · 0.80
checkWriteMethod · 0.45

Tested by

no test coverage detected