0
0

Hi,

At first I play background song and record wav file at the same time. Next I play background song parallel with recorded wav. In the beginning voices are synchronized, but after 20 seconds one can hear the difference: record is more and more ahead of background song. After playing them 90 seconds difference can be nearly 1 second.

For testing purpose I play background song from the speaker so background song is actually recorded through microphone and hearing the difference is confident. It’s not in my head. ๐Ÿ˜› I’m using PockePC 2003 SE.

Some snippets from the code:

For recording I use:
[code:3qb00zr1]fsoundRecSample = FSOUND_Sample_Alloc(FSOUND_FREE, RECORDRATE, FSOUND_MONO | FSOUND_16BITS | FSOUND_LOOP_NORMAL, RECORDRATE, 255, 128, 255);
signed char record = FSOUND_Record_StartSample(fsoundRecSample, TRUE);[/code:3qb00zr1]
I have a thread where I save voice into wav file like in recordtodisk example. Recording is all good except if my synchronizing bug might be in there.

Playing is simple:
[code:3qb00zr1]fsoundRecord = FSOUND_Stream_Open(stRecordFileName, 0, 0, 0);
fsoundSong = FSOUND_Stream_Open(stSongFileName, 0, 0, 0);
FSOUND_Stream_Play(FSOUND_FREE, fsoundRecord);
FSOUND_Stream_Play(FSOUND_FREE, fsoundSong);[/code:3qb00zr1]

I also tried to see if there is difference during play:
[code:3qb00zr1]FSOUND_Stream_GetTime(fsoundSong),
FSOUND_Stream_GetTime(fsoundRecord)[/code:3qb00zr1]
But no growing difference in there.

Any suggestions what might go wrong or how to fix? Or could this be some kind of a bug in FMOD?

  • You must to post comments
0
0

On the second thought problem might be in recording. Background song is 89133ms and recorded wav is 88324ms. Shorter background song is 13067ms and recorded wav 12905ms. So there is dynamic increase of differences..

Pretty same ratios:
89 133 / 88 324 = 1.00915946
13 067 / 12 905 = 1.01255327

Where does data lose.. ๐Ÿ˜•

  • You must to post comments
0
0

Can someone notice any bugs:
[code:2imw64z6] unsigned int len1 = 0, len2 = 0;
void *ptr1= NULL, *ptr2 = NULL;
int blocklength = 0;
unsigned int recordpos = 0, lastrecordpos = 0;
unsigned int soundlength;
unsigned int ElapsedSeconds = 0;
DataLength = 0;

    WriteWavHeader();

    soundlength = FSOUND_Sample_GetLength(fsoundRecSample);

    do
    {  
        recordpos = FSOUND_Record_GetPosition();

        if (recordpos != lastrecordpos)
        {
            blocklength = (int)recordpos - (int)lastrecordpos;

            if (blocklength < 0)
            {
                blocklength += soundlength;
            }

            FSOUND_Sample_Lock(fsoundRecSample,
                lastrecordpos * NUMBEROFCHANNELS * 2, 
                blocklength * NUMBEROFCHANNELS * 2,
                &ptr1, &ptr2, &len1, &len2);

            if (ptr1 && len1)
            {
                //Calculate sum of written data
                DataLength += fwrite(ptr1, 1, len1, flRecord);
            }
            if (ptr2 && len2)
            {
                //Calculate sum of written data
                DataLength += fwrite(ptr2, 1, len2, flRecord);
            }

            FSOUND_Sample_Unlock(fsoundRecSample, ptr1, ptr2, len1, len2);

        }

        lastrecordpos = recordpos;
        Sleep(10);

    } while ((Recording == RUNNING) && (FSOUND_Stream_GetTime(fsoundStream1) < songLengthMilliSeconds));

    FSOUND_Record_Stop();
    WriteWavHeader();
    fclose(flRecord);[/code:2imw64z6]

Personally I wonder why or when blocklength is negative:
[code:2imw64z6]if (blocklength < 0)
{
blocklength += soundlength;
}[/code:2imw64z6]

And why second and third parameter is multiplied by two:
[code:2imw64z6]SOUND_Sample_Lock(fsoundRecSample,
lastrecordpos * NUMBEROFCHANNELS * 2,
blocklength * NUMBEROFCHANNELS * 2,
&ptr1, &ptr2, &len1, &len2);[/code:2imw64z6]

  • You must to post comments
0
0

if you are using a recording device instead of simply ripping the output directly from fmod, you will get possible differences in hardware. The way you are doing it is probably never going to be accurate.

  • You must to post comments
0
0

[quote="brett":1o2pz04b]if you are using a recording device instead of simply ripping the output directly from fmod, you will get possible differences in hardware. The way you are doing it is probably never going to be accurate.[/quote:1o2pz04b]

Do you mean: Recording device == PocketPC microphone?

I have no intention to rip output, I just recorded without headphones to actually hear the real difference. If I record with headphones and make my own noices, I still can notice difference, especially in the end.

Point is that if I record total time of 89133ms, should I not get record with the lenght of 89133ms? :)

Or how else there is possible to lose data regular if not in "savetofile"-function?

If there is no way to fix this properly, I’m going to try put some extra data equally in the file during recording. Any suggestion what data should I try to put so it would disturb as little as possible?

  • You must to post comments
0
0

[quote="Surur":2vfw46yi]I’m going to try put some extra data equally in the file during recording. Any suggestion what data should I try to put so it would disturb as little as possible?[/quote:2vfw46yi]

So I made changes into code and the length of the record is satisfactory:
[code:2vfw46yi]...
if ( ptr2 && len2 )
{
DataLength += fwrite(ptr2, 1, len2, flRecord);
}

//Write silence to replace missing data
for (int i = 0; i < 9; i++)
{
putc(0x00, flRecord);
putc(0x00, flRecord);
DataLength += 2;
}

FSOUND_Sample_Unlock(fsoundRecSample, ptr1, ptr2, len1, len2);
...[/code:2vfw46yi]

But you can hear small flaws in the record. Any ideas?

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.