Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Sample sizes in Qt audio example

    General and Desktop
    audio audio waveform audio device audio recording audio record
    2
    5
    347
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Rasva last edited by

      Hello,
      I've started to recently dive into Qt and I've been playing with the Qt audio example. However I ran into a problem. When I change the sample size from the default 8 to 16 then the visual representation starts to go weird. It constantly shows as if there was sound (even if the microphone is turned off or when it's completely quiet) but you can tell when there are loud noises for example tapping on the microphone. I've tried changing the visual representation (x and y on the chart) but that doesn't seem to fix it. The microphone is recording in dual channel 16 bit 44100 Hz so compatibility with 16 bit shouldn't be an issue either. Any suggestions?
      Thank you for your time.

      1 Reply Last reply Reply Quote 0
      • Kent-Dorfman
        Kent-Dorfman last edited by

        remember that sound samples can be signed or unsigned. What happens when you resize a byte to a short with respect to the two's complement value?

        See enum QAudioFormat::SampleType

        1 Reply Last reply Reply Quote 1
        • R
          Rasva last edited by

          I don't think this is the problem here, the same thing occurs with either signed or unsigned int. Or were you suggesting a different change?

          1 Reply Last reply Reply Quote 0
          • Kent-Dorfman
            Kent-Dorfman last edited by

            I'm not suggesting a change. I'm trying to give you some hints as to where your problem lies. Do you understand how PCM is used to generate a sound wave form? or what happens to a digital sound sample when the availabe bitrange is changed or it's format is modified?

            As a simple example question:

            you have an unsigned 8 bit sound sample and you cast it to an unsigned short value of 16 bits? What happens to the volume of that sample?

            1 Reply Last reply Reply Quote 1
            • R
              Rasva last edited by

              Thank you for your help, I've probably identified the problem - one of the input parameters was a char (8 bit). I've tried to fix it using the following code to reformat it so that it can be used properly for 16 bit but I keep getting the same problem

              /* Function with char as one of the parameters - qint64 XYSeriesIODevice::writeData(const char *data, qint64 maxSize) - same as in the Qt audio example**/
              
                  int bitsPerSample = 16;
                  int bytesPerSample = (bitsPerSample / BITS_IN_BYTE);
                  int signalLength = (strlen(data) ) / numChannels / bytesPerSample;
                  short* signal = (short*)malloc(sizeof(short) * signalLength);
              
                  for(int i = 0; i < signalLength; i++){
                      int index =  i * numChannels * bytesPerSample;
              
                      memcpy(&signal[i], &data[index], sizeof(short));
                  }
              

              Any suggestions?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post