/*Main encoding loop (one frame per iteration)*/
while (1) {
nb_samples = inopt.read_samples(inopt.readdata,input,frame_size);
ret = ope_encoder_write_float(enc, input, nb_samples);
Currently read_samples would do an fread(...) call for every frame, and IIUC each such call results in a
read-syscall and user<>kernel switch. I wonder if it would speed up if a large buffer is first read and then encoded at once - the underlying libopus API seems to support encoding multiple frames at once.
Would it be faster to do this?
If so, maybe a bufsize option can be introduced or even a command line switch for a regime where whole input is read in-memory / or input is open as mmap.
Also every read_samples/wav_read call alloca-tes a buffer dynamically for every frame.
https://github.com/xiph/opus-tools/blob/master/src/opusenc.c#L1116-L1119 :
Currently
read_samples
would do anfread(...)
call for every frame, and IIUC each such call results in aread
-syscall and user<>kernel switch. I wonder if it would speed up if a large buffer is first read and then encoded at once - the underlying libopus API seems to support encoding multiple frames at once.Would it be faster to do this?
If so, maybe a bufsize option can be introduced or even a command line switch for a regime where whole input is read in-memory / or input is open as mmap.
Also every
read_samples
/wav_read
callalloca
-tes a buffer dynamically for every frame.