Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sample sizes in Qt audio example
QtWS25 Last Chance

Sample sizes in Qt audio example

Scheduled Pinned Locked Moved Unsolved General and Desktop
audioaudio waveformaudio deviceaudio recordingaudio record
5 Posts 2 Posters 856 Views
  • 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 Offline
    R Offline
    Rasva
    wrote on 8 Jul 2019, 09:27 last edited by
    #1

    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
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 8 Jul 2019, 16:55 last edited by
      #2

      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
      1
      • R Offline
        R Offline
        Rasva
        wrote on 10 Jul 2019, 15:21 last edited by
        #3

        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
        0
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 10 Jul 2019, 19:12 last edited by
          #4

          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
          1
          • R Offline
            R Offline
            Rasva
            wrote on 16 Jul 2019, 14:42 last edited by
            #5

            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
            0

            2/5

            8 Jul 2019, 16:55

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved