portaudio - Interpreting inputBuffer's Value in a Callback -


i basing code off of portaudio's paex_record_file.c example. 1 of parameters in callback inputbuffer, , wanted use data calculate other numbers double/float type. changed file .raw .txt, notepad still cannot read it, leading me believe data not encoded number. how data stored in inputbuffer , how can arithmetic (add, multiply, divide, etc)?

this how initialized inputparameters:

inputparameters.device = pa_getdefaultinputdevice(); /* default input device */ if (inputparameters.device == panodevice) {     fprintf(stderr,"error: no default input device.\n");     goto error; } inputparameters.channelcount = 2;                    /* stereo input */ inputparameters.sampleformat = pafloat32; inputparameters.suggestedlatency = pa_getdeviceinfo( inputparameters.device )->defaultlowinputlatency; inputparameters.hostapispecificstreaminfo = null; 

this question related print floats audio input callback function (unanswered).

the inputbuffer parameter callback void*. actual type of underlying buffer depends on parameters , flags pass pa_openstream.

if specified pafloat32 there float* in there somewhere. 2 possibilities:

  1. interleaved: inputparameters.sampleformat = pafloat32;
  2. non-interleaved: inputparameters.sampleformat = pafloat32|panoninterleaved;

you specified interleaved option. in case, inputbuffer points single buffer of interleaved floats. can write:

float *samples = (float*)inputbuffer; 

in 2 channel stream samples contain interleaved left , right samples, e.g.:

samples[0]; // first left sample samples[1]; // first right sample samples[2]; // second left sample samples[3]; // second right sample // etc. 

for completeness: if had been non-interleaved stream inputbuffer points array of pointers single-channel buffers. extract buffer pointers write like:

float *left = ((float **) inputbuffer)[0]; float *right = ((float **) inputbuffer)[1]; 

note in cases framesperbuffer counts frames not samples. frame includes 1 sample each channel. example, in stereo stream, frame includes both left , right channel samples.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -