• Advertisement
Sign in to follow this  

DirectXAudio

This topic is 4342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, i am writing a wrapper for DirectxSudio and so far it works fine, but i wanted to use a Resourcefile loader for the audio files now and so i got the file in memory now in a char* variable. So far i have been useing the folowing code to load the sound from a file.
  if (FAILED(lpLoader->LoadObjectFromFile(
        CLSID_DirectMusicSegment,  
        IID_IDirectMusicSegment8,  
        wstrFileName,              
        (LPVOID*) &lpSegBackgroundMusic)))
    {
        MessageBox( NULL, "Fehler beim Laden der Datei", 
                          "AddBackgroundMusic", MB_OK );   
    }

Can anyone tell me how i load the soundfile when the file is already loaded to memory? thx a lot in advance!

Share this post


Link to post
Share on other sites
Advertisement
thx a lot dave

this is what i came up with:


bool FBSSoundManager::Load(bool BGSound, std::string ResourceName, std::string FileName){
FBSFileLoaderInterface* File = new FBSFileLoaderInterface();
if(!File->Open(ResourceName.c_str())){
FBSLogFile::WriteToLog("EngineLog.txt", "Could not open Sound Resource");
return false;
}
int size = File->GetResourceSize(FileName);
Allocate(size);
std::string data;
data = File->GetResource(FileName);

DMUS_OBJECTDESC objDesc;
objDesc.dwSize = sizeof(DMUS_OBJECTDESC);
objDesc.guidClass = CLSID_DirectMusicSegment;
objDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY;
objDesc.pbMemData = (BYTE *) data.c_str();
objDesc.llMemLength = size;


FBSSound* temp = new FBSSound();
temp->SetSize(size);
temp->SetResourceFileName(ResourceName);
float Time = timeGetTime()/100;
temp->SetAccess(Time);



IDirectMusicSegment8* tempSound;
m_lpLoader->GetObject(&objDesc, IID_IDirectMusicSegment8, (void**) &tempSound);
tempSound->Download(m_lpPerformance);

if(BGSound == false){
temp->SetSound(tempSound);
m_PrioMap.insert(PrioValType(Time,FileName));
m_SoundMap.insert(SoundMapValType(FileName,temp));
}else{
m_lpSegBackgroundMusic = tempSound;
}
File->Close();
return true;
}







the program crashes at:

m_lpLoader->GetObject(&objDesc, IID_IDirectMusicSegment8, (void**) &tempSound);


any idea why this is?:)

[Edited by - Rozik on April 6, 2006 5:44:41 PM]

Share this post


Link to post
Share on other sites
I have a feeling it might have to do with trying to store sound data in a std::string. It may also be that m_lpLoader is NULL. If you run the program though your debugger it should give you a pretty good idea of what's going wrong there.

Share this post


Link to post
Share on other sites
Ok i ran the debugger

what made the comp crash was this line of code:

tempSound->Download(m_lpPerformance);

Now the system doesnt crash but i dont get any sound

the loader is not NULL

i try to play the sound like this:

m_lpPerformance->PlaySegmentEx(
tempSound, // abzuspielendes Segment
NULL,
NULL,
DMUS_SEGF_SECONDARY, // im sekundären Buffer
0, // Stelle, an der gestartet werden soll
NULL,
NULL,
NULL
);

the value of the tempSound is 0xcccccccc which doesnt look right.

the zipfile loader i am using was written to load images and returns the data in char* i store that in a string till i create the object
not sur eif i handle that the right way:)

any ideas please?

Share this post


Link to post
Share on other sites
That 0xcccccccc is a value placed by the debugger into uninitialized pointers. So, basically your attempt to create the segment is failing.

I'm pretty sure it's because of you're trying to store your sound data into a std::string. Since sound data can contain valid zero-bytes, the string is probably truncating your sound data at the first zero it encounters. You should be allocating a block of memory to hold the sound data and passing a pointer to that block into the DMUS_OBJECTDESC structure. Once the segment is created, you can deallocate that memory block.

Share this post


Link to post
Share on other sites
that sounds good:9

but sorry i am a newb:) how cna i do something like that?

would it help if i used char* instead of string?

Share this post


Link to post
Share on other sites
Are you using the proper error-checking techniques for those method calls? Crashing may be a result of un-intitialized interfaces due to a previously failed creation. Another to check on: DirectAudio uses wide characters for text input and as I recall, when I tried using 8-bit strings it simply caused the application to crash. Try converting to "std::string" or "wchar_t".

Share this post


Link to post
Share on other sites
well i dont think the path is a problem since the data is already in memory

i ran the debugger like a million times now and centered it down to one point i think

when i do this:


int size;
size = FBSZipFileInterface::instance()->GetZipObjectSize(ResourceName,FileName);
Allocate(size);
char * data = FBSZipFileInterface::instance()->LoadZipObject(ResourceName,FileName);

DMUS_OBJECTDESC objDesc;
objDesc.dwSize = sizeof(DMUS_OBJECTDESC);
objDesc.guidClass = CLSID_DirectMusicSegment;
objDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY;
objDesc.pbMemData = (LPBYTE)data;
objDesc.llMemLength = size;



i get an bad pointer for pbMemData even though data seems to be valid

+ data 0x00b56c80 "RIFF¢" char *
+ objDesc.pbMemData 0xcccccccc <Bad Ptr> unsigned char *

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement