Correct decoding opusPortaudio + Opus encoding / decoding audio input5.1 Channels with PortAudioDecoding Opus audio dataPython : PortAudio + Opus encoding/decodingUsing Opus with PortAudioDecode Opus-48 using WiresharkJoining Portaudio and OpusPortaudio + Opus: Horrible sound qualityDecode Ogg/Opus fileDecoding with Opus API using opus_decode_float

How old can references or sources in a thesis be?

Mage Armor with Defense fighting style (for Adventurers League bladeslinger)

What is the word for reserving something for yourself before others do?

Problem of parity - Can we draw a closed path made up of 20 line segments...

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Why Is Death Allowed In the Matrix?

can i play a electric guitar through a bass amp?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Is it legal for company to use my work email to pretend I still work there?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Has the BBC provided arguments for saying Brexit being cancelled is unlikely?

Languages that we cannot (dis)prove to be Context-Free

Why are electrically insulating heatsinks so rare? Is it just cost?

Prove that NP is closed under karp reduction?

Can I ask the recruiters in my resume to put the reason why I am rejected?

Why doesn't H₄O²⁺ exist?

How do I create uniquely male characters?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

Which models of the Boeing 737 are still in production?

What do you call a Matrix-like slowdown and camera movement effect?

Is this a crack on the carbon frame?

Smoothness of finite-dimensional functional calculus

What are the differences between the usage of 'it' and 'they'?

How can bays and straits be determined in a procedurally generated map?



Correct decoding opus


Portaudio + Opus encoding / decoding audio input5.1 Channels with PortAudioDecoding Opus audio dataPython : PortAudio + Opus encoding/decodingUsing Opus with PortAudioDecode Opus-48 using WiresharkJoining Portaudio and OpusPortaudio + Opus: Horrible sound qualityDecode Ogg/Opus fileDecoding with Opus API using opus_decode_float






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I had a need to transmit sound over the network and for this I chose libraries "PortAudio" and "Opus". I am new to working with sound and therefore i don’t know many thing.I am new to working with sound and therefore i don’t know many things, but i read the documentation and looked at some examples, but i still have some problems with encoding/decoding with Opus. I do not understand how to correctly restore the original encoded PСM.I have some sequence of actions:
Some consts



const int FRAMES_PER_BUFFER = 960;
const int SAMPLE_RATE = 48000;
int NUM_CHANNELS = 2;
int totalFrames = 2 * SAMPLE_RATE; /* Record for a few seconds. */
int numSamples = totalFrames * 2;
int numBytes = numSamples * sizeof(float);
float *sampleBlock = nullptr;
int bytesOfPacket = 0;
unsigned char *packet = nullptr;



  1. I get PСM to sampleBlock



    paError = Pa_ReadStream(**&stream, sampleBlock, totalFrames);
    if (paError != paNoError)
    cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
    std::system("pause");




  2. Encoding sampleBlock



    OpusEncoder *encoder;
    int error;
    int size;
    encoder = opus_encoder_create(SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP, &error);
    size = opus_encoder_get_size(NUM_CHANNELS);
    encoder = (OpusEncoder *)malloc(size);
    packet = new unsigned char[480];

    error = opus_encoder_init(encoder, SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP);
    if (error == -1)
    return -1;


    bytesOfPacket = opus_encode_float(encoder, sampleBlock, FRAMES_PER_BUFFER, packet, 480);
    opus_encoder_destroy(encoder);


    Ok, i received a encoded packet to Opus




  3. Decoding



    OpusDecoder *decoder;
    int error;
    int size;
    decoder = opus_decoder_create(SAMPLE_RATE, NUM_CHANNELS, &error);
    size = opus_decoder_get_size(NUM_CHANNELS);
    decoder = (OpusDecoder *)malloc(size);
    error = opus_decoder_init(decoder, SAMPLE_RATE, NUM_CHANNELS);

    opus_decode_float(decoder, packet, bytesOfPacket, sampleBlock, 480, 0);
    opus_decoder_destroy(decoder);


    Here i am trying to decode the Opus back to the PCM and save the result to the sampleBlock




  4. Playing the sound



    paError = Pa_WriteStream(**&stream, sampleBlock, totalFrames);
    if (paError != paNoError)
    cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
    std::system("pause");



    I get silence. I don't really understand the subtleties in working with sound since i am new to this business. Help please understand what is wrong.











