1999-08-14 12:06:35 +00:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Name: sndulaw.cpp
|
|
|
|
// Purpose:
|
|
|
|
// Date: 08/11/1999
|
|
|
|
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
|
|
|
// CVSID: $Id$
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "sndulaw.cpp"
|
|
|
|
#endif
|
|
|
|
|
1999-08-17 17:51:33 +00:00
|
|
|
#include <wx/wxprec.h>
|
1999-08-14 12:06:35 +00:00
|
|
|
#include "sndbase.h"
|
|
|
|
#include "sndfile.h"
|
|
|
|
#include "sndpcm.h"
|
|
|
|
#include "sndulaw.h"
|
|
|
|
#include "g72x.h"
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxSoundFormatUlaw
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wxSoundFormatUlaw::wxSoundFormatUlaw()
|
|
|
|
: m_srate(22050)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSoundFormatUlaw::~wxSoundFormatUlaw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate)
|
|
|
|
{
|
|
|
|
m_srate = srate;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxUint32 wxSoundFormatUlaw::GetSampleRate() const
|
|
|
|
{
|
|
|
|
return m_srate;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSoundFormatBase *wxSoundFormatUlaw::Clone() const
|
|
|
|
{
|
|
|
|
wxSoundFormatUlaw *ulaw = new wxSoundFormatUlaw();
|
|
|
|
|
|
|
|
ulaw->m_srate = m_srate;
|
|
|
|
return ulaw;
|
|
|
|
}
|
|
|
|
|
1999-08-15 10:15:05 +00:00
|
|
|
wxUint32 wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes) const
|
1999-08-14 12:06:35 +00:00
|
|
|
{
|
|
|
|
return (bytes / m_srate);
|
|
|
|
}
|
|
|
|
|
1999-08-15 10:15:05 +00:00
|
|
|
wxUint32 wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time) const
|
1999-08-14 12:06:35 +00:00
|
|
|
{
|
|
|
|
return time * m_srate;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase& frmt2) const
|
|
|
|
{
|
|
|
|
wxSoundFormatUlaw *ulaw = (wxSoundFormatUlaw *)&frmt2;
|
|
|
|
|
|
|
|
if (frmt2.GetType() != wxSOUND_ULAW)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return (ulaw->m_srate != m_srate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxSoundStreamUlaw
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream& sndio)
|
|
|
|
: wxSoundStreamCodec(sndio)
|
|
|
|
{
|
|
|
|
// PCM converter
|
|
|
|
m_router = new wxSoundRouterStream(sndio);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSoundStreamUlaw::~wxSoundStreamUlaw()
|
|
|
|
{
|
|
|
|
delete m_router;
|
|
|
|
}
|
|
|
|
|
1999-08-27 17:40:40 +00:00
|
|
|
wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
|
1999-08-14 12:06:35 +00:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-08-27 17:40:40 +00:00
|
|
|
wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)
|
1999-08-14 12:06:35 +00:00
|
|
|
{
|
|
|
|
wxUint16 *old_linear;
|
|
|
|
register wxUint16 *linear_buffer;
|
|
|
|
register const wxUint8 *ulaw_buffer;
|
1999-08-27 17:40:40 +00:00
|
|
|
register wxUint32 countdown = len;
|
1999-08-14 12:06:35 +00:00
|
|
|
|
|
|
|
old_linear = linear_buffer = new wxUint16[len*2];
|
|
|
|
ulaw_buffer = (const wxUint8 *)buffer;
|
|
|
|
|
|
|
|
while (countdown != 0) {
|
|
|
|
*linear_buffer++ = ulaw2linear(*ulaw_buffer++);
|
|
|
|
countdown--;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_router->Write(old_linear, len * 2);
|
|
|
|
|
|
|
|
delete[] old_linear;
|
|
|
|
|
|
|
|
return *m_router;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format)
|
|
|
|
{
|
|
|
|
if (format.GetType() != wxSOUND_ULAW) {
|
|
|
|
m_snderror = wxSOUND_INVFRMT;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSoundFormatPcm pcm;
|
|
|
|
wxSoundFormatUlaw *ulaw;
|
|
|
|
|
|
|
|
wxSoundStreamCodec::SetSoundFormat(format);
|
|
|
|
|
|
|
|
ulaw = (wxSoundFormatUlaw *)m_sndformat;
|
|
|
|
|
|
|
|
pcm.SetSampleRate(ulaw->GetSampleRate());
|
|
|
|
pcm.SetBPS(16);
|
|
|
|
pcm.SetChannels(1);
|
|
|
|
pcm.Signed(TRUE);
|
|
|
|
pcm.SetOrder(wxBYTE_ORDER);
|
|
|
|
|
|
|
|
m_router->SetSoundFormat(pcm);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|