0
0

Hi
Im using following code for playing a avi sound :
[code:1ceb3zaq]
FMOD_RESULT ATSound::createStreamFromAvi(FMOD_MODE mode)
{
FMOD_RESULT result=FMOD_ERR_FILE_BAD;
PAVIFILE pAviFile;
//AVIFILEINFO avi_file_info;
PAVISTREAM pAudio;
AVISTREAMINFO stream_info;
LPBYTE pBuffer;

/*fmod definitions*/ 
FMOD_CREATESOUNDEXINFO exinfo; 
/*********************************************************************************************************/ 

/*begin AVI read functions*/ 
AVIFileOpen(&pAviFile, filename.c_str(), OF_READ, NULL);//open somefile.avi 

//open the audio stream 
if(AVIFileGetStream(pAviFile,&pAudio,streamtypeAUDIO,0)) 
{ 
    ATSoundSystem::errcheck(this,"ATSound,AVIFileGetStream,Error getting audio stream.",result); 
} 

//get some info about the stream 
if(AVIStreamInfo(pAudio, &stream_info, sizeof(stream_info))) 
{ 
    ATSoundSystem::errcheck(this,"ATSound,AVIStreamInfo,Error getting avi stream info.",result); 
} 

long Samples_per_second = stream_info.dwRate/stream_info.dwScale; 
float Length_in_seconds = (float)stream_info.dwLength * (float)stream_info.dwScale/(float)stream_info.dwRate; 
float buffersize=Length_in_seconds * (float)Samples_per_second; /*figure out how large the buffer has too be here*/ 

/* puts("AVISTREAMINFO:");
printf("Scale is %ld \n",stream_info.dwScale);
printf("Rate is %ld \n",stream_info.dwRate);
printf("Start is %ld \n",stream_info.dwStart);
printf("Length is %ld \n",stream_info.dwLength);
printf("Rate in samples per second is %ld \n",Samples_per_second);
printf("Length in seconds is %.02f \n",Length_in_seconds);
printf("Buffer is length x rate = %.02f samples \n",Length_in_seconds(float)Samples_per_second );
printf("Audio skew is %ld \n",stream_info.dwInitialFrames);
printf("Suggested buffer size is %ld \n",stream_info.dwSuggestedBufferSize);
*/
long aSize; //get the size of the audio stream
/
start of sound ini*/
if(AVIStreamReadFormat(pAudio,AVIStreamStart(pAudio),NULL,&aSize))
{
ATSoundSystem::errcheck(this,"ATSound,AVIStreamReadFormat,Error with stream format.",result);
}
LPBYTE pChunk = new BYTE[aSize];
if(AVIStreamReadFormat(pAudio,AVIStreamStart(pAudio),pChunk,&aSize))
{
ATSoundSystem::errcheck(this,"ATSound,AVIStreamReadFormat(pChunk),Error with stream format.",result);
}

LPWAVEFORMATEX pWaveFormatex = (LPWAVEFORMATEX) pChunk; 

/* puts("Wave format data: ");
printf("Format tag is 0 x %x \n",pWaveFormatex->wFormatTag);
printf("Number of channels are %d \n",pWaveFormatex->nChannels);
printf("Bits per sample are %d \n",pWaveFormatex->wBitsPerSample);
printf("Samples per second are %ld \n",pWaveFormatex->nSamplesPerSec);
printf("Average bytes per second are %ld \n",pWaveFormatex->nAvgBytesPerSec);
printf("Block Align is %d \n",pWaveFormatex->nBlockAlign);
printf("CB size is %d \n",pWaveFormatex->cbSize);
*/

long lASize; 
if(AVIStreamRead(pAudio,0,(LONG)buffersize,NULL,0,&lASize,NULL)) 
{ 
    ATSoundSystem::errcheck(this,"ATSound,AVIStreamRead,Error with stream read.",result); 
} 

/*
printf("Buffer size is %ld. \n",lASize);
*/

long plSamples; 
long plBytes; 

pBuffer = new BYTE[lASize];//create buffer for audio 

if(AVIStreamRead(pAudio,0,(LONG)buffersize,pBuffer,lASize,&plBytes,&plSamples)) 
{ 
    ATSoundSystem::errcheck(this,"ATSound,AVIStreamRead,Error.",result); 
} 

/* printf("The number of samples read were %ld \n",plSamples);
printf("The number of bytes read were %ld \n",plBytes);
/
/
start loading sound stream into Fmod/
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.length = lASize;
/
exinfo.format=FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency=44100;
exinfo.suggestedsoundtype=FMOD_SOUND_TYPE_WAV;
*/
result = ATSoundSystem::getSystem()->createStream((const char *)pBuffer ,FMOD_SOFTWARE | FMOD_OPENMEMORY |FMOD_2D | FMOD_CREATECOMPRESSEDSAMPLE | FMOD_LOWMEM, &exinfo , &sound);
return result;
}
[/code:1ceb3zaq]

