mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-12 19:18:20 +00:00
Use ReadFile
to read opus sounds in editor
This commit is contained in:
parent
0a463320cf
commit
de2744cb2a
|
@ -3744,36 +3744,26 @@ void CEditor::AddSound(const char *pFileName, int StorageType, void *pUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load external
|
// load external
|
||||||
IOHANDLE SoundFile = pEditor->Storage()->OpenFile(pFileName, IOFLAG_READ, StorageType);
|
void *pData;
|
||||||
if(!SoundFile)
|
unsigned DataSize;
|
||||||
|
if(!pEditor->Storage()->ReadFile(pFileName, StorageType, &pData, &DataSize))
|
||||||
{
|
{
|
||||||
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the whole file into memory
|
|
||||||
int DataSize = io_length(SoundFile);
|
|
||||||
|
|
||||||
if(DataSize <= 0)
|
|
||||||
{
|
|
||||||
io_close(SoundFile);
|
|
||||||
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *pData = malloc((unsigned)DataSize);
|
|
||||||
io_read(SoundFile, pData, (unsigned)DataSize);
|
|
||||||
io_close(SoundFile);
|
|
||||||
|
|
||||||
// load sound
|
// load sound
|
||||||
int SoundId = pEditor->Sound()->LoadOpusFromMem(pData, (unsigned)DataSize, true);
|
int SoundId = pEditor->Sound()->LoadOpusFromMem(pData, (unsigned)DataSize, true);
|
||||||
if(SoundId == -1)
|
if(SoundId == -1)
|
||||||
|
{
|
||||||
|
free(pData);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// add sound
|
// add sound
|
||||||
CEditorSound *pSound = new CEditorSound(pEditor);
|
CEditorSound *pSound = new CEditorSound(pEditor);
|
||||||
pSound->m_SoundID = SoundId;
|
pSound->m_SoundID = SoundId;
|
||||||
pSound->m_DataSize = (unsigned)DataSize;
|
pSound->m_DataSize = DataSize;
|
||||||
pSound->m_pData = pData;
|
pSound->m_pData = pData;
|
||||||
str_copy(pSound->m_aName, aBuf, sizeof(pSound->m_aName));
|
str_copy(pSound->m_aName, aBuf, sizeof(pSound->m_aName));
|
||||||
pEditor->m_Map.m_vpSounds.push_back(pSound);
|
pEditor->m_Map.m_vpSounds.push_back(pSound);
|
||||||
|
@ -3796,27 +3786,14 @@ void CEditor::ReplaceSound(const char *pFileName, int StorageType, void *pUser)
|
||||||
CEditor *pEditor = (CEditor *)pUser;
|
CEditor *pEditor = (CEditor *)pUser;
|
||||||
|
|
||||||
// load external
|
// load external
|
||||||
IOHANDLE SoundFile = pEditor->Storage()->OpenFile(pFileName, IOFLAG_READ, StorageType);
|
void *pData;
|
||||||
if(!SoundFile)
|
unsigned DataSize;
|
||||||
|
if(!pEditor->Storage()->ReadFile(pFileName, StorageType, &pData, &DataSize))
|
||||||
{
|
{
|
||||||
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the whole file into memory
|
|
||||||
int DataSize = io_length(SoundFile);
|
|
||||||
|
|
||||||
if(DataSize <= 0)
|
|
||||||
{
|
|
||||||
io_close(SoundFile);
|
|
||||||
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFileName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *pData = malloc((unsigned)DataSize);
|
|
||||||
io_read(SoundFile, pData, (unsigned)DataSize);
|
|
||||||
io_close(SoundFile);
|
|
||||||
|
|
||||||
CEditorSound *pSound = pEditor->m_Map.m_vpSounds[pEditor->m_SelectedSound];
|
CEditorSound *pSound = pEditor->m_Map.m_vpSounds[pEditor->m_SelectedSound];
|
||||||
|
|
||||||
// unload sample
|
// unload sample
|
||||||
|
|
|
@ -545,24 +545,11 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
|
||||||
str_format(aBuf, sizeof(aBuf), "mapres/%s.opus", pName);
|
str_format(aBuf, sizeof(aBuf), "mapres/%s.opus", pName);
|
||||||
|
|
||||||
// load external
|
// load external
|
||||||
IOHANDLE SoundFile = pStorage->OpenFile(pName, IOFLAG_READ, IStorage::TYPE_ALL);
|
if(pStorage->ReadFile(pName, IStorage::TYPE_ALL, &pSound->m_pData, &pSound->m_DataSize))
|
||||||
if(SoundFile)
|
|
||||||
{
|
|
||||||
// read the whole file into memory
|
|
||||||
pSound->m_DataSize = io_length(SoundFile);
|
|
||||||
|
|
||||||
if(pSound->m_DataSize > 0)
|
|
||||||
{
|
|
||||||
pSound->m_pData = malloc(pSound->m_DataSize);
|
|
||||||
io_read(SoundFile, pSound->m_pData, pSound->m_DataSize);
|
|
||||||
}
|
|
||||||
io_close(SoundFile);
|
|
||||||
if(pSound->m_DataSize > 0)
|
|
||||||
{
|
{
|
||||||
pSound->m_SoundID = m_pEditor->Sound()->LoadOpusFromMem(pSound->m_pData, pSound->m_DataSize, true);
|
pSound->m_SoundID = m_pEditor->Sound()->LoadOpusFromMem(pSound->m_pData, pSound->m_DataSize, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pSound->m_DataSize = pItem->m_SoundDataSize;
|
pSound->m_DataSize = pItem->m_SoundDataSize;
|
||||||
|
|
Loading…
Reference in a new issue