Skip to content

Conversation

@Saafo
Copy link

@Saafo Saafo commented Aug 5, 2024

The use of fread function in example code is:

short buf[2*READ_SIZE];
int ret = fread(buf, 2*sizeof(short), READ_SIZE, fin);

But according to fread documentation, although the 2nd and 3rd parameters will be multiplied together, the return value will be different(in case of full-read, the return value will be equal to 3rd parameter according to my test locally). So the variable ret will be different(prior is 256, current is 512, which equals to the length of buf).

Only this issue is fixed, the 3rd parameter of ope_encoder_write will write all data correctly. Otherwise it will write only half of the data, resulting in only half time length of the opus product in my local test(I'm using a 16000 sample rate, 1 channel pcm file for test. Already changed the ope_encoder_create_file parameters to 16000, 1, 0 for the local test).

Meanwhile, I'm not sure why we add a 2* with READ_SIZE for the buf, we can remove both 2* if it's useless.

@Saafo Saafo changed the title fix misuse of fread in example fix misusing of fread in example Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant