I am programming a lip-sync software for animation.
I take a .wav file, and split its 44100 samples pr.sec into 25 or 30 equally big chunks, depending on chosen frames pr. sec.
I have a QTableWidget, where I can enter characters for every frame. Every character is mapped with a picture of a mouth, and when I press SPACE I hear the audio, and see the pictures in sync with the audio. No problems
When I want to search in the audio, frame by frame, I can do it with the up/down-arrow keys. It works if I press these keys two or three times pr. sec., but if I hold one of the keys down, the application crashes. Why?
I would like to avoid hacks like sleep-functions, but what should I do?
Here is the code that plays the active frame.
mouthFrame = activeFrame;
QFile audioFil
(audioFileName
);
int offset = dataOffset + 8 + ((activeFrame - 1) * samplesPerFrame * blockAlign);
audioFil.seek(offset);
ba = audioFil.read(i * samplesPerFrame * blockAlign );
audioFil.close();
output = new QAudioOutput(format,this);
output->start(audioBuffer);
output->setNotifyInterval(1000/fps);
connect(output, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
connect(output, SIGNAL(notify()),this, SLOT(showMouth()));
do {
loop.exec();
} while(output->state() == QAudio::ActiveState);
output->stop();
audioBuffer->close();
delete output;
mouthFrame = activeFrame;
QFile audioFil(audioFileName);
if (audioFil.open(QIODevice::ReadOnly)){
int offset = dataOffset + 8 + ((activeFrame - 1) * samplesPerFrame * blockAlign);
audioFil.seek(offset);
ba = audioFil.read(i * samplesPerFrame * blockAlign );
audioFil.close();
QBuffer* audioBuffer = new QBuffer(&ba);
audioBuffer->open(QIODevice::ReadOnly);
output = new QAudioOutput(format,this);
output->start(audioBuffer);
output->setNotifyInterval(1000/fps);
QEventLoop loop;
connect(output, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
connect(output, SIGNAL(notify()),this, SLOT(showMouth()));
do {
loop.exec();
} while(output->state() == QAudio::ActiveState);
output->stop();
audioBuffer->close();
delete output;
To copy to clipboard, switch view to plain text mode
As I said, it works if you're patient...
Could it be improved?
David
Bookmarks