Removed unnecessary code from utilsunx.cpp
Corrected the support for seeking in wxSoundFileStream. Added support for seeking in wxMultimediaBoard Reindentation of the code (conforming or nearly to the coding standard) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -31,11 +31,13 @@
|
||||
wxSoundAiff::wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
m_base_offset = wxInvalidOffset;
|
||||
}
|
||||
|
||||
wxSoundAiff::wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
m_base_offset = wxInvalidOffset;
|
||||
}
|
||||
|
||||
wxSoundAiff::~wxSoundAiff()
|
||||
@@ -49,133 +51,142 @@ wxString wxSoundAiff::GetCodecName() const
|
||||
|
||||
bool wxSoundAiff::CanRead()
|
||||
{
|
||||
wxUint32 signature1, signature2, len;
|
||||
|
||||
if (m_input->Read(&signature1, 4).LastRead() != 4)
|
||||
return FALSE;
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature1) != FORM_SIGNATURE) {
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Read(&len, 4);
|
||||
if (m_input->LastRead() != 4) {
|
||||
m_input->Ungetch(&len, m_input->LastRead());
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_input->Read(&signature2, 4).LastRead() != 4) {
|
||||
m_input->Ungetch(&signature2, m_input->LastRead());
|
||||
wxUint32 signature1, signature2, len;
|
||||
|
||||
if (m_input->Read(&signature1, 4).LastRead() != 4)
|
||||
return FALSE;
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature1) != FORM_SIGNATURE) {
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Read(&len, 4);
|
||||
if (m_input->LastRead() != 4) {
|
||||
m_input->Ungetch(&len, m_input->LastRead());
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_input->Read(&signature2, 4).LastRead() != 4) {
|
||||
m_input->Ungetch(&signature2, m_input->LastRead());
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Ungetch(&signature2, 4);
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Ungetch(&signature2, 4);
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
|
||||
if (
|
||||
wxUINT32_SWAP_ON_BE(signature2) != AIFF_SIGNATURE &&
|
||||
wxUINT32_SWAP_ON_BE(signature2) != AIFC_SIGNATURE)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
||||
if (
|
||||
wxUINT32_SWAP_ON_BE(signature2) != AIFF_SIGNATURE &&
|
||||
wxUINT32_SWAP_ON_BE(signature2) != AIFC_SIGNATURE)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#define FAIL_WITH(condition, err) if (condition) { m_snderror = err; return FALSE; }
|
||||
|
||||
bool wxSoundAiff::PrepareToPlay()
|
||||
{
|
||||
wxDataInputStream data(*m_input);
|
||||
wxUint32 signature, len, ssnd;
|
||||
bool end_headers;
|
||||
|
||||
if (!m_input) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
data.BigEndianOrdered(TRUE);
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != FORM_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "FORM"
|
||||
|
||||
len = data.Read32();
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
// dummy len
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(
|
||||
wxUINT32_SWAP_ON_BE(signature) != AIFF_SIGNATURE &&
|
||||
wxUINT32_SWAP_ON_BE(signature) != AIFC_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "AIFF" / "AIFC"
|
||||
|
||||
end_headers = FALSE;
|
||||
while (!end_headers) {
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
len = data.Read32();
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
switch (wxUINT32_SWAP_ON_BE(signature)) {
|
||||
case COMM_SIGNATURE: { // "COMM"
|
||||
wxUint16 channels, bps;
|
||||
wxUint32 num_samples;
|
||||
double srate;
|
||||
wxSoundFormatPcm sndformat;
|
||||
|
||||
data >> channels >> num_samples >> bps >> srate;
|
||||
|
||||
sndformat.SetSampleRate((wxUint32) srate);
|
||||
sndformat.SetBPS(bps);
|
||||
sndformat.SetChannels(channels);
|
||||
sndformat.Signed(FALSE);
|
||||
sndformat.SetOrder(wxBIG_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
wxDataInputStream data(*m_input);
|
||||
wxUint32 signature, len, ssnd;
|
||||
bool end_headers;
|
||||
|
||||
if (!m_input) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
m_input->SeekI(len-18, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
case SSND_SIGNATURE: { // "SSND"
|
||||
data >> ssnd;
|
||||
// m_input->SeekI(4, wxFromCurrent); // Pass an INT32
|
||||
// m_input->SeekI(len-4, wxFromCurrent); // Pass the rest
|
||||
m_input->SeekI(ssnd + 4, wxFromCurrent);
|
||||
FinishPreparation(len - 8);
|
||||
end_headers = TRUE;
|
||||
break;
|
||||
|
||||
data.BigEndianOrdered(TRUE);
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != FORM_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "FORM"
|
||||
|
||||
len = data.Read32();
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
// dummy len
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(
|
||||
wxUINT32_SWAP_ON_BE(signature) != AIFF_SIGNATURE &&
|
||||
wxUINT32_SWAP_ON_BE(signature) != AIFC_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "AIFF" / "AIFC"
|
||||
|
||||
end_headers = FALSE;
|
||||
while (!end_headers) {
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
len = data.Read32();
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
switch (wxUINT32_SWAP_ON_BE(signature)) {
|
||||
case COMM_SIGNATURE: { // "COMM"
|
||||
wxUint16 channels, bps;
|
||||
wxUint32 num_samples;
|
||||
double srate;
|
||||
wxSoundFormatPcm sndformat;
|
||||
|
||||
data >> channels >> num_samples >> bps >> srate;
|
||||
|
||||
sndformat.SetSampleRate((wxUint32) srate);
|
||||
sndformat.SetBPS(bps);
|
||||
sndformat.SetChannels(channels);
|
||||
sndformat.Signed(FALSE);
|
||||
sndformat.SetOrder(wxBIG_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
m_input->SeekI(len-18, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
case SSND_SIGNATURE: { // "SSND"
|
||||
data >> ssnd;
|
||||
// m_input->SeekI(4, wxFromCurrent); // Pass an INT32
|
||||
// m_input->SeekI(len-4, wxFromCurrent); // Pass the rest
|
||||
m_input->SeekI(ssnd + 4, wxFromCurrent);
|
||||
m_base_offset = m_input->TellI();
|
||||
FinishPreparation(len - 8);
|
||||
end_headers = TRUE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundAiff::PrepareToRecord(unsigned long time)
|
||||
bool wxSoundAiff::PrepareToRecord(wxUint32 time)
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxSoundAiff::FinishRecording()
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxSoundAiff::RepositionStream(wxUint32 position)
|
||||
{
|
||||
if (m_base_offset == wxInvalidOffset)
|
||||
return FALSE;
|
||||
m_input->SeekI(m_base_offset, wxFromStart);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxUint32 wxSoundAiff::GetData(void *buffer, wxUint32 len)
|
||||
{
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
}
|
||||
|
||||
wxUint32 wxSoundAiff::PutData(const void *buffer, wxUint32 len)
|
||||
{
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user