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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Can't find variable: document ReactNative Js2019 Community Moderator ElectionReactNative: how to center text?Can't find variable: navigate - ReactNative navigationReact Native error: “Can't find variable: TouchableHighlight”How to use Expo.DocumentPicker.getDocumentAsync properly. [Expo] [ReactNative]Can't find variable: regeneratorRuntime (ReactNative)Reactnative Expo It is advisable for a StartUp?Can't find variable : Self / Can't install firebaseNPM Install Error in installing ReactNative CLIContacts Displaying in App using ReactnativeFacebook login error: can't find variable: Alert

          Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices