Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outframes always = 0 with op_open_memory ? #30

Closed
fredvs opened this issue Jan 29, 2017 · 11 comments
Closed

outframes always = 0 with op_open_memory ? #30

fredvs opened this issue Jan 29, 2017 · 11 comments

Comments

@fredvs
Copy link

fredvs commented Jan 29, 2017

Hello and congrat for that wonderful project.

I have done a translation of the C header into pascal:

https://github.com/fredvs/uos/blob/master/src/uos_opusfile.pas

op_open_file() is working like charm with op_read().

But with op_open_memory() I have problem: op_read() gives always 0 as result.

Why ?

Thanks.

Fre;D

Using op_open_file()

HandleOP := op_open_memory(BufferURL[0],PipeBufferSize, Err);

op_test_open(StreamIn[x].Data.HandleOP);

I can retrieve the tags infos, all seems ok.

But for reading, using this gives 0 outframes:

outframes :=
op_read_float(Data.HandleOP, at Buffer[0], Wantframesm, nil);

@fredvs
Copy link
Author

fredvs commented Jan 29, 2017

Hello.

Some more explanation:

===> The code (in Pascal):

PipeBufferSize := 4096;
Wantframes := 1024;
HandleOP := op_open_memory(Buffer_byte[0],PipeBufferSize, Err);
Outframes := op_read_float(HandleOP,@Buffer_float[0], Wantframes, nil);

The result:
===> Err = 0
===> Outframes = 0

(Part of) data of memory Buffer_byte:

OggS��s��T=����OpusHead����OggS�s����;����OpusTags�Encoded with GStreamer Opusenc��ALBUM=Summer 2016
ARTIST=Kungs DATE=2016�DESCRIPTION=Loop Guitar.
GENRE=Dance�TITLE=guit_kungs.opusOggS�C�s���粫,���������������������
��6.)'�"@����uR���׼�e�A��+���&j}�����h1P� ���d��F����Ȱ(�x3K�.�M9W���t����!����R��/��i5�h���DH�U54��%
�$cĶ4Z�e���K����l̾q�i�(5����e�E�+��b�z��=
�kɡ)ډf�{s������9U����y��QX.Y!�Āz(��^a�G-K���Xް�s����Rh3SeZ��������_Ce���a���H7�o��0���c<����X�" p��
rsC���l;X|���0a>-���p�4���m��r'���$�L��@�#�g���Y��\��F�f�E;D�C3u��'�t����o�4�uF�J�W/!-���FC�)V��%S}��fL�4�x��P�U�I�\k��
Z�$�=���
�!4�ǁa6�L���X�.ep��B}�y>�4\Щ8��da?���5���G����#wn�h-0p!;K� �8��d����a���t�u�S� (f;�t�����:ȝ�6������r~o=Ӭo�AMg��gO�T���������xfNO��v.�6h�&�ݖM���1��K����5�LZҥ8��R���\��+T���Č�һ"w\˛��׈��������3&k�^�s�G �Kl6n�'p�;LH5wwOO� 3*��KP�cdI/���n�IƤ"����x�MQ��Z��v�v+y�]�ۍ0������F�@��7BL�<����Y@����%�a��C�,6���N}�}��0�Ř ���n�϶�r�����������>�tj��gV���#s rh����~�#��v����K6��j�oi �[���L�G���6��������NM_@�C��9�lp+�%�����+ٞA.���;�n6��{�F��Z�t���F��a������L�5{���@�f �C������r������h���[�l��2�7w�����"���N��i;t��J빀���h?/�s@�ط��x��9�7�� فF;��Űle}xٝx� �E�� uТ.��!NQ�%�g�;�A3�(���zy���F���������?�T]��I�4�+v��G4ɚ������"҅zo�F��� ���mm݌^�ǀh��M2
��v�,&�Vm�"t�����W�O�����k
��M�CZC�����a��
�{(k�r��I�����4�U*�|WV����nn��O2k$�����"��������=��L�%
�VVu�[*74��ۊ�
9�������mu��������A�m��a�������q��Kk.��N�p��|��b0�� ��'�K�
*���,&����lC�%�\���̲Qq�or�F:�3pV.9G�J������������s�]t���� �̩��G7���#&��
�e������ɒŧ�a��>�T

Fre;D

@tdaede
Copy link
Contributor

tdaede commented Jan 30, 2017

My first thought is that your buffer size of 4096 seems kind of small... with op_open_memory you're expected to give it the whole file.

@fredvs
Copy link
Author

fredvs commented Jan 30, 2017

Hello and thanks to answer.

with op_open_memory you're expected to give it the whole file.

Ha, but for internet streaming, only a buffer will be given.
I have try with > 4k ==> same result : outframes = 0.

IMO, it seems that Buffer_byte entered in op_open_memory :

HandleOP := op_open_memory(Buffer_byte,PipeBufferSize, Err);

That Buffer_byte is not used in HandleOP:

outframes := op_read_float(HandleOP, at Buffer[0], Wantframes, nil);

Thanks.

Fre;D

@fredvs
Copy link
Author

fredvs commented Jan 30, 2017

My first thought is that your buffer size of 4096 seems kind of small..

Ooops, wait, I try just now with buffer size of 32768 and... =>

Outframes = 960 => part of Buffer_float :

OUTPUT DATA AFTER ------------------------------
|1.497329258E-15|7.976823725E-16|1.053572953E-14|1.416983206E-14|4.160564173E-14|5.061418271E-14|1.145734169E-13|1.031588823E-13|2.113849731E-13|1.950407067E-13|3.359531891E-13|3.398339552E-13|4.791735585E-13|5.920528824E-13|6.257254372E-13|9.335471849E-13|7.733262815E-13|1.188091509E-12|9.587536928E-13|1.484348885E-12|1.224514088E-12|1.695904051E-12|1.727135795E-12|1.562433668E-12|2.427822917E-12|1.295814259E-12|2.721563643E-12|1.122110326E-12|2.970792232E-12|1.62301856E-12|3.838969073E-12|2.293267789E-12|4.843023985E-12|2.284443034E-12|5.548845671E-12|2.675828743E-12|6.294744673E-12|3.880955453E-12|8.067684541E-12|4.635028472E-12|1.00626044E-11|4.249789323E-12|1.125298726E-11|3.546743845E-12|1.26623009E-11

So, yes, there is some movement there ;-)

It is on the good way.

But why only 960 frames for buffer-in of 32768 bytes (maybe it is normal ?) ?

There is not yet sound, there is a arithmetic error with that buffer-out.

But there is great progress.

Of course, any comment is highly welcome.

@tdaede : many thanks, now I am full of hope to do Opus-web-streaming work for the Pascal community.

Fre;D

@rillian
Copy link
Contributor

rillian commented Jan 30, 2017

Each call to op_read_*() will return one packet's worth of decoded data, 960 samples in this case. The API expects you to call op_read_float() in a loop so you can play the output, or do whatever else you want to as each piece of compressed data is decoded.

@fredvs
Copy link
Author

fredvs commented Jan 30, 2017

Hello rillian.

Yep, yep, yep, I get (bad) sound but it will work, sure.

op_read_float() works like charm with op_open_file.

It will work also with op_open_memory.

OK, great, I begin to understand better how Opus work, now time to tune it.

Write you later with a perfect sound from a Opus-web_streamed file.

Fre;D

@fredvs
Copy link
Author

fredvs commented Jan 31, 2017

Re-hello.

What is the ratio between ASize and length of BufferURL here ? :

HandleOP := op_open_memory(BufferURL, ASize , Err);

(if ASize = 100, length of BufferURL ⁼ ?)

And here, if ASize = 100, length of BufferFloat = ?, BSize = ?

op_read_float(HandleOP, BufferFloat, BSize, nil);

Many thanks.

Fre;D

@tdaede
Copy link
Contributor

tdaede commented Jan 31, 2017

See documentation here: https://opus-codec.org/docs/opusfile_api-0.5/group__stream__open__close.html#gaffc5769a1e5977f186f77a1fb08cb248

It's the size of the file in bytes. It doesn't directly correlate with op_read_float, as the bitrate of the file may change.

If you want to do network streaming, you might want op_open_callbacks instead, which will call your application whenever you do an op_read_float but more input data is needed. Don't know how callbacks work with Pascal/Delphi, though. Also note that there's op_open_url, which will open and play from a HTTP stream for you.

@fredvs
Copy link
Author

fredvs commented Jan 31, 2017

Hello.

I did try to use op_open_url but without success. Even adding methods for libopusurl.so (did not find h header with this). Also I prefer use my own code for streaming and have access to the pipe.

For op_open_callbacks, I try also but without luck, I will re-try.

Thanks for doc but I do not see the ratio between between ASize and length of BufferURL in

HandleOP := op_open_memory(BufferURL, ASize , Err);

Thanks.

Fre;D

@fredvs
Copy link
Author

fredvs commented Jan 31, 2017

Hello.

Fixed !

The main problem was a ajustement of buffer size.

Perfect sound from https Opus file.

Many thanks.

Fre;D

@fredvs fredvs closed this as completed Jan 31, 2017
@rillian
Copy link
Contributor

rillian commented Jan 31, 2017

Glad you got it working!

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

No branches or pull requests

3 participants