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:
Guilhem Lavaux 2000-02-25 19:07:14 +00:00
parent a9c3ed030e
commit 794bcc2dea
14 changed files with 905 additions and 817 deletions

View File

@ -45,3 +45,4 @@ You need to move the three files included in this directory:
- utilsunx.cpp => src/unix - utilsunx.cpp => src/unix
- process.cpp => src/common - process.cpp => src/common
- process.h => include/wx - process.h => include/wx
- utilsexc.cpp => src/msw

View File

@ -69,64 +69,66 @@
class MMBoardSoundFile: public MMBoardFile { class MMBoardSoundFile: public MMBoardFile {
public: public:
MMBoardSoundFile(const wxString& filename); MMBoardSoundFile(const wxString& filename);
~MMBoardSoundFile(); ~MMBoardSoundFile();
bool NeedWindow(); bool NeedWindow();
void SetWindow(wxWindow *window); void SetWindow(wxWindow *window);
void Play(); void Play();
void Pause(); void Pause();
void Resume(); void Resume();
void Stop(); void Stop();
MMBoardTime GetPosition(); MMBoardTime GetPosition();
MMBoardTime GetLength(); MMBoardTime GetLength();
void SetPosition(MMBoardTime btime);
bool IsStopped();
bool IsPaused(); bool IsStopped();
bool IsPaused();
wxString GetStringType();
wxString GetStringInformation(); wxString GetStringType();
wxString GetStringInformation();
protected: protected:
wxSoundFileStream *GetDecoder(); wxSoundFileStream *GetDecoder();
wxSoundStream *m_output_stream;
wxInputStream *m_input_stream;
wxSoundFileStream *m_file_stream;
wxSoundStream *m_output_stream; MMBoardTime m_length;
wxInputStream *m_input_stream; wxUint8 m_file_type;
wxSoundFileStream *m_file_stream;
MMBoardTime m_length;
wxUint8 m_file_type;
}; };
class MMBoardVideoFile: public MMBoardFile { class MMBoardVideoFile: public MMBoardFile {
public: public:
MMBoardVideoFile(const wxString& filename); MMBoardVideoFile(const wxString& filename);
~MMBoardVideoFile(); ~MMBoardVideoFile();
bool NeedWindow(); bool NeedWindow();
void SetWindow(wxWindow *window); void SetWindow(wxWindow *window);
void Play(); void Play();
void Pause(); void Pause();
void Resume(); void Resume();
void Stop(); void Stop();
MMBoardTime GetPosition(); MMBoardTime GetPosition();
MMBoardTime GetLength(); MMBoardTime GetLength();
void SetPosition(MMBoardTime btime);
bool IsStopped();
bool IsPaused(); bool IsStopped();
bool IsPaused();
wxString GetStringType();
wxString GetStringInformation(); wxString GetStringType();
wxString GetStringInformation();
protected: protected:
wxWindow *m_output_window; wxWindow *m_output_window;
wxVideoBaseDriver *m_video_driver; wxVideoBaseDriver *m_video_driver;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -143,95 +145,106 @@ protected:
MMBoardSoundFile::MMBoardSoundFile(const wxString& filename) MMBoardSoundFile::MMBoardSoundFile(const wxString& filename)
: MMBoardFile() : MMBoardFile()
{ {
m_input_stream = new wxFileInputStream(filename); m_input_stream = new wxFileInputStream(filename);
m_output_stream = MMBoardManager::OpenSoundStream(); m_output_stream = MMBoardManager::OpenSoundStream();
m_file_stream = GetDecoder();
if (!m_file_stream) {
SetError(MMBoard_UnknownFile);
return;
}
// Compute length m_file_stream = GetDecoder();
wxUint32 length, seconds;
if (!m_file_stream) {
SetError(MMBoard_UnknownFile);
return;
}
// Compute length
wxUint32 length, seconds;
length = m_file_stream->GetLength(); length = m_file_stream->GetLength();
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length);
m_length.seconds = seconds % 60; m_length.seconds = seconds % 60;
m_length.minutes = (seconds / 60) % 60; m_length.minutes = (seconds / 60) % 60;
m_length.hours = seconds / 3600; m_length.hours = seconds / 3600;
} }
MMBoardSoundFile::~MMBoardSoundFile() MMBoardSoundFile::~MMBoardSoundFile()
{ {
if (m_file_stream) if (m_file_stream)
delete m_file_stream; delete m_file_stream;
MMBoardManager::UnrefSoundStream(m_output_stream); MMBoardManager::UnrefSoundStream(m_output_stream);
delete m_input_stream; delete m_input_stream;
} }
wxSoundFileStream *MMBoardSoundFile::GetDecoder() wxSoundFileStream *MMBoardSoundFile::GetDecoder()
{ {
wxSoundFileStream *f_stream; wxSoundFileStream *f_stream;
// First, we try a Wave decoder // First, we try a Wave decoder
f_stream = new wxSoundWave(*m_input_stream, *m_output_stream); f_stream = new wxSoundWave(*m_input_stream, *m_output_stream);
m_file_type = MMBoard_WAVE; m_file_type = MMBoard_WAVE;
if (f_stream->CanRead()) if (f_stream->CanRead())
return f_stream; return f_stream;
delete f_stream; delete f_stream;
// Then, a AIFF decoder // Then, a AIFF decoder
f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream); f_stream = new wxSoundAiff(*m_input_stream, *m_output_stream);
m_file_type = MMBoard_AIFF; m_file_type = MMBoard_AIFF;
if (f_stream->CanRead()) if (f_stream->CanRead())
return f_stream; return f_stream;
delete f_stream; delete f_stream;
m_file_type = MMBoard_UNKNOWNTYPE; m_file_type = MMBoard_UNKNOWNTYPE;
// TODO: automate // TODO: automate
return NULL; return NULL;
} }
MMBoardTime MMBoardSoundFile::GetLength() MMBoardTime MMBoardSoundFile::GetLength()
{ {
return m_length; return m_length;
} }
bool MMBoardSoundFile::IsStopped() bool MMBoardSoundFile::IsStopped()
{ {
return m_file_stream->IsStopped(); return m_file_stream->IsStopped();
} }
bool MMBoardSoundFile::IsPaused() bool MMBoardSoundFile::IsPaused()
{ {
return m_file_stream->IsPaused(); return m_file_stream->IsPaused();
} }
MMBoardTime MMBoardSoundFile::GetPosition() MMBoardTime MMBoardSoundFile::GetPosition()
{ {
wxUint32 length, seconds; wxUint32 length, seconds;
MMBoardTime file_time; MMBoardTime file_time;
file_time.seconds = file_time.minutes = file_time.hours = 0; file_time.seconds = file_time.minutes = file_time.hours = 0;
if (m_file_stream->IsStopped()) 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; return file_time;
}
length = m_file_stream->GetPosition(); void MMBoardSoundFile::SetPosition(MMBoardTime btime)
seconds = m_file_stream->GetSoundFormat().GetTimeFromBytes(length); {
file_time.seconds = seconds % 60; wxUint32 itime;
file_time.minutes = (seconds / 60) % 60;
file_time.hours = seconds / 3600;
return file_time; itime = btime.seconds + btime.minutes * 60 + btime.hours;
m_file_stream->SetPosition(
m_file_stream->GetSoundFormat().GetBytesFromTime(itime)
);
} }
bool MMBoardSoundFile::NeedWindow() bool MMBoardSoundFile::NeedWindow()
{ {
return FALSE; return FALSE;
} }
void MMBoardSoundFile::SetWindow(wxWindow *window) void MMBoardSoundFile::SetWindow(wxWindow *window)
@ -240,37 +253,37 @@ void MMBoardSoundFile::SetWindow(wxWindow *window)
void MMBoardSoundFile::Play() void MMBoardSoundFile::Play()
{ {
m_file_stream->Play(); m_file_stream->Play();
} }
void MMBoardSoundFile::Pause() void MMBoardSoundFile::Pause()
{ {
m_file_stream->Pause(); m_file_stream->Pause();
} }
void MMBoardSoundFile::Resume() void MMBoardSoundFile::Resume()
{ {
m_file_stream->Resume(); m_file_stream->Resume();
} }
void MMBoardSoundFile::Stop() void MMBoardSoundFile::Stop()
{ {
m_file_stream->Stop(); m_file_stream->Stop();
} }
wxString MMBoardSoundFile::GetStringType() wxString MMBoardSoundFile::GetStringType()
{ {
switch (m_file_type) { switch (m_file_type) {
case MMBoard_WAVE: case MMBoard_WAVE:
return wxString(wxT("WAVE file")); return wxString(wxT("WAVE file"));
break; break;
case MMBoard_AIFF: case MMBoard_AIFF:
return wxString(wxT("AIFF file")); return wxString(wxT("AIFF file"));
break; break;
default: default:
return wxString(wxT("Unknown file")); return wxString(wxT("Unknown file"));
break; break;
} }
} }
wxString MMBoardSoundFile::GetStringInformation() wxString MMBoardSoundFile::GetStringInformation()
@ -392,6 +405,10 @@ MMBoardTime MMBoardVideoFile::GetLength()
return btime; return btime;
} }
void MMBoardVideoFile::SetPosition(MMBoardTime btime)
{
}
bool MMBoardVideoFile::IsStopped() bool MMBoardVideoFile::IsStopped()
{ {
return m_video_driver->IsStopped(); return m_video_driver->IsStopped();

View File

@ -54,7 +54,8 @@ class MMBoardFile {
virtual MMBoardTime GetPosition() = 0; virtual MMBoardTime GetPosition() = 0;
virtual MMBoardTime GetLength() = 0; virtual MMBoardTime GetLength() = 0;
virtual void SetPosition(MMBoardTime btime) = 0;
virtual bool IsStopped() = 0; virtual bool IsStopped() = 0;
virtual bool IsPaused() = 0; virtual bool IsPaused() = 0;

View File

@ -71,43 +71,44 @@
class MMBoardFrame : public wxFrame class MMBoardFrame : public wxFrame
{ {
public: public:
// ctor(s) // ctor(s)
MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size); MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
// dtor // dtor
~MMBoardFrame(); ~MMBoardFrame();
// event handlers // event handlers
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
void OnOpen(wxCommandEvent& event); void OnOpen(wxCommandEvent& event);
void OnPlay(wxCommandEvent& event); void OnPlay(wxCommandEvent& event);
void OnStop(wxCommandEvent& event); void OnStop(wxCommandEvent& event);
void OnPause(wxCommandEvent& event); void OnPause(wxCommandEvent& event);
void OnRefreshInfo(wxEvent& event); void OnEject(wxCommandEvent& event);
void OnRefreshInfo(wxEvent& event);
void OpenVideoWindow(); void OnSetPosition(wxCommandEvent& event);
void CloseVideoWindow();
void OpenVideoWindow();
void CloseVideoWindow();
private:
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
private: private:
// any class wishing to process wxWindows events must use this macro void UpdateMMedInfo();
DECLARE_EVENT_TABLE() void UpdateInfoText();
private: MMBoardFile *m_opened_file;
void UpdateMMedInfo();
void UpdateInfoText(); wxSlider *m_positionSlider;
wxBitmapButton *m_playButton, *m_pauseButton, *m_stopButton, *m_ejectButton;
MMBoardFile *m_opened_file; wxStaticText *m_fileType, *m_infoText;
wxWindow *m_video_window;
wxSlider *m_positionSlider;
wxBitmapButton *m_playButton, *m_pauseButton, *m_stopButton, *m_ejectButton; wxPanel *m_panel;
wxStaticText *m_fileType, *m_infoText; wxSizer *m_sizer;
wxWindow *m_video_window;
wxTimer *m_refreshTimer;
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_PlayButton, MMBoardFrame::OnPlay)
EVT_BUTTON(MMBoard_StopButton, MMBoardFrame::OnStop) EVT_BUTTON(MMBoard_StopButton, MMBoardFrame::OnStop)
EVT_BUTTON(MMBoard_PauseButton, MMBoardFrame::OnPause) 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) EVT_CUSTOM(wxEVT_TIMER, MMBoard_RefreshInfo, MMBoardFrame::OnRefreshInfo)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -190,39 +193,39 @@ bool MMBoardApp::OnInit()
wxUint8 MMBoardApp::TestMultimediaCaps() wxUint8 MMBoardApp::TestMultimediaCaps()
{ {
wxSoundStream *dev; wxSoundStream *dev;
wxUint8 caps; wxUint8 caps;
caps = 0; caps = 0;
#ifdef __UNIX__ #ifdef __UNIX__
// We now test the ESD support // We now test the ESD support
dev = new wxSoundStreamESD(); dev = new wxSoundStreamESD();
if (dev->GetError() == wxSOUND_NOERR) if (dev->GetError() == wxSOUND_NOERR)
caps |= MM_SOUND_ESD; caps |= MM_SOUND_ESD;
delete dev; delete dev;
// We test the OSS (Open Sound System) support. // We test the OSS (Open Sound System) support.
#if 0 #if 0
dev = new wxSoundStreamOSS(); dev = new wxSoundStreamOSS();
if (dev->GetError() == wxSOUND_NOERR) if (dev->GetError() == wxSOUND_NOERR)
caps |= MM_SOUND_OSS; caps |= MM_SOUND_OSS;
delete dev; delete dev;
#endif #endif
#endif #endif
#ifdef __WIN32__ #ifdef __WIN32__
// We test the Windows sound support. // We test the Windows sound support.
dev = new wxSoundStreamWin(); dev = new wxSoundStreamWin();
if (dev->GetError() == wxSOUND_NOERR) if (dev->GetError() == wxSOUND_NOERR)
caps |= MM_SOUND_WIN; caps |= MM_SOUND_WIN;
delete dev; delete dev;
#endif #endif
return caps; return caps;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -243,20 +246,20 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
SetIcon(wxICON(mondrian)); SetIcon(wxICON(mondrian));
// create a menu bar // 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 // the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu; 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->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... // now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar(); wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, _T("&File")); menuBar->Append(menuFile, wxT("&File"));
menuBar->Append(helpMenu, _T("&Help")); menuBar->Append(helpMenu, wxT("&Help"));
// ... and attach this menu bar to the frame // ... and attach this menu bar to the frame
SetMenuBar(menuBar); SetMenuBar(menuBar);
@ -264,7 +267,7 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only) // create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(3); CreateStatusBar(3);
SetStatusText(_T("Welcome to wxWindows!")); SetStatusText(wxT("Welcome to wxWindows!"));
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
// Misc variables // Misc variables
@ -277,7 +280,8 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
wxDefaultPosition, wxSize(300, -1), wxDefaultPosition, wxSize(300, -1),
wxSL_HORIZONTAL | wxSL_AUTOTICKS); wxSL_HORIZONTAL | wxSL_AUTOTICKS);
m_positionSlider->SetPageSize(60); // 60 secs m_positionSlider->SetPageSize(60); // 60 secs
m_positionSlider->Enable(FALSE);
// Initialize info panel // Initialize info panel
wxPanel *infoPanel = new wxPanel( m_panel, -1); wxPanel *infoPanel = new wxPanel( m_panel, -1);
infoPanel->SetBackgroundColour(*wxBLACK); infoPanel->SetBackgroundColour(*wxBLACK);
@ -285,7 +289,7 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
wxBoxSizer *infoSizer = new wxBoxSizer(wxVERTICAL); 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); wxStaticLine *line = new wxStaticLine(infoPanel, -1);
m_infoText = new wxStaticText(infoPanel, -1, ""); m_infoText = new wxStaticText(infoPanel, -1, "");
@ -346,10 +350,10 @@ MMBoardFrame::MMBoardFrame(const wxString& title, const wxPoint& pos, const wxSi
MMBoardFrame::~MMBoardFrame() MMBoardFrame::~MMBoardFrame()
{ {
if (m_opened_file) if (m_opened_file)
delete m_opened_file; delete m_opened_file;
delete m_refreshTimer; delete m_refreshTimer;
} }
void MMBoardFrame::OpenVideoWindow() void MMBoardFrame::OpenVideoWindow()
@ -366,14 +370,14 @@ void MMBoardFrame::OpenVideoWindow()
void MMBoardFrame::CloseVideoWindow() void MMBoardFrame::CloseVideoWindow()
{ {
if (!m_video_window) if (!m_video_window)
return; return;
m_sizer->Remove(m_video_window); m_sizer->Remove(m_video_window);
delete m_video_window; delete m_video_window;
m_video_window = NULL; m_video_window = NULL;
m_sizer->Fit(this); m_sizer->Fit(this);
} }
// event handlers // event handlers
@ -387,93 +391,97 @@ void MMBoardFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
void MMBoardFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MMBoardFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{ {
wxString msg; wxString msg;
msg.Printf( _T("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n") msg.Printf( wxT("wxWindows Multimedia board v1.0a, wxMMedia v2.0a:\n")
_T("an example of the capabilities of the wxWindows multimedia classes.\n") wxT("an example of the capabilities of the wxWindows multimedia classes.\n")
_T("Copyright 1999, 2000, Guilhem Lavaux.\n")); wxT("Copyright 1999, 2000, Guilhem Lavaux.\n"));
wxMessageBox(msg, "About MMBoard", wxOK | wxICON_INFORMATION, this); wxMessageBox(msg, "About MMBoard", wxOK | wxICON_INFORMATION, this);
} }
void MMBoardFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) void MMBoardFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
{ {
wxString selected_file; wxString selected_file;
if (m_opened_file) { if (m_opened_file) {
if (!m_opened_file->IsStopped()) { if (!m_opened_file->IsStopped()) {
wxCommandEvent event2; wxCommandEvent event2;
OnStop(event2); OnStop(event2);
}
delete m_opened_file;
} }
delete m_opened_file;
} // select a file to be opened
selected_file = wxLoadFileSelector("multimedia", "*", NULL, this);
// select a file to be opened if (selected_file.IsNull())
selected_file = wxLoadFileSelector("multimedia", "*", NULL, this); return;
if (selected_file.IsNull())
return; m_opened_file = MMBoardManager::Open(selected_file);
m_opened_file = MMBoardManager::Open(selected_file); // Change the range values of the slider.
MMBoardTime length;
// 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);
length = m_opened_file->GetLength();
m_positionSlider->SetRange(0, length.hours * 3600 + length.minutes * 60 + length.seconds); // Update misc info
UpdateMMedInfo();
// Update misc info
UpdateMMedInfo(); SetStatusText(selected_file, 2);
SetStatusText(selected_file, 2); // Update info text
UpdateInfoText();
// Update info text
UpdateInfoText(); // Enable a few buttons
m_playButton->Enable(TRUE);
// Enable a few buttons m_ejectButton->Enable(TRUE);
m_playButton->Enable(TRUE); m_positionSlider->Enable(TRUE);
m_ejectButton->Enable(TRUE);
if (m_opened_file->NeedWindow()) {
if (m_opened_file->NeedWindow()) { OpenVideoWindow();
OpenVideoWindow(); m_opened_file->SetWindow(m_video_window);
m_opened_file->SetWindow(m_video_window); } else
} else CloseVideoWindow();
CloseVideoWindow();
} }
void MMBoardFrame::UpdateInfoText() void MMBoardFrame::UpdateInfoText()
{ {
wxString infotext1, infotext2; wxString infotext1, infotext2;
if (m_opened_file) { if (m_opened_file) {
infotext1 = _T("File type:\n\t"); infotext1 = wxT("File type:\n\t");
infotext1 += m_opened_file->GetStringType() + _T("\n"); infotext1 += m_opened_file->GetStringType() + wxT("\n");
infotext2 = _T("File informations:\n\n"); infotext2 = wxT("File informations:\n\n");
infotext2 += m_opened_file->GetStringInformation(); infotext2 += m_opened_file->GetStringInformation();
} else { } else {
infotext1 = _T("File type: \n\tNo file opened"); infotext1 = wxT("File type: \n\tNo file opened");
infotext2 = _T("File informations:\nNo information\n\n\n\n\n"); infotext2 = wxT("File informations:\nNo information\n\n\n\n\n");
} }
m_fileType->SetLabel(infotext1); m_fileType->SetLabel(infotext1);
m_infoText->SetLabel(infotext2); m_infoText->SetLabel(infotext2);
} }
void MMBoardFrame::UpdateMMedInfo() void MMBoardFrame::UpdateMMedInfo()
{ {
wxString temp_string; wxString temp_string;
MMBoardTime current, length; 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) { // We refresh the status bar
current = m_opened_file->GetPosition(); temp_string.Printf(wxT("%02d:%02d / %02d:%02d"), current.hours * 60 + current.minutes,
length = m_opened_file->GetLength(); current.seconds, length.hours * 60 + length.minutes, length.seconds);
} SetStatusText(temp_string, 1);
// We refresh the status bar // We set the slider position
temp_string.Printf("%02d:%02d / %02d:%02d", current.hours * 60 + current.minutes, m_positionSlider->SetValue(current.hours * 3600 + current.minutes * 60 + current.seconds);
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)) void MMBoardFrame::OnRefreshInfo(wxEvent& WXUNUSED(event))
{ {
UpdateMMedInfo(); UpdateMMedInfo();
if (m_opened_file->IsStopped()) { if (m_opened_file->IsStopped()) {
m_refreshTimer->Stop(); m_refreshTimer->Stop();
m_playButton->Enable(TRUE); m_playButton->Enable(TRUE);
m_stopButton->Enable(FALSE); m_stopButton->Enable(FALSE);
m_pauseButton->Enable(FALSE); m_pauseButton->Enable(FALSE);
} }
} }
void MMBoardFrame::OnPlay(wxCommandEvent& WXUNUSED(event)) void MMBoardFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{ {
m_stopButton->Enable(TRUE); m_stopButton->Enable(TRUE);
m_pauseButton->Enable(TRUE); m_pauseButton->Enable(TRUE);
m_playButton->Enable(FALSE); m_playButton->Enable(FALSE);
if (m_opened_file->IsPaused()) { if (m_opened_file->IsPaused()) {
m_opened_file->Resume(); m_opened_file->Resume();
return; return;
} }
m_refreshTimer->Start(1000, FALSE); m_refreshTimer->Start(1000, FALSE);
m_opened_file->Play(); m_opened_file->Play();
m_stopButton->Enable(TRUE); m_stopButton->Enable(TRUE);
m_pauseButton->Enable(TRUE); m_pauseButton->Enable(TRUE);
m_playButton->Enable(FALSE); m_playButton->Enable(FALSE);
} }
void MMBoardFrame::OnStop(wxCommandEvent& WXUNUSED(event)) void MMBoardFrame::OnStop(wxCommandEvent& WXUNUSED(event))
{ {
m_opened_file->Stop(); m_opened_file->Stop();
m_refreshTimer->Stop(); m_refreshTimer->Stop();
m_stopButton->Enable(FALSE); m_stopButton->Enable(FALSE);
m_playButton->Enable(TRUE); m_playButton->Enable(TRUE);
UpdateMMedInfo(); UpdateMMedInfo();
} }
void MMBoardFrame::OnPause(wxCommandEvent& WXUNUSED(event)) void MMBoardFrame::OnPause(wxCommandEvent& WXUNUSED(event))
{ {
m_opened_file->Pause(); m_opened_file->Pause();
m_playButton->Enable(TRUE); m_playButton->Enable(TRUE);
m_pauseButton->Enable(FALSE); 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();
}

View File

@ -31,11 +31,13 @@
wxSoundAiff::wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound) wxSoundAiff::wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound)
: wxSoundFileStream(stream, io_sound) : wxSoundFileStream(stream, io_sound)
{ {
m_base_offset = wxInvalidOffset;
} }
wxSoundAiff::wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound) wxSoundAiff::wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound)
: wxSoundFileStream(stream, io_sound) : wxSoundFileStream(stream, io_sound)
{ {
m_base_offset = wxInvalidOffset;
} }
wxSoundAiff::~wxSoundAiff() wxSoundAiff::~wxSoundAiff()
@ -49,133 +51,142 @@ wxString wxSoundAiff::GetCodecName() const
bool wxSoundAiff::CanRead() bool wxSoundAiff::CanRead()
{ {
wxUint32 signature1, signature2, len; wxUint32 signature1, signature2, len;
if (m_input->Read(&signature1, 4).LastRead() != 4) if (m_input->Read(&signature1, 4).LastRead() != 4)
return FALSE; return FALSE;
if (wxUINT32_SWAP_ON_BE(signature1) != FORM_SIGNATURE) { if (wxUINT32_SWAP_ON_BE(signature1) != FORM_SIGNATURE) {
m_input->Ungetch(&signature1, 4); m_input->Ungetch(&signature1, 4);
return FALSE; return FALSE;
} }
m_input->Read(&len, 4); m_input->Read(&len, 4);
if (m_input->LastRead() != 4) { if (m_input->LastRead() != 4) {
m_input->Ungetch(&len, m_input->LastRead()); m_input->Ungetch(&len, m_input->LastRead());
m_input->Ungetch(&signature1, 4); m_input->Ungetch(&signature1, 4);
return FALSE; return FALSE;
} }
if (m_input->Read(&signature2, 4).LastRead() != 4) { if (m_input->Read(&signature2, 4).LastRead() != 4) {
m_input->Ungetch(&signature2, m_input->LastRead()); 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(&len, 4);
m_input->Ungetch(&signature1, 4); m_input->Ungetch(&signature1, 4);
return FALSE;
} if (
wxUINT32_SWAP_ON_BE(signature2) != AIFF_SIGNATURE &&
m_input->Ungetch(&signature2, 4); wxUINT32_SWAP_ON_BE(signature2) != AIFC_SIGNATURE)
m_input->Ungetch(&len, 4); return FALSE;
m_input->Ungetch(&signature1, 4);
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; } #define FAIL_WITH(condition, err) if (condition) { m_snderror = err; return FALSE; }
bool wxSoundAiff::PrepareToPlay() bool wxSoundAiff::PrepareToPlay()
{ {
wxDataInputStream data(*m_input); wxDataInputStream data(*m_input);
wxUint32 signature, len, ssnd; wxUint32 signature, len, ssnd;
bool end_headers; bool end_headers;
if (!m_input) { if (!m_input) {
m_snderror = wxSOUND_INVSTRM; 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))
return FALSE; return FALSE;
m_input->SeekI(len-18, wxFromCurrent);
break;
} }
case SSND_SIGNATURE: { // "SSND"
data >> ssnd; data.BigEndianOrdered(TRUE);
// m_input->SeekI(4, wxFromCurrent); // Pass an INT32
// m_input->SeekI(len-4, wxFromCurrent); // Pass the rest FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
m_input->SeekI(ssnd + 4, wxFromCurrent); FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != FORM_SIGNATURE, wxSOUND_INVSTRM);
FinishPreparation(len - 8); // "FORM"
end_headers = TRUE;
break; 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: return TRUE;
m_input->SeekI(len, wxFromCurrent);
break;
}
}
return TRUE;
} }
bool wxSoundAiff::PrepareToRecord(unsigned long time) bool wxSoundAiff::PrepareToRecord(wxUint32 time)
{ {
// TODO // TODO
return FALSE; return FALSE;
} }
bool wxSoundAiff::FinishRecording() bool wxSoundAiff::FinishRecording()
{ {
// TODO // TODO
return FALSE; 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) 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) wxUint32 wxSoundAiff::PutData(const void *buffer, wxUint32 len)
{ {
return m_output->Write(buffer, len).LastWrite(); return m_output->Write(buffer, len).LastWrite();
} }

View File

@ -22,7 +22,7 @@
// //
class wxSoundAiff: public wxSoundFileStream { class wxSoundAiff: public wxSoundFileStream {
public: public:
wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound); wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound);
wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound); wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound);
~wxSoundAiff(); ~wxSoundAiff();
@ -30,13 +30,16 @@ class wxSoundAiff: public wxSoundFileStream {
bool CanRead(); bool CanRead();
wxString GetCodecName() const; wxString GetCodecName() const;
protected: protected:
bool PrepareToPlay(); bool PrepareToPlay();
bool PrepareToRecord(unsigned long time); bool PrepareToRecord(wxUint32 time);
bool FinishRecording(); bool FinishRecording();
bool RepositionStream(wxUint32 position);
wxUint32 GetData(void *buffer, wxUint32 len); wxUint32 GetData(void *buffer, wxUint32 len);
wxUint32 PutData(const void *buffer, wxUint32 len); wxUint32 PutData(const void *buffer, wxUint32 len);
protected:
off_t m_base_offset;
}; };
#endif #endif

View File

@ -37,7 +37,8 @@ typedef enum {
wxSOUND_NOFORMAT, wxSOUND_NOFORMAT,
wxSOUND_PCM, wxSOUND_PCM,
wxSOUND_ULAW, wxSOUND_ULAW,
wxSOUND_G72X wxSOUND_G72X,
wxSOUND_MSADPCM
} wxSoundFormatType; } wxSoundFormatType;
// --------------------- // ---------------------

View File

@ -27,13 +27,13 @@
wxSoundRouterStream::wxSoundRouterStream(wxSoundStream& sndio) wxSoundRouterStream::wxSoundRouterStream(wxSoundStream& sndio)
: wxSoundStreamCodec(sndio) : wxSoundStreamCodec(sndio)
{ {
m_router = NULL; m_router = NULL;
} }
wxSoundRouterStream::~wxSoundRouterStream() wxSoundRouterStream::~wxSoundRouterStream()
{ {
if (m_router) if (m_router)
delete m_router; delete m_router;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -42,16 +42,16 @@ wxSoundRouterStream::~wxSoundRouterStream()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len) wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len)
{ {
if (m_router) { if (m_router) {
m_router->Read(buffer, len); m_router->Read(buffer, len);
m_snderror = m_router->GetError(); m_snderror = m_router->GetError();
m_lastcount = m_router->GetLastAccess(); m_lastcount = m_router->GetLastAccess();
} else { } else {
m_sndio->Read(buffer, len); m_sndio->Read(buffer, len);
m_snderror = m_sndio->GetError(); m_snderror = m_sndio->GetError();
m_lastcount = m_sndio->GetLastAccess(); m_lastcount = m_sndio->GetLastAccess();
} }
return *this; return *this;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -59,14 +59,14 @@ wxSoundStream& wxSoundRouterStream::Read(void *buffer, wxUint32 len)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len) wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len)
{ {
if (m_router) { if (m_router) {
m_router->Write(buffer, len); m_router->Write(buffer, len);
m_snderror = m_router->GetError(); m_snderror = m_router->GetError();
m_lastcount = m_router->GetLastAccess(); m_lastcount = m_router->GetLastAccess();
} else { } else {
m_sndio->Write(buffer, len); m_sndio->Write(buffer, len);
m_snderror = m_sndio->GetError(); m_snderror = m_sndio->GetError();
m_lastcount = m_sndio->GetLastAccess(); m_lastcount = m_sndio->GetLastAccess();
} }
return *this; return *this;
} }
@ -80,32 +80,34 @@ wxSoundStream& wxSoundRouterStream::Write(const void *buffer, wxUint32 len)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format) bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
{ {
if (m_router) if (m_router)
delete m_router; delete m_router;
if (m_sndio->SetSoundFormat(format)) { // First, we try to setup the sound device
wxSoundStream::SetSoundFormat(m_sndio->GetSoundFormat()); 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; 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) bool wxSoundRouterStream::StartProduction(int evt)
{ {
if (!m_router) { if (!m_router) {
if (m_sndio->StartProduction(evt)) if (m_sndio->StartProduction(evt))
return TRUE; return TRUE;
m_snderror = m_sndio->GetError(); m_snderror = m_sndio->GetError();
m_lastcount = m_sndio->GetLastAccess(); 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; 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() bool wxSoundRouterStream::StopProduction()
{ {
if (!m_router) { if (!m_router) {
if (m_sndio->StopProduction()) if (m_sndio->StopProduction())
return TRUE; return TRUE;
m_snderror = m_sndio->GetError(); m_snderror = m_sndio->GetError();
m_lastcount = m_sndio->GetLastAccess(); 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; return FALSE;
}
if (m_router->StopProduction())
return TRUE;
m_snderror = m_router->GetError();
m_lastcount = m_router->GetLastAccess();
return FALSE;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// wxSoundFileStream: generic reader // wxSoundFileStream: generic reader
@ -172,12 +173,12 @@ bool wxSoundRouterStream::StopProduction()
wxSoundFileStream::wxSoundFileStream(wxInputStream& stream, wxSoundFileStream::wxSoundFileStream(wxInputStream& stream,
wxSoundStream& io_sound) wxSoundStream& io_sound)
: m_codec(io_sound), m_sndio(&io_sound), : m_codec(io_sound), m_sndio(&io_sound),
m_input(&stream), m_output(NULL), m_state(wxSOUND_FILE_STOPPED) m_input(&stream), m_output(NULL), m_state(wxSOUND_FILE_STOPPED)
{ {
m_length = 0; m_length = 0;
m_bytes_left = 0; m_bytes_left = 0;
m_prepared = FALSE; m_prepared = FALSE;
} }
wxSoundFileStream::wxSoundFileStream(wxOutputStream& stream, wxSoundFileStream::wxSoundFileStream(wxOutputStream& stream,
@ -213,7 +214,7 @@ bool wxSoundFileStream::Play()
return TRUE; return TRUE;
} }
bool wxSoundFileStream::Record(unsigned long time) bool wxSoundFileStream::Record(wxUint32 time)
{ {
if (m_state != wxSOUND_FILE_STOPPED) if (m_state != wxSOUND_FILE_STOPPED)
return FALSE; return FALSE;
@ -346,6 +347,9 @@ wxUint32 wxSoundFileStream::SetPosition(wxUint32 new_position)
if (!m_prepared) if (!m_prepared)
return 0; return 0;
if (!RepositionStream(new_position))
return m_length-m_bytes_left;
if (new_position >= m_length) { if (new_position >= m_length) {
m_bytes_left = 0; m_bytes_left = 0;
return m_length; return m_length;

View File

@ -14,7 +14,7 @@
#include "sndbase.h" #include "sndbase.h"
#include "sndcodec.h" #include "sndcodec.h"
#define wxSOUND_INFINITE_TIME ((unsigned long)-1) #define wxSOUND_INFINITE_TIME ((wxUint32)-1)
// //
// Codec router class // Codec router class
@ -51,73 +51,76 @@ typedef enum {
// //
class wxSoundFileStream: public wxSoundStream { class wxSoundFileStream: public wxSoundStream {
public: public:
wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound); wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound); wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
~wxSoundFileStream(); ~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, ...) // These three functions deals with the length, the position in the sound file.
bool Play(); // All the values are expressed in bytes. If you need the values expressed
bool Record(unsigned long time); // in terms of time, you have to use GetSoundFormat().GetTimeFromBytes(...)
bool Stop(); wxUint32 GetLength();
bool Pause(); wxUint32 GetPosition();
bool Resume(); wxUint32 SetPosition(wxUint32 new_position);
// Functions which return the current state // These two functions use the sound format specified by GetSoundFormat().
bool IsStopped() const { return m_state == wxSOUND_FILE_STOPPED; } // All samples must be encoded in that format.
bool IsPaused() const { return m_state == wxSOUND_FILE_PAUSED; } wxSoundStream& Read(void *buffer, wxUint32 len);
wxSoundStream& Write(const void *buffer, wxUint32 len);
// A user should not call these two functions. Several things must be done before calling them.
// Users should use Play(), ... // This function set the sound format of the file. !! It must be used only
bool StartProduction(int evt); // when you are in output mode (concerning the file) !! If you are in
bool StopProduction(); // input mode (concerning the file) you can't use this function to modify
// the format of the samples returned by Read() !
// These three functions deals with the length, the position in the sound file. // For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
// All the values are expressed in bytes. If you need the values expressed in terms of bool SetSoundFormat(const wxSoundFormatBase& format);
// time, you have to use GetSoundFormat().GetTimeFromBytes(...)
wxUint32 GetLength(); // This function returns the Codec name. This is useful for those who want to build
wxUint32 GetPosition(); // a player (But also in some other case).
wxUint32 SetPosition(wxUint32 new_position); virtual wxString GetCodecName() const;
// These two functions use the sound format specified by GetSoundFormat(). All samples // You should use this function to test whether this file codec can read
// must be encoded in that format. // the stream you passed to it.
wxSoundStream& Read(void *buffer, wxUint32 len); virtual bool CanRead() { return FALSE; }
wxSoundStream& Write(const void *buffer, wxUint32 len);
protected:
// This function set the sound format of the file. !! It must be used only when you are wxSoundRouterStream m_codec;
// in output mode (concerning the file) !! If you are in input mode (concerning the file) wxSoundStream *m_sndio;
// You can't use this function to modify the format of the samples returned by Read() ! wxInputStream *m_input;
// For this action, you must use wxSoundRouterStream applied to wxSoundFileStream. wxOutputStream *m_output;
bool SetSoundFormat(const wxSoundFormatBase& format);
wxSoundFileState m_state, m_oldstate;
// This function returns the Codec name. This is useful for those who want to build wxUint32 m_length, m_bytes_left;
// a player (But also in some other case). bool m_prepared;
virtual wxString GetCodecName() const;
protected:
// You should use this function to test whether this file codec can read the stream you passed virtual bool PrepareToPlay() = 0;
// to it. virtual bool PrepareToRecord(wxUint32 time) = 0;
virtual bool CanRead() { return FALSE; } virtual bool FinishRecording() = 0;
virtual bool RepositionStream(wxUint32 position) = 0;
protected: void FinishPreparation(wxUint32 len);
wxSoundRouterStream m_codec;
wxSoundStream *m_sndio; virtual wxUint32 GetData(void *buffer, wxUint32 len) = 0;
wxInputStream *m_input; virtual wxUint32 PutData(const void *buffer, wxUint32 len) = 0;
wxOutputStream *m_output;
void OnSoundEvent(int evt);
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);
}; };
#endif #endif

View File

@ -10,6 +10,10 @@
#endif #endif
#include <wx/wxprec.h> #include <wx/wxprec.h>
#ifndef WX_PRECOMP
#endif
#include "sndbase.h" #include "sndbase.h"
#include "sndfile.h" #include "sndfile.h"
#include "sndpcm.h" #include "sndpcm.h"
@ -84,7 +88,8 @@ wxSoundStreamUlaw::~wxSoundStreamUlaw()
wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len) wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
{ {
return *this; // TODO
return *this;
} }
wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len) wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)

View File

@ -12,7 +12,6 @@
#pragma interface "sndulaw.h" #pragma interface "sndulaw.h"
#endif #endif
#include <stddef.h>
#include "sndcodec.h" #include "sndcodec.h"
#include "sndbase.h" #include "sndbase.h"
@ -27,6 +26,9 @@ class WXDLLEXPORT wxSoundFormatUlaw: public wxSoundFormatBase {
void SetSampleRate(wxUint32 srate); void SetSampleRate(wxUint32 srate);
wxUint32 GetSampleRate() const; wxUint32 GetSampleRate() const;
void SetChannels(wxUint8 channels);
wxUint8 GetChannels() const;
wxSoundFormatType GetType() const { return wxSOUND_ULAW; } wxSoundFormatType GetType() const { return wxSOUND_ULAW; }
wxSoundFormatBase *Clone() const; wxSoundFormatBase *Clone() const;

View File

@ -31,17 +31,19 @@
#define DATA_SIGNATURE BUILD_SIGNATURE('d','a','t','a') #define DATA_SIGNATURE BUILD_SIGNATURE('d','a','t','a')
#define HEADER_SIZE 4+4 + 4+4+16 + 4+4 #define HEADER_SIZE 4+4 + 4+4+16 + 4+4
// 4+4 => NAME + LEN // 4+4 => NAME + LEN
// 16 => fmt size // 16 => fmt size
wxSoundWave::wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound) 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) wxSoundWave::wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound)
: wxSoundFileStream(stream, io_sound) : wxSoundFileStream(stream, io_sound)
{ {
m_base_offset = wxInvalidOffset;
} }
wxSoundWave::~wxSoundWave() wxSoundWave::~wxSoundWave()
@ -57,276 +59,297 @@ wxString wxSoundWave::GetCodecName() const
bool wxSoundWave::CanRead() bool wxSoundWave::CanRead()
{ {
wxUint32 len, signature1, signature2; wxUint32 len, signature1, signature2;
m_snderror = wxSOUND_NOERR; 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); m_input->Ungetch(&signature1, 4);
return FALSE;
}
m_input->Read(&len, 4); // Test the second signature
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM); if (wxUINT32_SWAP_ON_BE(signature2) != WAVE_SIGNATURE)
return FALSE;
FAIL_WITH(m_input->Read(&signature2, 4).LastRead() != 4, wxSOUND_INVSTRM);
m_input->Ungetch(&signature2, 4); return TRUE;
m_input->Ungetch(&len, 4);
m_input->Ungetch(&signature1, 4);
if (wxUINT32_SWAP_ON_BE(signature2) != WAVE_SIGNATURE)
return FALSE;
return TRUE;
} }
bool wxSoundWave::HandleOutputPCM(wxDataInputStream& data, wxUint16 channels, bool wxSoundWave::HandleOutputPCM(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec, wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl) wxUint16 byte_p_spl, wxUint16 bits_p_spl)
{ {
wxSoundFormatPcm sndformat; wxSoundFormatPcm sndformat;
sndformat.SetSampleRate(sample_fq); sndformat.SetSampleRate(sample_fq);
sndformat.SetBPS(bits_p_spl); sndformat.SetBPS(bits_p_spl);
sndformat.SetChannels(channels); sndformat.SetChannels(channels);
sndformat.Signed(TRUE); sndformat.Signed(TRUE);
sndformat.SetOrder(wxLITTLE_ENDIAN); sndformat.SetOrder(wxLITTLE_ENDIAN);
if (!SetSoundFormat(sndformat)) if (!SetSoundFormat(sndformat))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
bool wxSoundWave::HandleOutputG721(wxDataInputStream& data, wxUint16 channels, bool wxSoundWave::HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec, wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl) wxUint16 byte_p_spl, wxUint16 bits_p_spl)
{ {
wxSoundFormatG72X sndformat; wxSoundFormatG72X sndformat;
sndformat.SetSampleRate(sample_fq); sndformat.SetSampleRate(sample_fq);
sndformat.SetG72XType(wxSOUND_G721); sndformat.SetG72XType(wxSOUND_G721);
if (!SetSoundFormat(sndformat)) if (!SetSoundFormat(sndformat))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
bool wxSoundWave::PrepareToPlay() bool wxSoundWave::PrepareToPlay()
{ {
wxUint32 signature, len; wxUint32 signature, len;
bool end_headers; bool end_headers;
if (!m_input) {
m_snderror = wxSOUND_INVSTRM;
return FALSE;
}
wxDataInputStream data(*m_input);
data.BigEndianOrdered(FALSE);
if (!m_input) { // Get the first signature
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) {
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM); 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(); len = data.Read32();
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM); FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
// dummy len
switch (wxUINT32_SWAP_ON_BE(signature)) { // Get the second signature
case FMT_SIGNATURE: { // "fmt " FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
wxUint16 format, channels, byte_p_spl, bits_p_spl; FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != WAVE_SIGNATURE, wxSOUND_INVSTRM);
wxUint32 sample_fq, byte_p_sec; // "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 // Get the common parameters
>> byte_p_sec >> byte_p_spl >> bits_p_spl; data >> format >> channels >> sample_fq
>> byte_p_sec >> byte_p_spl >> bits_p_spl;
switch (format) {
case 0x01: switch (format) {
if (!HandleOutputPCM(data, channels, sample_fq, case 0x01: // PCM
byte_p_sec, byte_p_spl, bits_p_spl)) if (!HandleOutputPCM(data, channels, sample_fq,
return FALSE; byte_p_sec, byte_p_spl, bits_p_spl))
break; return FALSE;
case 0x40: break;
if (!HandleOutputG721(data, channels, sample_fq, case 0x40: // G721
byte_p_sec, byte_p_spl, bits_p_spl)) if (!HandleOutputG721(data, channels, sample_fq,
return FALSE; byte_p_sec, byte_p_spl, bits_p_spl))
break; return FALSE;
default: break;
m_snderror = wxSOUND_NOCODEC; default:
return FALSE; m_snderror = wxSOUND_NOCODEC;
} return FALSE;
break; }
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" return TRUE;
end_headers = TRUE;
FinishPreparation(len);
break;
default:
m_input->SeekI(len, wxFromCurrent);
break;
}
}
return TRUE;
} }
wxSoundFormatBase *wxSoundWave::HandleInputPCM(wxDataOutputStream& data) wxSoundFormatBase *wxSoundWave::HandleInputPCM(wxDataOutputStream& data)
{ {
wxUint16 format, channels, byte_p_spl, bits_p_spl; wxUint16 format, channels, byte_p_spl, bits_p_spl;
wxUint32 sample_fq, byte_p_sec; wxUint32 sample_fq, byte_p_sec;
wxSoundFormatPcm *pcm; wxSoundFormatPcm *pcm;
pcm = (wxSoundFormatPcm *)(m_sndformat->Clone()); pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
// Write block length // Write block length
data.Write32(16); data.Write32(16);
sample_fq = pcm->GetSampleRate(); sample_fq = pcm->GetSampleRate();
bits_p_spl = pcm->GetBPS(); bits_p_spl = pcm->GetBPS();
channels = pcm->GetChannels(); channels = pcm->GetChannels();
byte_p_spl = pcm->GetBPS() / 8; byte_p_spl = pcm->GetBPS() / 8;
byte_p_sec = pcm->GetBytesFromTime(1); byte_p_sec = pcm->GetBytesFromTime(1);
format = 0x01; format = 0x01;
pcm->Signed(TRUE); pcm->Signed(TRUE);
pcm->SetOrder(wxLITTLE_ENDIAN); pcm->SetOrder(wxLITTLE_ENDIAN);
data << format << channels << sample_fq data << format << channels << sample_fq
<< byte_p_sec << byte_p_spl << bits_p_spl; << byte_p_sec << byte_p_spl << bits_p_spl;
return pcm; return pcm;
} }
wxSoundFormatBase *wxSoundWave::HandleInputG72X(wxDataOutputStream& data) wxSoundFormatBase *wxSoundWave::HandleInputG72X(wxDataOutputStream& data)
{ {
wxUint16 format, channels, byte_p_spl, bits_p_spl; wxUint16 format, channels, byte_p_spl, bits_p_spl;
wxUint32 sample_fq, byte_p_sec; wxUint32 sample_fq, byte_p_sec;
wxSoundFormatG72X *g72x; wxSoundFormatG72X *g72x;
// Write block length // Write block length
data.Write32(16); data.Write32(16);
g72x = (wxSoundFormatG72X *)(m_sndformat->Clone()); g72x = (wxSoundFormatG72X *)(m_sndformat->Clone());
if (g72x->GetG72XType() != wxSOUND_G721) { if (g72x->GetG72XType() != wxSOUND_G721) {
delete g72x; delete g72x;
return NULL; return NULL;
} }
sample_fq = g72x->GetSampleRate(); sample_fq = g72x->GetSampleRate();
bits_p_spl = 4; bits_p_spl = 4;
channels = 1; channels = 1;
byte_p_spl = 0; byte_p_spl = 0;
byte_p_sec = g72x->GetBytesFromTime(1); byte_p_sec = g72x->GetBytesFromTime(1);
format = 0x40; format = 0x40;
data << format << channels << sample_fq data << format << channels << sample_fq
<< byte_p_sec << byte_p_spl << bits_p_spl; << byte_p_sec << byte_p_spl << bits_p_spl;
return g72x; return g72x;
} }
bool wxSoundWave::PrepareToRecord(unsigned long time) bool wxSoundWave::PrepareToRecord(wxUint32 time)
{ {
#define WRITE_SIGNATURE(s,sig) \ #define WRITE_SIGNATURE(s,sig) \
signature = sig; \ signature = sig; \
signature = wxUINT32_SWAP_ON_BE(signature); \ signature = wxUINT32_SWAP_ON_BE(signature); \
FAIL_WITH(s->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM); FAIL_WITH(s->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM);
wxUint32 signature; wxUint32 signature;
wxMemoryOutputStream fmt_data; wxMemoryOutputStream fmt_data;
if (!m_output) { if (!m_output) {
m_snderror = wxSOUND_INVSTRM; m_snderror = wxSOUND_INVSTRM;
return FALSE; 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); wxDataOutputStream data(*m_output);
wxDataOutputStream fmt_d_data(fmt_data);
if (!SetSoundFormat(*frmt)) {
delete frmt; data.BigEndianOrdered(FALSE);
return 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; // We, finally, copy the header block to the output stream
} {
char *out_buf;
data << (fmt_data.GetSize() + m_sndformat->GetBytesFromTime(time)); out_buf = new char[fmt_data.GetSize()];
{ fmt_data.CopyTo(out_buf, fmt_data.GetSize());
char *out_buf; m_output->Write(out_buf, fmt_data.GetSize());
out_buf = new char[fmt_data.GetSize()];
delete[] out_buf;
fmt_data.CopyTo(out_buf, fmt_data.GetSize()); }
m_output->Write(out_buf, fmt_data.GetSize());
WRITE_SIGNATURE(m_output, DATA_SIGNATURE);
delete[] out_buf; data.Write32(m_sndformat->GetBytesFromTime(time));
} return TRUE;
WRITE_SIGNATURE(m_output, DATA_SIGNATURE);
data.Write32(m_sndformat->GetBytesFromTime(time));
return TRUE;
} }
bool wxSoundWave::FinishRecording() bool wxSoundWave::FinishRecording()
{ {
if (m_output->SeekO(0, wxFromStart) == wxInvalidOffset) if (m_output->SeekO(0, wxFromStart) == wxInvalidOffset)
// We can't but there is no error. // 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; 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; return TRUE;
// TODO: Update headers when we stop before the specified time (if possible)
return TRUE;
} }
wxUint32 wxSoundWave::GetData(void *buffer, wxUint32 len) 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) wxUint32 wxSoundWave::PutData(const void *buffer, wxUint32 len)
{ {
return m_output->Write(buffer, len).LastWrite(); return m_output->Write(buffer, len).LastWrite();
} }

View File

@ -24,7 +24,7 @@
// //
class wxSoundWave: public wxSoundFileStream { class wxSoundWave: public wxSoundFileStream {
public: public:
wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound); wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound);
wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound); wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound);
~wxSoundWave(); ~wxSoundWave();
@ -32,10 +32,11 @@ class wxSoundWave: public wxSoundFileStream {
bool CanRead(); bool CanRead();
wxString GetCodecName() const; wxString GetCodecName() const;
protected: protected:
bool PrepareToPlay(); bool PrepareToPlay();
bool PrepareToRecord(unsigned long time); bool PrepareToRecord(wxUint32 time);
bool FinishRecording(); bool FinishRecording();
bool RepositionStream(wxUint32 position);
wxUint32 GetData(void *buffer, wxUint32 len); wxUint32 GetData(void *buffer, wxUint32 len);
wxUint32 PutData(const 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); wxUint16 byte_p_spl, wxUint16 bits_p_spl);
wxSoundFormatBase *HandleInputPCM(wxDataOutputStream& data); wxSoundFormatBase *HandleInputPCM(wxDataOutputStream& data);
wxSoundFormatBase *HandleInputG72X(wxDataOutputStream& data); wxSoundFormatBase *HandleInputG72X(wxDataOutputStream& data);
protected:
off_t m_base_offset;
}; };
#endif #endif

