0
0

Hi there,

I’m learning how to use FMOD 3.
I want to get levels from a channel in real time for big sounds (stream) and display it in a widget with Qt4.

I’ve 2 problems.

[b:3lueqakr]First problem :[/b:3lueqakr]
My test program works well in Console.
I’ve still a problem. When I stop the stream and i restart it, the FSOUND_GetCurrentLevels don’t work anyway. Do you have a suggestion ?

[code:3lueqakr]

include <stdio.h>

include <stdlib.h>

if defined(WIN32) || defined(_WIN64) || defined(WATCOMC)

#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

else

#include &quot;../../lib/fmoc/inc/wincompat.h&quot;

endif

include "fmod.h"

int main()
{
int channel,key, amp;
float vuval, l, r;
FSOUND_STREAM *musique = NULL;
FSOUND_Init(44100, 1, FSOUND_INIT_ACCURATEVULEVELS);
musique = FSOUND_Stream_Open("../../data/sound.wav", 0, 0, 0);
FSOUND_SetVolume(FSOUND_ALL, 120);
channel = FSOUND_Stream_Play(FSOUND_FREE, musique);
FSOUND_SAMPLE * smp;
smp = FSOUND_Stream_GetSample(musique);
printf("Playing %s\n", FSOUND_Sample_GetName(smp));
printf("====================================\n");
do
{
if (kbhit())
{
key = getch();
if (key == ‘s’){FSOUND_Stream_Stop(musique);}
if (key == ‘p’){FSOUND_Stream_Play(FSOUND_FREE, musique);}
}
FSOUND_GetCurrentLevels(channel, &l, &r);
amp = FSOUND_GetAmplitude(channel);
vuval = (l+r) * 0.5f;
vuval *= 18.0f;
printf("VU-left:%f VU-right:%f VU:%f AMP=%d \r",l,r,vuval,amp);
Sleep(10);
} while (key!=27);
FSOUND_Close();
return 0;
}
[/code:3lueqakr]

[b:3lueqakr]Second problem :[/b:3lueqakr]
I tried to take this code into QT application.
I’ve three files :
– a simple "main.cpp" to open and create QApplication.
– and "Window.h" and "Window.cpp" files.

My "Window.h" file :
[code:3lueqakr]
class Window : public QWidget
{
Q_OBJECT

public:
Window();
~Window(){}

public slots:
void play();
void stop();
void updateVU();

private:
QPushButton *m_boutonPlay;
QPushButton *m_boutonStop;
QTextEdit *m_log;
FSOUND_STREAM *musique;
int *channel;
QTimer *timer;
QLCDNumber *lcd;

};
[/code:3lueqakr]

In my "Window.cpp" file, I want to correctly implement play() and updateVU() methods :

[code:3lueqakr]
Window::Window()
{
// Qt Widgets
m_boutonPlay = new QPushButton ("Play", this);
m_boutonPlay->move(10, 10);
m_boutonStop = new QPushButton ("Stop", this);
m_boutonStop->move(10, 40);
m_log = new QTextEdit(this);
m_log->move(10,70);
lcd = new QLCDNumber(this);
lcd->move(100,10);
setWindowTitle("Test-Process");
resize(280,300);

// My sound
FSOUND_Init(44100, 1,0);
musique = FSOUND_Stream_Open(&quot;../../data/sound.wav&quot;, 0, 0, 0);
FSOUND_SetVolume(FSOUND_ALL, 120);

// Personnal timer
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateVU()));

// Connections
QObject::connect(m_boutonPlay, SIGNAL(clicked()), this, SLOT(play()));
QObject::connect(m_boutonStop, SIGNAL(clicked()), this, SLOT(stop()));

}

void Window::play()
{
int chan = FSOUND_Stream_Play(FSOUND_FREE, musique);
channel =&chan;
timer->start(50); // call updateVU() method every 50 msec.
}

void Window::stop()
{
FSOUND_Stream_Stop(musique);
timer->stop();
}

void Window::updateVU()
{
QString num;
float vuval, l, r;
FSOUND_GetCurrentLevels(*channel, &l, &r);
vuval = (l+r) * 0.5f;
vuval *= 18.0f;
num.setNum(vuval);
m_log->append(num);
lcd->display(num);
}
[/code:3lueqakr]

The result are wrong float numbers for VU with no changes.

I test with this solution :

[code:3lueqakr]
void Window::play()
{
int chan = FSOUND_Stream_Play(FSOUND_FREE, musique);
channel =&chan;
do
{
updateVU();
Sleep(50);
} while (FSOUND_IsPlaying(*channel));
}
[/code:3lueqakr]

The result are good float numbers (I think) but this kind of looping method freeze the application and don’t display numbers during sound’s playing.

Any suggestions would be sincerly welcome.
Thanks.

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.