0
0

I want to develop a voice chat software,but I can’t playback audio smooth,
this is my code:
[code:3lolz9h5]

include <vcl.h>

pragma hdrstop

include "fmod.h"

include "fmod_errors.h"

include "Unit4.h"

include <windows.h>

include <stdio.h>

include <conio.h>

include <math.h>

include <list.h>

//—————————————————————————

pragma package(smart_init)

pragma link "ACMWaveIO"

pragma resource "*.dfm"

TForm1 *Form1;

FMOD_SYSTEM *sys=NULL;
FMOD_SOUND *sound=NULL;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
FMOD_MODE mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_SOFTWARE;
FMOD_CREATESOUNDEXINFO createsoundexinfo;
unsigned int version;
int channels = 2;

std::list<unsigned char*>audio;

FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)
{
Form1->Memo1->Lines->Add(IntToStr(datalen));

if (datalen==9600)
{
    return FMOD_OK;
}

if (audio.size()==0)
{
    Form1-&gt;Memo1-&gt;Lines-&gt;Add(&quot;ERROR&quot;);
    memset(data,0,datalen);
    return FMOD_OK;
}
unsigned char *buf = audio.front();
memcpy(data,buf,4800);
audio.pop_front();
GlobalFree(buf);
return FMOD_OK;

}

FMOD_RESULT F_CALLBACK pcmsetposcallback(FMOD_SOUND sound, int subsound, unsigned int position, FMOD_TIMEUNIT postype)
{
/

This is useful if the user calls Sound::setPosition and you want to seek your data accordingly.
*/
Form1->Memo1->Lines->Add("pos");
return FMOD_OK;
}

//—————————————————————————
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//—————————————————————————

void __fastcall TForm1::Button1Click(TObject *Sender)
{
FMOD_System_Create(&sys);
FMOD_System_Init(sys, 32, FMOD_INIT_NORMAL, NULL);

memset(&amp;createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
createsoundexinfo.cbsize            = sizeof(FMOD_CREATESOUNDEXINFO);        
createsoundexinfo.decodebuffersize  = 1200;                                  
createsoundexinfo.length            = 4800*100;                              
createsoundexinfo.numchannels       = channels;                              
createsoundexinfo.defaultfrequency  = 8000;                                  
createsoundexinfo.format            = FMOD_SOUND_FORMAT_PCM16;               
createsoundexinfo.pcmreadcallback   = pcmreadcallback;                       
createsoundexinfo.pcmsetposcallback = pcmsetposcallback;                     

FMOD_System_SetOutput(sys,FMOD_OUTPUTTYPE_WINMM);
FMOD_System_SetStreamBufferSize(sys,480000,FMOD_TIMEUNIT_RAWBYTES);
FMOD_System_CreateStream(sys, 0, mode, &amp;createsoundexinfo, &amp;sound);
FMOD_System_PlaySound(sys, FMOD_CHANNEL_FREE, sound, 0, &amp;channel);

}
//—————————————————————————

void __fastcall TForm1::FormCreate(TObject *Sender)
{
ACMWaveIN1->OPEN();
}
//—————————————————————————

void __fastcall TForm1::ACMWaveIN1Data(TObject *Sender, PChar Data,
int Size)
{
if (!sound) return;

unsigned char *buf = (unsigned char*)GlobalAlloc(GPTR,4800);
memcpy(buf,Data,Size);
audio.push_back(buf);

FMOD_System_Update(sys);

}
//—————————————————————————

[/code:3lolz9h5]

audio format:
pcm16,8k HZ, 4800 bytes a sample.

  • You must to post comments
0
0

I logged the datalen,
It is 4800 bytes, expect the first time callback, is 9600 bytes.
[quote:2tm3z8mr]
createsoundexinfo.decodebuffersize = 1200; // important
createsoundexinfo.length = 4800*100; // important [/quote:2tm3z8mr]

  • You must to post comments
0
0

The problem is resolved,the wavein data is broken by total record
virtual sound card device driver,the fmod is perfect,thank you very much for your reply.
Regards.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.