View File

@ -286,8 +286,6 @@ class wxProcessFileInputStream: public wxInputStream {
protected: protected:
size_t OnSysRead(void *buffer, size_t bufsize); size_t OnSysRead(void *buffer, size_t bufsize);
off_t OnSysSeek(off_t seek, wxSeekMode mode);
off_t OnSysTell() const;
protected: protected:
int m_fd; int m_fd;
@ -300,8 +298,6 @@ class wxProcessFileOutputStream: public wxOutputStream {
protected: protected:
size_t OnSysWrite(const void *buffer, size_t bufsize); size_t OnSysWrite(const void *buffer, size_t bufsize);
off_t OnSysSeek(off_t seek, wxSeekMode mode);
off_t OnSysTell() const;
protected: protected:
int m_fd; int m_fd;
@ -332,18 +328,6 @@ size_t wxProcessFileInputStream::OnSysRead(void *buffer, size_t bufsize)
return ret; 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) wxProcessFileOutputStream::wxProcessFileOutputStream(int fd)
{ {
m_fd = fd; m_fd = fd;
@ -367,17 +351,6 @@ size_t wxProcessFileOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
return ret; return ret;
} }
off_t wxProcessFileOutputStream::OnSysSeek(off_t WXUNUSED(seek),
wxSeekMode WXUNUSED(mode))
{
return wxInvalidOffset;
}
off_t wxProcessFileOutputStream::OnSysTell() const
{
return wxInvalidOffset;
}
#endif #endif
long wxExecute(wxChar **argv, long wxExecute(wxChar **argv,