Always i have FMOD_ERR_FORMAT error after running ATSoundSystem::getSystem()->createStream()! i don’t know how can i solve the error, i very tried!
My avi format :
Audio: 44,100 Hz, 16 Bit, Stereo (wav uncompressed)
Video: 25.000 fps, 1024x768x24

Thank you for any help.
H.Ahmadi

  • You must to post comments
0
0

FMOD_CREATECOMPRESSEDSAMPLE and createStream are mutually exclusive. Streams can read compressed data anyway so this flag isn’t necessary.

The way you’re creating an in memory buffer and calling createStream, there isn’t any way to know when FMOD has got to the end of the buffer and needs more data. The FMOD_CREATESOUNDEXINFO struct contains callbacks for that purpose. You can specifiy the name_or_data parameter to be zero and then supply FMOD with data using those callbacks. There is example usage in manualdecode example.

-Pete

  • You must to post comments
0
0

[quote="peter":1ckqnwsl]FMOD_CREATECOMPRESSEDSAMPLE and createStream are mutually exclusive. Streams can read compressed data anyway so this flag isn’t necessary.[/quote:1ckqnwsl]
Removing of it don’t solve the error.
here is new statement that also have the error:
result = ATSoundSystem::getSystem()->createStream((const char *)pBuffer ,FMOD_OPENMEMORY, &exinfo , &sound);

Also this may can help you that what is my problem:
Aftre reading wave buffer from a AVI file, the buffer is not contain a correct wave header!
https://ccrma.stanford.edu/courses/422/ … aveFormat/
I mean that in first of the buffer there is no "riff" words!

Note: I traced all of source lines, all things is correct and even pWaveFormatex is contain correct information about the AVI wave file. Seems that the only problem is in createStream that can not create sound from the stream!
[quote="peter":1ckqnwsl]
The way you’re creating an in memory buffer and calling createStream, there isn’t any way to know when FMOD has got to the end of the buffer and needs more data. The FMOD_CREATESOUNDEXINFO struct contains callbacks for that purpose. You can specifiy the name_or_data parameter to be zero and then supply FMOD with data using those callbacks. There is example usage in manualdecode example.
-Pete[/quote:1ckqnwsl]
Thanks for your tips.
In Examples i have no example with name of "manualdecode", is it only in new version? Im using FMod 30/01/09 4.22.02

Best Regards.
H.Ahmadi

  • You must to post comments
0
0

Ok that example was added in April ’09 so that would explain why you don’t have it. I reccomend you download a newer version of the API just to look at that example, it has everything you need.

  • You must to post comments
0
0

[quote="peter":pexfe2cf]Ok that example was added in April ’09 so that would explain why you don’t have it. I reccomend you download a newer version of the API just to look at that example, it has everything you need.[/quote:pexfe2cf]
After download and looking on the project im understand allthings in FMOD side, but what about extracting sound part of AVI?
The code that captured from one thread from this froum seems don’t work and FMOD always return FMOD_ERR_FORMAT.
I tested all settings and parameters from "manualdecode " project over it but also don’t work. I also tried on google with some existing source code for OpenAL but the same code with my video and FMOD return FMOD_ERR_FORMAT.
Can you help me more about extracting and streaming the sound part of AVI and if the code is correct why i have error!?

Thank you for your attention.
H.Ahmadi

  • You must to post comments
0
0

I would recommend you try working it the other way, try putting the AVI reading code into the manual decode example. So take the code where you get the sound buffer from the AVI file and put that into the PCM read callback.

-Pete

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.