share|improve this question




























    1















    I had a need to transmit sound over the network and for this I chose libraries "PortAudio" and "Opus". I am new to working with sound and therefore i don’t know many thing.I am new to working with sound and therefore i don’t know many things, but i read the documentation and looked at some examples, but i still have some problems with encoding/decoding with Opus. I do not understand how to correctly restore the original encoded PСM.I have some sequence of actions:
    Some consts



    const int FRAMES_PER_BUFFER = 960;
    const int SAMPLE_RATE = 48000;
    int NUM_CHANNELS = 2;
    int totalFrames = 2 * SAMPLE_RATE; /* Record for a few seconds. */
    int numSamples = totalFrames * 2;
    int numBytes = numSamples * sizeof(float);
    float *sampleBlock = nullptr;
    int bytesOfPacket = 0;
    unsigned char *packet = nullptr;



    1. I get PСM to sampleBlock



      paError = Pa_ReadStream(**&stream, sampleBlock, totalFrames);
      if (paError != paNoError)
      cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
      std::system("pause");




    2. Encoding sampleBlock



      OpusEncoder *encoder;
      int error;
      int size;
      encoder = opus_encoder_create(SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP, &error);
      size = opus_encoder_get_size(NUM_CHANNELS);
      encoder = (OpusEncoder *)malloc(size);
      packet = new unsigned char[480];

      error = opus_encoder_init(encoder, SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP);
      if (error == -1)
      return -1;


      bytesOfPacket = opus_encode_float(encoder, sampleBlock, FRAMES_PER_BUFFER, packet, 480);
      opus_encoder_destroy(encoder);


      Ok, i received a encoded packet to Opus




    3. Decoding



      OpusDecoder *decoder;
      int error;
      int size;
      decoder = opus_decoder_create(SAMPLE_RATE, NUM_CHANNELS, &error);
      size = opus_decoder_get_size(NUM_CHANNELS);
      decoder = (OpusDecoder *)malloc(size);
      error = opus_decoder_init(decoder, SAMPLE_RATE, NUM_CHANNELS);

      opus_decode_float(decoder, packet, bytesOfPacket, sampleBlock, 480, 0);
      opus_decoder_destroy(decoder);


      Here i am trying to decode the Opus back to the PCM and save the result to the sampleBlock




    4. Playing the sound



      paError = Pa_WriteStream(**&stream, sampleBlock, totalFrames);
      if (paError != paNoError)
      cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
      std::system("pause");



      I get silence. I don't really understand the subtleties in working with sound since i am new to this business. Help please understand what is wrong.











    share|improve this question
























      1












      1








      1








      I had a need to transmit sound over the network and for this I chose libraries "PortAudio" and "Opus". I am new to working with sound and therefore i don’t know many thing.I am new to working with sound and therefore i don’t know many things, but i read the documentation and looked at some examples, but i still have some problems with encoding/decoding with Opus. I do not understand how to correctly restore the original encoded PСM.I have some sequence of actions:
      Some consts



      const int FRAMES_PER_BUFFER = 960;
      const int SAMPLE_RATE = 48000;
      int NUM_CHANNELS = 2;
      int totalFrames = 2 * SAMPLE_RATE; /* Record for a few seconds. */
      int numSamples = totalFrames * 2;
      int numBytes = numSamples * sizeof(float);
      float *sampleBlock = nullptr;
      int bytesOfPacket = 0;
      unsigned char *packet = nullptr;



      1. I get PСM to sampleBlock



        paError = Pa_ReadStream(**&stream, sampleBlock, totalFrames);
        if (paError != paNoError)
        cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
        std::system("pause");




      2. Encoding sampleBlock



        OpusEncoder *encoder;
        int error;
        int size;
        encoder = opus_encoder_create(SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP, &error);
        size = opus_encoder_get_size(NUM_CHANNELS);
        encoder = (OpusEncoder *)malloc(size);
        packet = new unsigned char[480];

        error = opus_encoder_init(encoder, SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP);
        if (error == -1)
        return -1;


        bytesOfPacket = opus_encode_float(encoder, sampleBlock, FRAMES_PER_BUFFER, packet, 480);
        opus_encoder_destroy(encoder);


        Ok, i received a encoded packet to Opus




      3. Decoding



        OpusDecoder *decoder;
        int error;
        int size;
        decoder = opus_decoder_create(SAMPLE_RATE, NUM_CHANNELS, &error);
        size = opus_decoder_get_size(NUM_CHANNELS);
        decoder = (OpusDecoder *)malloc(size);
        error = opus_decoder_init(decoder, SAMPLE_RATE, NUM_CHANNELS);

        opus_decode_float(decoder, packet, bytesOfPacket, sampleBlock, 480, 0);
        opus_decoder_destroy(decoder);


        Here i am trying to decode the Opus back to the PCM and save the result to the sampleBlock




      4. Playing the sound



        paError = Pa_WriteStream(**&stream, sampleBlock, totalFrames);
        if (paError != paNoError)
        cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
        std::system("pause");



        I get silence. I don't really understand the subtleties in working with sound since i am new to this business. Help please understand what is wrong.











      share|improve this question














      I had a need to transmit sound over the network and for this I chose libraries "PortAudio" and "Opus". I am new to working with sound and therefore i don’t know many thing.I am new to working with sound and therefore i don’t know many things, but i read the documentation and looked at some examples, but i still have some problems with encoding/decoding with Opus. I do not understand how to correctly restore the original encoded PСM.I have some sequence of actions:
      Some consts



      const int FRAMES_PER_BUFFER = 960;
      const int SAMPLE_RATE = 48000;
      int NUM_CHANNELS = 2;
      int totalFrames = 2 * SAMPLE_RATE; /* Record for a few seconds. */
      int numSamples = totalFrames * 2;
      int numBytes = numSamples * sizeof(float);
      float *sampleBlock = nullptr;
      int bytesOfPacket = 0;
      unsigned char *packet = nullptr;



      1. I get PСM to sampleBlock



        paError = Pa_ReadStream(**&stream, sampleBlock, totalFrames);
        if (paError != paNoError)
        cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
        std::system("pause");




      2. Encoding sampleBlock



        OpusEncoder *encoder;
        int error;
        int size;
        encoder = opus_encoder_create(SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP, &error);
        size = opus_encoder_get_size(NUM_CHANNELS);
        encoder = (OpusEncoder *)malloc(size);
        packet = new unsigned char[480];

        error = opus_encoder_init(encoder, SAMPLE_RATE, NUM_CHANNELS, OPUS_APPLICATION_VOIP);
        if (error == -1)
        return -1;


        bytesOfPacket = opus_encode_float(encoder, sampleBlock, FRAMES_PER_BUFFER, packet, 480);
        opus_encoder_destroy(encoder);


        Ok, i received a encoded packet to Opus




      3. Decoding



        OpusDecoder *decoder;
        int error;
        int size;
        decoder = opus_decoder_create(SAMPLE_RATE, NUM_CHANNELS, &error);
        size = opus_decoder_get_size(NUM_CHANNELS);
        decoder = (OpusDecoder *)malloc(size);
        error = opus_decoder_init(decoder, SAMPLE_RATE, NUM_CHANNELS);

        opus_decode_float(decoder, packet, bytesOfPacket, sampleBlock, 480, 0);
        opus_decoder_destroy(decoder);


        Here i am trying to decode the Opus back to the PCM and save the result to the sampleBlock




      4. Playing the sound



        paError = Pa_WriteStream(**&stream, sampleBlock, totalFrames);
        if (paError != paNoError)
        cout << "PortAudio error : " << Pa_GetErrorText(paError) << endl;
        std::system("pause");



        I get silence. I don't really understand the subtleties in working with sound since i am new to this business. Help please understand what is wrong.








      portaudio opus






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 at 2:19









      FWOFWO

      62




      62






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073382%2fcorrect-decoding-opus%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073382%2fcorrect-decoding-opus%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229