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:
parent
a9c3ed030e
commit
794bcc2dea
@ -45,3 +45,4 @@ You need to move the three files included in this directory:
|
||||
- utilsunx.cpp => src/unix
|
||||
- process.cpp => src/common
|
||||
- process.h => include/wx
|
||||
- utilsexc.cpp => src/msw
|
||||
|
@ -69,64 +69,66 @@
|
||||
|
||||
class MMBoardSoundFile: public MMBoardFile {
|
||||
public:
|
||||
MMBoardSoundFile(const wxString& filename);
|
||||
~MMBoardSoundFile();
|
||||
|
||||
bool NeedWindow();
|
||||
|
||||
void SetWindow(wxWindow *window);
|
||||
|
||||
void Play();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Stop();
|
||||
|
||||
MMBoardTime GetPosition();
|
||||
MMBoardTime GetLength();
|
||||
|
||||
bool IsStopped();
|
||||
bool IsPaused();
|
||||
|
||||
wxString GetStringType();
|
||||
wxString GetStringInformation();
|
||||
|
||||
MMBoardSoundFile(const wxString& filename);
|
||||
~MMBoardSoundFile();
|
||||
|
||||
bool NeedWindow();
|
||||
|
||||
void SetWindow(wxWindow *window);
|
||||
|
||||
void Play();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Stop();
|
||||
|
||||
MMBoardTime GetPosition();
|
||||
MMBoardTime GetLength();
|
||||
void SetPosition(MMBoardTime btime);
|
||||
|
||||
bool IsStopped();
|
||||
bool IsPaused();
|
||||
|
||||
wxString GetStringType();
|
||||
wxString GetStringInformation();
|
||||
|
||||
protected:
|
||||
wxSoundFileStream *GetDecoder();
|
||||
wxSoundFileStream *GetDecoder();
|
||||
|
||||
wxSoundStream *m_output_stream;
|
||||
wxInputStream *m_input_stream;
|
||||
wxSoundFileStream *m_file_stream;
|
||||
|
||||
wxSoundStream *m_output_stream;
|
||||
wxInputStream *m_input_stream;
|
||||
wxSoundFileStream *m_file_stream;
|
||||
|
||||
MMBoardTime m_length;
|
||||
wxUint8 m_file_type;
|
||||
MMBoardTime m_length;
|
||||
wxUint8 m_file_type;
|
||||
};
|
||||
|
||||
class MMBoardVideoFile: public MMBoardFile {
|
||||
public:
|
||||
MMBoardVideoFile(const wxString& filename);
|
||||
~MMBoardVideoFile();
|
||||
|
||||
bool NeedWindow();
|
||||
|
||||
void SetWindow(wxWindow *window);
|
||||
|
||||
void Play();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Stop();
|
||||
|
||||
MMBoardTime GetPosition();
|
||||
MMBoardTime GetLength();
|
||||
|
||||
bool IsStopped();
|
||||
bool IsPaused();
|
||||
|
||||
wxString GetStringType();
|
||||
wxString GetStringInformation();
|
||||
|
||||
MMBoardVideoFile(const wxString& filename);
|
||||
~MMBoardVideoFile();
|
||||
|
||||
bool NeedWindow();
|
||||
|
||||
void SetWindow(wxWindow *window);
|
||||
|
||||
void Play();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Stop();
|
||||
|
||||
MMBoardTime GetPosition();
|
||||
MMBoardTime GetLength();
|
||||
void SetPosition(MMBoardTime btime);
|
||||
|
||||
bool IsStopped();
|
||||
bool IsPaused();
|
||||
|
||||
wxString GetStringType();
|
||||
wxString GetStringInformation();
|
||||
|
||||
protected:
|
||||
wxWindow *m_output_window;
|
||||
wxVideoBaseDriver *m_video_driver;
|
||||
wxWindow *m_output_window;
|
||||
wxVideoBaseDriver *m_video_driver;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -143,95 +145,106 @@ protected:
|
||||
MMBoardSoundFile::MMBoardSoundFile(const wxString& filename)
|
||||
: MMBoardFile()
|
||||
{
|
||||
m_input_stream = new wxFileInputStream(filename);
|
||||
m_output_stream = MMBoardManager::OpenSoundStream();
|
||||
|
||||
m_file_stream = GetDecoder();
|
||||
|
||||
if (!m_file_stream) {
|
||||
SetError(MMBoard_UnknownFile);
|
||||
return;
|
||||
}
|
||||
m_input_stream = new wxFileInputStream(filename);
|
||||
m_output_stream = MMBoardManager::OpenSoundStream();
|
||||
|
||||
// Compute length
|
||||
wxUint32 length, seconds;
|
||||
m_file_stream = GetDecoder();
|
||||
|
||||
if (!m_file_stream) {
|
||||
SetError(MMBoard_UnknownFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute length
|
||||
wxUint32 length, seconds;
|
||||
|
||||
length = m_file_stream->GetLength();
|
||||
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
|
||||
m_length.seconds = seconds % 60;
|
||||
m_length.minutes = (seconds / 60) % 60;
|
||||
m_length.hours = seconds / 3600;
|
||||
length = m_file_stream->GetLength();
|
||||
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
|
||||
m_length.seconds = seconds % 60;
|
||||
m_length.minutes = (seconds / 60) % 60;
|
||||
m_length.hours = seconds / 3600;
|
||||
}
|
||||
|
||||
MMBoardSoundFile::~MMBoardSoundFile()
|
||||
{
|
||||
if (m_file_stream)
|
||||
delete m_file_stream;
|
||||
MMBoardManager::UnrefSoundStream(m_output_stream);
|
||||
delete m_input_stream;
|
||||
if (m_file_stream)
|
||||
delete m_file_stream;
|
||||
MMBoardManager::UnrefSoundStream(m_output_stream);
|
||||
delete m_input_stream;
|
||||
}
|
||||
|
||||
wxSoundFileStream *MMBoardSoundFile::GetDecoder()
|
||||
{
|
||||
wxSoundFileStream *f_stream;
|
||||
|
||||
// First, we try a Wave decoder
|
||||
f_stream = new wxSoundWave(*m_input_stream, *m_output_stream);
|
||||
m_file_type = MMBoard_WAVE;
|
||||
if (f_stream->CanRead())
|
||||
return f_stream;
|
||||
delete f_stream;
|
||||
|
||||
// Then, a AIFF decoder
|
||||
f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream);
|
||||
m_file_type = MMBoard_AIFF;
|
||||
if (f_stream->CanRead())
|
||||
return f_stream;
|
||||
delete f_stream;
|
||||
|
||||
m_file_type = MMBoard_UNKNOWNTYPE;
|
||||
|
||||
// TODO: automate
|
||||
|
||||
return NULL;
|
||||
wxSoundFileStream *f_stream;
|
||||
|
||||
// First, we try a Wave decoder
|
||||
f_stream = new wxSoundWave(*m_input_stream, *m_output_stream);
|
||||
m_file_type = MMBoard_WAVE;
|
||||
if (f_stream->CanRead())
|
||||
return f_stream;
|
||||
delete f_stream;
|
||||
|
||||
// Then, a AIFF decoder
|
||||
f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream);
|
||||
m_file_type = MMBoard_AIFF;
|
||||
if (f_stream->CanRead())
|
||||
return f_stream;
|
||||
delete f_stream;
|
||||
|
||||
m_file_type = MMBoard_UNKNOWNTYPE;
|
||||
|
||||
// TODO: automate
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MMBoardTime MMBoardSoundFile::GetLength()
|
||||
{
|
||||
return m_length;
|
||||
return m_length;
|
||||
}
|
||||
|
||||
bool MMBoardSoundFile::IsStopped()
|
||||
{
|
||||
return m_file_stream->IsStopped();
|
||||
return m_file_stream->IsStopped();
|
||||
}
|
||||
|
||||
bool MMBoardSoundFile::IsPaused()
|
||||
{
|
||||
return m_file_stream->IsPaused();
|
||||
return m_file_stream->IsPaused();
|
||||
}
|
||||
|
||||
MMBoardTime MMBoardSoundFile::GetPosition()
|
||||
{
|
||||
wxUint32 length, seconds;
|
||||
MMBoardTime file_time;
|
||||
|
||||
file_time.seconds = file_time.minutes = file_time.hours = 0;
|
||||
if (m_file_stream->IsStopped())
|
||||
wxUint32 length, seconds;
|
||||
MMBoardTime file_time;
|
||||
|
||||
file_time.seconds = file_time.minutes = file_time.hours = 0;
|
||||
if (m_file_stream->IsStopped())
|
||||
return file_time;
|
||||
|
||||
length = m_file_stream->GetPosition();
|
||||
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
|
||||
file_time.seconds = seconds % 60;
|
||||
file_time.minutes = (seconds / 60) % 60;
|
||||
file_time.hours = seconds / 3600;
|
||||
|
||||
return file_time;
|
||||
}
|
||||
|
||||
length = m_file_stream->GetPosition();
|
||||
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
|
||||
file_time.seconds = seconds % 60;
|
||||
file_time.minutes = (seconds / 60) % 60;
|
||||
file_time.hours = seconds / 3600;
|
||||
void MMBoardSoundFile::SetPosition(MMBoardTime btime)
|
||||
{
|
||||
wxUint32 itime;
|
||||
|
||||
return file_time;
|
||||
itime = btime.seconds + btime.minutes * 60 + btime.hours;
|
||||
|
||||
m_file_stream->SetPosition(
|
||||
m_file_stream->GetSoundFormat().GetBytesFromTime(itime)
|
||||
);
|
||||
}
|
||||
|
||||
bool MMBoardSoundFile::NeedWindow()
|
||||
{
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MMBoardSoundFile::SetWindow(wxWindow *window)
|
||||
@ -240,37 +253,37 @@ void MMBoardSoundFile::SetWindow(wxWindow *window)
|
||||
|
||||
void MMBoardSoundFile::Play()
|
||||
{
|
||||
m_file_stream->Play();
|
||||
m_file_stream->Play();
|
||||
}
|
||||
|
||||
void MMBoardSoundFile::Pause()
|
||||
{
|
||||
m_file_stream->Pause();
|
||||
m_file_stream->Pause();
|
||||
}
|
||||
|
||||
void MMBoardSoundFile::Resume()
|
||||
{
|
||||
m_file_stream->Resume();
|
||||
m_file_stream->Resume();
|
||||
}
|
||||
|
||||
void MMBoardSoundFile::Stop()
|
||||
{
|
||||
m_file_stream->Stop();
|
||||
m_file_stream->Stop();
|
||||
}
|
||||
|
||||
wxString MMBoardSoundFile::GetStringType()
|
||||
{
|
||||
switch (m_file_type) {
|
||||
case MMBoard_WAVE:
|
||||
return wxString(wxT("WAVE file"));
|
||||
break;
|
||||
case MMBoard_AIFF:
|
||||
return wxString(wxT("AIFF file"));
|
||||
break;
|
||||
default:
|
||||
return wxString(wxT("Unknown file"));
|
||||
break;
|
||||
}
|
||||
switch (m_file_type) {
|
||||
case MMBoard_WAVE:
|
||||
return wxString(wxT("WAVE file"));
|
||||
break;
|
||||
case MMBoard_AIFF:
|
||||
return wxString(wxT("AIFF file"));
|
||||
break;
|
||||
default:
|
||||
return wxString(wxT("Unknown file"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wxString MMBoardSoundFile::GetStringInformation()
|
||||
@ -392,6 +405,10 @@ MMBoardTime MMBoardVideoFile::GetLength()
|
||||
return btime;
|
||||
}
|
||||
|
||||
void MMBoardVideoFile::SetPosition(MMBoardTime btime)
|
||||
{
|
||||
}
|
||||
|
||||
bool MMBoardVideoFile::IsStopped()
|
||||
{
|
||||
return m_video_driver->IsStopped();
|
||||
|
@ -54,7 +54,8 @@ class MMBoardFile {
|
||||
|
||||
virtual MMBoardTime GetPosition() = 0;
|
||||
virtual MMBoardTime GetLength() = 0;
|
||||
|
||||
virtual void SetPosition(MMBoardTime btime) = 0;
|
||||
|
||||
virtual bool IsStopped() = 0;
|
||||
virtual bool IsPaused() = 0;
|
||||
|
||||
|
@ -71,43 +71,44 @@
|
||||
class MMBoardFrame : public wxFrame
|
||||
{
|
||||
public:
|
||||
// ctor(s)
|
||||
MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
// dtor
|
||||
~MMBoardFrame();
|
||||
|
||||
// event handlers
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnOpen(wxCommandEvent& event);
|
||||
void OnPlay(wxCommandEvent& event);
|
||||
void OnStop(wxCommandEvent& event);
|
||||
void OnPause(wxCommandEvent& event);
|
||||
void OnRefreshInfo(wxEvent& event);
|
||||
|
||||
void OpenVideoWindow();
|
||||
void CloseVideoWindow();
|
||||
// ctor(s)
|
||||
MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
// dtor
|
||||
~MMBoardFrame();
|
||||
|
||||
// event handlers
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnOpen(wxCommandEvent& event);
|
||||
void OnPlay(wxCommandEvent& event);
|
||||
void OnStop(wxCommandEvent& event);
|
||||
void OnPause(wxCommandEvent& event);
|
||||
void OnEject(wxCommandEvent& event);
|
||||
void OnRefreshInfo(wxEvent& event);
|
||||
void OnSetPosition(wxCommandEvent& event);
|
||||
|
||||
void OpenVideoWindow();
|
||||
void CloseVideoWindow();
|
||||
|
||||
private:
|
||||
// any class wishing to process wxWindows events must use this macro
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
// any class wishing to process wxWindows events must use this macro
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
void UpdateMMedInfo();
|
||||
void UpdateInfoText();
|
||||
|
||||
MMBoardFile *m_opened_file;
|
||||
|
||||
wxSlider *m_positionSlider;
|
||||
wxBitmapButton *m_playButton, *m_pauseButton, *m_stopButton, *m_ejectButton;
|
||||
wxStaticText *m_fileType, *m_infoText;
|
||||
wxWindow *m_video_window;
|
||||
|
||||
wxPanel *m_panel;
|
||||
wxSizer *m_sizer;
|
||||
|
||||
wxTimer *m_refreshTimer;
|
||||
|
||||
void UpdateMMedInfo();
|
||||
void UpdateInfoText();
|
||||
|
||||
MMBoardFile *m_opened_file;
|
||||
|
||||
wxSlider *m_positionSlider;
|
||||
wxBitmapButton *m_playButton, *m_pauseButton, *m_stopButton, *m_ejectButton;
|
||||
wxStaticText *m_fileType, *m_infoText;
|
||||
wxWindow *m_video_window;
|
||||
|
||||
wxPanel *m_panel;
|
||||
wxSizer *m_sizer;
|
||||
|
||||
wxTimer *m_refreshTimer;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -141,6 +142,8 @@ BEGIN_EVENT_TABLE(MMBoardFrame, wxFrame)
|
||||
EVT_BUTTON(MMBoard_PlayButton, MMBoardFrame::OnPlay)
|
||||
EVT_BUTTON(MMBoard_StopButton, MMBoardFrame::OnStop)
|
||||
EVT_BUTTON(MMBoard_PauseButton, MMBoardFrame::OnPause)
|
||||
EVT_BUTTON(MMBoard_EjectButton, MMBoardFrame::OnEject)
|
||||
EVT_SLIDER(MMBoard_PositionSlider, MMBoardFrame::OnSetPosition)
|
||||
EVT_CUSTOM(wxEVT_TIMER, MMBoard_RefreshInfo, MMBoardFrame::OnRefreshInfo)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
@ -190,39 +193,39 @@ bool MMBoardApp::OnInit()
|
||||
|
||||
wxUint8 MMBoardApp::TestMultimediaCaps()
|
||||
{
|
||||
wxSoundStream *dev;
|
||||
wxUint8 caps;
|
||||
|
||||
caps = 0;
|
||||
|
||||
wxSoundStream *dev;
|
||||
wxUint8 caps;
|
||||
|
||||
caps = 0;
|
||||
|
||||
#ifdef __UNIX__
|
||||
// We now test the ESD support
|
||||
|
||||
dev = new wxSoundStreamESD();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_ESD;
|
||||
delete dev;
|
||||
|
||||
// We test the OSS (Open Sound System) support.
|
||||
|
||||
// We now test the ESD support
|
||||
|
||||
dev = new wxSoundStreamESD();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_ESD;
|
||||
delete dev;
|
||||
|
||||
// We test the OSS (Open Sound System) support.
|
||||
|
||||
#if 0
|
||||
dev = new wxSoundStreamOSS();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_OSS;
|
||||
delete dev;
|
||||
dev = new wxSoundStreamOSS();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_OSS;
|
||||
delete dev;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
// We test the Windows sound support.
|
||||
// We test the Windows sound support.
|
||||
|
||||
dev = new wxSoundStreamWin();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_WIN;
|
||||
delete dev;
|
||||
dev = new wxSoundStreamWin();
|
||||
if (dev->GetError() == wxSOUND_NOERR)
|
||||
caps |= MM_SOUND_WIN;
|
||||
delete dev;
|
||||
#endif
|
||||
|
||||
return caps;
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -243,20 +246,20 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
|
||||
SetIcon(wxICON(mondrian));
|
||||
|
||||
// create a menu bar
|
||||
wxMenu *menuFile = new wxMenu(_T(""), wxMENU_TEAROFF);
|
||||
wxMenu *menuFile = new wxMenu(wxT(""), wxMENU_TEAROFF);
|
||||
|
||||
// the "About" item should be in the help menu
|
||||
wxMenu *helpMenu = new wxMenu;
|
||||
helpMenu->Append(MMBoard_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
|
||||
helpMenu->Append(MMBoard_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
|
||||
|
||||
menuFile->Append(MMBoard_Open, _T("&Open\tAlt-O"), _T("Open file"));
|
||||
menuFile->Append(MMBoard_Open, wxT("&Open\tAlt-O"), wxT("Open file"));
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(MMBoard_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
|
||||
menuFile->Append(MMBoard_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
|
||||
|
||||
// now append the freshly created menu to the menu bar...
|
||||
wxMenuBar *menuBar = new wxMenuBar();
|
||||
menuBar->Append(menuFile, _T("&File"));
|
||||
menuBar->Append(helpMenu, _T("&Help"));
|
||||
menuBar->Append(menuFile, wxT("&File"));
|
||||
menuBar->Append(helpMenu, wxT("&Help"));
|
||||
|
||||
// ... and attach this menu bar to the frame
|
||||
SetMenuBar(menuBar);
|
||||
@ -264,7 +267,7 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
|
||||
#if wxUSE_STATUSBAR
|
||||
// create a status bar just for fun (by default with 1 pane only)
|
||||
CreateStatusBar(3);
|
||||
SetStatusText(_T("Welcome to wxWindows!"));
|
||||
SetStatusText(wxT("Welcome to wxWindows!"));
|
||||
#endif // wxUSE_STATUSBAR
|
||||
|
||||
// Misc variables
|
||||
@ -277,7 +280,8 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
|
||||
wxDefaultPosition, wxSize(300, -1),
|
||||
wxSL_HORIZONTAL | wxSL_AUTOTICKS);
|
||||
m_positionSlider->SetPageSize(60); // 60 secs
|
||||
|
||||
m_positionSlider->Enable(FALSE);
|
||||
|
||||
// Initialize info panel
|
||||
wxPanel *infoPanel = new wxPanel( m_panel, -1);
|
||||
infoPanel->SetBackgroundColour(*wxBLACK);
|
||||
@ -285,7 +289,7 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
|
||||
|
||||
wxBoxSizer *infoSizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
m_fileType = new wxStaticText(infoPanel, -1, _T(""));
|
||||
m_fileType = new wxStaticText(infoPanel, -1, wxT(""));
|
||||
wxStaticLine *line = new wxStaticLine(infoPanel, -1);
|
||||
m_infoText = new wxStaticText(infoPanel, -1, "");
|
||||
|
||||
@ -346,10 +350,10 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
|
||||
|
||||
MMBoardFrame::~MMBoardFrame()
|
||||
{
|
||||
if (m_opened_file)
|
||||
delete m_opened_file;
|
||||
|
||||
delete m_refreshTimer;
|
||||
if (m_opened_file)
|
||||
delete m_opened_file;
|
||||
|
||||
delete m_refreshTimer;
|
||||
}
|
||||
|
||||
void MMBoardFrame::OpenVideoWindow()
|
||||
@ -366,14 +370,14 @@ void MMBoardFrame::OpenVideoWindow()
|
||||
|
||||
void MMBoardFrame::CloseVideoWindow()
|
||||
{
|
||||
if (!m_video_window)
|
||||
return;
|
||||
|
||||
m_sizer->Remove(m_video_window);
|
||||
delete m_video_window;
|
||||
m_video_window = NULL;
|
||||
|
||||
m_sizer->Fit(this);
|
||||
if (!m_video_window)
|
||||
return;
|
||||
|
||||
m_sizer->Remove(m_video_window);
|
||||
delete m_video_window;
|
||||
m_video_window = NULL;
|
||||
|
||||
m_sizer->Fit(this);
|
||||
}
|
||||
|
||||
// event handlers
|
||||
@ -387,93 +391,97 @@ void MMBoardFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
void MMBoardFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString msg;
|
||||
msg.Printf( _T("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
|
||||
_T("an example of the capabilities of the wxWindows multimedia classes.\n")
|
||||
_T("Copyright 1999, 2000, Guilhem Lavaux.\n"));
|
||||
msg.Printf( wxT("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
|
||||
wxT("an example of the capabilities of the wxWindows multimedia classes.\n")
|
||||
wxT("Copyright 1999, 2000, Guilhem Lavaux.\n"));
|
||||
|
||||
wxMessageBox(msg, "About MMBoard", wxOK | wxICON_INFORMATION, this);
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString selected_file;
|
||||
|
||||
if (m_opened_file) {
|
||||
if (!m_opened_file->IsStopped()) {
|
||||
wxCommandEvent event2;
|
||||
OnStop(event2);
|
||||
wxString selected_file;
|
||||
|
||||
if (m_opened_file) {
|
||||
if (!m_opened_file->IsStopped()) {
|
||||
wxCommandEvent event2;
|
||||
OnStop(event2);
|
||||
}
|
||||
delete m_opened_file;
|
||||
}
|
||||
delete m_opened_file;
|
||||
}
|
||||
|
||||
// select a file to be opened
|
||||
selected_file = wxLoadFileSelector("multimedia", "*", NULL, this);
|
||||
if (selected_file.IsNull())
|
||||
return;
|
||||
|
||||
m_opened_file = MMBoardManager::Open(selected_file);
|
||||
|
||||
// Change the range values of the slider.
|
||||
MMBoardTime length;
|
||||
|
||||
length = m_opened_file->GetLength();
|
||||
m_positionSlider->SetRange(0, length.hours * 3600 + length.minutes * 60 + length.seconds);
|
||||
|
||||
// Update misc info
|
||||
UpdateMMedInfo();
|
||||
|
||||
SetStatusText(selected_file, 2);
|
||||
|
||||
// Update info text
|
||||
UpdateInfoText();
|
||||
|
||||
// Enable a few buttons
|
||||
m_playButton->Enable(TRUE);
|
||||
m_ejectButton->Enable(TRUE);
|
||||
|
||||
if (m_opened_file->NeedWindow()) {
|
||||
OpenVideoWindow();
|
||||
m_opened_file->SetWindow(m_video_window);
|
||||
} else
|
||||
CloseVideoWindow();
|
||||
|
||||
// select a file to be opened
|
||||
selected_file = wxLoadFileSelector("multimedia", "*", NULL, this);
|
||||
if (selected_file.IsNull())
|
||||
return;
|
||||
|
||||
m_opened_file = MMBoardManager::Open(selected_file);
|
||||
|
||||
// Change the range values of the slider.
|
||||
MMBoardTime length;
|
||||
|
||||
length = m_opened_file->GetLength();
|
||||
m_positionSlider->SetRange(0, length.hours * 3600 + length.minutes * 60 + length.seconds);
|
||||
|
||||
// Update misc info
|
||||
UpdateMMedInfo();
|
||||
|
||||
SetStatusText(selected_file, 2);
|
||||
|
||||
// Update info text
|
||||
UpdateInfoText();
|
||||
|
||||
// Enable a few buttons
|
||||
m_playButton->Enable(TRUE);
|
||||
m_ejectButton->Enable(TRUE);
|
||||
m_positionSlider->Enable(TRUE);
|
||||
|
||||
if (m_opened_file->NeedWindow()) {
|
||||
OpenVideoWindow();
|
||||
m_opened_file->SetWindow(m_video_window);
|
||||
} else
|
||||
CloseVideoWindow();
|
||||
}
|
||||
|
||||
void MMBoardFrame::UpdateInfoText()
|
||||
{
|
||||
wxString infotext1, infotext2;
|
||||
|
||||
if (m_opened_file) {
|
||||
infotext1 = _T("File type:\n\t");
|
||||
infotext1 += m_opened_file->GetStringType() + _T("\n");
|
||||
|
||||
infotext2 = _T("File informations:\n\n");
|
||||
infotext2 += m_opened_file->GetStringInformation();
|
||||
} else {
|
||||
infotext1 = _T("File type: \n\tNo file opened");
|
||||
infotext2 = _T("File informations:\nNo information\n\n\n\n\n");
|
||||
}
|
||||
|
||||
m_fileType->SetLabel(infotext1);
|
||||
m_infoText->SetLabel(infotext2);
|
||||
wxString infotext1, infotext2;
|
||||
|
||||
if (m_opened_file) {
|
||||
infotext1 = wxT("File type:\n\t");
|
||||
infotext1 += m_opened_file->GetStringType() + wxT("\n");
|
||||
|
||||
infotext2 = wxT("File informations:\n\n");
|
||||
infotext2 += m_opened_file->GetStringInformation();
|
||||
} else {
|
||||
infotext1 = wxT("File type: \n\tNo file opened");
|
||||
infotext2 = wxT("File informations:\nNo information\n\n\n\n\n");
|
||||
}
|
||||
|
||||
m_fileType->SetLabel(infotext1);
|
||||
m_infoText->SetLabel(infotext2);
|
||||
}
|
||||
|
||||
void MMBoardFrame::UpdateMMedInfo()
|
||||
{
|
||||
wxString temp_string;
|
||||
MMBoardTime current, length;
|
||||
wxString temp_string;
|
||||
MMBoardTime current, length;
|
||||
|
||||
if (m_opened_file) {
|
||||
current = m_opened_file->GetPosition();
|
||||
length = m_opened_file->GetLength();
|
||||
} else {
|
||||
current.hours = current.minutes = current.seconds = 0;
|
||||
length = current;
|
||||
}
|
||||
|
||||
if (m_opened_file) {
|
||||
current = m_opened_file->GetPosition();
|
||||
length = m_opened_file->GetLength();
|
||||
}
|
||||
|
||||
// We refresh the status bar
|
||||
temp_string.Printf("%02d:%02d / %02d:%02d", current.hours * 60 + current.minutes,
|
||||
current.seconds, length.hours * 60 + length.minutes, length.seconds);
|
||||
SetStatusText(temp_string, 1);
|
||||
|
||||
// We set the slider position
|
||||
m_positionSlider->SetValue(current.hours * 3600 + current.minutes * 60 + current.seconds);
|
||||
// We refresh the status bar
|
||||
temp_string.Printf(wxT("%02d:%02d / %02d:%02d"), current.hours * 60 + current.minutes,
|
||||
current.seconds, length.hours * 60 + length.minutes, length.seconds);
|
||||
SetStatusText(temp_string, 1);
|
||||
|
||||
// We set the slider position
|
||||
m_positionSlider->SetValue(current.hours * 3600 + current.minutes * 60 + current.seconds);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -481,51 +489,83 @@ void MMBoardFrame::UpdateMMedInfo()
|
||||
|
||||
void MMBoardFrame::OnRefreshInfo(wxEvent& WXUNUSED(event))
|
||||
{
|
||||
UpdateMMedInfo();
|
||||
|
||||
if (m_opened_file->IsStopped()) {
|
||||
m_refreshTimer->Stop();
|
||||
m_playButton->Enable(TRUE);
|
||||
m_stopButton->Enable(FALSE);
|
||||
m_pauseButton->Enable(FALSE);
|
||||
}
|
||||
UpdateMMedInfo();
|
||||
|
||||
if (m_opened_file->IsStopped()) {
|
||||
m_refreshTimer->Stop();
|
||||
m_playButton->Enable(TRUE);
|
||||
m_stopButton->Enable(FALSE);
|
||||
m_pauseButton->Enable(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_stopButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(TRUE);
|
||||
m_playButton->Enable(FALSE);
|
||||
|
||||
if (m_opened_file->IsPaused()) {
|
||||
m_opened_file->Resume();
|
||||
return;
|
||||
}
|
||||
|
||||
m_refreshTimer->Start(1000, FALSE);
|
||||
|
||||
m_opened_file->Play();
|
||||
|
||||
m_stopButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(TRUE);
|
||||
m_playButton->Enable(FALSE);
|
||||
m_stopButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(TRUE);
|
||||
m_playButton->Enable(FALSE);
|
||||
|
||||
if (m_opened_file->IsPaused()) {
|
||||
m_opened_file->Resume();
|
||||
return;
|
||||
}
|
||||
|
||||
m_refreshTimer->Start(1000, FALSE);
|
||||
|
||||
m_opened_file->Play();
|
||||
|
||||
m_stopButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(TRUE);
|
||||
m_playButton->Enable(FALSE);
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnStop(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_opened_file->Stop();
|
||||
m_refreshTimer->Stop();
|
||||
m_opened_file->Stop();
|
||||
m_refreshTimer->Stop();
|
||||
|
||||
m_stopButton->Enable(FALSE);
|
||||
m_playButton->Enable(TRUE);
|
||||
|
||||
UpdateMMedInfo();
|
||||
m_stopButton->Enable(FALSE);
|
||||
m_playButton->Enable(TRUE);
|
||||
|
||||
UpdateMMedInfo();
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnPause(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_opened_file->Pause();
|
||||
|
||||
m_playButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(FALSE);
|
||||
m_opened_file->Pause();
|
||||
|
||||
m_playButton->Enable(TRUE);
|
||||
m_pauseButton->Enable(FALSE);
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnEject(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_opened_file->Stop();
|
||||
|
||||
delete m_opened_file;
|
||||
m_opened_file = NULL;
|
||||
|
||||
m_playButton->Enable(FALSE);
|
||||
m_pauseButton->Enable(FALSE);
|
||||
m_stopButton->Enable(FALSE);
|
||||
m_ejectButton->Enable(FALSE);
|
||||
m_positionSlider->Enable(FALSE);
|
||||
|
||||
UpdateInfoText();
|
||||
UpdateMMedInfo();
|
||||
}
|
||||
|
||||
void MMBoardFrame::OnSetPosition(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxUint32 itime;
|
||||
MMBoardTime btime;
|
||||
|
||||
itime = m_positionSlider->GetValue();
|
||||
btime.seconds = itime % 60;
|
||||
btime.minutes = (itime / 60) % 60;
|
||||
btime.hours = itime / 3600;
|
||||
m_opened_file->SetPosition(btime);
|
||||
|
||||
UpdateMMedInfo();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
//
|
||||
|
||||
class wxSoundAiff: public wxSoundFileStream {
|
||||
public:
|
||||
public:
|
||||
wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundAiff();
|
||||
@ -30,13 +30,16 @@ class wxSoundAiff: public wxSoundFileStream {
|
||||
bool CanRead();
|
||||
wxString GetCodecName() const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
bool PrepareToPlay();
|
||||
bool PrepareToRecord(unsigned long time);
|
||||
bool PrepareToRecord(wxUint32 time);
|
||||
bool FinishRecording();
|
||||
bool RepositionStream(wxUint32 position);
|
||||
|
||||
wxUint32 GetData(void *buffer, wxUint32 len);
|
||||
wxUint32 PutData(const void *buffer, wxUint32 len);
|
||||
protected:
|
||||
off_t m_base_offset;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -37,7 +37,8 @@ typedef enum {
|
||||
wxSOUND_NOFORMAT,
|
||||
wxSOUND_PCM,
|
||||
wxSOUND_ULAW,
|
||||
wxSOUND_G72X
|
||||
wxSOUND_G72X,
|
||||
wxSOUND_MSADPCM
|
||||
} wxSoundFormatType;
|
||||
|
||||
// ---------------------
|
||||
|
@ -27,13 +27,13 @@
|
||||
wxSoundRouterStream::wxSoundRouterStream(wxSoundStream& sndio)
|
||||
: wxSoundStreamCodec(sndio)
|
||||
{
|
||||
m_router = NULL;
|
||||
m_router = NULL;
|
||||
}
|
||||
|
||||
wxSoundRouterStream::~wxSoundRouterStream()
|
||||
{
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -42,16 +42,16 @@ wxSoundRouterStream::~wxSoundRouterStream()
|
||||
// --------------------------------------------------------------------------
|
||||
wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len)
|
||||
{
|
||||
if (m_router) {
|
||||
m_router->Read(buffer, len);
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
} else {
|
||||
m_sndio->Read(buffer, len);
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
}
|
||||
return *this;
|
||||
if (m_router) {
|
||||
m_router->Read(buffer, len);
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
} else {
|
||||
m_sndio->Read(buffer, len);
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -59,14 +59,14 @@ wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len)
|
||||
// --------------------------------------------------------------------------
|
||||
wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len)
|
||||
{
|
||||
if (m_router) {
|
||||
m_router->Write(buffer, len);
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
} else {
|
||||
m_sndio->Write(buffer, len);
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
if (m_router) {
|
||||
m_router->Write(buffer, len);
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
} else {
|
||||
m_sndio->Write(buffer, len);
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -80,32 +80,34 @@ wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len)
|
||||
// --------------------------------------------------------------------------
|
||||
bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
|
||||
if (m_sndio->SetSoundFormat(format)) {
|
||||
wxSoundStream::SetSoundFormat(m_sndio->GetSoundFormat());
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
|
||||
// First, we try to setup the sound device
|
||||
if (m_sndio->SetSoundFormat(format)) {
|
||||
// We are lucky, it is working.
|
||||
wxSoundStream::SetSoundFormat(m_sndio->GetSoundFormat());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch(format.GetType()) {
|
||||
case wxSOUND_NOFORMAT:
|
||||
return FALSE;
|
||||
case wxSOUND_PCM:
|
||||
m_router = new wxSoundStreamPcm(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
case wxSOUND_ULAW:
|
||||
m_router = new wxSoundStreamUlaw(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
case wxSOUND_G72X:
|
||||
m_router = new wxSoundStreamG72X(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
}
|
||||
wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch(format.GetType()) {
|
||||
case wxSOUND_NOFORMAT:
|
||||
return FALSE;
|
||||
case wxSOUND_PCM:
|
||||
m_router = new wxSoundStreamPcm(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
case wxSOUND_ULAW:
|
||||
m_router = new wxSoundStreamUlaw(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
case wxSOUND_G72X:
|
||||
m_router = new wxSoundStreamG72X(*m_sndio);
|
||||
m_router->SetSoundFormat(format);
|
||||
break;
|
||||
}
|
||||
wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -126,21 +128,21 @@ wxUint32 wxSoundRouterStream::GetBestSize() const
|
||||
// --------------------------------------------------------------------------
|
||||
bool wxSoundRouterStream::StartProduction(int evt)
|
||||
{
|
||||
if (!m_router) {
|
||||
if (m_sndio->StartProduction(evt))
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
if (!m_router) {
|
||||
if (m_sndio->StartProduction(evt))
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_router->StartProduction(evt))
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_router->StartProduction(evt))
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -148,23 +150,22 @@ bool wxSoundRouterStream::StartProduction(int evt)
|
||||
// --------------------------------------------------------------------------
|
||||
bool wxSoundRouterStream::StopProduction()
|
||||
{
|
||||
if (!m_router) {
|
||||
if (m_sndio->StopProduction())
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
if (!m_router) {
|
||||
if (m_sndio->StopProduction())
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_sndio->GetError();
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_router->StopProduction())
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_router->StopProduction())
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSoundFileStream: generic reader
|
||||
@ -172,12 +173,12 @@ bool wxSoundRouterStream::StopProduction()
|
||||
|
||||
wxSoundFileStream::wxSoundFileStream(wxInputStream& stream,
|
||||
wxSoundStream& io_sound)
|
||||
: m_codec(io_sound), m_sndio(&io_sound),
|
||||
m_input(&stream), m_output(NULL), m_state(wxSOUND_FILE_STOPPED)
|
||||
: m_codec(io_sound), m_sndio(&io_sound),
|
||||
m_input(&stream), m_output(NULL), m_state(wxSOUND_FILE_STOPPED)
|
||||
{
|
||||
m_length = 0;
|
||||
m_bytes_left = 0;
|
||||
m_prepared = FALSE;
|
||||
m_length = 0;
|
||||
m_bytes_left = 0;
|
||||
m_prepared = FALSE;
|
||||
}
|
||||
|
||||
wxSoundFileStream::wxSoundFileStream(wxOutputStream& stream,
|
||||
@ -213,7 +214,7 @@ bool wxSoundFileStream::Play()
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Record(unsigned long time)
|
||||
bool wxSoundFileStream::Record(wxUint32 time)
|
||||
{
|
||||
if (m_state != wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
@ -346,6 +347,9 @@ wxUint32 wxSoundFileStream::SetPosition(wxUint32 new_position)
|
||||
if (!m_prepared)
|
||||
return 0;
|
||||
|
||||
if (!RepositionStream(new_position))
|
||||
return m_length-m_bytes_left;
|
||||
|
||||
if (new_position >= m_length) {
|
||||
m_bytes_left = 0;
|
||||
return m_length;
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
|
||||
#define wxSOUND_INFINITE_TIME ((unsigned long)-1)
|
||||
#define wxSOUND_INFINITE_TIME ((wxUint32)-1)
|
||||
|
||||
//
|
||||
// Codec router class
|
||||
@ -51,73 +51,76 @@ typedef enum {
|
||||
//
|
||||
|
||||
class wxSoundFileStream: public wxSoundStream {
|
||||
public:
|
||||
wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundFileStream();
|
||||
public:
|
||||
wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundFileStream();
|
||||
|
||||
// Usual sound file calls (Play, Stop, ...)
|
||||
bool Play();
|
||||
bool Record(wxUint32 time);
|
||||
bool Stop();
|
||||
bool Pause();
|
||||
bool Resume();
|
||||
|
||||
// Functions which return the current state
|
||||
bool IsStopped() const { return m_state == wxSOUND_FILE_STOPPED; }
|
||||
bool IsPaused() const { return m_state == wxSOUND_FILE_PAUSED; }
|
||||
|
||||
// A user should not call these two functions.
|
||||
// Several things must be done before calling them.
|
||||
// Users should use Play(), ...
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
// Usual sound file calls (Play, Stop, ...)
|
||||
bool Play();
|
||||
bool Record(unsigned long time);
|
||||
bool Stop();
|
||||
bool Pause();
|
||||
bool Resume();
|
||||
|
||||
// Functions which return the current state
|
||||
bool IsStopped() const { return m_state == wxSOUND_FILE_STOPPED; }
|
||||
bool IsPaused() const { return m_state == wxSOUND_FILE_PAUSED; }
|
||||
|
||||
// A user should not call these two functions. Several things must be done before calling them.
|
||||
// Users should use Play(), ...
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
// These three functions deals with the length, the position in the sound file.
|
||||
// All the values are expressed in bytes. If you need the values expressed in terms of
|
||||
// time, you have to use GetSoundFormat().GetTimeFromBytes(...)
|
||||
wxUint32 GetLength();
|
||||
wxUint32 GetPosition();
|
||||
wxUint32 SetPosition(wxUint32 new_position);
|
||||
|
||||
// These two functions use the sound format specified by GetSoundFormat(). All samples
|
||||
// must be encoded in that format.
|
||||
wxSoundStream& Read(void *buffer, wxUint32 len);
|
||||
wxSoundStream& Write(const void *buffer, wxUint32 len);
|
||||
|
||||
// This function set the sound format of the file. !! It must be used only when you are
|
||||
// in output mode (concerning the file) !! If you are in input mode (concerning the file)
|
||||
// You can't use this function to modify the format of the samples returned by Read() !
|
||||
// For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
// This function returns the Codec name. This is useful for those who want to build
|
||||
// a player (But also in some other case).
|
||||
virtual wxString GetCodecName() const;
|
||||
|
||||
// You should use this function to test whether this file codec can read the stream you passed
|
||||
// to it.
|
||||
virtual bool CanRead() { return FALSE; }
|
||||
|
||||
protected:
|
||||
wxSoundRouterStream m_codec;
|
||||
wxSoundStream *m_sndio;
|
||||
wxInputStream *m_input;
|
||||
wxOutputStream *m_output;
|
||||
|
||||
wxSoundFileState m_state, m_oldstate;
|
||||
wxUint32 m_length, m_bytes_left;
|
||||
bool m_prepared;
|
||||
|
||||
protected:
|
||||
virtual bool PrepareToPlay() = 0;
|
||||
virtual bool PrepareToRecord(unsigned long time) = 0;
|
||||
virtual bool FinishRecording() = 0;
|
||||
void FinishPreparation(wxUint32 len);
|
||||
|
||||
virtual wxUint32 GetData(void *buffer, wxUint32 len) = 0;
|
||||
virtual wxUint32 PutData(const void *buffer, wxUint32 len) = 0;
|
||||
|
||||
void OnSoundEvent(int evt);
|
||||
// These three functions deals with the length, the position in the sound file.
|
||||
// All the values are expressed in bytes. If you need the values expressed
|
||||
// in terms of time, you have to use GetSoundFormat().GetTimeFromBytes(...)
|
||||
wxUint32 GetLength();
|
||||
wxUint32 GetPosition();
|
||||
wxUint32 SetPosition(wxUint32 new_position);
|
||||
|
||||
// These two functions use the sound format specified by GetSoundFormat().
|
||||
// All samples must be encoded in that format.
|
||||
wxSoundStream& Read(void *buffer, wxUint32 len);
|
||||
wxSoundStream& Write(const void *buffer, wxUint32 len);
|
||||
|
||||
// This function set the sound format of the file. !! It must be used only
|
||||
// when you are in output mode (concerning the file) !! If you are in
|
||||
// input mode (concerning the file) you can't use this function to modify
|
||||
// the format of the samples returned by Read() !
|
||||
// For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
// This function returns the Codec name. This is useful for those who want to build
|
||||
// a player (But also in some other case).
|
||||
virtual wxString GetCodecName() const;
|
||||
|
||||
// You should use this function to test whether this file codec can read
|
||||
// the stream you passed to it.
|
||||
virtual bool CanRead() { return FALSE; }
|
||||
|
||||
protected:
|
||||
wxSoundRouterStream m_codec;
|
||||
wxSoundStream *m_sndio;
|
||||
wxInputStream *m_input;
|
||||
wxOutputStream *m_output;
|
||||
|
||||
wxSoundFileState m_state, m_oldstate;
|
||||
wxUint32 m_length, m_bytes_left;
|
||||
bool m_prepared;
|
||||
|
||||
protected:
|
||||
virtual bool PrepareToPlay() = 0;
|
||||
virtual bool PrepareToRecord(wxUint32 time) = 0;
|
||||
virtual bool FinishRecording() = 0;
|
||||
virtual bool RepositionStream(wxUint32 position) = 0;
|
||||
void FinishPreparation(wxUint32 len);
|
||||
|
||||
virtual wxUint32 GetData(void *buffer, wxUint32 len) = 0;
|
||||
virtual wxUint32 PutData(const void *buffer, wxUint32 len) = 0;
|
||||
|
||||
void OnSoundEvent(int evt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,10 @@
|
||||
#endif
|
||||
|
||||
#include <wx/wxprec.h>
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndpcm.h"
|
||||
@ -84,7 +88,8 @@ wxSoundStreamUlaw::~wxSoundStreamUlaw()
|
||||
|
||||
wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
|
||||
{
|
||||
return *this;
|
||||
// TODO
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)
|
||||
|
@ -12,7 +12,6 @@
|
||||
#pragma interface "sndulaw.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sndcodec.h"
|
||||
#include "sndbase.h"
|
||||
|
||||
@ -27,6 +26,9 @@ class WXDLLEXPORT wxSoundFormatUlaw: public wxSoundFormatBase {
|
||||
void SetSampleRate(wxUint32 srate);
|
||||
wxUint32 GetSampleRate() const;
|
||||
|
||||
void SetChannels(wxUint8 channels);
|
||||
wxUint8 GetChannels() const;
|
||||
|
||||
wxSoundFormatType GetType() const { return wxSOUND_ULAW; }
|
||||
wxSoundFormatBase *Clone() const;
|
||||
|
||||
|
@ -31,17 +31,19 @@
|
||||
#define DATA_SIGNATURE BUILD_SIGNATURE('d','a','t','a')
|
||||
|
||||
#define HEADER_SIZE 4+4 + 4+4+16 + 4+4
|
||||
// 4+4 => NAME + LEN
|
||||
// 16 => fmt size
|
||||
// 4+4 => NAME + LEN
|
||||
// 16 => fmt size
|
||||
|
||||
wxSoundWave::wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
m_base_offset = wxInvalidOffset;
|
||||
}
|
||||
|
||||
wxSoundWave::wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
m_base_offset = wxInvalidOffset;
|
||||
}
|
||||
|
||||
wxSoundWave::~wxSoundWave()
|
||||
@ -57,276 +59,297 @@ wxString wxSoundWave::GetCodecName() const
|
||||
|
||||
bool wxSoundWave::CanRead()
|
||||
{
|
||||
wxUint32 len, signature1, signature2;
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
wxUint32 len, signature1, signature2;
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature1, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
// Test the main signatures:
|
||||
// "RIFF"
|
||||
FAIL_WITH(m_input->Read(&signature1, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature1) != RIFF_SIGNATURE) {
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature1) != RIFF_SIGNATURE) {
|
||||
// Pass the global length
|
||||
m_input->Read(&len, 4);
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
// Get the second signature
|
||||
FAIL_WITH(m_input->Read(&signature2, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
// Ungetch all
|
||||
m_input->Ungetch(&signature2, 4);
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Read(&len, 4);
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature2, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
m_input->Ungetch(&signature2, 4);
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch(&signature1, 4);
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature2) != WAVE_SIGNATURE)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
// Test the second signature
|
||||
if (wxUINT32_SWAP_ON_BE(signature2) != WAVE_SIGNATURE)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::HandleOutputPCM(wxDataInputStream& data, wxUint16 channels,
|
||||
wxUint32 sample_fq, wxUint32 byte_p_sec,
|
||||
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
|
||||
wxUint32 sample_fq, wxUint32 byte_p_sec,
|
||||
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
|
||||
{
|
||||
wxSoundFormatPcm sndformat;
|
||||
|
||||
sndformat.SetSampleRate(sample_fq);
|
||||
sndformat.SetBPS(bits_p_spl);
|
||||
sndformat.SetChannels(channels);
|
||||
sndformat.Signed(TRUE);
|
||||
sndformat.SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
wxSoundFormatPcm sndformat;
|
||||
|
||||
sndformat.SetSampleRate(sample_fq);
|
||||
sndformat.SetBPS(bits_p_spl);
|
||||
sndformat.SetChannels(channels);
|
||||
sndformat.Signed(TRUE);
|
||||
sndformat.SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
|
||||
wxUint32 sample_fq, wxUint32 byte_p_sec,
|
||||
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
|
||||
wxUint32 sample_fq, wxUint32 byte_p_sec,
|
||||
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
|
||||
{
|
||||
wxSoundFormatG72X sndformat;
|
||||
|
||||
sndformat.SetSampleRate(sample_fq);
|
||||
sndformat.SetG72XType(wxSOUND_G721);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
wxSoundFormatG72X sndformat;
|
||||
|
||||
sndformat.SetSampleRate(sample_fq);
|
||||
sndformat.SetG72XType(wxSOUND_G721);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::PrepareToPlay()
|
||||
{
|
||||
wxUint32 signature, len;
|
||||
bool end_headers;
|
||||
wxUint32 signature, len;
|
||||
bool end_headers;
|
||||
|
||||
if (!m_input) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxDataInputStream data(*m_input);
|
||||
data.BigEndianOrdered(FALSE);
|
||||
|
||||
if (!m_input) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxDataInputStream data(*m_input);
|
||||
data.BigEndianOrdered(FALSE);
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != RIFF_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "RIFF"
|
||||
|
||||
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) != WAVE_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "WAVE"
|
||||
|
||||
end_headers = FALSE;
|
||||
while (!end_headers) {
|
||||
// Get the first signature
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != RIFF_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "RIFF"
|
||||
|
||||
len = data.Read32();
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
// dummy len
|
||||
|
||||
switch (wxUINT32_SWAP_ON_BE(signature)) {
|
||||
case FMT_SIGNATURE: { // "fmt "
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
// Get the second signature
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != WAVE_SIGNATURE, wxSOUND_INVSTRM);
|
||||
// "WAVE"
|
||||
|
||||
end_headers = FALSE;
|
||||
// Chunk loop
|
||||
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 FMT_SIGNATURE: { // "fmt "
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
|
||||
data >> format >> channels >> sample_fq
|
||||
>> byte_p_sec >> byte_p_spl >> bits_p_spl;
|
||||
|
||||
switch (format) {
|
||||
case 0x01:
|
||||
if (!HandleOutputPCM(data, channels, sample_fq,
|
||||
byte_p_sec, byte_p_spl, bits_p_spl))
|
||||
return FALSE;
|
||||
break;
|
||||
case 0x40:
|
||||
if (!HandleOutputG721(data, channels, sample_fq,
|
||||
byte_p_sec, byte_p_spl, bits_p_spl))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
m_snderror = wxSOUND_NOCODEC;
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
// Get the common parameters
|
||||
data >> format >> channels >> sample_fq
|
||||
>> byte_p_sec >> byte_p_spl >> bits_p_spl;
|
||||
|
||||
switch (format) {
|
||||
case 0x01: // PCM
|
||||
if (!HandleOutputPCM(data, channels, sample_fq,
|
||||
byte_p_sec, byte_p_spl, bits_p_spl))
|
||||
return FALSE;
|
||||
break;
|
||||
case 0x40: // G721
|
||||
if (!HandleOutputG721(data, channels, sample_fq,
|
||||
byte_p_sec, byte_p_spl, bits_p_spl))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
m_snderror = wxSOUND_NOCODEC;
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DATA_SIGNATURE: // "data"
|
||||
m_base_offset = m_input->TellI();
|
||||
end_headers = TRUE;
|
||||
FinishPreparation(len);
|
||||
break;
|
||||
default:
|
||||
// We pass the chunk
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case DATA_SIGNATURE: // "data"
|
||||
end_headers = TRUE;
|
||||
FinishPreparation(len);
|
||||
break;
|
||||
default:
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxSoundFormatBase *wxSoundWave::HandleInputPCM(wxDataOutputStream& data)
|
||||
{
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
wxSoundFormatPcm *pcm;
|
||||
|
||||
pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
|
||||
|
||||
// Write block length
|
||||
data.Write32(16);
|
||||
|
||||
sample_fq = pcm->GetSampleRate();
|
||||
bits_p_spl = pcm->GetBPS();
|
||||
channels = pcm->GetChannels();
|
||||
byte_p_spl = pcm->GetBPS() / 8;
|
||||
byte_p_sec = pcm->GetBytesFromTime(1);
|
||||
format = 0x01;
|
||||
|
||||
pcm->Signed(TRUE);
|
||||
pcm->SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
data << format << channels << sample_fq
|
||||
<< byte_p_sec << byte_p_spl << bits_p_spl;
|
||||
|
||||
return pcm;
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
wxSoundFormatPcm *pcm;
|
||||
|
||||
pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
|
||||
|
||||
// Write block length
|
||||
data.Write32(16);
|
||||
|
||||
sample_fq = pcm->GetSampleRate();
|
||||
bits_p_spl = pcm->GetBPS();
|
||||
channels = pcm->GetChannels();
|
||||
byte_p_spl = pcm->GetBPS() / 8;
|
||||
byte_p_sec = pcm->GetBytesFromTime(1);
|
||||
format = 0x01;
|
||||
|
||||
pcm->Signed(TRUE);
|
||||
pcm->SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
data << format << channels << sample_fq
|
||||
<< byte_p_sec << byte_p_spl << bits_p_spl;
|
||||
|
||||
return pcm;
|
||||
}
|
||||
|
||||
wxSoundFormatBase *wxSoundWave::HandleInputG72X(wxDataOutputStream& data)
|
||||
{
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
wxSoundFormatG72X *g72x;
|
||||
|
||||
// Write block length
|
||||
data.Write32(16);
|
||||
|
||||
g72x = (wxSoundFormatG72X *)(m_sndformat->Clone());
|
||||
if (g72x->GetG72XType() != wxSOUND_G721) {
|
||||
delete g72x;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sample_fq = g72x->GetSampleRate();
|
||||
bits_p_spl = 4;
|
||||
channels = 1;
|
||||
byte_p_spl = 0;
|
||||
byte_p_sec = g72x->GetBytesFromTime(1);
|
||||
format = 0x40;
|
||||
data << format << channels << sample_fq
|
||||
<< byte_p_sec << byte_p_spl << bits_p_spl;
|
||||
|
||||
return g72x;
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
wxSoundFormatG72X *g72x;
|
||||
|
||||
// Write block length
|
||||
data.Write32(16);
|
||||
|
||||
g72x = (wxSoundFormatG72X *)(m_sndformat->Clone());
|
||||
if (g72x->GetG72XType() != wxSOUND_G721) {
|
||||
delete g72x;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sample_fq = g72x->GetSampleRate();
|
||||
bits_p_spl = 4;
|
||||
channels = 1;
|
||||
byte_p_spl = 0;
|
||||
byte_p_sec = g72x->GetBytesFromTime(1);
|
||||
format = 0x40;
|
||||
data << format << channels << sample_fq
|
||||
<< byte_p_sec << byte_p_spl << bits_p_spl;
|
||||
|
||||
return g72x;
|
||||
}
|
||||
|
||||
bool wxSoundWave::PrepareToRecord(unsigned long time)
|
||||
bool wxSoundWave::PrepareToRecord(wxUint32 time)
|
||||
{
|
||||
#define WRITE_SIGNATURE(s,sig) \
|
||||
signature = sig; \
|
||||
signature = wxUINT32_SWAP_ON_BE(signature); \
|
||||
FAIL_WITH(s->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
wxUint32 signature;
|
||||
wxMemoryOutputStream fmt_data;
|
||||
|
||||
if (!m_output) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxDataOutputStream data(*m_output);
|
||||
wxDataOutputStream fmt_d_data(fmt_data);
|
||||
|
||||
data.BigEndianOrdered(FALSE);
|
||||
fmt_d_data.BigEndianOrdered(FALSE);
|
||||
|
||||
WRITE_SIGNATURE(m_output, RIFF_SIGNATURE);
|
||||
|
||||
FAIL_WITH(m_output->LastWrite() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
WRITE_SIGNATURE((&fmt_data), WAVE_SIGNATURE);
|
||||
|
||||
{
|
||||
wxSoundFormatBase *frmt;
|
||||
|
||||
WRITE_SIGNATURE((&fmt_data), FMT_SIGNATURE);
|
||||
|
||||
switch (m_sndformat->GetType()) {
|
||||
case wxSOUND_PCM:
|
||||
frmt = HandleInputPCM(fmt_d_data);
|
||||
break;
|
||||
case wxSOUND_G72X:
|
||||
frmt = HandleInputG72X(fmt_d_data);
|
||||
break;
|
||||
default:
|
||||
m_snderror = wxSOUND_NOCODEC;
|
||||
return FALSE;
|
||||
|
||||
wxUint32 signature;
|
||||
wxMemoryOutputStream fmt_data;
|
||||
|
||||
if (!m_output) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FAIL_WITH(!frmt, wxSOUND_NOCODEC);
|
||||
|
||||
if (!SetSoundFormat(*frmt)) {
|
||||
delete frmt;
|
||||
return FALSE;
|
||||
|
||||
wxDataOutputStream data(*m_output);
|
||||
wxDataOutputStream fmt_d_data(fmt_data);
|
||||
|
||||
data.BigEndianOrdered(FALSE);
|
||||
fmt_d_data.BigEndianOrdered(FALSE);
|
||||
|
||||
WRITE_SIGNATURE(m_output, RIFF_SIGNATURE);
|
||||
|
||||
FAIL_WITH(m_output->LastWrite() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
WRITE_SIGNATURE((&fmt_data), WAVE_SIGNATURE);
|
||||
|
||||
{
|
||||
wxSoundFormatBase *frmt;
|
||||
|
||||
WRITE_SIGNATURE((&fmt_data), FMT_SIGNATURE);
|
||||
|
||||
switch (m_sndformat->GetType()) {
|
||||
case wxSOUND_PCM:
|
||||
frmt = HandleInputPCM(fmt_d_data);
|
||||
break;
|
||||
case wxSOUND_G72X:
|
||||
frmt = HandleInputG72X(fmt_d_data);
|
||||
break;
|
||||
default:
|
||||
m_snderror = wxSOUND_NOCODEC;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
FAIL_WITH(!frmt, wxSOUND_NOCODEC);
|
||||
|
||||
if (!SetSoundFormat(*frmt)) {
|
||||
delete frmt;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
delete frmt;
|
||||
}
|
||||
|
||||
data << (fmt_data.GetSize() + m_sndformat->GetBytesFromTime(time));
|
||||
|
||||
delete frmt;
|
||||
}
|
||||
|
||||
data << (fmt_data.GetSize() + m_sndformat->GetBytesFromTime(time));
|
||||
|
||||
{
|
||||
char *out_buf;
|
||||
out_buf = new char[fmt_data.GetSize()];
|
||||
|
||||
fmt_data.CopyTo(out_buf, fmt_data.GetSize());
|
||||
m_output->Write(out_buf, fmt_data.GetSize());
|
||||
|
||||
delete[] out_buf;
|
||||
}
|
||||
|
||||
WRITE_SIGNATURE(m_output, DATA_SIGNATURE);
|
||||
data.Write32(m_sndformat->GetBytesFromTime(time));
|
||||
return TRUE;
|
||||
// We, finally, copy the header block to the output stream
|
||||
{
|
||||
char *out_buf;
|
||||
out_buf = new char[fmt_data.GetSize()];
|
||||
|
||||
fmt_data.CopyTo(out_buf, fmt_data.GetSize());
|
||||
m_output->Write(out_buf, fmt_data.GetSize());
|
||||
|
||||
delete[] out_buf;
|
||||
}
|
||||
|
||||
WRITE_SIGNATURE(m_output, DATA_SIGNATURE);
|
||||
data.Write32(m_sndformat->GetBytesFromTime(time));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::FinishRecording()
|
||||
{
|
||||
if (m_output->SeekO(0, wxFromStart) == wxInvalidOffset)
|
||||
// We can't but there is no error.
|
||||
if (m_output->SeekO(0, wxFromStart) == wxInvalidOffset)
|
||||
// We can't but there is no error.
|
||||
return TRUE;
|
||||
|
||||
if (m_bytes_left == 0)
|
||||
return TRUE;
|
||||
|
||||
// TODO: Update headers when we stop before the specified time (if possible)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (m_bytes_left == 0)
|
||||
bool wxSoundWave::RepositionStream(wxUint32 position)
|
||||
{
|
||||
if (m_base_offset == wxInvalidOffset)
|
||||
return FALSE;
|
||||
m_input->SeekI(m_base_offset, wxFromStart);
|
||||
return TRUE;
|
||||
|
||||
// TODO: Update headers when we stop before the specified time (if possible)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxUint32 wxSoundWave::GetData(void *buffer, wxUint32 len)
|
||||
{
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
}
|
||||
|
||||
wxUint32 wxSoundWave::PutData(const void *buffer, wxUint32 len)
|
||||
{
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
//
|
||||
|
||||
class wxSoundWave: public wxSoundFileStream {
|
||||
public:
|
||||
public:
|
||||
wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundWave();
|
||||
@ -32,10 +32,11 @@ class wxSoundWave: public wxSoundFileStream {
|
||||
bool CanRead();
|
||||
wxString GetCodecName() const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
bool PrepareToPlay();
|
||||
bool PrepareToRecord(unsigned long time);
|
||||
bool PrepareToRecord(wxUint32 time);
|
||||
bool FinishRecording();
|
||||
bool RepositionStream(wxUint32 position);
|
||||
|
||||
wxUint32 GetData(void *buffer, wxUint32 len);
|
||||
wxUint32 PutData(const void *buffer, wxUint32 len);
|
||||
@ -48,6 +49,9 @@ class wxSoundWave: public wxSoundFileStream {
|
||||
wxUint16 byte_p_spl, wxUint16 bits_p_spl);
|
||||
wxSoundFormatBase *HandleInputPCM(wxDataOutputStream& data);
|
||||
wxSoundFormatBase *HandleInputG72X(wxDataOutputStream& data);
|
||||
|
||||
protected:
|
||||
off_t m_base_offset;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -286,8 +286,6 @@ class wxProcessFileInputStream: public wxInputStream {
|
||||
|
||||
protected:
|
||||
size_t OnSysRead(void *buffer, size_t bufsize);
|
||||
off_t OnSysSeek(off_t seek, wxSeekMode mode);
|
||||
off_t OnSysTell() const;
|
||||
|
||||
protected:
|
||||
int m_fd;
|
||||
@ -300,8 +298,6 @@ class wxProcessFileOutputStream: public wxOutputStream {
|
||||
|
||||
protected:
|
||||
size_t OnSysWrite(const void *buffer, size_t bufsize);
|
||||
off_t OnSysSeek(off_t seek, wxSeekMode mode);
|
||||
off_t OnSysTell() const;
|
||||
|
||||
protected:
|
||||
int m_fd;
|
||||
@ -332,18 +328,6 @@ size_t wxProcessFileInputStream::OnSysRead(void *buffer, size_t bufsize)
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t wxProcessFileInputStream::OnSysSeek(off_t WXUNUSED(seek),
|
||||
wxSeekMode WXUNUSED(mode))
|
||||
{
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
off_t wxProcessFileInputStream::OnSysTell() const
|
||||
{
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
|
||||
wxProcessFileOutputStream::wxProcessFileOutputStream(int fd)
|
||||
{
|
||||
m_fd = fd;
|
||||
@ -367,17 +351,6 @@ size_t wxProcessFileOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t wxProcessFileOutputStream::OnSysSeek(off_t WXUNUSED(seek),
|
||||
wxSeekMode WXUNUSED(mode))
|
||||
{
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
off_t wxProcessFileOutputStream::OnSysTell() const
|
||||
{
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
long wxExecute(wxChar **argv,
|
||||
|
Loading…
Reference in New Issue
Block a user