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

Method convertAndCopyFrameSamplesToMatrix

src/ffmpeg/ffmpegSource.cpp:352–569  ·  view source on GitHub ↗

converts a part of the samples in avFrame to float format, optionally mixing them down to Mono, and copies them to mat_

Source from the content-addressed store, hash-verified

350
351// converts a part of the samples in avFrame to float format, optionally mixing them down to Mono, and copies them to mat_
352void cFFmpegSource::convertAndCopyFrameSamplesToMatrix(int index, int numSamples)
353{
354 if (index + numSamples > avFrame->nb_samples)
355 COMP_ERR("parameters 'index' and 'numSamples' out of range");
356 if (numSamples > blocksizeW_)
357 COMP_ERR("parameter 'numSamples' out of range");
358
359 if (mat_ == NULL) {
360 allocMat(monoMixdown ? 1 : avCodecContext->channels, blocksizeW_);
361 }
362
363 int nChan = avCodecContext->channels;
364
365 if (!monoMixdown) {
366 switch (avCodecContext->sample_fmt) {
367 case AV_SAMPLE_FMT_U8: // unsigned 8 bits, packed
368 for (int i = index; i < index + numSamples; i++)
369 for (int ch = 0; ch < nChan; ch++) {
370 mat_->set(ch, i - index, (((uint8_t *)avFrame->extended_data[0])[i*nChan+ch]-128)/(FLOAT_DMEM)127.0);
371 }
372 break;
373 case AV_SAMPLE_FMT_U8P: // unsigned 8 bits, planar
374 for (int i = index; i < index + numSamples; i++)
375 for (int ch = 0; ch < nChan; ch++) {
376 mat_->set(ch, i - index, (((uint8_t *)avFrame->extended_data[ch])[i]-128)/(FLOAT_DMEM)127.0);
377 }
378 break;
379 case AV_SAMPLE_FMT_S16: // signed 16 bits, packed
380 for (int i = index; i < index + numSamples; i++)
381 for (int ch = 0; ch < nChan; ch++) {
382 mat_->set(ch, i - index, ((int16_t *)avFrame->extended_data[0])[i*nChan+ch]/(FLOAT_DMEM)32767.0);
383 }
384 break;
385 case AV_SAMPLE_FMT_S16P: // signed 16 bits, planar
386 for (int i = index; i < index + numSamples; i++)
387 for (int ch = 0; ch < nChan; ch++) {
388 mat_->set(ch, i - index, ((int16_t *)avFrame->extended_data[ch])[i]/(FLOAT_DMEM)32767.0);
389 }
390 break;
391 case AV_SAMPLE_FMT_S32: // signed 32 bits, packed
392 for (int i = index; i < index + numSamples; i++)
393 for (int ch = 0; ch < nChan; ch++) {
394 mat_->set(ch, i - index, ((int32_t *)avFrame->extended_data[0])[i*nChan+ch]/(FLOAT_DMEM)2147483647.0);
395 }
396 break;
397 case AV_SAMPLE_FMT_S32P: // signed 32 bits, planar
398 for (int i = index; i < index + numSamples; i++)
399 for (int ch = 0; ch < nChan; ch++) {
400 mat_->set(ch, i - index, ((int32_t *)avFrame->extended_data[ch])[i]/(FLOAT_DMEM)2147483647.0);
401 }
402 break;
403 case AV_SAMPLE_FMT_FLT: // IEEE float 32 bits, packed
404 for (int i = index; i < index + numSamples; i++)
405 for (int ch = 0; ch < nChan; ch++) {
406 mat_->set(ch, i - index, (FLOAT_DMEM)((float *)avFrame->extended_data[0])[i*nChan+ch]);
407 }
408 break;
409 case AV_SAMPLE_FMT_FLTP: // IEEE float 32 bits, planar

Callers

nothing calls this directly

Calls 1

setMethod · 0.45

Tested by

no test coverage detected