Spectrum analyzer demo, the HZ is 0 ~ 1000, how to change this?



  • spectrum analyzer demo, the supported HZ is 0 ~ 1000
    how to change this? fro example 0 ~20000Hz

    I have change this in http://doc.qt.nokia.com/latest/demos-spectrum-app-spectrum-h.html but it will not work.
    // Lower bound of first band in the spectrum
    const qreal SpectrumLowFreq = 0.0; // Hz

    // Upper band of last band in the spectrum
    const qreal SpectrumHighFreq = 1000.0; // Hz



  • You don't know grep, do you?

    @
    Qt/qt-everywhere-commercial-src-4.7.1/demos/spectrum/app $ grep 1000 *
    engine.cpp:const qint64 BufferDurationUs = 10 * 1000000;
    engine.cpp:const int LevelWindowUs = 0.1 * 1000000;
    spectrum.h:const qreal SpectrumHighFreq = 1000.0; // Hz
    spectrum.h:const qint64 WaveformWindowDuration = 500 * 1000;
    tonegeneratordialog.cpp:const int ToneGeneratorFreqMax = 1000;
    utils.cpp: return (bytes * 1000000) /
    utils.cpp: * microSeconds / 1000000;
    @

    I leave it to your eyes to grab the right file.

    And yes, I would call it probably a bug, that the constant of spectrum.h is not used.



  • dear my friends, I do not fully understand you.
    I have already changed :
    // Lower bound of first band in the spectrum
    const qreal SpectrumLowFreq = 0.0; // Hz

    // Upper band of last band in the spectrum
    const qreal SpectrumHighFreq = 1000.0; // Hz

    but this will not work.

    what should I change?

    thanks



  • Take another good look at what was posted by Volker. Do you spot another 1000 somewhere that may be relevant?



  • change this: tonegeneratordialog.cpp:const int ToneGeneratorFreqMax = 1000;
    this will not work. tried.



  • For me it works.



  • which version do you use? I use QT4.6



  • there are 3 mode for this demo:

    1. play the generated tone.
    2. recode the sound
    3. play the file

    I changed the ToneGeneratorFreqMax = 1000 to 20000.
    from the sound that I heard, the Frequency is changed.
    But the spectrograph is not changed accordingly, which means the bars shown to the user do not work well.



  • Did you change both values?
    Did you have a look at SpectrumNumBands?



  • Yes. I change all the value.
    SpectrumNumBands is the 10, that's fine for me.

    when I debug I notice that all the frequency will result a bar index, either 0 or 1.
    So I think there may be a bug in the Spectrograph::updateBars()



  • I can't help on that. You'll have to check the sources. They seem quite simple to me.



  • I have the following :

    Where exactly in spectrumanalyser demo is a code for getting the RAW PCM data from .wav file? and how to use this demo's functions to get it.

    i'm working on sound processing system and i'm new with qt.

    I would be grateful if someone could paste small example how to do get pcm data ;)

    thanks for your reply ;)



  • hey can you please elaborate your problem this way we cant help u out be specific with your problem....

    then only we can help you...



  • thanks,
    Ok, so I want to open the .wav file, get audio (PCM) data, and do some signal processing using external library (for example mel-cepstrum coefficients analysis)
    so i open the wav file using:
    @showFileDialog(){
    }@
    this function calls m_engine->loadFile(fileNames.front()); function
    In next step i would like to create the buffer/vector for audio data and write this data to it and then analyse them. I don't know how to create this buffer and get the pcm data.
    i look for adequate functions and find this:
    @if (m_file) {
    m_file->seek(0);
    m_bufferPosition = 0;
    m_dataLength = 0;
    if (isPCMS16LE(m_file->fileFormat())) {
    result = initialize();
    }if(m_spectrumAnalyser.isReady()) {
    m_spectrumBuffer = QByteArray::fromRawData(m_buffer.constData() + position m_bufferPosition, m_spectrumBufferLength);
    m_spectrumPosition = position;
    m_spectrumAnalyser.calculate(m_spectrumBuffer, m_format);
    }@
    so i see that i have to get some kind of m_buffer and m_format from .wav file and i don't see the proper way to do it. It would be great if someone could paste some simple code with solution to open .wav file, creating the buffer, getting the necessary parameters from this file (for example number of samples, m_format?), writting pcm data to the buffer, and how to read this data. In MATLAB there is wavread function for reading this kind of data.
    thanks for your reply ;)



  • spectrum analyser is having that functuionality u dont have to write anything for that...

    when u say,

    @result = initialize();@

    this method automatically initialises tha m_buffer and m_format..

    check it properly..



  • Thank you shoyeb ;)

    ok, I created the pushbutton and and i want to calculate the spectrum of 30000 us with step of 10000 us. how can i set up this values for my use?
    I connected my slot to this button and this work properly spectrum. How to enable that the spectrum is calculated only if the position of calculating is less than the signal? - my program is still crushing after a few click ;(
    @my function{
    if (isPCMS16LE(m_file->fileFormat())) {
    result = initialize();
    }
    if (m_file) {
    m_file->seek(0);
    m_bufferPosition = 0;
    m_dataLength = 0;
    }

            //bufor itd
            if(m_spectrumAnalyser.isReady()) {
                m_spectrumBuffer = QByteArray::fromRawData(m_buffer.constData() + classify_position - m_bufferPosition,
                                                           m_spectrumBufferLength);
                m_spectrumPosition = classify_position + 10000;// step of windowing
    
                m_spectrumAnalyser.calculate(m_spectrumBuffer, m_format);
    

    }
    }

    @ how to initialize m_spectrumBufferLength and position to the values i mentioned?
    and where/how i can add spectrumanalyser functions to calculate the spectrum only if the position is less than duration of signal?

    please help me



  • in engine.cpp file on top there are two constants..

    @const qint64 BufferDurationUs = 1 * 1000000;
    const int NotifyIntervalMs = 10;@

    where first value is amount of data to be processed in microseconds and second one is to set the notify interval, watever value u set in notify interval after that duration only ur data processing is done...

    m_spectrumBufferLength is fixed and its value is initialized in utils.h or utils.h u dat can check ...



  • and how can i add the functionality of computing spectrum only if the position of computing is less than duration of whole signal,

    or mayby how can i get the info about duration of whole signal (in microseconds or sample number )?



  • the first line tells you the duration of entire signal i.e

    @const qint64 BufferDurationUs = 1 * 1000000;@

    this tells that the duration of entire singnal is one second...



  • yes, but i mean not recorded signal but opened and played wave file, how to obtain this information.
    thanks



  • check this...

    @if (isPCMS16LE(m_file->fileFormat())) {
    result = initialize();@

    and

    if (result) {
    m_analysisFile = new WavFile(this);
    m_analysisFile->open(fileName);
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.