Removed wxMMedia
Added wxMMedia2: it should work on linux (wave read/write, aiff read only) I begin to write windows driver now Added some file to filelist.txt Make configure build wxMMedia2 makefiles git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3381 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f1f5976f1f
commit
526ddb13e2
@ -2733,6 +2733,9 @@ AC_OUTPUT([
|
||||
samples/html/help/Makefile
|
||||
samples/html/printing/Makefile
|
||||
samples/html/test/Makefile
|
||||
utils/wxMMedia2/Makefile
|
||||
utils/wxMMedia2/lib/Makefile
|
||||
utils/wxMMedia2/sample/Makefile
|
||||
],
|
||||
[
|
||||
chmod +x wx-config
|
||||
|
@ -264,6 +264,7 @@ xpmhand.cpp M
|
||||
threadpsx.cpp U
|
||||
utilsunx.cpp U
|
||||
gsocket.c U
|
||||
gsockunx.h U
|
||||
|
||||
gsockgtk.c R
|
||||
win_gtk.c R
|
||||
@ -294,6 +295,7 @@ font.cpp R
|
||||
frame.cpp R
|
||||
gauge.cpp R
|
||||
gdiobj.cpp R
|
||||
gsockgtk.c R
|
||||
icon.cpp R
|
||||
listbox.cpp R
|
||||
main.cpp R
|
||||
@ -455,6 +457,7 @@ gauge.h W
|
||||
gdicmn.h W
|
||||
gdiobj.h W
|
||||
grid.h W
|
||||
gsocket.h W
|
||||
hash.h W
|
||||
help.h W
|
||||
helpbase.h W
|
||||
|
@ -1,7 +0,0 @@
|
||||
-------------
|
||||
| TODO list |
|
||||
-------------
|
||||
|
||||
* Update the sound fragmenter to the new codec scheme.
|
||||
* Fix the codec scheme.
|
||||
* Add more codec.
|
@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
| WARNING: This sub-package doesn't work, so don't try to compile it if you |
|
||||
| don't want to make some development on it. |
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
If you want to build it rename Makefile.bd in Makefile and Makefile.ibd in
|
||||
Makefile.in. After that, rerun config.status.
|
@ -1,91 +0,0 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Patrick Halke, modified by Guilhem Lavaux
|
||||
# Created: 1997
|
||||
# Updated:
|
||||
# Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds 32bit wxstring library for Windows 3.1
|
||||
# and Borland C++ 4.x
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
!include $(WXDIR)\src\makeb32.env
|
||||
|
||||
WXLIBDIR = $(WXDIR)\lib
|
||||
WXLIB = $(WXDIR)\lib\wx32.lib
|
||||
WXINC = $(WXDIR)\include\msw
|
||||
WXBASESRC = $(WXDIR)\src\base
|
||||
WXBASEINC = $(WXDIR)\include\base
|
||||
LIBS=$(WXLIB) cw32 import32 ole2w32
|
||||
|
||||
!ifndef DEBUG
|
||||
DEBUG=0
|
||||
!endif
|
||||
|
||||
!if "$(FINAL)" == "0"
|
||||
LINKFLAGS=/v /Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -Od
|
||||
DEBUG_FLAGS= -v -DDEBUG=$(DEBUG)
|
||||
!else
|
||||
LINKFLAGS=/Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -O2
|
||||
DEBUG_FLAGS = -DDEBUG=$(DEBUG)
|
||||
!endif
|
||||
|
||||
CPPFLAGS=$(DEBUG_FLAGS) $(OPT) @$(CFG)
|
||||
|
||||
LIBTARGET= $(WXLIBDIR)\wxmmedia.lib
|
||||
|
||||
.c.obj:
|
||||
bcc32 $(CPPFLAGS) -P- -c {$< }
|
||||
|
||||
OBJECTS = sndsnd.$(OBJSUFF) sndwav.$(OBJSUFF) vidbdrv.$(OBJSUFF) \
|
||||
sndfile.$(OBJSUFF) sndwin.$(OBJSUFF) mmdata.$(OBJSUFF) \
|
||||
mmfile.$(OBJSUFF) mmsolve.$(OBJSUFF) sndfrag.$(OBJSUFF) \
|
||||
cdbase.$(OBJSUFF) cdwin.$(OBJSUFF) vidwin.$(OBJSUFF) \
|
||||
mmriff.$(OBJSUFF)
|
||||
|
||||
all: $(LIBTARGET)
|
||||
|
||||
$(LIBTARGET): $(OBJECTS)
|
||||
erase $(LIBTARGET)
|
||||
tlib $(LIBTARGET) /P32 @&&!
|
||||
+$(OBJECTS:.obj =.obj +)
|
||||
!
|
||||
|
||||
sndsnd.$(OBJSUFF): sndsnd.$(SRCSUFF) sndsnd.h
|
||||
|
||||
sndwin.$(OBJSUFF): sndwin.$(SRCSUFF) sndwin.h
|
||||
|
||||
sndfile.$(OBJSUFF): sndfile.$(SRCSUFF) sndfile.h
|
||||
|
||||
sndwav.$(OBJSUFF): sndwav.$(SRCSUFF) sndwav.h
|
||||
|
||||
sndfrag.$(OBJSUFF): sndfrag.$(SRCSUFF) sndfrag.h
|
||||
|
||||
mmdata.$(OBJSUFF): mmdata.$(SRCSUFF)
|
||||
|
||||
mmfile.$(OBJSUFF): mmfile.$(SRCSUFF) mmfile.h
|
||||
|
||||
mmsolve.$(OBJSUFF): mmsolve.$(SRCSUFF) mmsolve.h
|
||||
|
||||
vidbdrv.$(OBJSUFF): vidbdrv.$(SRCSUFF) vidbdrv.h
|
||||
|
||||
cdbase.$(OBJSUFF): cdbase.$(SRCSUFF) cdbase.h
|
||||
|
||||
cdwin.$(OBJSUFF): cdwin.$(SRCSUFF) cdwin.h
|
||||
|
||||
vidwin.$(OBJSUFF): vidwin.$(SRCSUFF) vidwin.h
|
||||
|
||||
mmriff.$(OBJSUFF): mmriff.$(SRCSUFF) mmriff.h
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase $(LIBTARGET)
|
||||
-erase *.exe
|
||||
-erase *.res
|
||||
-erase *.map
|
||||
-erase *.rws
|
@ -1,90 +0,0 @@
|
||||
#
|
||||
# File: makefile.nt
|
||||
# Author: Stefan Hammes (stefan.hammes@urz.uni-heidelberg.de) / Julian Smart / Petr Houser (1996)
|
||||
# Created: 1995
|
||||
# Updated:=09
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds wxSock library for Windows NT / Win95
|
||||
|
||||
# Change WXDIR or WXWIN to wherever wxWindows is found
|
||||
!include <..\..\src\ntwxwin.mak>
|
||||
|
||||
WXMMEDDIR = $(WXDIR)\utils\wxmmedia
|
||||
WXMMEDINC = $(WXMMEDDIR)
|
||||
WXMMEDLIB = $(WXDIR)\lib\wxmmedia.lib
|
||||
INC=-I$(WXBASEINC) -I$(WXINC) -I$(WXMMEDINC)
|
||||
|
||||
WXLIB = $(WXDIR)\lib\wx.lib
|
||||
|
||||
LIBS=$(WXSOCKLIB) $(LIBS)
|
||||
#LIBS=$(WXLIB) $(WXSTRINGLIB) oldnames libw llibcew llibce commdlg shell
|
||||
|
||||
OBJECTS = mmdata.obj mmfile.obj sndfile.obj sndsnd.obj sndwin.obj\
|
||||
sndwav.obj sndfrag.obj vidbase.obj
|
||||
|
||||
all: $(WXMMEDLIB)
|
||||
|
||||
wx:
|
||||
cd $(WXDIR)\src\msw
|
||||
nmake -f makefile.nt
|
||||
cd $(ITSYDIR)
|
||||
|
||||
demo:
|
||||
|
||||
$(WXMMEDLIB): $(OBJECTS)
|
||||
-erase $(WXSOCKLIB)
|
||||
$(implib) @<<
|
||||
-out:$(WXSOCKLIB)
|
||||
-machine:$(CPU)
|
||||
$(OBJECTS)
|
||||
<<
|
||||
|
||||
MMdata.obj: MMdata.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
MMfile.obj: MMfile.$(SRCSUFF)
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
SNDfile.obj: SNDfile.$(SRCSUFF) SNDfile.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
SNDwav.obj: SNDwav.$(SRCSUFF) SNDwav.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
SNDwin.obj: SNDwin.$(SRCSUFF) SNDwin.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
SNDsnd.obj: SNDsnd.$(SRCSUFF) SNDsnd.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
SNDfrag.obj: SNDfrag.$(SRCSUFF) SNDfrag.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
VIDbase.obj: VIDbase.$(SRCSUFF) VIDbase.h
|
||||
cl @<<
|
||||
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
|
||||
<<
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.lib
|
||||
-erase *.res
|
||||
-erase *.sbr
|
||||
-erase *.pdb
|
@ -1,96 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmdata.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#include "mmfile.h"
|
||||
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrmt.h"
|
||||
#if defined(__UNIX__)
|
||||
#include "snduss.h"
|
||||
#endif
|
||||
#include "sndfrag.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndwav.h"
|
||||
#include "sndaiff.h"
|
||||
#include "sndau.h"
|
||||
#include "sndpcm.h"
|
||||
#include "sndmulaw.h"
|
||||
#include "sndadpcm.h"
|
||||
#include "vidbase.h"
|
||||
#if defined(__X__) || defined(__WXGTK__)
|
||||
#include "vidxanm.h"
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
#include "sndwin.h"
|
||||
#include "cdwin.h"
|
||||
#include "vidwin.h"
|
||||
#endif
|
||||
#include "cdbase.h"
|
||||
#ifdef __UNIX__
|
||||
#include "cdunix.h"
|
||||
#endif
|
||||
#include "mmsolve.h"
|
||||
// #include "midfile.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxSound, wxObject)
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxSndBuffer, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSndSimpleBuffer, wxSndBuffer)
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxSoundCodec, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSoundPcmCodec, wxSoundCodec)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSoundMulawCodec, wxSoundCodec)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSoundAdpcmCodec, wxSoundCodec)
|
||||
|
||||
#ifdef __UNIX__
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxUssSound, wxSound)
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxWinSound, wxSound)
|
||||
#endif
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxSndFileCodec, wxMMediaFile)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSndWavCodec, wxSndFileCodec)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSndAuCodec, wxSndFileCodec)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSndAiffCodec, wxSndFileCodec)
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxVideoBaseDriver, wxMMediaFile)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxVideoOutput, wxWindow)
|
||||
#if defined(__X__) || defined(__WXGTK__)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
|
||||
#endif
|
||||
#ifdef __WINDOWS__
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxVideoWindows, wxVideoBaseDriver)
|
||||
#endif
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxCDAudio, wxObject)
|
||||
#ifdef linux
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCDAudioLinux, wxCDAudio)
|
||||
#else
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCDAudioWin, wxCDAudio)
|
||||
#endif
|
||||
|
||||
// IMPLEMENT_ABSTRACT_CLASS(wxMidiFile, wxObject)
|
||||
|
||||
wxMediaFileSolve::wxMFileList *wxMediaFileSolve::m_first = NULL;
|
||||
wxUint8 wxMediaFileSolve::m_devnum = 0;
|
||||
|
||||
MMD_REGISTER_FILE("audio/x-wav", "Wav Player", wxSndWavCodec, "wav")
|
||||
MMD_REGISTER_FILE("audio/x-aiff", "Aiff Player", wxSndAiffCodec, "aif")
|
||||
MMD_REGISTER_FILE("audio/x-au", "Sun Audio File Player", wxSndAuCodec, "au")
|
||||
#if defined(__X__) || defined(__WXGTK__)
|
||||
MMD_REGISTER_FILE("video/*", "Video Player", wxVideoXANIM, "mov")
|
||||
#else
|
||||
MMD_REGISTER_FILE("video/avi", "AVI Player", wxVideoWindows, "avi")
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmedia.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __MMEDIA_H__
|
||||
#define __MMEDIA_H__
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
#include "sndwin.h"
|
||||
#define wxSoundDevice wxWinSound
|
||||
|
||||
#include "vidwin.h"
|
||||
#define wxVideoDevice wxVideoWindows
|
||||
|
||||
#else
|
||||
|
||||
#include "snduss.h"
|
||||
#define wxSoundDevice wxUssSound
|
||||
|
||||
#include "vidxanm.h"
|
||||
#define wxVideoDevice wxVideoXANIM
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,199 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmfile.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include <wx/stream.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
#include "mmfile.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxMMediaFile::wxMMediaFile()
|
||||
: m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
|
||||
m_tmpfname((char *)NULL), m_mfname((char *)NULL),
|
||||
m_seekable(FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
wxMMediaFile::wxMMediaFile(wxOutputStream& os, bool seekable)
|
||||
: m_istream(NULL), m_i_temp(NULL), m_ostream(&os), m_o_temp(NULL),
|
||||
m_tmpfname((char *)NULL), m_mfname((char *)NULL),
|
||||
m_seekable(seekable)
|
||||
{
|
||||
}
|
||||
|
||||
wxMMediaFile::wxMMediaFile(wxInputStream& is, bool preload, bool seekable)
|
||||
: m_istream(&is), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
|
||||
m_tmpfname((char *)NULL), m_mfname((char *)NULL),
|
||||
m_seekable(seekable)
|
||||
{
|
||||
if (preload) {
|
||||
wxStreamBuffer *streamb = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
|
||||
streamb->Fixed(FALSE);
|
||||
streamb->Flushable(FALSE);
|
||||
|
||||
m_o_temp = new wxOutputStream(streamb);
|
||||
m_i_temp = new wxInputStream(streamb);
|
||||
|
||||
m_o_temp->Write(is);
|
||||
streamb->ResetBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
wxMMediaFile::wxMMediaFile(const wxString& fname)
|
||||
: m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
|
||||
m_tmpfname((char *)NULL), m_mfname(fname),
|
||||
m_seekable(TRUE)
|
||||
{
|
||||
wxFileStream *s = new wxFileStream(fname);
|
||||
|
||||
m_mfname = fname;
|
||||
m_istream = s;
|
||||
m_ostream = s;
|
||||
}
|
||||
|
||||
void wxMMediaFile::SetFile(wxInputStream& str, bool preload, bool seekable)
|
||||
{
|
||||
CleanUpPrevious();
|
||||
m_istream = &str;
|
||||
m_ostream = NULL;
|
||||
m_seekable = seekable;
|
||||
|
||||
if (preload) {
|
||||
wxStreamBuffer *streamb = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
|
||||
streamb->Fixed(FALSE);
|
||||
streamb->Flushable(FALSE);
|
||||
|
||||
m_o_temp = new wxOutputStream(streamb);
|
||||
m_i_temp = new wxInputStream(streamb);
|
||||
|
||||
m_o_temp->Write(str);
|
||||
streamb->ResetBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
void wxMMediaFile::SetFile(wxOutputStream& str, bool seekable)
|
||||
{
|
||||
CleanUpPrevious();
|
||||
m_ostream = &str;
|
||||
m_istream = NULL;
|
||||
m_seekable = seekable;
|
||||
}
|
||||
|
||||
void wxMMediaFile::SetFile(const wxString& fname)
|
||||
{
|
||||
CleanUpPrevious();
|
||||
|
||||
m_mfname = fname;
|
||||
wxFileStream *f = new wxFileStream(fname);
|
||||
|
||||
SetFile(*f, FALSE, TRUE);
|
||||
}
|
||||
|
||||
void wxMMediaFile::CleanUpPrevious()
|
||||
{
|
||||
if (m_i_temp) {
|
||||
m_i_temp->SeekI(0);
|
||||
|
||||
if (m_ostream)
|
||||
m_ostream->Write(*m_i_temp);
|
||||
|
||||
delete (m_i_temp->InputStreamBuffer());
|
||||
delete m_i_temp;
|
||||
delete m_o_temp;
|
||||
|
||||
if (m_tmpfname)
|
||||
wxRemoveFile(m_tmpfname);
|
||||
}
|
||||
|
||||
if (!m_mfname.IsNull() && m_mfname != "")
|
||||
delete m_istream;
|
||||
|
||||
m_i_temp = NULL;
|
||||
m_o_temp = NULL;
|
||||
m_istream = NULL;
|
||||
m_ostream = NULL;
|
||||
}
|
||||
|
||||
wxMMediaFile::~wxMMediaFile()
|
||||
{
|
||||
CleanUpPrevious();
|
||||
}
|
||||
|
||||
wxMMtime wxMMediaFile::GetLength()
|
||||
{
|
||||
wxMMtime mm_time = {-1, 0, 0};
|
||||
return mm_time;
|
||||
}
|
||||
|
||||
wxMMtime wxMMediaFile::GetPosition()
|
||||
{
|
||||
wxMMtime mm_time = {0, 0, 0};
|
||||
return mm_time;
|
||||
}
|
||||
|
||||
wxInputStream *wxMMediaFile::GetIRawData()
|
||||
{
|
||||
if (!m_istream)
|
||||
return NULL;
|
||||
|
||||
if (!m_seekable && !m_i_temp)
|
||||
CacheIO();
|
||||
|
||||
return (m_i_temp) ? m_i_temp : m_istream;
|
||||
}
|
||||
|
||||
wxOutputStream *wxMMediaFile::GetORawData()
|
||||
{
|
||||
if (!m_ostream)
|
||||
return NULL;
|
||||
|
||||
if (!m_seekable && !m_i_temp)
|
||||
CacheIO();
|
||||
|
||||
return (m_o_temp) ? m_o_temp : m_ostream;
|
||||
}
|
||||
|
||||
wxString wxMMediaFile::GetCurrentFile()
|
||||
{
|
||||
if (!m_istream && !m_ostream)
|
||||
return wxString((char *)NULL);
|
||||
|
||||
if (!m_mfname && !m_i_temp)
|
||||
CacheIO();
|
||||
|
||||
return (!m_tmpfname.IsEmpty()) ? m_tmpfname : m_mfname;
|
||||
}
|
||||
|
||||
void wxMMediaFile::CacheIO()
|
||||
{
|
||||
if ((!m_istream && !m_ostream) || m_i_temp)
|
||||
return;
|
||||
|
||||
m_tmpfname = wxGetTempFileName("mmd");
|
||||
|
||||
wxFileStream *tmpstream = new wxFileStream(m_tmpfname);
|
||||
m_i_temp = tmpstream;
|
||||
m_o_temp = tmpstream;
|
||||
|
||||
if (m_istream)
|
||||
tmpstream->wxOutputStream::Write(*m_istream);
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmfile.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __MMD_file_H__
|
||||
#define __MMD_file_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "wx/string.h"
|
||||
#include "wx/stream.h"
|
||||
#include "mmtype.h"
|
||||
|
||||
///
|
||||
typedef enum {
|
||||
wxMMFILE_NOERROR,
|
||||
wxMMFILE_INVALID,
|
||||
wxMMFILE_EOF
|
||||
} ///
|
||||
wxMMFileError;
|
||||
|
||||
typedef struct {
|
||||
wxInt8 hours;
|
||||
wxUint8 minutes, seconds;
|
||||
} wxMMtime;
|
||||
|
||||
/// Common base class for multimedia file.
|
||||
class wxMMediaFile {
|
||||
public:
|
||||
wxMMediaFile();
|
||||
///
|
||||
wxMMediaFile(wxInputStream& is, bool preload, bool seekable);
|
||||
///
|
||||
wxMMediaFile(wxOutputStream& is, bool seekable);
|
||||
///
|
||||
wxMMediaFile(const wxString& fname);
|
||||
///
|
||||
virtual ~wxMMediaFile();
|
||||
|
||||
///
|
||||
wxInputStream *GetIRawData();
|
||||
wxOutputStream *GetORawData();
|
||||
///
|
||||
wxString GetCurrentFile();
|
||||
|
||||
///
|
||||
virtual void SetFile(wxInputStream& is,
|
||||
bool preload = FALSE, bool seekable = FALSE);
|
||||
///
|
||||
virtual void SetFile(wxOutputStream& is, bool seekable = FALSE);
|
||||
///
|
||||
void SetFile(const wxString& fname);
|
||||
|
||||
///
|
||||
wxMMFileError GetFileError() const { return m_mmerror; }
|
||||
///
|
||||
virtual wxMMtime GetLength();
|
||||
///
|
||||
virtual wxMMtime GetPosition();
|
||||
///
|
||||
virtual bool StartPlay() = 0;
|
||||
///
|
||||
virtual void StopPlay() = 0;
|
||||
protected:
|
||||
///
|
||||
wxMMFileError m_mmerror;
|
||||
///
|
||||
wxInputStream *m_istream, *m_i_temp;
|
||||
///
|
||||
wxOutputStream *m_ostream, *m_o_temp;
|
||||
///
|
||||
wxString m_tmpfname, m_mfname;
|
||||
///
|
||||
bool m_seekable;
|
||||
|
||||
///
|
||||
void CacheIO();
|
||||
///
|
||||
void CleanUpPrevious();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,215 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmriff.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "mmriff.h"
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmfile.h"
|
||||
#include "mmriff.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxRiffCodec::wxRiffCodec() :
|
||||
riff_i_stream(NULL), riff_o_stream(NULL), chunk_length(INVALID_CHUNK_LEN)
|
||||
{
|
||||
}
|
||||
|
||||
wxRiffCodec::wxRiffCodec(wxInputStream& s) :
|
||||
riff_i_stream(&s), riff_o_stream(NULL), chunk_length(INVALID_CHUNK_LEN)
|
||||
{
|
||||
}
|
||||
|
||||
wxRiffCodec::wxRiffCodec(wxOutputStream& s) :
|
||||
riff_i_stream(NULL), riff_o_stream(&s), chunk_length(INVALID_CHUNK_LEN)
|
||||
{
|
||||
}
|
||||
|
||||
wxRiffCodec::~wxRiffCodec()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxRiffCodec::RiffReset(wxUint8 mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case RIFF_READ:
|
||||
if (!riff_i_stream)
|
||||
return FALSE;
|
||||
riff_i_stream->SeekI(0);
|
||||
chunk_length = INVALID_CHUNK_LEN;
|
||||
return TRUE;
|
||||
case RIFF_WRITE:
|
||||
if (!riff_o_stream)
|
||||
return FALSE;
|
||||
riff_o_stream->SeekO(0);
|
||||
chunk_length = INVALID_CHUNK_LEN;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::ReadData(void *data, wxUint32 size)
|
||||
{
|
||||
if (!riff_i_stream)
|
||||
return FALSE;
|
||||
|
||||
if (chunk_length != INVALID_CHUNK_LEN && (wxUint32)chunk_length < size) {
|
||||
riff_error = wxMMFILE_EOF;
|
||||
return FALSE;
|
||||
}
|
||||
if (chunk_length != INVALID_CHUNK_LEN)
|
||||
chunk_length -= size;
|
||||
|
||||
bool ret = (riff_i_stream->Read((char *)data, size).LastRead() == size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::WriteData(void *data, wxUint32 size)
|
||||
{
|
||||
if (!riff_o_stream)
|
||||
return FALSE;
|
||||
|
||||
if (chunk_length < size) {
|
||||
riff_error = wxMMFILE_EOF;
|
||||
return FALSE;
|
||||
}
|
||||
chunk_length -= size;
|
||||
|
||||
riff_o_stream->Write(data, size);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::Read32(wxUint32& i32)
|
||||
{
|
||||
wxUint8 i8[4];
|
||||
|
||||
if (!ReadData(i8, 4))
|
||||
return FALSE;
|
||||
|
||||
i32 = i8[0];
|
||||
i32 |= ((wxUint32)i8[1]) << 8;
|
||||
i32 |= ((wxUint32)i8[2]) << 16;
|
||||
i32 |= ((wxUint32)i8[3]) << 24;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::Write32(wxUint32 i32)
|
||||
{
|
||||
wxUint8 i8[4];
|
||||
|
||||
i8[0] = i32 & 0xff;
|
||||
i8[1] = (i32 >> 8) & 0xff;
|
||||
i8[2] = (i32 >> 16) & 0xff;
|
||||
i8[3] = (i32 >> 24) & 0xff;
|
||||
|
||||
if (!WriteData(i8, 4))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::Read16(wxUint16& i16)
|
||||
{
|
||||
wxUint8 i8[2];
|
||||
|
||||
if (!ReadData(i8, 2))
|
||||
return FALSE;
|
||||
|
||||
i16 = i8[0];
|
||||
i16 |= ((wxUint16)i8[1]) << 8;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::Write16(wxUint16 i16)
|
||||
{
|
||||
wxUint8 i8[2];
|
||||
|
||||
i8[0] = i16 & 0xff;
|
||||
i8[1] = (i16 >> 8) & 0xff;
|
||||
|
||||
if (!WriteData(i8, 2))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::Skip(wxUint32 skip)
|
||||
{
|
||||
if (!riff_i_stream || (chunk_length != INVALID_CHUNK_LEN && (wxInt32)skip > chunk_length))
|
||||
return FALSE;
|
||||
|
||||
if (chunk_length != INVALID_CHUNK_LEN)
|
||||
chunk_length -= skip;
|
||||
riff_i_stream->SeekI(skip, wxFromCurrent);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxRiffCodec::CreateChunk(const wxString& name, wxUint32 size)
|
||||
{
|
||||
if (!riff_o_stream || name.Length() != 4)
|
||||
return FALSE;
|
||||
|
||||
if (riff_o_stream->Write(name.GetData(), 4).LastError()) {
|
||||
riff_error = wxMMFILE_EOF;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chunk_length = size+4;
|
||||
|
||||
return Write32(size);
|
||||
}
|
||||
|
||||
bool wxRiffCodec::FindChunk(const wxString& name, bool from_here)
|
||||
{
|
||||
char buf[5];
|
||||
wxString str2;
|
||||
|
||||
if (!riff_i_stream)
|
||||
return FALSE;
|
||||
|
||||
if (chunk_length != INVALID_CHUNK_LEN && !from_here)
|
||||
Skip(chunk_length);
|
||||
while (1) {
|
||||
if (riff_i_stream->Read(buf, 4).LastError()) {
|
||||
riff_error = wxMMFILE_EOF;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chunk_length = INVALID_CHUNK_LEN;
|
||||
if (!Read32(chunk_length)) {
|
||||
riff_error = wxMMFILE_EOF;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
buf[4] = 0;
|
||||
str2 = buf;
|
||||
if ((!name.IsNull()) && str2 != name) {
|
||||
Skip(chunk_length);
|
||||
continue;
|
||||
}
|
||||
|
||||
m_chunk = str2;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmriff.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated:
|
||||
// Copyright: (C) 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __MM_riff_H__
|
||||
#define __MM_riff_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmtype.h"
|
||||
#include "mmfile.h"
|
||||
|
||||
#define RIFF_READ 0
|
||||
#define RIFF_WRITE 1
|
||||
#define INVALID_CHUNK_LEN ((wxUint32)-1)
|
||||
|
||||
///
|
||||
class wxRiffCodec {
|
||||
public:
|
||||
///
|
||||
wxRiffCodec();
|
||||
///
|
||||
wxRiffCodec(wxOutputStream& s);
|
||||
///
|
||||
wxRiffCodec(wxInputStream& s);
|
||||
///
|
||||
virtual ~wxRiffCodec();
|
||||
|
||||
///
|
||||
void SetFile(wxInputStream& s) { cout << "RIFF:SetFile(i)" << endl; riff_i_stream = &s; riff_o_stream = NULL; }
|
||||
///
|
||||
void SetFile(wxOutputStream& s) { cout << "RIFF::SetFile(o)" << endl; riff_i_stream = NULL; riff_o_stream = &s; }
|
||||
|
||||
///
|
||||
bool Read32(wxUint32& i32);
|
||||
///
|
||||
bool Read16(wxUint16& i16);
|
||||
///
|
||||
bool ReadData(void *data, wxUint32 size);
|
||||
///
|
||||
bool Skip(wxUint32 skip);
|
||||
|
||||
///
|
||||
bool Write32(wxUint32 i32);
|
||||
///
|
||||
bool Write16(wxUint16 i16);
|
||||
///
|
||||
bool WriteData(void *data, wxUint32 size);
|
||||
|
||||
///
|
||||
inline wxUint32 GetChunkLength() const { return chunk_length; }
|
||||
///
|
||||
inline const wxString& GetChunkName() const { return m_chunk; }
|
||||
|
||||
///
|
||||
bool RiffReset(wxUint8 state);
|
||||
|
||||
///
|
||||
bool FindChunk(const wxString& name = "", bool from_here = FALSE);
|
||||
///
|
||||
bool CreateChunk(const wxString& name, wxUint32 chunk_size);
|
||||
|
||||
///
|
||||
inline wxMMFileError GetError() const { return riff_error; }
|
||||
|
||||
protected:
|
||||
wxInputStream *riff_i_stream;
|
||||
wxOutputStream *riff_o_stream;
|
||||
wxUint32 chunk_length;
|
||||
wxMMFileError riff_error;
|
||||
wxString m_chunk;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,124 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmsolve.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include "mmsolve.h"
|
||||
|
||||
wxMMediaFile *wxMediaFileSolve::ByExtension(const wxString& filename)
|
||||
{
|
||||
wxMFileList *list = m_first;
|
||||
wxString tmp, f_ext;
|
||||
int pos = filename.Find('.', TRUE)+1;
|
||||
|
||||
tmp = filename;
|
||||
f_ext = tmp(pos, filename.Length()-pos);
|
||||
|
||||
printf("f_ext = %s\n", f_ext.GetData());
|
||||
while (list) {
|
||||
printf("list->ext = %s\n", list->ext.GetData());
|
||||
if (list->ext.CompareTo(f_ext) == 0) {
|
||||
wxMMediaFile *mmf = list->creator();
|
||||
return mmf;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxMMediaFile *wxMediaFileSolve::ByName(const wxString& name)
|
||||
{
|
||||
wxMFileList *list = m_first;
|
||||
|
||||
while (list) {
|
||||
if (list->name == name)
|
||||
return (wxMMediaFile *)(list->creator());
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool wxMatchMimeType(const wxString& mime_obj, const wxString& type)
|
||||
{
|
||||
#ifdef USE_GNU_WXSTRING
|
||||
wxString mime2_obj = mime_obj;
|
||||
wxString type2 = type;
|
||||
#define mime_obj mime2_obj
|
||||
#define type type2
|
||||
#endif
|
||||
|
||||
if (mime_obj.Find('*') != -1) {
|
||||
wxString part_str1[2], part_str2[2];
|
||||
|
||||
part_str1[0] = mime_obj.BeforeFirst('/');
|
||||
part_str1[1] = mime_obj.AfterFirst('/');
|
||||
|
||||
part_str2[0] = type.BeforeFirst('/');
|
||||
part_str2[1] = type.AfterFirst('/');
|
||||
|
||||
if (part_str1[0] == "*" && part_str1[1] == "*")
|
||||
return TRUE;
|
||||
|
||||
if (part_str1[0] == "*" && part_str1[1] == part_str2[1])
|
||||
return TRUE;
|
||||
|
||||
if (part_str1[1] == "*" && part_str1[0] == part_str2[1])
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
if (mime_obj == type)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxMMediaFile *wxMediaFileSolve::ByType(const wxString& type)
|
||||
{
|
||||
wxMFileList *list = m_first;
|
||||
|
||||
while (list) {
|
||||
if (wxMatchMimeType(*(list->mime_type), type))
|
||||
return (wxMMediaFile *)(list->creator());
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wxMediaFileSolve::ListMDevice(wxString*& names, wxUint8& devices)
|
||||
{
|
||||
wxMFileList *list = m_first;
|
||||
wxUint8 d = 0;
|
||||
|
||||
if (!m_devnum) {
|
||||
names = NULL;
|
||||
return;
|
||||
}
|
||||
devices = m_devnum;
|
||||
names = new wxString[devices];
|
||||
|
||||
while (list) {
|
||||
names[d++] = list->name;
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
wxMMDfileRegister::wxMMDfileRegister(wxMediaFileCreator cbk,
|
||||
char *mtype, char *ext, char *name)
|
||||
{
|
||||
wxMediaFileSolve::wxMFileList *entry = new wxMediaFileSolve::wxMFileList;
|
||||
|
||||
entry->next = wxMediaFileSolve::m_first;
|
||||
entry->creator = cbk;
|
||||
entry->mime_type = wxString(mtype);
|
||||
entry->name = wxString(name);
|
||||
entry->ext = wxString(ext);
|
||||
wxMediaFileSolve::m_devnum++;
|
||||
wxMediaFileSolve::m_first = entry;
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmsolve.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __MMD_solve_H__
|
||||
#define __MMD_solve_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx/wxprec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmfile.h"
|
||||
|
||||
/** @name Solver classes */
|
||||
//@{
|
||||
|
||||
typedef wxMMediaFile *(*wxMediaFileCreator)();
|
||||
|
||||
/** wxMediaFileSolve is a class to do name resolution on multimedia files
|
||||
* @memo Multimedia file solver
|
||||
* @author Guilhem Lavaux
|
||||
*/
|
||||
class WXDLLEXPORT wxMediaFileSolve : public wxObject {
|
||||
protected:
|
||||
typedef struct wxMFileList {
|
||||
wxMediaFileCreator creator;
|
||||
wxString mime_type, name, ext;
|
||||
wxMFileList *next;
|
||||
} wxMFileList;
|
||||
|
||||
static wxMFileList *m_first;
|
||||
static wxUint8 m_devnum;
|
||||
|
||||
friend class wxMMDfileRegister;
|
||||
public:
|
||||
wxMediaFileSolve() : wxObject() {}
|
||||
~wxMediaFileSolve() {}
|
||||
|
||||
/** It resolves using the extension of the specified filename
|
||||
* @memo
|
||||
* @return the multimedia codec
|
||||
* @param filename
|
||||
*/
|
||||
static wxMMediaFile *ByExtension(const wxString& filename);
|
||||
|
||||
/** It resolves using the real name of a codec
|
||||
* @memo
|
||||
* @return the multimedia codec
|
||||
* @param devname
|
||||
*/
|
||||
static wxMMediaFile *ByName(const wxString& devname);
|
||||
|
||||
/** It resolves using a mime type
|
||||
* @memo
|
||||
* @return the multimedia codec
|
||||
* @param mimetype
|
||||
*/
|
||||
static wxMMediaFile *ByType(const wxString& mimetype);
|
||||
|
||||
/** It lists all codecs currently registered in "names". "names" is allocated
|
||||
* by it and devices returns the number of codecs the list contains
|
||||
* @memo
|
||||
* @return nothing
|
||||
* @param names an array
|
||||
* @param devices
|
||||
*/
|
||||
static void ListMDevice(wxString*& names, wxUint8& devices);
|
||||
};
|
||||
|
||||
///
|
||||
class wxMMDfileRegister {
|
||||
public:
|
||||
///
|
||||
wxMMDfileRegister(wxMediaFileCreator cbk, char *mtype, char *ext, char *name);
|
||||
};
|
||||
|
||||
#define MMD_REGISTER_FILE(mtype, name, class, ext) \
|
||||
static wxMMediaFile *wxMediaFileConstructor_##class() { return new class(); } \
|
||||
wxMMDfileRegister mmd_##class(wxMediaFileConstructor_##class, mtype, ext, name);
|
||||
|
||||
//@}
|
||||
|
||||
#endif
|
@ -1,41 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mmtype.h
|
||||
// Purpose: wxMMedia (imported from wxSocket)
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __SOCKTYPEH__
|
||||
#define __SOCKTYPEH__
|
||||
|
||||
#ifdef __UNIX__
|
||||
#include <stl_config.h>
|
||||
#endif
|
||||
|
||||
/// Type to use for 8 bits unsigned integers
|
||||
typedef unsigned char wxUint8;
|
||||
/// Type to use for 16 bits unsigned integers
|
||||
typedef unsigned short wxUint16;
|
||||
/// Type to use for 32 bits unsigned integers
|
||||
typedef unsigned long wxUint32;
|
||||
#if HAVE_UINT64
|
||||
/// Type to use for 64 bits unsigned integers
|
||||
typedef unsigned long long wxUint64;
|
||||
#endif
|
||||
|
||||
/// Type to use for 8 bits signed integers
|
||||
typedef char wxInt8;
|
||||
/// Type to use for 16 bits signed integers
|
||||
typedef short wxInt16;
|
||||
/// Type to use for 32 bits signed integers
|
||||
typedef long wxInt32;
|
||||
#if HAVE_UINT64
|
||||
/// Type to use for 64 bits signed integers
|
||||
typedef long long wxInt64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,118 +0,0 @@
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndmulaw.h"
|
||||
#endif
|
||||
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrmt.h"
|
||||
#include "sndadpcm.h"
|
||||
#include "adpcm/g72x.h"
|
||||
|
||||
wxSoundAdpcmCodec::wxSoundAdpcmCodec()
|
||||
: wxSoundCodec()
|
||||
{
|
||||
// TODO: For the moment, only 1 channel is supported.
|
||||
m_codec_state = new g72x_state;
|
||||
g72x_init_state(m_codec_state);
|
||||
}
|
||||
|
||||
wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
|
||||
{
|
||||
m_srate = format.GetSampleRate();
|
||||
}
|
||||
|
||||
int wxSoundAdpcmCodec::GetBits(int nbits)
|
||||
{
|
||||
unsigned int mask;
|
||||
int bits;
|
||||
|
||||
if (m_bits_waiting == 0)
|
||||
m_current_byte = m_in_sound->GetChar();
|
||||
|
||||
mask = (1 << nbits) - 1;
|
||||
bits = m_current_byte & mask;
|
||||
m_current_byte >>= nbits;
|
||||
m_bits_waiting -= nbits;
|
||||
return bits;
|
||||
}
|
||||
|
||||
void wxSoundAdpcmCodec::Decode()
|
||||
{
|
||||
int smp, bits;
|
||||
wxSoundDataFormat pref_frmt;
|
||||
|
||||
pref_frmt = GetPreferredFormat(0);
|
||||
if (!(m_io_format == pref_frmt))
|
||||
ChainCodecAfter(pref_frmt);
|
||||
|
||||
bits = GetBits(4);
|
||||
if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
|
||||
while (!StreamOk()) {
|
||||
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
|
||||
m_out_sound->PutChar(smp & 0x00ff);
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
bits = GetBits(4);
|
||||
}
|
||||
} else {
|
||||
while (!StreamOk()) {
|
||||
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
m_out_sound->PutChar(smp & 0x00ff);
|
||||
bits = GetBits(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxSoundAdpcmCodec::Encode()
|
||||
{
|
||||
/*
|
||||
int smp;
|
||||
wxSoundDataFormat pref_frmt;
|
||||
|
||||
pref_frmt = GetPreferredFormat(0);
|
||||
if (!(m_io_format == pref_frmt))
|
||||
ChainCodecAfter(pref_frmt);
|
||||
|
||||
bits = GetBits(4);
|
||||
if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
|
||||
while (!StreamOk()) {
|
||||
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
|
||||
m_out_sound->PutChar(smp & 0x00ff);
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
bits = GetBits(4);
|
||||
}
|
||||
} else {
|
||||
while (!StreamOk()) {
|
||||
smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
m_out_sound->PutChar(smp & 0x00ff);
|
||||
bits = GetBits(4);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
size_t wxSoundAdpcmCodec::GetByteRate() const
|
||||
{
|
||||
return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
|
||||
}
|
||||
|
||||
wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
|
||||
{
|
||||
wxSoundDataFormat format;
|
||||
|
||||
format.SetCodecNo(WXSOUND_PCM);
|
||||
format.SetSampleRate(m_srate);
|
||||
format.SetBps(16);
|
||||
format.SetChannels(1);
|
||||
format.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
#ifdef USE_BE_MACH
|
||||
format.SetByteOrder(wxSND_SAMPLE_BE);
|
||||
#else
|
||||
format.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
#endif
|
||||
return format;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef __MEDIA_SNDADPCM_H__
|
||||
#define __MEDIA_SNDADPCM_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "sndfrmt.h"
|
||||
|
||||
class wxSoundAdpcmCodec : public wxSoundCodec {
|
||||
DECLARE_DYNAMIC_CLASS(wxSoundAdpcmCodec)
|
||||
public:
|
||||
wxSoundAdpcmCodec();
|
||||
~wxSoundAdpcmCodec();
|
||||
|
||||
size_t GetByteRate() const;
|
||||
wxSoundDataFormat GetPreferredFormat(int codec = 0) const;
|
||||
int GetBits(int bits);
|
||||
|
||||
void Decode();
|
||||
void Encode();
|
||||
|
||||
void InitWith(const wxSoundDataFormat& format);
|
||||
protected:
|
||||
struct g72x_state *m_codec_state;
|
||||
int m_bits_waiting, m_current_byte;
|
||||
int m_srate;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,252 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndaiff.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: February 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndaiff.h"
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx/wxprec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "wx/datstrm.h"
|
||||
#include "sndaiff.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#define READ_DATA(n) m_istream->Read(tmp_buf,n)
|
||||
#define WRITE_DATA(n) m_ostream->Write(tmp_buf,n)
|
||||
|
||||
#define READ_STRING(s,n) \
|
||||
READ_DATA(n); \
|
||||
tmp_buf[n] = 0; \
|
||||
s = tmp_buf;
|
||||
|
||||
#define WRITE_STRING(s,n) WRITE_DATA((const char *)s, n)
|
||||
|
||||
#define READ32(i) \
|
||||
READ_DATA(4); \
|
||||
i = (unsigned long)tmp_buf[3] | \
|
||||
((unsigned long)tmp_buf[2] << 8) | \
|
||||
((unsigned long)tmp_buf[1] << 16) | \
|
||||
((unsigned long)tmp_buf[0] << 24);
|
||||
|
||||
#define WRITE32(i) \
|
||||
tmp_buf[3] = i & 0xFF; \
|
||||
tmp_buf[2] = (i >> 8) & 0xFF; \
|
||||
tmp_buf[1] = (i >> 16) & 0xFF; \
|
||||
tmp_buf[0] = (i >> 24) & 0xFF; \
|
||||
WRITE_DATA(4);
|
||||
|
||||
#define READ16(i) \
|
||||
READ_DATA(2); \
|
||||
i = (unsigned short)tmp_buf[1] | \
|
||||
((unsigned short)tmp_buf[0] << 8);
|
||||
|
||||
wxSndAiffCodec::wxSndAiffCodec()
|
||||
: wxSndFileCodec()
|
||||
{
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndAiffCodec::wxSndAiffCodec(wxOutputStream& s, bool seekable)
|
||||
: wxSndFileCodec(s, seekable)
|
||||
{
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndAiffCodec::wxSndAiffCodec(wxInputStream& s, bool preload, bool seekable)
|
||||
: wxSndFileCodec(s, preload, seekable)
|
||||
{
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndAiffCodec::wxSndAiffCodec(const wxString& fname)
|
||||
: wxSndFileCodec(fname)
|
||||
{
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxUint32 wxSndAiffCodec::PrepareToPlay()
|
||||
{
|
||||
char tmp_buf[5];
|
||||
wxString chunk_name;
|
||||
|
||||
wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
|
||||
|
||||
READ_STRING(chunk_name, 4);
|
||||
if (chunk_name != "FORM")
|
||||
return 0;
|
||||
m_istream->SeekI(4, wxFromCurrent);
|
||||
|
||||
READ_STRING(chunk_name, 4);
|
||||
if (chunk_name != "AIFF" && chunk_name != "AIFC")
|
||||
return 0;
|
||||
|
||||
// To check whether the file is good
|
||||
m_spos = 0;
|
||||
m_slen = 0;
|
||||
m_sndformat.SetSampleRate(0);
|
||||
while (!m_spos || !m_sndformat.GetSampleRate()) {
|
||||
READ_STRING(chunk_name, 4);
|
||||
READ32(m_chunksize);
|
||||
|
||||
if (chunk_name == "SSND")
|
||||
ParseSSND();
|
||||
if (chunk_name == "COMM")
|
||||
ParseCOMM();
|
||||
else
|
||||
m_istream->SeekI(m_chunksize, wxFromCurrent);
|
||||
}
|
||||
|
||||
m_sndmode = wxSND_OUTPUT;
|
||||
|
||||
wxUint32 sec1 = m_slen / m_sndformat.GetCodec()->GetByteRate(),
|
||||
sec2 = sec1 % 3600;
|
||||
|
||||
m_sndtime.hours = sec1 / 3600;
|
||||
m_sndtime.minutes = sec2 / 60;
|
||||
m_sndtime.seconds = sec2 % 60;
|
||||
|
||||
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
|
||||
|
||||
m_istream->SeekI(m_spos, wxFromStart);
|
||||
wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
|
||||
|
||||
return m_slen;
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::ParseCOMM()
|
||||
{
|
||||
wxDataInputStream data_s(*m_istream);
|
||||
char tmp_buf[10];
|
||||
wxUint16 channels;
|
||||
wxUint32 srate, num_samples;
|
||||
wxUint16 bps;
|
||||
|
||||
READ16(channels);
|
||||
READ32(num_samples);
|
||||
READ16(bps);
|
||||
|
||||
srate = (wxUint32)data_s.ReadDouble();
|
||||
m_sndformat.SetSampleRate(srate);
|
||||
m_sndformat.SetBps(bps);
|
||||
m_sndformat.SetChannels(channels);
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_BE);
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_UNSIGNED);
|
||||
ChangeCodec(WXSOUND_PCM);
|
||||
|
||||
m_istream->SeekI(m_chunksize-18, wxFromCurrent);
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::ParseSSND()
|
||||
{
|
||||
wxDataInputStream data_s(*m_istream);
|
||||
char tmp_buf[10];
|
||||
|
||||
READ32(m_spos);
|
||||
m_istream->SeekI(4, wxFromCurrent);
|
||||
|
||||
m_slen = m_chunksize - m_spos;
|
||||
m_spos += m_istream->TellI();
|
||||
}
|
||||
|
||||
wxSndAiffCodec::~wxSndAiffCodec()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxSndAiffCodec::OnNeedData(char *buf, wxUint32 size)
|
||||
{
|
||||
m_istream->Read(buf, size);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSndAiffCodec::OnWriteData(char *buf, wxUint32 size)
|
||||
{
|
||||
return ( !(m_ostream->Write(buf, size).LastError()) );
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::WriteCOMM()
|
||||
{
|
||||
/*
|
||||
wxDataOutputStream data_s(*m_ostream);
|
||||
char tmp_buf[10];
|
||||
wxUint16 channels;
|
||||
wxUint32 srate, num_samples;
|
||||
wxUint16 bps;
|
||||
|
||||
m_chunksize = 18;
|
||||
WRITE32(m_chunksize);
|
||||
channels = m_sndformat.GetChannels();
|
||||
srate = m_sndformat.GetSampleRate();
|
||||
bps = m_sndformat.GetBps();
|
||||
|
||||
WRITE16(channels);
|
||||
WRITE32(num_samples);
|
||||
WRITE16(bps);
|
||||
|
||||
data_s.WriteDouble((double)srate);
|
||||
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_BE);
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_UNSIGNED);
|
||||
ChangeCodec(WXSOUND_PCM);
|
||||
*/
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::WriteSSND(wxUint32 fsize)
|
||||
{
|
||||
/*
|
||||
char tmp_buf[10];
|
||||
|
||||
WRITE32(m_spos);
|
||||
// WRITE32(dummy ??);
|
||||
|
||||
m_slen = m_chunksize - m_spos;
|
||||
m_spos += m_istream->TellI();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
bool wxSndAiffCodec::PrepareToRecord(wxUint32 m_fsize)
|
||||
{
|
||||
wxUint32 total_size = m_fsize + 0;
|
||||
char tmp_buf[10];
|
||||
|
||||
m_ostream->Write("FORM", 4);
|
||||
WRITE32(total_size);
|
||||
|
||||
m_ostream->Write("AIFF", 4);
|
||||
|
||||
WriteCOMM();
|
||||
WriteSSND(m_fsize);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::SetFile(wxInputStream& s, bool preload, bool seekable)
|
||||
{
|
||||
wxMMediaFile::SetFile(s, preload, seekable);
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
}
|
||||
|
||||
void wxSndAiffCodec::SetFile(wxOutputStream& s, bool seekable)
|
||||
{
|
||||
wxMMediaFile::SetFile(s, seekable);
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndaiff.h
|
||||
// Purpose: wxMMedia Aiff Codec
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: February 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_aiff_H__
|
||||
#define __SND_aiff_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmriff.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
///
|
||||
class wxSndAiffCodec : public wxSndFileCodec {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxSndAiffCodec)
|
||||
public:
|
||||
///
|
||||
wxSndAiffCodec();
|
||||
///
|
||||
wxSndAiffCodec(wxInputStream& s, bool preload = FALSE, bool seekable = TRUE);
|
||||
///
|
||||
wxSndAiffCodec(wxOutputStream& s, bool seekable = TRUE);
|
||||
///
|
||||
wxSndAiffCodec(const wxString& fname);
|
||||
///
|
||||
virtual ~wxSndAiffCodec();
|
||||
|
||||
virtual bool OnNeedData(char *buf, wxUint32 size);
|
||||
virtual bool OnWriteData(char *buf, wxUint32 size);
|
||||
|
||||
virtual wxUint32 PrepareToPlay();
|
||||
virtual bool PrepareToRecord(wxUint32 file_size);
|
||||
|
||||
virtual void SetFile(wxInputStream& s, bool preload = FALSE,
|
||||
bool seekable = FALSE);
|
||||
virtual void SetFile(wxOutputStream& s,
|
||||
bool seekable = FALSE);
|
||||
protected:
|
||||
void ParseCOMM();
|
||||
void ParseSSND();
|
||||
|
||||
void WriteCOMM();
|
||||
void WriteSSND(wxUint32 file_size);
|
||||
|
||||
protected:
|
||||
wxUint32 m_spos, m_slen;
|
||||
wxUint32 m_chunksize;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,112 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndau.cpp
|
||||
// Purpose: wxMMedia Sun Audio File Codec
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated:
|
||||
// Copyright: (C) 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndau.h"
|
||||
#endif
|
||||
|
||||
#include "mmriff.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndau.h"
|
||||
|
||||
#define AU_ISDN_ULAW 1
|
||||
#define AU_PCM_8BITS 2
|
||||
#define AU_PCM_16BITS 3
|
||||
#define AU_ADPCM 23
|
||||
|
||||
wxSndAuCodec::wxSndAuCodec()
|
||||
: wxSndFileCodec()
|
||||
{
|
||||
}
|
||||
|
||||
wxSndAuCodec::wxSndAuCodec(wxInputStream& s, bool preload, bool seekable)
|
||||
: wxSndFileCodec(s, preload, seekable)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndAuCodec::wxSndAuCodec(wxOutputStream& s, bool seekable)
|
||||
: wxSndFileCodec(s, seekable)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndAuCodec::wxSndAuCodec(const wxString& fname)
|
||||
: wxSndFileCodec(fname)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndAuCodec::~wxSndAuCodec()
|
||||
{
|
||||
}
|
||||
|
||||
wxUint32 wxSndAuCodec::PrepareToPlay()
|
||||
{
|
||||
wxString id;
|
||||
char temp_buf[5];
|
||||
int offset, srate, codec, ch_count;
|
||||
size_t len;
|
||||
|
||||
m_istream->Read(temp_buf, 4);
|
||||
temp_buf[4] = 0;
|
||||
|
||||
id = temp_buf;
|
||||
if (id != ".snd") {
|
||||
m_mmerror = wxMMFILE_INVALID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define READ_BE_32(i) \
|
||||
m_istream->Read(temp_buf, 4); \
|
||||
i = (unsigned long)temp_buf[0] << 24; \
|
||||
i |= (unsigned long)temp_buf[1] << 16; \
|
||||
i |= (unsigned long)temp_buf[2] << 8; \
|
||||
i |= (unsigned long)temp_buf[3];
|
||||
|
||||
READ_BE_32(offset);
|
||||
READ_BE_32(len);
|
||||
READ_BE_32(codec);
|
||||
READ_BE_32(srate);
|
||||
READ_BE_32(ch_count);
|
||||
|
||||
m_sndformat.SetSampleRate(srate);
|
||||
m_sndformat.SetChannels(ch_count);
|
||||
switch (codec) {
|
||||
case AU_ISDN_ULAW:
|
||||
ChangeCodec(WXSOUND_ULAW);
|
||||
break;
|
||||
case AU_PCM_8BITS:
|
||||
ChangeCodec(WXSOUND_PCM);
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
break;
|
||||
case AU_PCM_16BITS:
|
||||
ChangeCodec(WXSOUND_PCM);
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
break;
|
||||
case AU_ADPCM:
|
||||
ChangeCodec(WXSOUND_ADPCM);
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
bool wxSndAuCodec::OnNeedData(char *buf, wxUint32 size)
|
||||
{
|
||||
return m_istream->Read(buf, size).LastError();
|
||||
}
|
||||
|
||||
bool wxSndAuCodec::OnWriteData(char *buf, wxUint32 size)
|
||||
{
|
||||
return m_ostream->Write(buf, size).LastError();
|
||||
}
|
||||
|
||||
bool wxSndAuCodec::PrepareToRecord(wxUint32 file_size)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndau.h
|
||||
// Purpose: wxMMedia Sun Audio File Codec
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated:
|
||||
// Copyright: (C) 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_au_H__
|
||||
#define __SND_au_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmriff.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
///
|
||||
class wxSndAuCodec : public wxSndFileCodec {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxSndAuCodec)
|
||||
public:
|
||||
///
|
||||
wxSndAuCodec();
|
||||
///
|
||||
wxSndAuCodec(wxInputStream& s, bool preload = FALSE, bool seekable = TRUE);
|
||||
///
|
||||
wxSndAuCodec(wxOutputStream& s, bool seekable = TRUE);
|
||||
///
|
||||
wxSndAuCodec(const wxString& fname);
|
||||
///
|
||||
virtual ~wxSndAuCodec();
|
||||
|
||||
bool OnNeedData(char *buf, wxUint32 size);
|
||||
bool OnWriteData(char *buf, wxUint32 size);
|
||||
|
||||
wxUint32 PrepareToPlay();
|
||||
bool PrepareToRecord(wxUint32 file_size);
|
||||
|
||||
protected:
|
||||
wxUint32 m_spos, m_slen;
|
||||
wxUint32 m_chunksize;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,325 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfile.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndfile.h"
|
||||
#endif
|
||||
|
||||
#include "mmedia.h"
|
||||
#include "sndfile.h"
|
||||
#ifdef WX_PRECOMP
|
||||
#include <wx/wxprec.h>
|
||||
#else
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
#include <wx/module.h>
|
||||
#include "sndfrmt.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxSndFileCodec::wxSndFileCodec()
|
||||
: wxMMediaFile(), wxSndBuffer(),
|
||||
m_fstate(wxSFILE_STOPPED)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndFileCodec::wxSndFileCodec(wxOutputStream& s, bool seekable)
|
||||
: wxMMediaFile(s, seekable),
|
||||
wxSndBuffer(),
|
||||
m_fstate(wxSFILE_STOPPED)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndFileCodec::wxSndFileCodec(wxInputStream& s, bool preload, bool seekable)
|
||||
: wxMMediaFile(s, preload, seekable),
|
||||
wxSndBuffer(),
|
||||
m_fstate(wxSFILE_STOPPED)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndFileCodec::wxSndFileCodec(const wxString& fname)
|
||||
: wxMMediaFile(fname), wxSndBuffer(),
|
||||
m_fstate(wxSFILE_STOPPED)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndFileCodec::~wxSndFileCodec()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndFileCodec::Play(wxSound& snd)
|
||||
{
|
||||
if (m_fstate != wxSFILE_STOPPED || IsSet(wxSND_BUFLOCKED))
|
||||
return;
|
||||
|
||||
if (m_fstate != wxSFILE_PREPARED_TO_PLAY)
|
||||
if (!(m_fsize = PrepareToPlay()))
|
||||
return;
|
||||
|
||||
m_fpos = 0;
|
||||
m_fstate = wxSFILE_PLAYING;
|
||||
|
||||
Set(wxSND_BUFREADY | wxSND_KEEPQUEUED);
|
||||
snd.QueueBuffer(*this);
|
||||
}
|
||||
|
||||
void wxSndFileCodec::Stop(wxSound& snd)
|
||||
{
|
||||
if (m_fstate == wxSFILE_STOPPED)
|
||||
return;
|
||||
|
||||
snd.UnqueueBuffer(*this);
|
||||
Clear(wxSND_BUFREADY | wxSND_KEEPQUEUED);
|
||||
m_fstate = wxSFILE_STOPPED;
|
||||
}
|
||||
|
||||
void wxSndFileCodec::Record(wxSound& snd,
|
||||
const wxSoundDataFormat& format,
|
||||
wxUint32 seconds)
|
||||
{
|
||||
wxUint32 byterate;
|
||||
|
||||
if (m_fstate != wxSFILE_STOPPED)
|
||||
return;
|
||||
|
||||
m_sndformat = format;
|
||||
byterate = m_sndformat.GetCodec()->GetByteRate();
|
||||
|
||||
m_fsize = seconds*byterate;
|
||||
if (!PrepareToRecord(m_fsize))
|
||||
return;
|
||||
if (IsSet(wxSND_BUFLOCKED))
|
||||
return;
|
||||
|
||||
wxUint32 sec1 = m_fsize / byterate,
|
||||
sec2 = sec1 % 3600;
|
||||
|
||||
m_sndtime.hours = sec1 / 3600;
|
||||
m_sndtime.minutes = sec2 / 60;
|
||||
m_sndtime.seconds = sec2 % 60;
|
||||
|
||||
m_fdone = m_fpos = 0;
|
||||
m_fstate = wxSFILE_RECORDING;
|
||||
|
||||
m_sndmode = wxSND_INPUT;
|
||||
|
||||
Set(wxSND_BUFREADY | wxSND_KEEPQUEUED);
|
||||
snd.QueueBuffer(*this);
|
||||
}
|
||||
|
||||
void wxSndFileCodec::OnNeedOutputData(char *data, wxUint32& size)
|
||||
{
|
||||
wxUint32 datas_left = m_fsize-m_fpos;
|
||||
|
||||
if (m_fstate != wxSFILE_PLAYING) {
|
||||
size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!datas_left) {
|
||||
size = 0;
|
||||
m_fpos = 0;
|
||||
m_fstate = wxSFILE_STOPPED;
|
||||
Clear(wxSND_KEEPQUEUED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (size > datas_left)
|
||||
size = datas_left;
|
||||
|
||||
if (!OnNeedData(data, size)) {
|
||||
size = 0;
|
||||
m_fpos = 0;
|
||||
m_fstate = wxSFILE_STOPPED;
|
||||
Clear(wxSND_KEEPQUEUED);
|
||||
return;
|
||||
}
|
||||
|
||||
m_fpos += size;
|
||||
}
|
||||
|
||||
void wxSndFileCodec::OnBufferInFinished(char *iobuf, wxUint32& size)
|
||||
{
|
||||
wxUint32 datas_left = m_fsize-m_fdone;
|
||||
|
||||
if (m_fstate != wxSFILE_RECORDING) {
|
||||
size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!datas_left) {
|
||||
size = 0;
|
||||
Clear(wxSND_KEEPQUEUED); // To be sure.
|
||||
return;
|
||||
}
|
||||
|
||||
if (size > datas_left)
|
||||
size = datas_left;
|
||||
|
||||
OnWriteData(iobuf, size);
|
||||
m_fdone += size;
|
||||
}
|
||||
|
||||
wxMMtime wxSndFileCodec::GetPosition()
|
||||
{
|
||||
wxMMtime mm_time;
|
||||
wxUint32 sec1, sec2;
|
||||
wxUint32 byterate;
|
||||
|
||||
byterate = m_sndformat.GetCodec()->GetByteRate();
|
||||
|
||||
if (m_fpos && byterate) {
|
||||
sec1 = m_fpos / byterate;
|
||||
sec2 = sec1 % 3600;
|
||||
mm_time.hours = sec1 / 3600;
|
||||
mm_time.minutes = sec2 / 60;
|
||||
mm_time.seconds = sec2 % 60;
|
||||
} else {
|
||||
mm_time.hours = 0;
|
||||
mm_time.minutes = 0;
|
||||
mm_time.seconds = 0;
|
||||
}
|
||||
|
||||
return mm_time;
|
||||
}
|
||||
|
||||
wxMMtime wxSndFileCodec::GetLength()
|
||||
{
|
||||
if (m_sndtime.hours == -1 && m_istream)
|
||||
m_fsize = PrepareToPlay();
|
||||
|
||||
return m_sndtime;
|
||||
}
|
||||
|
||||
bool wxSndFileCodec::TranslateBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
#define TMP_BUFSIZE 10240
|
||||
|
||||
wxStreamBuffer *tmp_buf;
|
||||
wxSoundCodec *codec_in, *codec_out;
|
||||
wxSoundDataFormat std_format;
|
||||
|
||||
if (!m_ostream || !buf.RestartBuffer(wxSND_OUTPUT))
|
||||
return FALSE;
|
||||
|
||||
m_sndformat = buf.GetFormat();
|
||||
codec_in = buf.GetCurrentCodec();
|
||||
|
||||
m_fdone = 0;
|
||||
|
||||
if (!PrepareToRecord(m_fsize))
|
||||
return FALSE;
|
||||
|
||||
codec_out = GetCurrentCodec();
|
||||
m_fsize = (int)(((float)buf.GetSize() / codec_in->GetByteRate()) *
|
||||
codec_out->GetByteRate());
|
||||
|
||||
if (!PrepareToRecord(m_fsize))
|
||||
return FALSE;
|
||||
|
||||
codec_out = GetCurrentCodec();
|
||||
codec_in->InitIO(m_sndformat);
|
||||
codec_out->InitIO(m_sndformat);
|
||||
|
||||
tmp_buf = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
tmp_buf->Fixed(TRUE);
|
||||
tmp_buf->Flushable(FALSE);
|
||||
tmp_buf->SetBufferIO(TMP_BUFSIZE);
|
||||
|
||||
m_fstate = wxSFILE_RECORDING;
|
||||
|
||||
while (m_fdone < m_fsize) {
|
||||
tmp_buf->ResetBuffer();
|
||||
codec_in->SetOutStream(tmp_buf);
|
||||
codec_in->Decode();
|
||||
|
||||
tmp_buf->ResetBuffer();
|
||||
codec_out->SetInStream(tmp_buf);
|
||||
codec_out->Encode();
|
||||
|
||||
buf.OnBufferOutFinished();
|
||||
}
|
||||
delete tmp_buf;
|
||||
|
||||
m_fstate = wxSFILE_STOPPED;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSndFileCodec::RestartBuffer(wxSndMode mode)
|
||||
{
|
||||
if (IsSet(wxSND_BUFLOCKED))
|
||||
return FALSE;
|
||||
|
||||
m_fdone = 0;
|
||||
m_fpos = 0;
|
||||
|
||||
if (mode == wxSND_OUTPUT && m_istream) {
|
||||
m_fsize = PrepareToPlay();
|
||||
m_fstate = wxSFILE_PLAYING;
|
||||
return TRUE;
|
||||
}
|
||||
if (mode == wxSND_INPUT && m_ostream) {
|
||||
m_fsize = 0;
|
||||
m_fstate = wxSFILE_RECORDING;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxUint32 wxSndFileCodec::GetSize() const
|
||||
{
|
||||
return m_fsize;
|
||||
}
|
||||
|
||||
wxUint32 wxSndFileCodec::Available() const
|
||||
{
|
||||
if (m_fstate == wxSFILE_STOPPED)
|
||||
return 0;
|
||||
return m_fsize-m_fpos;
|
||||
}
|
||||
|
||||
//
|
||||
// Simple API
|
||||
//
|
||||
static wxSoundDevice *dev_snd = NULL;
|
||||
|
||||
bool wxSndFileCodec::StartPlay()
|
||||
{
|
||||
if (!dev_snd)
|
||||
dev_snd = new wxSoundDevice;
|
||||
|
||||
Play(*dev_snd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSndFileCodec::StopPlay()
|
||||
{
|
||||
if (!dev_snd)
|
||||
return;
|
||||
|
||||
Stop(*dev_snd);
|
||||
m_fpos = 0;
|
||||
}
|
||||
|
||||
class wxSoundModule : public wxModule {
|
||||
DECLARE_DYNAMIC_CLASS(wxSoundModule)
|
||||
public:
|
||||
virtual bool OnInit() { return TRUE; }
|
||||
virtual void OnExit() {
|
||||
if (dev_snd)
|
||||
delete dev_snd;
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxSoundModule, wxModule)
|
@ -1,93 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfile.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_file_H__
|
||||
#define __SND_file_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmfile.h"
|
||||
#include "sndsnd.h"
|
||||
|
||||
///
|
||||
class wxSndFileCodec : public wxMMediaFile, public wxSndBuffer {
|
||||
///
|
||||
DECLARE_ABSTRACT_CLASS(wxSndFileCodec)
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
wxSFILE_STOPPED,
|
||||
wxSFILE_PLAYING,
|
||||
wxSFILE_RECORDING,
|
||||
wxSFILE_PREPARED_TO_PLAY,
|
||||
wxSFILE_PREPARED_TO_RECORD,
|
||||
} FileState;
|
||||
|
||||
protected:
|
||||
wxUint32 m_fsize, m_fpos, m_fdone;
|
||||
FileState m_fstate;
|
||||
wxMMtime m_sndtime;
|
||||
public:
|
||||
|
||||
///
|
||||
wxSndFileCodec();
|
||||
///
|
||||
wxSndFileCodec(wxInputStream& s, bool preload, bool seekable);
|
||||
///
|
||||
wxSndFileCodec(wxOutputStream& s, bool seekable);
|
||||
///
|
||||
wxSndFileCodec(const wxString& fname);
|
||||
///
|
||||
virtual ~wxSndFileCodec();
|
||||
|
||||
///
|
||||
void Play(wxSound& snd);
|
||||
///
|
||||
void Stop(wxSound& snd);
|
||||
///
|
||||
void Record(wxSound& snd,
|
||||
const wxSoundDataFormat& format, wxUint32 seconds);
|
||||
|
||||
///
|
||||
void OnNeedOutputData(char *data, wxUint32& size);
|
||||
///
|
||||
void OnBufferInFinished(char *iobuf, wxUint32& size);
|
||||
|
||||
///
|
||||
virtual bool OnNeedData(char *buf, wxUint32 size) = 0;
|
||||
///
|
||||
virtual bool OnWriteData(char *buf, wxUint32 size) = 0;
|
||||
///
|
||||
virtual wxUint32 PrepareToPlay() = 0;
|
||||
///
|
||||
virtual bool PrepareToRecord(wxUint32 file_size) = 0;
|
||||
///
|
||||
virtual bool TranslateBuffer(wxSndBuffer& buf);
|
||||
///
|
||||
virtual bool RestartBuffer(wxSndMode mode);
|
||||
///
|
||||
virtual wxUint32 GetSize() const;
|
||||
///
|
||||
virtual wxUint32 Available() const;
|
||||
///
|
||||
virtual wxMMtime GetLength();
|
||||
|
||||
///
|
||||
wxMMtime GetPosition();
|
||||
|
||||
///
|
||||
virtual bool StartPlay();
|
||||
///
|
||||
virtual void StopPlay();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,271 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfrag.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndfrag.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "sndfrag.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxFragmentBuffer::wxFragmentBuffer(wxSound& io_drv)
|
||||
: m_iodrv(&io_drv), m_maxoq(0), m_maxiq(0),
|
||||
m_lstoptrs(NULL), m_lstiptrs(NULL),
|
||||
m_buf2free(FALSE), m_dontq(FALSE), m_freeing(FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
wxFragmentBuffer::~wxFragmentBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void wxFragmentBuffer::AbortBuffer(wxSndBuffer *buf)
|
||||
{
|
||||
for (wxUint8 i=0;i<m_maxoq;i++)
|
||||
if (m_lstoptrs[i].buffers->Member(buf)) {
|
||||
if (m_lstoptrs[i].state == wxBUFFER_PLAYING)
|
||||
// TODO: Do something.
|
||||
;
|
||||
m_lstoptrs[i].state = wxBUFFER_TOFREE;
|
||||
}
|
||||
|
||||
for (wxUint8 i=0;i<m_maxiq;i++)
|
||||
if (m_lstiptrs[i].buffers->Member(buf)) {
|
||||
if (m_lstiptrs[i].state == wxBUFFER_PLAYING)
|
||||
// Do something.
|
||||
;
|
||||
m_lstiptrs[i].state = wxBUFFER_TOFREE;
|
||||
}
|
||||
}
|
||||
|
||||
wxFragmentBuffer::wxFragBufPtr *wxFragmentBuffer::FindFreeBuffer(
|
||||
wxFragBufPtr *list, wxUint8 max_queue)
|
||||
{
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
for (wxUint8 i=0;i<max_queue;i++) {
|
||||
if (list[i].state == wxBUFFER_FREE)
|
||||
return &list[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool wxFragmentBuffer::NotifyOutputBuffer(wxSndBuffer *buf)
|
||||
{
|
||||
wxFragBufPtr *ptr;
|
||||
wxSoundCodec *codec = buf->GetCurrentCodec();
|
||||
|
||||
if (!m_iodrv->OnSetupDriver(*buf, wxSND_OUTPUT))
|
||||
return FALSE;
|
||||
|
||||
while (1) {
|
||||
// Find the first free (at least partly free) output buffer
|
||||
ptr = FindFreeBuffer(m_lstoptrs, m_maxoq);
|
||||
// No free : go out !
|
||||
if (ptr == NULL)
|
||||
return FALSE;
|
||||
|
||||
// Normally, these three functions could be called only once.
|
||||
codec->SetOutStream(ptr->sndbuf);
|
||||
codec->InitIO(m_drvformat);
|
||||
codec->InitMode(wxSoundCodec::DECODING);
|
||||
|
||||
// Fill it up
|
||||
codec->Decode();
|
||||
|
||||
// No data to fill the buffer: dequeue the current wxSndBuffer
|
||||
if (codec->Available() == 0) {
|
||||
if (buf->IsNotSet(wxSND_KEEPQUEUED)) {
|
||||
buf->Set(wxSND_UNQUEUEING);
|
||||
m_iodrv->m_buffers.DeleteObject(buf);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Data: append it to the list
|
||||
ptr->buffers->Append(buf);
|
||||
|
||||
// Output buffer full: send it to the driver
|
||||
if (ptr->sndbuf->GetDataLeft() == 0) {
|
||||
ptr->state = wxBUFFER_FFILLED;
|
||||
OnBufferFilled(ptr, wxSND_OUTPUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool wxFragmentBuffer::NotifyInputBuffer(wxSndBuffer *buf)
|
||||
{
|
||||
wxFragBufPtr *ptr;
|
||||
size_t inc;
|
||||
|
||||
if (!m_iodrv->OnSetupDriver(*buf, wxSND_INPUT))
|
||||
return FALSE;
|
||||
|
||||
while (1) {
|
||||
ptr = FindFreeBuffer(m_lstiptrs, m_maxiq);
|
||||
if (ptr == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (buf->Available() == 0) {
|
||||
if (buf->IsNotSet(wxSND_KEEPQUEUED)) {
|
||||
buf->Set(wxSND_UNQUEUEING);
|
||||
m_iodrv->m_buffers.DeleteObject(buf);
|
||||
}
|
||||
|
||||
if (LastBuffer() == NULL && ptr->sndbuf->GetIntPosition() != 0) {
|
||||
ptr->state = wxBUFFER_FFILLED;
|
||||
if (!OnBufferFilled(ptr, wxSND_INPUT))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
ptr->buffers->Append(buf);
|
||||
|
||||
// TODO: Add an "incrementer" in wxStreamBuffer.
|
||||
inc = (buf->Available() < ptr->sndbuf->GetDataLeft()) ?
|
||||
buf->Available() : ptr->sndbuf->GetDataLeft();
|
||||
|
||||
ptr->sndbuf->SetIntPosition(ptr->sndbuf->GetIntPosition() + inc);
|
||||
|
||||
if (ptr->sndbuf->GetDataLeft() == 0) {
|
||||
ptr->state = wxBUFFER_FFILLED;
|
||||
if (!OnBufferFilled(ptr, wxSND_INPUT))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxFragmentBuffer::FreeBufToFree(bool force)
|
||||
{
|
||||
wxUint8 i;
|
||||
// Garbage collecting
|
||||
|
||||
m_dontq = TRUE;
|
||||
m_buf2free = FALSE;
|
||||
|
||||
for (i=0;i<m_maxoq;i++) {
|
||||
if ((m_lstoptrs[i].state == wxBUFFER_TOFREE) ||
|
||||
(force && m_lstoptrs[i].state == wxBUFFER_FFILLED))
|
||||
ClearBuffer(&m_lstoptrs[i]);
|
||||
}
|
||||
|
||||
for (i=0;i<m_maxiq;i++) {
|
||||
if ((m_lstiptrs[i].state == wxBUFFER_TOFREE) ||
|
||||
(force && m_lstoptrs[i].state == wxBUFFER_FFILLED))
|
||||
ClearBuffer(&m_lstiptrs[i]);
|
||||
}
|
||||
|
||||
m_dontq = FALSE;
|
||||
}
|
||||
|
||||
void wxFragmentBuffer::ClearBuffer(wxFragBufPtr *ptr)
|
||||
{
|
||||
wxNode *node;
|
||||
wxSndBuffer *buf;
|
||||
wxSoundCodec *codec;
|
||||
|
||||
node = ptr->buffers->First();
|
||||
|
||||
while (node) {
|
||||
buf = (wxSndBuffer *)node->Data();
|
||||
|
||||
if (buf->GetMode() == wxSND_OUTPUT) {
|
||||
buf->OnBufferOutFinished();
|
||||
} else {
|
||||
codec = buf->GetCurrentCodec();
|
||||
|
||||
// Normally, these three functions could be called only once.
|
||||
codec->SetInStream(ptr->sndbuf);
|
||||
codec->InitIO(m_drvformat);
|
||||
codec->InitMode(wxSoundCodec::ENCODING);
|
||||
|
||||
// As there is an "auto-stopper" in the codec, we don't worry ...
|
||||
codec->Encode();
|
||||
}
|
||||
|
||||
if (buf->IsSet(wxSND_UNQUEUEING))
|
||||
buf->Clear(wxSND_UNQUEUEING | wxSND_BUFLOCKED | wxSND_BUFREADY);
|
||||
|
||||
delete node;
|
||||
node = ptr->buffers->First();
|
||||
}
|
||||
|
||||
ptr->sndbuf->ResetBuffer();
|
||||
ptr->state = wxBUFFER_FREE;
|
||||
}
|
||||
|
||||
void wxFragmentBuffer::OnBufferFinished(wxFragBufPtr *ptr)
|
||||
{
|
||||
wxNode *node;
|
||||
wxSndBuffer *buf;
|
||||
bool ret = TRUE;
|
||||
|
||||
if (m_freeing) {
|
||||
ptr->state = wxBUFFER_TOFREE;
|
||||
m_buf2free = TRUE;
|
||||
return;
|
||||
}
|
||||
m_freeing = TRUE;
|
||||
|
||||
// Clean up the old buffer.
|
||||
if (ptr && ptr->state != wxBUFFER_FREE)
|
||||
ClearBuffer(ptr);
|
||||
|
||||
// Garbage collecting ...
|
||||
if (m_buf2free)
|
||||
FreeBufToFree();
|
||||
|
||||
// If we are queueing, return immediately.
|
||||
if (m_dontq) {
|
||||
m_freeing = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
node = m_iodrv->m_buffers.First();
|
||||
|
||||
while (node && ret) {
|
||||
buf = (wxSndBuffer *)node->Data();
|
||||
node = node->Next();
|
||||
|
||||
buf->HardLock();
|
||||
|
||||
// Stop request on this buffer.
|
||||
if (buf->IsSet(wxSND_BUFSTOP)) {
|
||||
buf->Clear(wxSND_BUFSTOP);
|
||||
continue;
|
||||
}
|
||||
switch (buf->GetMode()) {
|
||||
case wxSND_OUTPUT:
|
||||
ret = NotifyOutputBuffer(buf);
|
||||
break;
|
||||
case wxSND_INPUT:
|
||||
ret = NotifyInputBuffer(buf);
|
||||
break;
|
||||
case wxSND_DUPLEX:
|
||||
case wxSND_OTHER_IO:
|
||||
// ret = NotifyDuplexBuffer(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
buf->HardUnlock();
|
||||
}
|
||||
m_freeing = FALSE;
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfrag.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __SND_frag_H__
|
||||
#define __SND_frag_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "sndsnd.h"
|
||||
|
||||
///
|
||||
class wxFragmentBuffer {
|
||||
protected:
|
||||
wxSound *m_iodrv;
|
||||
|
||||
///
|
||||
wxUint8 m_maxoq, m_maxiq;
|
||||
|
||||
///
|
||||
typedef enum {
|
||||
wxBUFFER_FREE,
|
||||
wxBUFFER_FFILLED,
|
||||
wxBUFFER_TOFREE,
|
||||
wxBUFFER_PLAYING
|
||||
} BufState;
|
||||
public:
|
||||
///
|
||||
typedef struct {
|
||||
// Local stream buffer for this fragment.
|
||||
wxStreamBuffer *sndbuf;
|
||||
// Data the driver would like to pass to the callback.
|
||||
char *user_data;
|
||||
// Buffers included in this fragment.
|
||||
wxList *buffers;
|
||||
// State of the fragment.
|
||||
BufState state;
|
||||
} wxFragBufPtr;
|
||||
protected:
|
||||
//
|
||||
wxFragBufPtr *m_optrs, *m_iptrs;
|
||||
//
|
||||
wxFragBufPtr *m_lstoptrs, *m_lstiptrs;
|
||||
//
|
||||
bool m_buf2free, m_dontq, m_freeing;
|
||||
//
|
||||
wxSoundDataFormat m_drvformat;
|
||||
public:
|
||||
wxFragmentBuffer(wxSound& io_drv);
|
||||
virtual ~wxFragmentBuffer();
|
||||
|
||||
// These functions initializes the fragments. They must initialize
|
||||
// m_lstoptrs, m_lstiptrs, m_maxoq, m_maxiq.
|
||||
virtual void AllocIOBuffer() = 0;
|
||||
virtual void FreeIOBuffer() = 0;
|
||||
|
||||
void AbortBuffer(wxSndBuffer *buf);
|
||||
|
||||
// Find a free (or partly free) fragment.
|
||||
wxFragBufPtr *FindFreeBuffer(wxFragBufPtr *list, wxUint8 max_queue);
|
||||
// Add this sound buffer to an "OUTPUT" fragment.
|
||||
bool NotifyOutputBuffer(wxSndBuffer *buf);
|
||||
// Add this sound buffer to an "INPUT" fragment.
|
||||
bool NotifyInputBuffer(wxSndBuffer *buf);
|
||||
|
||||
// Called when a fragment is finished.
|
||||
void OnBufferFinished(wxFragBufPtr *ptr);
|
||||
|
||||
// Called when a fragment is full and it should be flushed in the sound card.
|
||||
virtual bool OnBufferFilled(wxFragBufPtr *ptr, wxSndMode mode) = 0;
|
||||
|
||||
inline wxSndBuffer *LastBuffer() {
|
||||
wxNode *node = m_iodrv->m_buffers.Last();
|
||||
|
||||
if (!node) return NULL;
|
||||
return (wxSndBuffer *)node->Data();
|
||||
}
|
||||
inline wxSndBuffer *FirstBuffer() {
|
||||
wxNode *node = m_iodrv->m_buffers.First();
|
||||
|
||||
if (!node) return NULL;
|
||||
return (wxSndBuffer *)node->Data();
|
||||
}
|
||||
protected:
|
||||
void FreeBufToFree(bool force = FALSE);
|
||||
void ClearBuffer(wxFragBufPtr *ptr);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,295 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfrmt.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated: December 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndfrmt.h"
|
||||
#endif
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrmt.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSoundDataFormat
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxSoundDataFormat::wxSoundDataFormat()
|
||||
{
|
||||
m_srate = 22050;
|
||||
m_bps = 8;
|
||||
m_channels = 1;
|
||||
m_codno = 1;
|
||||
m_codec = NULL;
|
||||
m_codchange = FALSE;
|
||||
m_codcreate = TRUE;
|
||||
}
|
||||
|
||||
wxSoundDataFormat::wxSoundDataFormat(const wxSoundDataFormat& format)
|
||||
{
|
||||
m_srate = format.m_srate;
|
||||
m_bps = format.m_bps;
|
||||
m_channels = format.m_channels;
|
||||
m_codno = format.m_codno;
|
||||
m_sign = format.m_sign;
|
||||
m_byteorder = format.m_byteorder;
|
||||
m_codchange = FALSE;
|
||||
m_codcreate = TRUE;
|
||||
m_codec = NULL;
|
||||
}
|
||||
|
||||
wxSoundDataFormat::~wxSoundDataFormat()
|
||||
{
|
||||
wxDELETE(m_codec);
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::SetChannels(int channels)
|
||||
{
|
||||
m_channels = channels;
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::SetBps(int bps)
|
||||
{
|
||||
m_bps = bps;
|
||||
CodecChange();
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::SetSign(int sign)
|
||||
{
|
||||
m_sign = sign;
|
||||
CodecChange();
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::SetByteOrder(int byteorder)
|
||||
{
|
||||
m_byteorder = byteorder;
|
||||
CodecChange();
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::SetCodecNo(int codno)
|
||||
{
|
||||
m_codno = codno;
|
||||
m_codchange = TRUE;
|
||||
CodecChange();
|
||||
}
|
||||
|
||||
wxSoundCodec *wxSoundDataFormat::GetCodec()
|
||||
{
|
||||
if (!m_codcreate)
|
||||
return NULL;
|
||||
|
||||
if (m_codchange)
|
||||
wxDELETE(m_codec);
|
||||
|
||||
if (m_codec)
|
||||
return m_codec;
|
||||
|
||||
m_codchange = FALSE;
|
||||
m_codec = wxSoundCodec::Get(m_codno);
|
||||
CodecChange();
|
||||
|
||||
return m_codec;
|
||||
}
|
||||
|
||||
void wxSoundDataFormat::CodecChange()
|
||||
{
|
||||
wxSoundCodec *codec = GetCodec();
|
||||
|
||||
if (!codec)
|
||||
return;
|
||||
|
||||
switch (m_codno) {
|
||||
case WXSOUND_PCM: {
|
||||
wxSoundPcmCodec *pcm_codec = (wxSoundPcmCodec *)codec;
|
||||
|
||||
pcm_codec->m_orig_format.SetSampleRate(m_srate);
|
||||
pcm_codec->m_orig_format.SetBps(m_bps);
|
||||
pcm_codec->m_orig_format.SetChannels(m_channels);
|
||||
pcm_codec->m_orig_format.SetByteOrder(m_byteorder);
|
||||
pcm_codec->m_orig_format.SetSign(m_sign);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
codec->InitWith(*this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wxSoundDataFormat& wxSoundDataFormat::operator =(const wxSoundDataFormat& format)
|
||||
{
|
||||
wxDELETE(m_codec);
|
||||
|
||||
m_srate = format.m_srate;
|
||||
m_bps = format.m_bps;
|
||||
m_channels = format.m_channels;
|
||||
m_codno = format.m_codno;
|
||||
m_sign = format.m_sign;
|
||||
m_byteorder = format.m_byteorder;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxSoundDataFormat::operator ==(const wxSoundDataFormat& format) const
|
||||
{
|
||||
if (m_codno != format.m_codno || m_srate != format.m_srate ||
|
||||
m_bps != format.m_bps || m_channels != format.m_channels)
|
||||
return FALSE;
|
||||
|
||||
if (m_codno == WXSOUND_PCM &&
|
||||
(m_sign != format.m_sign || m_byteorder != format.m_byteorder))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSoundCodec
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "sndpcm.h"
|
||||
#include "sndadpcm.h"
|
||||
//#include "sndalaw.h"
|
||||
#include "sndmulaw.h"
|
||||
|
||||
static wxClassInfo *l_sound_formats[] = {
|
||||
NULL,
|
||||
CLASSINFO(wxSoundPcmCodec),
|
||||
CLASSINFO(wxSoundAdpcmCodec),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, // CLASSINFO(wxSoundAlawCodec),
|
||||
CLASSINFO(wxSoundMulawCodec)
|
||||
};
|
||||
|
||||
static int l_nb_formats = WXSIZEOF(l_sound_formats);
|
||||
|
||||
wxSoundCodec::wxSoundCodec()
|
||||
{
|
||||
m_in_sound = NULL;
|
||||
m_out_sound = NULL;
|
||||
m_init = TRUE;
|
||||
m_chain_codec = NULL;
|
||||
}
|
||||
|
||||
wxSoundCodec::~wxSoundCodec()
|
||||
{
|
||||
if (m_mode != WAITING)
|
||||
ExitMode();
|
||||
}
|
||||
|
||||
void wxSoundCodec::InitIO(const wxSoundDataFormat& format)
|
||||
{
|
||||
m_io_format = format;
|
||||
}
|
||||
|
||||
void wxSoundCodec::InitMode(ModeType mode)
|
||||
{
|
||||
wxStreamBuffer *buf_snd;
|
||||
|
||||
m_mode = mode;
|
||||
if (!m_chain_codec) {
|
||||
if (m_mode == ENCODING) {
|
||||
m_out_sound = new wxStreamBuffer(*this, wxStreamBuffer::write);
|
||||
m_out_sound->SetBufferIO(1024);
|
||||
} else {
|
||||
m_in_sound = new wxStreamBuffer(*this, wxStreamBuffer::read);
|
||||
m_in_sound->SetBufferIO(1024);
|
||||
}
|
||||
}
|
||||
if (m_chain_codec) {
|
||||
if (m_chain_before) {
|
||||
m_chain_codec->SetInStream(m_in_sound);
|
||||
buf_snd = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
buf_snd->Fixed(FALSE);
|
||||
m_chain_codec->SetOutStream(buf_snd);
|
||||
m_chain_codec->Decode();
|
||||
buf_snd->Seek(0, wxFromStart);
|
||||
m_in_sound = buf_snd;
|
||||
} else {
|
||||
buf_snd = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
buf_snd->Fixed(FALSE);
|
||||
|
||||
m_chain_codec->SetInStream(buf_snd);
|
||||
m_chain_codec->SetOutStream(m_out_sound);
|
||||
m_out_sound = buf_snd;
|
||||
|
||||
buf_snd->Seek(0, wxFromStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxSoundCodec::ExitMode()
|
||||
{
|
||||
if (m_chain_codec) {
|
||||
if (m_chain_before) {
|
||||
delete m_in_sound;
|
||||
m_in_sound = m_chain_codec->GetInStream();
|
||||
} else {
|
||||
delete m_out_sound;
|
||||
m_out_sound = m_chain_codec->GetOutStream();
|
||||
}
|
||||
}
|
||||
m_mode = WAITING;
|
||||
}
|
||||
|
||||
bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat& format)
|
||||
{
|
||||
m_chain_codec = format.GetCodec();
|
||||
|
||||
if (!m_chain_codec)
|
||||
return FALSE;
|
||||
|
||||
m_chain_before = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat& format)
|
||||
{
|
||||
m_chain_codec = format.GetCodec();
|
||||
|
||||
if (!m_chain_codec)
|
||||
return FALSE;
|
||||
|
||||
m_chain_before = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSoundCodec::CopyToOutput()
|
||||
{
|
||||
m_out_sound->Write(m_in_sound);
|
||||
}
|
||||
|
||||
size_t wxSoundCodec::Available()
|
||||
{
|
||||
return m_io_sndbuf->Available();
|
||||
}
|
||||
|
||||
size_t wxSoundCodec::OnSysRead(void *buffer, size_t bsize)
|
||||
{
|
||||
wxUint32 s = bsize;
|
||||
m_io_sndbuf->OnNeedOutputData((char *)buffer, s);
|
||||
return bsize;
|
||||
}
|
||||
|
||||
size_t wxSoundCodec::OnSysWrite(const void *buffer, size_t bsize)
|
||||
{
|
||||
wxUint32 s = bsize;
|
||||
m_io_sndbuf->OnBufferInFinished((char *)buffer, s);
|
||||
return bsize;
|
||||
}
|
||||
|
||||
wxSoundCodec *wxSoundCodec::Get(int no)
|
||||
{
|
||||
if (no < 0 || no >= l_nb_formats)
|
||||
return NULL;
|
||||
|
||||
if (!l_sound_formats[no])
|
||||
return NULL;
|
||||
|
||||
return (wxSoundCodec *)l_sound_formats[no]->CreateObject();
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndfrmt.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated: December 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __SNDFRMT_H__
|
||||
#define __SNDFRMT_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <wx/object.h>
|
||||
#include <wx/stream.h>
|
||||
|
||||
class wxSndBuffer;
|
||||
|
||||
// Standard Microsoft types (why change ?)
|
||||
#define WXSOUND_PCM 0x0001
|
||||
#define WXSOUND_ADPCM 0x0002
|
||||
#define WXSOUND_ALAW 0x0006
|
||||
#define WXSOUND_ULAW 0x0007
|
||||
|
||||
class wxSoundCodec;
|
||||
class wxSoundDataFormat {
|
||||
public:
|
||||
wxSoundDataFormat();
|
||||
wxSoundDataFormat(const wxSoundDataFormat& format);
|
||||
~wxSoundDataFormat();
|
||||
|
||||
void SetSampleRate(int srate) { m_srate = srate; }
|
||||
void SetChannels(int channels);
|
||||
void SetStereo(bool on);
|
||||
void SetCodecNo(int no);
|
||||
int GetCodecNo() { return m_codno; }
|
||||
void SetCodecCreate(bool create) { m_codcreate = create; }
|
||||
|
||||
int GetSampleRate() const { return m_srate; }
|
||||
int GetChannels() const { return m_channels; }
|
||||
bool GetStereo() const { return (m_channels == 2); }
|
||||
int GetCodecNo() const { return m_codno; }
|
||||
|
||||
wxSoundCodec *GetCodec();
|
||||
|
||||
wxSoundDataFormat& operator =(const wxSoundDataFormat& format);
|
||||
bool operator ==(const wxSoundDataFormat& format) const;
|
||||
bool operator !=(const wxSoundDataFormat& format) const
|
||||
{ return !(operator ==(format)); }
|
||||
|
||||
/// PCM format
|
||||
void SetByteOrder(int order);
|
||||
void SetSign(int sign);
|
||||
int GetByteOrder() const { return m_byteorder; }
|
||||
int GetSign() const { return m_sign; }
|
||||
|
||||
void SetBps(int bps);
|
||||
int GetBps() const { return m_bps; }
|
||||
|
||||
protected:
|
||||
void CodecChange();
|
||||
|
||||
protected:
|
||||
int m_srate, m_bps, m_channels, m_codno;
|
||||
int m_byteorder, m_sign;
|
||||
bool m_codchange, m_codcreate;
|
||||
wxSoundCodec *m_codec;
|
||||
};
|
||||
|
||||
class wxSoundCodec : public wxObject, public wxStreamBase {
|
||||
DECLARE_ABSTRACT_CLASS(wxSoundCodec)
|
||||
public:
|
||||
typedef enum {
|
||||
WAITING = 0,
|
||||
ENCODING,
|
||||
DECODING
|
||||
} ModeType;
|
||||
public:
|
||||
wxSoundCodec();
|
||||
virtual ~wxSoundCodec();
|
||||
|
||||
void SetIOBuffer(wxSndBuffer *sndbuf) { m_io_sndbuf = sndbuf; }
|
||||
size_t Available();
|
||||
|
||||
void InitIO(const wxSoundDataFormat& format);
|
||||
virtual void InitWith(const wxSoundDataFormat& format) {}
|
||||
|
||||
inline void SetInStream(wxStreamBuffer *s)
|
||||
{ m_in_sound = s; }
|
||||
inline void SetOutStream(wxStreamBuffer *s)
|
||||
{ m_out_sound = s; }
|
||||
inline wxStreamBuffer *GetInStream() const { return m_in_sound; }
|
||||
inline wxStreamBuffer *GetOutStream() const { return m_out_sound; }
|
||||
|
||||
inline bool StreamOk() const
|
||||
{ return (m_in_sound->Stream()->LastError() == wxStream_NOERROR) &&
|
||||
(m_out_sound->Stream()->LastError() == wxStream_NOERROR); }
|
||||
|
||||
virtual size_t GetByteRate() const = 0;
|
||||
virtual wxSoundDataFormat GetPreferredFormat(int codec = 0) const = 0;
|
||||
|
||||
virtual void InitMode(ModeType mode);
|
||||
virtual void ExitMode();
|
||||
virtual void Decode() = 0;
|
||||
virtual void Encode() = 0;
|
||||
|
||||
static wxSoundCodec *Get(int no);
|
||||
|
||||
protected:
|
||||
void CopyToOutput();
|
||||
|
||||
unsigned short Convert8_16(unsigned char s) { return (s & 0xff) << 8; }
|
||||
unsigned char Convert16_8(unsigned short s) { return (s & 0xff00) >> 8; }
|
||||
|
||||
bool ChainCodecBefore(wxSoundDataFormat& cod_to);
|
||||
bool ChainCodecAfter(wxSoundDataFormat& cod_to);
|
||||
|
||||
// -------------
|
||||
// wxStream part
|
||||
// -------------
|
||||
size_t OnSysWrite(const void *buffer, size_t bsize);
|
||||
size_t OnSysRead(void *buffer, size_t bsize);
|
||||
|
||||
protected:
|
||||
wxSndBuffer *m_io_sndbuf;
|
||||
wxSoundDataFormat m_io_format;
|
||||
wxStreamBuffer *m_in_sound, *m_out_sound;
|
||||
wxSoundCodec *m_chain_codec;
|
||||
bool m_init, m_chain_before;
|
||||
ModeType m_mode;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,94 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndmulaw.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: December 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndmulaw.h"
|
||||
#endif
|
||||
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrmt.h"
|
||||
#include "sndmulaw.h"
|
||||
#include "adpcm/g72x.h"
|
||||
|
||||
wxSoundMulawCodec::wxSoundMulawCodec()
|
||||
: wxSoundCodec()
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundMulawCodec::~wxSoundMulawCodec()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSoundMulawCodec::Decode()
|
||||
{
|
||||
int smp;
|
||||
wxSoundDataFormat pref_frmt;
|
||||
|
||||
pref_frmt = GetPreferredFormat(0);
|
||||
if (m_io_format != pref_frmt)
|
||||
ChainCodecAfter(pref_frmt);
|
||||
|
||||
InitMode(DECODING);
|
||||
|
||||
while (!StreamOk()) {
|
||||
smp = ulaw2linear(m_in_sound->GetChar());
|
||||
#ifdef USE_BE_MACH
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
m_out_sound->PutChar(smp & 0xff);
|
||||
#else
|
||||
m_out_sound->PutChar(smp & 0xff);
|
||||
m_out_sound->PutChar((smp & 0xff00) >> 8);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void wxSoundMulawCodec::Encode()
|
||||
{
|
||||
int smp;
|
||||
wxSoundDataFormat pref_frmt;
|
||||
|
||||
pref_frmt = GetPreferredFormat(0);
|
||||
if (m_io_format != pref_frmt)
|
||||
ChainCodecBefore(pref_frmt);
|
||||
|
||||
InitMode(ENCODING);
|
||||
|
||||
while (!StreamOk()) {
|
||||
#ifdef USE_BE_MACH
|
||||
smp = ((unsigned short)m_in_sound->GetChar()) << 8;
|
||||
smp |= m_in_sound->GetChar() & 0xff;
|
||||
#else
|
||||
smp = m_in_sound->GetChar() & 0xff;
|
||||
smp |= ((unsigned short)m_in_sound->GetChar()) << 8;
|
||||
#endif
|
||||
m_out_sound->PutChar(linear2ulaw(smp));
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxSoundMulawCodec::GetByteRate() const
|
||||
{
|
||||
return m_srate;
|
||||
}
|
||||
|
||||
wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
|
||||
{
|
||||
wxSoundDataFormat format;
|
||||
|
||||
format.SetCodecNo(WXSOUND_PCM);
|
||||
format.SetSampleRate(m_srate);
|
||||
format.SetBps(16);
|
||||
format.SetChannels(1);
|
||||
format.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
#ifdef USE_BE_MACH
|
||||
format.SetByteOrder(wxSND_SAMPLE_BE);
|
||||
#else
|
||||
format.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
#endif
|
||||
return format;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#ifndef __MEDIA_SNDMULAW_H__
|
||||
#define __MEDIA_SNDMULAW_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "sndfrmt.h"
|
||||
|
||||
class wxSoundMulawCodec : public wxSoundCodec {
|
||||
DECLARE_DYNAMIC_CLASS(wxSoundMulawCodec)
|
||||
public:
|
||||
wxSoundMulawCodec();
|
||||
virtual ~wxSoundMulawCodec();
|
||||
|
||||
void SetSampleRate(int srate) { m_srate = srate; }
|
||||
|
||||
size_t GetByteRate() const;
|
||||
wxSoundDataFormat GetPreferredFormat(int codec = 0) const;
|
||||
|
||||
void Decode();
|
||||
void Encode();
|
||||
|
||||
protected:
|
||||
int m_srate;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,209 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndpcm.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1998
|
||||
// Updated: 1999
|
||||
// Copyright: (C) 1997, 1998, 1999, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndpcm.h"
|
||||
#endif
|
||||
#include "sndsnd.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
#define WX_BIG_ENDIAN 0
|
||||
|
||||
wxSoundPcmCodec::wxSoundPcmCodec()
|
||||
: wxSoundCodec()
|
||||
{
|
||||
m_orig_format.SetCodecCreate(FALSE);
|
||||
m_orig_format.SetCodecNo(WXSOUND_PCM);
|
||||
}
|
||||
|
||||
wxSoundPcmCodec::~wxSoundPcmCodec()
|
||||
{
|
||||
}
|
||||
|
||||
size_t wxSoundPcmCodec::GetByteRate() const
|
||||
{
|
||||
return (m_orig_format.GetBps()/8)*
|
||||
m_orig_format.GetSampleRate()*
|
||||
m_orig_format.GetChannels();
|
||||
}
|
||||
|
||||
wxSoundDataFormat wxSoundPcmCodec::GetPreferredFormat(int codec) const
|
||||
{
|
||||
wxSoundDataFormat prefFormat;
|
||||
|
||||
prefFormat = m_orig_format;
|
||||
return prefFormat;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Main part of the decoder
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void wxSoundPcmCodec::Decode()
|
||||
{
|
||||
if (m_io_format == m_orig_format) {
|
||||
CopyToOutput();
|
||||
return;
|
||||
}
|
||||
|
||||
// Swap bytes
|
||||
switch (m_io_format.GetBps()) {
|
||||
case 8:
|
||||
InputSign8();
|
||||
break;
|
||||
case 16:
|
||||
InputSwapAndSign16();
|
||||
break;
|
||||
case 32:
|
||||
case 64:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Change the sign of a 8-bit sample.
|
||||
|
||||
#define GET() (m_in_sound->GetChar())
|
||||
#define PUT(c) (m_out_sound->PutChar(c))
|
||||
|
||||
void wxSoundPcmCodec::InputSign8()
|
||||
{
|
||||
unsigned char signer = 0;
|
||||
|
||||
if (m_io_format.GetSign() != m_orig_format.GetSign())
|
||||
signer = 128;
|
||||
|
||||
while (StreamOk())
|
||||
PUT(GET() + signer);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Swap bytes and change the sign of a 16-bit sample.
|
||||
|
||||
void wxSoundPcmCodec::InputSwapAndSign16()
|
||||
{
|
||||
unsigned short signer1 = 0, signer2 = 0;
|
||||
bool swap = (m_io_format.GetByteOrder() != m_orig_format.GetByteOrder());
|
||||
register char temp, temp2;
|
||||
|
||||
if (m_io_format.GetSign() != m_orig_format.GetSign()) {
|
||||
if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE)
|
||||
signer2 = 0x80;
|
||||
else
|
||||
signer1 = 0x80;
|
||||
}
|
||||
|
||||
if (swap) {
|
||||
while (StreamOk()) {
|
||||
temp = GET();
|
||||
temp2 = GET();
|
||||
PUT(temp2 ^ signer2);
|
||||
if (!StreamOk()) {
|
||||
m_in_sound->WriteBack(temp);
|
||||
m_in_sound->WriteBack(temp2);
|
||||
break;
|
||||
}
|
||||
PUT(temp ^ signer1);
|
||||
}
|
||||
} else {
|
||||
while (StreamOk()) {
|
||||
temp = GET();
|
||||
temp2 = GET();
|
||||
PUT(temp ^ signer1);
|
||||
if (!StreamOk()) {
|
||||
m_in_sound->WriteBack(temp);
|
||||
m_in_sound->WriteBack(temp2);
|
||||
break;
|
||||
}
|
||||
PUT(GET() ^ signer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Encoder part.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void wxSoundPcmCodec::OutputSign8()
|
||||
{
|
||||
unsigned char signer = 0;
|
||||
|
||||
if (m_io_format.GetSign() != m_orig_format.GetSign())
|
||||
signer = 128;
|
||||
|
||||
while (StreamOk())
|
||||
PUT((char)(GET() + signer));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void wxSoundPcmCodec::OutputSwapAndSign16()
|
||||
{
|
||||
bool swap = (m_io_format.GetByteOrder() != m_orig_format.GetByteOrder());
|
||||
unsigned short signer1 = 0, signer2 = 0;
|
||||
register char temp, temp2;
|
||||
|
||||
if (m_io_format.GetSign() != m_orig_format.GetSign())
|
||||
if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE)
|
||||
signer1 = 0x80;
|
||||
else
|
||||
signer2 = 0x80;
|
||||
|
||||
if (swap) {
|
||||
while (StreamOk()) {
|
||||
temp = GET();
|
||||
temp2 = GET();
|
||||
PUT(temp2 ^ signer1);
|
||||
if (!StreamOk()) {
|
||||
m_in_sound->WriteBack(temp);
|
||||
m_in_sound->WriteBack(temp2);
|
||||
break;
|
||||
}
|
||||
PUT(temp ^ signer2);
|
||||
}
|
||||
} else {
|
||||
while (StreamOk()) {
|
||||
temp = GET();
|
||||
temp2 = GET();
|
||||
PUT(temp ^ signer1);
|
||||
if (!StreamOk()) {
|
||||
m_in_sound->WriteBack(temp);
|
||||
m_in_sound->WriteBack(temp2);
|
||||
break;
|
||||
}
|
||||
PUT(temp2 ^ signer2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void wxSoundPcmCodec::Encode()
|
||||
{
|
||||
if (m_io_format == m_orig_format) {
|
||||
CopyToOutput();
|
||||
return;
|
||||
}
|
||||
|
||||
// Swap bytes
|
||||
switch (m_io_format.GetBps()) {
|
||||
case 8:
|
||||
OutputSign8();
|
||||
break;
|
||||
case 16:
|
||||
OutputSwapAndSign16();
|
||||
break;
|
||||
case 32:
|
||||
case 64:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef __SNDPCM_H__
|
||||
#define __SNDPCM_H__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "sndfrmt.h"
|
||||
|
||||
class wxSoundPcmCodec : public wxSoundCodec {
|
||||
DECLARE_DYNAMIC_CLASS(wxSoundPcmCodec)
|
||||
public:
|
||||
wxSoundPcmCodec();
|
||||
virtual ~wxSoundPcmCodec();
|
||||
|
||||
size_t GetByteRate() const;
|
||||
wxSoundDataFormat GetPreferredFormat(int codec = 0) const;
|
||||
|
||||
void Decode();
|
||||
void Encode();
|
||||
|
||||
protected:
|
||||
void InputSign8();
|
||||
void InputSwapAndSign16();
|
||||
void OutputSign8();
|
||||
void OutputSwapAndSign16();
|
||||
|
||||
protected:
|
||||
friend class wxSoundDataFormat;
|
||||
wxSoundDataFormat m_orig_format;
|
||||
char m_char_stack;
|
||||
bool m_char_bool;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,262 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndsnd.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndsnd.h"
|
||||
#endif
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrmt.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#define PROCESS_EVENT() wxYield()
|
||||
// #define PROCESS_EVENT()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSndBuffer: base sound buffer class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxSndBuffer::wxSndBuffer()
|
||||
: m_sndmode(wxSND_OUTPUT), m_sndflags(0), m_sndoutput(NULL), m_sndcodec(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndBuffer::~wxSndBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndBuffer::Set(wxSndFlags flags)
|
||||
{
|
||||
m_sndflags |= flags;
|
||||
|
||||
if ((m_sndflags & wxSND_BUFAUTO) && (flags & wxSND_BUFREADY))
|
||||
m_sndoutput->QueueBuffer(*this);
|
||||
}
|
||||
|
||||
void wxSndBuffer::SetError(wxSndError error)
|
||||
{
|
||||
if (error == wxSND_NOERROR)
|
||||
Clear(wxSND_BUFERR);
|
||||
else
|
||||
Set(wxSND_BUFERR);
|
||||
|
||||
m_snderror = error;
|
||||
}
|
||||
|
||||
wxSndError wxSndBuffer::GetError()
|
||||
{
|
||||
if (IsNotSet(wxSND_BUFERR))
|
||||
return wxSND_NOERROR;
|
||||
Clear(wxSND_BUFERR);
|
||||
return m_snderror;
|
||||
}
|
||||
|
||||
void wxSndBuffer::OnPlayFinished()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndBuffer::OnBufferOutFinished()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndBuffer::OnBufferInFinished(char *WXUNUSED(iobuf),
|
||||
wxUint32& WXUNUSED(size))
|
||||
{
|
||||
}
|
||||
|
||||
bool wxSndBuffer::Wait()
|
||||
{
|
||||
if (IsNotSet(wxSND_BUFLOCKED))
|
||||
return FALSE;
|
||||
|
||||
while (IsSet(wxSND_BUFLOCKED))
|
||||
PROCESS_EVENT();
|
||||
|
||||
return IsNotSet(wxSND_BUFERR);
|
||||
}
|
||||
|
||||
void wxSndBuffer::HardLock()
|
||||
{
|
||||
m_mutex.Lock();
|
||||
}
|
||||
|
||||
void wxSndBuffer::HardUnlock()
|
||||
{
|
||||
m_mutex.Unlock();
|
||||
}
|
||||
|
||||
void wxSndBuffer::ChangeCodec(int no)
|
||||
{
|
||||
m_sndformat.SetCodecNo(no);
|
||||
m_sndcodec = m_sndformat.GetCodec();
|
||||
m_sndcodec->SetIOBuffer(this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSndSimpleBuffer: the simplest sound buffer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
wxSndSimpleBuffer::wxSndSimpleBuffer(char *buffer, wxUint32 bufsize,
|
||||
wxSndMode mode)
|
||||
: wxSndBuffer()
|
||||
{
|
||||
m_sndbuf = buffer;
|
||||
m_sndsize = bufsize;
|
||||
m_sndmode = mode;
|
||||
|
||||
m_sndptr = 0;
|
||||
}
|
||||
|
||||
wxSndSimpleBuffer::~wxSndSimpleBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndSimpleBuffer::OnNeedOutputData(char *iobuf, wxUint32& size)
|
||||
{
|
||||
char *buf = m_sndbuf + m_sndptr;
|
||||
wxUint32 nbdata_left = m_sndsize - m_sndptr;
|
||||
|
||||
if (m_sndptr >= m_sndsize) {
|
||||
size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (size > nbdata_left)
|
||||
size = nbdata_left;
|
||||
|
||||
m_sndptr += size;
|
||||
|
||||
memcpy(iobuf, buf, size);
|
||||
}
|
||||
|
||||
void wxSndSimpleBuffer::OnBufferOutFinished()
|
||||
{
|
||||
if (m_sndptr >= m_sndsize)
|
||||
OnPlayFinished();
|
||||
}
|
||||
|
||||
void wxSndSimpleBuffer::OnBufferInFinished(char *iobuf, wxUint32& size)
|
||||
{
|
||||
char *raw_buf = m_sndbuf + m_sndptr;
|
||||
wxUint32 data_left = m_sndsize - m_sndptr;
|
||||
|
||||
if (!data_left) {
|
||||
size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (size > data_left)
|
||||
size = data_left;
|
||||
|
||||
memcpy(raw_buf, iobuf, size);
|
||||
m_sndptr += size;
|
||||
}
|
||||
|
||||
void wxSndSimpleBuffer::SetData(char *buffer, wxUint32 bufsize,
|
||||
wxSndMode mode)
|
||||
{
|
||||
m_sndbuf = buffer;
|
||||
m_sndsize = bufsize;
|
||||
m_sndmode = mode;
|
||||
}
|
||||
|
||||
bool wxSndSimpleBuffer::RestartBuffer(wxSndMode mode)
|
||||
{
|
||||
m_sndptr = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxUint32 wxSndSimpleBuffer::GetSize() const
|
||||
{
|
||||
return m_sndsize;
|
||||
}
|
||||
|
||||
wxUint32 wxSndSimpleBuffer::Available() const
|
||||
{
|
||||
return m_sndsize - m_sndptr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxSound: base sound driver implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxSound::wxSound()
|
||||
: wxObject(),
|
||||
m_lastbuf(NULL), m_sndcbk(NULL), m_snderror(wxSND_NOERROR)
|
||||
{
|
||||
m_buffers.Clear();
|
||||
}
|
||||
|
||||
wxSound::~wxSound()
|
||||
{
|
||||
wxNode *node = m_buffers.First();
|
||||
|
||||
while (node) {
|
||||
wxSndBuffer *buf = (wxSndBuffer *)node->Data();
|
||||
|
||||
buf->Clear(wxSND_BUFLOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
bool wxSound::QueueBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
if (buf.IsSet(wxSND_BUFLOCKED) || buf.IsNotSet(wxSND_BUFREADY))
|
||||
return FALSE;
|
||||
|
||||
buf.Set(wxSND_BUFLOCKED);
|
||||
buf.SetOutput(*this);
|
||||
|
||||
m_buffers.Append(&buf);
|
||||
return Wakeup(buf);
|
||||
}
|
||||
|
||||
bool wxSound::UnqueueBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
wxNode *node;
|
||||
|
||||
if (buf.IsNotSet(wxSND_BUFLOCKED))
|
||||
return FALSE;
|
||||
|
||||
node = m_buffers.Member(&buf);
|
||||
if (!node)
|
||||
return FALSE;
|
||||
|
||||
StopBuffer(buf);
|
||||
node = m_buffers.Member(&buf);
|
||||
if (node)
|
||||
delete node;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSound::Callback(wxSndCallback cbk)
|
||||
{
|
||||
m_sndcbk = cbk;
|
||||
}
|
||||
|
||||
void wxSound::SetClientData(char *cdata)
|
||||
{
|
||||
m_cdata = cdata;
|
||||
}
|
||||
|
||||
void wxSound::OnPlayBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
m_lastbuf = &buf;
|
||||
if (m_sndcbk)
|
||||
m_sndcbk(*this, buf, m_cdata);
|
||||
}
|
@ -1,275 +0,0 @@
|
||||
/* Real -*- C++ -*- */
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndsnd.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __WX_SND_SOUND_H__
|
||||
#define __WX_SND_SOUND_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include <wx/thread.h>
|
||||
#include "sndfrmt.h"
|
||||
#include "mmtype.h"
|
||||
|
||||
class wxSound;
|
||||
class wxSndBuffer;
|
||||
|
||||
typedef enum {
|
||||
wxSND_OUTPUT,
|
||||
wxSND_INPUT,
|
||||
wxSND_DUPLEX,
|
||||
wxSND_OTHER_IO
|
||||
} /// The possible sound output modes
|
||||
wxSndMode;
|
||||
|
||||
typedef enum {
|
||||
wxSND_NOERROR = 0,
|
||||
wxSND_NOCAPS,
|
||||
wxSND_CANTOPEN,
|
||||
wxSND_NOMEM,
|
||||
wxSND_READERR,
|
||||
wxSND_WRITEERR,
|
||||
wxSND_CANTSET
|
||||
} /// Sound errors
|
||||
wxSndError;
|
||||
|
||||
/// Sound callback
|
||||
typedef void (*wxSndCallback)(wxSound&, wxSndBuffer&, char *);
|
||||
|
||||
/// Sound flags
|
||||
typedef wxUint16 wxSndFlags;
|
||||
|
||||
/** @name Sound buffer flags */
|
||||
/// buffer ready
|
||||
#define wxSND_BUFREADY 0x0001
|
||||
/// an error occured
|
||||
#define wxSND_BUFERR 0x0002
|
||||
/// buffer is in use
|
||||
#define wxSND_BUFLOCKED 0x0004
|
||||
/// the driver mustn't unqueue it
|
||||
#define wxSND_KEEPQUEUED 0x0008
|
||||
/// automatic: when BUFREADY is set play the buffer
|
||||
#define wxSND_BUFAUTO 0x0010
|
||||
///
|
||||
#define wxSND_UNFINISHED 0x0020
|
||||
/// buffer is nearly being unqueued
|
||||
#define wxSND_UNQUEUEING 0x0040
|
||||
/// driver wants the buffer stop
|
||||
#define wxSND_BUFSTOP 0x0080
|
||||
/// buffer will loop
|
||||
#define wxSND_LOOP 0x0100
|
||||
|
||||
/** @name Sound data format */
|
||||
/// little endian
|
||||
#define wxSND_SAMPLE_LE 0
|
||||
/// big endian
|
||||
#define wxSND_SAMPLE_BE 1
|
||||
/// unsigned samples
|
||||
#define wxSND_SAMPLE_UNSIGNED 0
|
||||
/// signed samples
|
||||
#define wxSND_SAMPLE_SIGNED 1
|
||||
|
||||
/** @name wxSndBuffer
|
||||
* @memo wxSndBuffer is the basic class for all the sound codec.
|
||||
* @author Guilhem Lavaux
|
||||
*/
|
||||
class wxSndBuffer : public wxObject {
|
||||
/// It is an abstract class
|
||||
DECLARE_ABSTRACT_CLASS(wxSndBuffer)
|
||||
protected:
|
||||
wxMutex m_mutex;
|
||||
/// output mode
|
||||
wxSndMode m_sndmode;
|
||||
/// last error
|
||||
wxSndError m_snderror;
|
||||
/// some flag
|
||||
wxSndFlags m_sndflags;
|
||||
/// last sound driver used
|
||||
wxSound *m_sndoutput;
|
||||
/// sound data format
|
||||
wxSoundDataFormat m_sndformat;
|
||||
/// current sound codec
|
||||
wxSoundCodec *m_sndcodec;
|
||||
public:
|
||||
/** @name constructor and destructor */
|
||||
//@{
|
||||
/// Construct an uninitialized wxSndBuffer
|
||||
wxSndBuffer();
|
||||
/// Destroy
|
||||
virtual ~wxSndBuffer();
|
||||
//@}
|
||||
|
||||
/** @name Functions returning the current state */
|
||||
//@{
|
||||
/// @return current mode
|
||||
inline wxSndMode GetMode() const { return m_sndmode; }
|
||||
/// @return sound data format
|
||||
inline wxSoundDataFormat& GetFormat() { return m_sndformat; }
|
||||
/// @return the size of the buffer
|
||||
virtual wxUint32 GetSize() const = 0;
|
||||
/// @return bytes left
|
||||
virtual wxUint32 Available() const = 0;
|
||||
|
||||
/** enable the specified flags
|
||||
* @param flags
|
||||
*/
|
||||
void Set(wxSndFlags flags);
|
||||
/** disable the specified flags
|
||||
* @param flags
|
||||
*/
|
||||
inline void Clear(wxSndFlags flags)
|
||||
{ m_sndflags &= ~flags; }
|
||||
/** Check if the specified flags is set
|
||||
* @param flags
|
||||
* @return TRUE if all flags is set
|
||||
*/
|
||||
inline bool IsSet(wxSndFlags flags) const
|
||||
{ return ((m_sndflags & flags) == flags); }
|
||||
/** Check if the specified flags is not set
|
||||
* @param flags
|
||||
* @return TRUE if at least one flag is not set
|
||||
*/
|
||||
inline bool IsNotSet(wxSndFlags flags) const
|
||||
{ return ((m_sndflags & flags) != flags); }
|
||||
/** Check if the buffer is currently being played
|
||||
* @return TRUE
|
||||
if the buffer is being played
|
||||
*/
|
||||
inline bool IsPlaying() const
|
||||
{ return IsSet(wxSND_BUFLOCKED); }
|
||||
//@}
|
||||
|
||||
///
|
||||
inline void SetOutput(wxSound& snd)
|
||||
{ m_sndoutput = &snd; }
|
||||
///
|
||||
inline wxSoundCodec *GetCurrentCodec() const
|
||||
{ return m_sndcodec; }
|
||||
///
|
||||
void HardLock();
|
||||
///
|
||||
void HardUnlock();
|
||||
|
||||
///
|
||||
wxSndError GetError();
|
||||
///
|
||||
void SetError(wxSndError err);
|
||||
|
||||
///
|
||||
virtual bool Wait();
|
||||
///
|
||||
virtual bool RestartBuffer(wxSndMode mode) = 0;
|
||||
///
|
||||
virtual bool Abort() { return TRUE; }
|
||||
|
||||
///
|
||||
virtual void OnPlayFinished();
|
||||
|
||||
/** Data exchanging functions */
|
||||
//@{
|
||||
///
|
||||
virtual void OnNeedOutputData(char *io_buf, wxUint32& size) = 0;
|
||||
///
|
||||
virtual void OnBufferOutFinished();
|
||||
///
|
||||
virtual void OnBufferInFinished(char *iobuf, wxUint32& size);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
void ChangeCodec(int no);
|
||||
};
|
||||
|
||||
class wxSndSimpleBuffer : public wxSndBuffer {
|
||||
DECLARE_DYNAMIC_CLASS(wxSndSimpleBuffer)
|
||||
protected:
|
||||
/// sound buffer
|
||||
char *m_sndbuf;
|
||||
/// size of the sound buffer
|
||||
wxUint32 m_sndsize;
|
||||
/// current position in the sound buffer
|
||||
wxUint32 m_sndptr;
|
||||
public:
|
||||
wxSndSimpleBuffer(char *buffer = NULL, wxUint32 bufsize = 0,
|
||||
wxSndMode mode = wxSND_OUTPUT);
|
||||
virtual ~wxSndSimpleBuffer();
|
||||
|
||||
void SetData(char *buffer, wxUint32 bufsize,
|
||||
wxSndMode mode = wxSND_OUTPUT);
|
||||
inline void SetSoundFormat(const wxSoundDataFormat& format);
|
||||
|
||||
void OnNeedOutputData(char *io_buf, wxUint32& size);
|
||||
void OnNeedInputData(wxUint32& size);
|
||||
|
||||
void OnBufferOutFinished();
|
||||
void OnBufferInFinished(char *iobuf, wxUint32& size);
|
||||
|
||||
bool RestartBuffer(wxSndMode mode);
|
||||
wxUint32 GetSize() const;
|
||||
wxUint32 Available() const;
|
||||
};
|
||||
|
||||
///
|
||||
class wxSound : public wxObject {
|
||||
///
|
||||
DECLARE_ABSTRACT_CLASS(wxSound)
|
||||
protected:
|
||||
friend class wxFragmentBuffer;
|
||||
|
||||
///
|
||||
wxSndBuffer *m_lastbuf;
|
||||
///
|
||||
wxList m_buffers;
|
||||
///
|
||||
wxSndCallback m_sndcbk;
|
||||
///
|
||||
wxSndError m_snderror;
|
||||
///
|
||||
char *m_cdata;
|
||||
public:
|
||||
///
|
||||
wxSound();
|
||||
///
|
||||
virtual ~wxSound();
|
||||
|
||||
///
|
||||
virtual bool QueueBuffer(wxSndBuffer& buf);
|
||||
///
|
||||
virtual bool UnqueueBuffer(wxSndBuffer& buf);
|
||||
///
|
||||
inline wxSndBuffer *LastBufferPlayed()
|
||||
{ return m_lastbuf; }
|
||||
|
||||
///
|
||||
wxSndError GetError() { return m_snderror; }
|
||||
|
||||
///
|
||||
void Callback(wxSndCallback cbk);
|
||||
///
|
||||
void SetClientData(char *cdata);
|
||||
///
|
||||
virtual void OnPlayBuffer(wxSndBuffer& buf);
|
||||
protected:
|
||||
///
|
||||
virtual bool Wakeup(wxSndBuffer& buf) = 0;
|
||||
///
|
||||
virtual void StopBuffer(wxSndBuffer& buf) = 0;
|
||||
|
||||
///
|
||||
virtual inline bool OnSetupDriver(wxSndBuffer& WXUNUSED(buf),
|
||||
wxSndMode WXUNUSED(mode))
|
||||
{ return TRUE; }
|
||||
};
|
||||
|
||||
#endif
|
@ -1,302 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: snduss.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "snduss.h"
|
||||
#endif
|
||||
|
||||
#include <sys/soundcard.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wx/app.h"
|
||||
#include "wx/utils.h"
|
||||
|
||||
#define WXMMEDIA_INTERNAL
|
||||
#include "snduss.h"
|
||||
#include "sndfrmt.h"
|
||||
|
||||
wxUssSound::wxUssSound()
|
||||
: wxSound(),
|
||||
m_srate(0), m_bps(0), m_stereo(0),
|
||||
m_mode(wxSND_OTHER_IO),
|
||||
m_stop_thrd(TRUE), m_sleeping(FALSE)
|
||||
{
|
||||
m_fd = -1;
|
||||
m_ussformat.SetCodecNo(WXSOUND_PCM);
|
||||
m_ussformat.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
m_ussformat.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
|
||||
m_sndbuf = new wxStreamBuffer(wxStreamBuffer::read_write);
|
||||
m_sndbuf->Flushable(FALSE);
|
||||
m_sndbuf->Fixed(TRUE);
|
||||
}
|
||||
|
||||
wxUssSound::~wxUssSound()
|
||||
{
|
||||
if (!m_stop_thrd) {
|
||||
m_stop_thrd = TRUE;
|
||||
if (m_sleeping) {
|
||||
m_sleep_mtx.Lock();
|
||||
m_sleep_cond.Signal();
|
||||
m_sleep_mtx.Unlock();
|
||||
}
|
||||
while (IsAlive())
|
||||
Yield();
|
||||
}
|
||||
|
||||
if (m_fd != -1)
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
bool wxUssSound::Wakeup(wxSndBuffer& WXUNUSED(buf))
|
||||
{
|
||||
printf("Waking up (wxUssSound::Wakeup) ...\n");
|
||||
if (m_stop_thrd) {
|
||||
m_stop_thrd = FALSE;
|
||||
Entry();
|
||||
// wxThread::Create();
|
||||
}
|
||||
|
||||
if (m_sleeping) {
|
||||
m_sleep_mtx.Lock();
|
||||
m_sleep_cond.Signal();
|
||||
m_sleep_mtx.Unlock();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxUssSound::StopBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
buf.HardLock();
|
||||
buf.Set(wxSND_BUFSTOP);
|
||||
buf.HardUnlock();
|
||||
while (buf.IsSet(wxSND_BUFSTOP))
|
||||
wxYield();
|
||||
// usleep(0);
|
||||
}
|
||||
|
||||
void wxUssSound::USS_Sleep()
|
||||
{
|
||||
bool ret;
|
||||
|
||||
printf("Asleeping ...\n");
|
||||
m_sleeping = TRUE;
|
||||
m_sleep_mtx.Lock();
|
||||
ret = m_sleep_cond.Wait(m_sleep_mtx, 10, 0);
|
||||
m_sleep_mtx.Unlock();
|
||||
m_sleeping = FALSE;
|
||||
|
||||
printf("Waking up ...\n");
|
||||
if (!ret)
|
||||
m_stop_thrd = TRUE;
|
||||
}
|
||||
|
||||
bool wxUssSound::DoInput(wxSndBuffer *buf)
|
||||
{
|
||||
wxUint32 bufsize;
|
||||
wxSoundCodec *codec = buf->GetCurrentCodec();
|
||||
|
||||
m_sndbuf->ResetBuffer();
|
||||
|
||||
bufsize = codec->Available();
|
||||
if (bufsize > m_max_bufsize)
|
||||
bufsize = m_max_bufsize;
|
||||
|
||||
if (!bufsize) {
|
||||
buf->Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
|
||||
return false;
|
||||
}
|
||||
read(m_fd, m_sndbuf->GetBufferStart(), bufsize);
|
||||
codec->Encode();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxUssSound::DoOutput(wxSndBuffer *buf)
|
||||
{
|
||||
wxSoundCodec *codec = buf->GetCurrentCodec();
|
||||
|
||||
m_sndbuf->ResetBuffer();
|
||||
|
||||
if (!codec->Available()) {
|
||||
buf->Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
|
||||
return FALSE;
|
||||
}
|
||||
codec->Decode();
|
||||
write(m_fd, m_sndbuf->GetBufferStart(), m_sndbuf->GetIntPosition());
|
||||
|
||||
// Well ... it's not accurate ! :-|
|
||||
buf->OnBufferOutFinished();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxUssSound::InitBuffer(wxSndBuffer *buf)
|
||||
{
|
||||
wxSoundCodec *codec;
|
||||
|
||||
if (!OnSetupDriver(*buf, buf->GetMode())) {
|
||||
if (buf->IsNotSet(wxSND_BUFREADY))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
codec = buf->GetCurrentCodec();
|
||||
switch (m_mode) {
|
||||
case wxSND_INPUT:
|
||||
codec->SetInStream(m_sndbuf);
|
||||
codec->InitIO(m_ussformat);
|
||||
codec->InitMode(wxSoundCodec::ENCODING);
|
||||
break;
|
||||
case wxSND_OUTPUT:
|
||||
codec->SetOutStream(m_sndbuf);
|
||||
codec->InitIO(m_ussformat);
|
||||
codec->InitMode(wxSoundCodec::DECODING);
|
||||
break;
|
||||
case wxSND_DUPLEX:
|
||||
case wxSND_OTHER_IO:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void *wxUssSound::Entry()
|
||||
{
|
||||
wxNode *node;
|
||||
wxSndBuffer *buf;
|
||||
|
||||
node = m_buffers.First();
|
||||
if (!node) {
|
||||
m_stop_thrd = FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = (wxSndBuffer *)node->Data();
|
||||
InitBuffer(buf);
|
||||
|
||||
while (!m_stop_thrd) {
|
||||
buf->HardLock();
|
||||
if (buf->IsSet(wxSND_BUFSTOP)) {
|
||||
buf->HardUnlock();
|
||||
goto sound_clean_buffer;
|
||||
}
|
||||
switch(m_mode) {
|
||||
case wxSND_INPUT:
|
||||
if (!DoInput(buf))
|
||||
goto sound_clean_buffer;
|
||||
break;
|
||||
case wxSND_OUTPUT:
|
||||
if (!DoOutput(buf))
|
||||
goto sound_clean_buffer;
|
||||
break;
|
||||
case wxSND_DUPLEX:
|
||||
case wxSND_OTHER_IO:
|
||||
goto sound_clean_buffer;
|
||||
break;
|
||||
}
|
||||
buf->HardUnlock();
|
||||
continue;
|
||||
|
||||
sound_clean_buffer:
|
||||
buf->GetCurrentCodec()->ExitMode();
|
||||
delete node;
|
||||
node = m_buffers.First();
|
||||
if (!node)
|
||||
USS_Sleep();
|
||||
if (node)
|
||||
buf = (wxSndBuffer *)node->Data();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool wxUssSound::OnSetupDriver(wxSndBuffer& buf, wxSndMode WXUNUSED(mode))
|
||||
{
|
||||
wxSoundDataFormat format;
|
||||
wxSoundCodec *codec;
|
||||
|
||||
codec = buf.GetCurrentCodec();
|
||||
format = codec->GetPreferredFormat(WXSOUND_PCM);
|
||||
|
||||
if ((format.GetSampleRate() != m_srate) ||
|
||||
(format.GetBps() != m_bps) ||
|
||||
(format.GetStereo() != m_stereo)) {
|
||||
|
||||
if (!SetupSound(format.GetSampleRate(), format.GetBps(),
|
||||
format.GetStereo())) {
|
||||
m_buffers.DeleteObject(&buf);
|
||||
buf.Clear(wxSND_BUFLOCKED | wxSND_BUFREADY);
|
||||
buf.SetError(wxSND_CANTSET);
|
||||
return FALSE;
|
||||
}
|
||||
m_mode = wxSND_OTHER_IO;
|
||||
}
|
||||
|
||||
if (buf.GetMode() != m_mode) {
|
||||
m_mode = buf.GetMode();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxUint32 wxUssSound::GetNbFragments()
|
||||
{
|
||||
struct audio_buf_info frag_info;
|
||||
|
||||
ioctl(m_fd, SNDCTL_DSP_GETOSPACE, &frag_info);
|
||||
|
||||
return frag_info.fragstotal;
|
||||
}
|
||||
|
||||
wxUint32 wxUssSound::GetFragmentSize()
|
||||
{
|
||||
return m_max_bufsize;
|
||||
}
|
||||
|
||||
bool wxUssSound::SetupSound(wxUint16 srate, wxUint8 bps, bool stereo)
|
||||
{
|
||||
int tmp;
|
||||
unsigned long tmp_ul;
|
||||
|
||||
if (m_fd != -1) {
|
||||
delete m_sndbuf;
|
||||
fsync(m_fd);
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
m_fd = open("/dev/dsp", O_RDWR);
|
||||
|
||||
tmp = stereo;
|
||||
if (ioctl(m_fd, SNDCTL_DSP_STEREO, &tmp) < 0)
|
||||
return FALSE;
|
||||
m_stereo = tmp;
|
||||
|
||||
tmp_ul = srate;
|
||||
if (ioctl(m_fd, SNDCTL_DSP_SPEED, &tmp_ul) < 0)
|
||||
return FALSE;
|
||||
m_srate = tmp_ul;
|
||||
|
||||
tmp = bps;
|
||||
if (ioctl(m_fd, SNDCTL_DSP_SAMPLESIZE, &tmp) < 0)
|
||||
return FALSE;
|
||||
m_bps = tmp;
|
||||
|
||||
ioctl(m_fd, SNDCTL_DSP_GETBLKSIZE, &tmp);
|
||||
m_max_bufsize = tmp;
|
||||
m_sndbuf->SetBufferIO(m_max_bufsize);
|
||||
|
||||
m_ussformat.SetBps(m_bps);
|
||||
m_ussformat.SetChannels((m_stereo) ? 2 : 1);
|
||||
m_ussformat.SetSampleRate(m_srate);
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: snduss.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_ussnd_H__
|
||||
#define __SND_ussnd_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <wx/thread.h>
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrag.h"
|
||||
#include "sndfrmt.h"
|
||||
|
||||
///
|
||||
class wxUssSound : public wxSound, public wxThread {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxUssSound)
|
||||
public:
|
||||
wxUssSound();
|
||||
///
|
||||
virtual ~wxUssSound();
|
||||
|
||||
///
|
||||
void OnNeedBuffer();
|
||||
protected:
|
||||
///
|
||||
virtual bool Wakeup(wxSndBuffer& buf);
|
||||
///
|
||||
void USS_Sleep();
|
||||
///
|
||||
virtual void StopBuffer(wxSndBuffer& buf);
|
||||
|
||||
///
|
||||
bool OnSetupDriver(wxSndBuffer& buf, wxSndMode mode);
|
||||
|
||||
///
|
||||
bool SetupSound(wxUint16 srate, wxUint8 bps, bool stereo);
|
||||
|
||||
///
|
||||
wxUint32 GetNbFragments();
|
||||
///
|
||||
wxUint32 GetFragmentSize();
|
||||
///
|
||||
void ThreadEntryPoint();
|
||||
|
||||
protected:
|
||||
///
|
||||
wxUint16 m_srate;
|
||||
///
|
||||
wxUint8 m_bps;
|
||||
///
|
||||
wxUint32 m_max_bufsize;
|
||||
///
|
||||
bool m_stereo;
|
||||
///
|
||||
wxSndMode m_mode;
|
||||
///
|
||||
wxSoundDataFormat m_ussformat;
|
||||
///
|
||||
wxStreamBuffer *m_sndbuf;
|
||||
///
|
||||
bool m_stop_thrd, m_sleeping;
|
||||
/// Sound file descriptor.
|
||||
int m_fd;
|
||||
/// Thread sleep mutexes and conditions.
|
||||
wxMutex m_sleep_mtx;
|
||||
wxCondition m_sleep_cond;
|
||||
|
||||
///
|
||||
bool InitBuffer(wxSndBuffer *buf);
|
||||
bool DoInput(wxSndBuffer *buf);
|
||||
bool DoOutput(wxSndBuffer *buf);
|
||||
|
||||
///
|
||||
virtual void *Entry();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,183 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndwav.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: February 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndwav.h"
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "sndwav.h"
|
||||
#include "sndfrmt.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxSndWavCodec::wxSndWavCodec()
|
||||
: wxSndFileCodec(), riff_codec()
|
||||
{
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndWavCodec::wxSndWavCodec(wxOutputStream& s, bool seekable)
|
||||
: wxSndFileCodec(s, seekable)
|
||||
{
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
riff_codec = wxRiffCodec(*m_ostream);
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndWavCodec::wxSndWavCodec(wxInputStream& s, bool preload, bool seekable)
|
||||
: wxSndFileCodec(s, preload, seekable)
|
||||
{
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
|
||||
riff_codec = wxRiffCodec(*m_istream);
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxSndWavCodec::wxSndWavCodec(const wxString& fname)
|
||||
: wxSndFileCodec(fname)
|
||||
{
|
||||
riff_codec = wxRiffCodec(*m_istream);
|
||||
m_sndtime.hours = -1;
|
||||
}
|
||||
|
||||
wxUint32 wxSndWavCodec::PrepareToPlay()
|
||||
{
|
||||
if (!riff_codec.RiffReset(RIFF_READ))
|
||||
return 0;
|
||||
|
||||
if (!riff_codec.FindChunk("RIFF", TRUE)) {
|
||||
wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char tmp_buf[5];
|
||||
riff_codec.ReadData(tmp_buf, 4);
|
||||
tmp_buf[4] = 0;
|
||||
if (wxString("WAVE") != tmp_buf) {
|
||||
wxSndFileCodec::m_mmerror = wxMMFILE_INVALID;
|
||||
return 0;
|
||||
}
|
||||
if (!riff_codec.FindChunk("fmt ", TRUE))
|
||||
return 0;
|
||||
|
||||
riff_codec.Read16(wav_hdr.format);
|
||||
riff_codec.Read16(wav_hdr.channels);
|
||||
riff_codec.Read32(wav_hdr.sample_fq);
|
||||
riff_codec.Read32(wav_hdr.byte_p_sec);
|
||||
riff_codec.Read16(wav_hdr.byte_p_spl);
|
||||
riff_codec.Read16(wav_hdr.bits_p_spl);
|
||||
|
||||
if (!riff_codec.FindChunk("data"))
|
||||
return 0;
|
||||
|
||||
m_sndmode = wxSND_OUTPUT;
|
||||
ChangeCodec(wav_hdr.format);
|
||||
|
||||
m_sndformat.SetSampleRate(wav_hdr.sample_fq);
|
||||
m_sndformat.SetBps(wav_hdr.bits_p_spl);
|
||||
m_sndformat.SetChannels(wav_hdr.channels);
|
||||
|
||||
if (wav_hdr.format == WXSOUND_PCM) {
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
}
|
||||
|
||||
wxUint32 sec1 = riff_codec.GetChunkLength() / wav_hdr.byte_p_sec,
|
||||
sec2 = sec1 % 3600;
|
||||
|
||||
m_sndtime.hours = sec1 / 3600;
|
||||
m_sndtime.minutes = sec2 / 60;
|
||||
m_sndtime.seconds = sec2 % 60;
|
||||
|
||||
wxSndFileCodec::m_mmerror = wxMMFILE_NOERROR;
|
||||
wxSndFileCodec::m_fstate = wxSFILE_PREPARED_TO_PLAY;
|
||||
|
||||
return riff_codec.GetChunkLength();
|
||||
}
|
||||
|
||||
wxSndWavCodec::~wxSndWavCodec()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxSndWavCodec::OnNeedData(char *buf, wxUint32 size)
|
||||
{
|
||||
return riff_codec.ReadData(buf, size);
|
||||
}
|
||||
|
||||
bool wxSndWavCodec::OnWriteData(char *buf, wxUint32 size)
|
||||
{
|
||||
return riff_codec.WriteData(buf, size);
|
||||
}
|
||||
|
||||
bool wxSndWavCodec::PrepareToRecord(wxUint32 m_fsize)
|
||||
{
|
||||
wxUint32 total_size;
|
||||
|
||||
if (!riff_codec.RiffReset(RIFF_WRITE))
|
||||
return FALSE;
|
||||
|
||||
total_size = 16 + sizeof(wav_hdr) + m_fsize;
|
||||
|
||||
if (!riff_codec.CreateChunk("RIFF", total_size))
|
||||
return FALSE;
|
||||
riff_codec.WriteData("WAVE", 4);
|
||||
if (!riff_codec.CreateChunk("fmt ", sizeof(wav_hdr)))
|
||||
return FALSE;
|
||||
|
||||
wav_hdr.format = m_sndformat.GetCodecNo(); // PCM_WAV_FORMAT
|
||||
wav_hdr.channels = m_sndformat.GetChannels();
|
||||
wav_hdr.sample_fq = m_sndformat.GetSampleRate();
|
||||
wav_hdr.byte_p_spl = (m_sndformat.GetBps() / 8) * wav_hdr.channels;
|
||||
wav_hdr.byte_p_sec = m_sndformat.GetCodec()->GetByteRate();
|
||||
wav_hdr.bits_p_spl = m_sndformat.GetBps();
|
||||
|
||||
if (wav_hdr.format == WXSOUND_PCM) {
|
||||
m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
|
||||
m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
|
||||
}
|
||||
|
||||
riff_codec.Write16(wav_hdr.format);
|
||||
riff_codec.Write16(wav_hdr.channels);
|
||||
riff_codec.Write32(wav_hdr.sample_fq);
|
||||
riff_codec.Write32(wav_hdr.byte_p_sec);
|
||||
riff_codec.Write16(wav_hdr.byte_p_spl);
|
||||
riff_codec.Write16(wav_hdr.bits_p_spl);
|
||||
|
||||
if (!riff_codec.CreateChunk("data", m_fsize))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxSndWavCodec::SetFile(wxInputStream& s, bool preload, bool seekable)
|
||||
{
|
||||
wxMMediaFile::SetFile(s, preload, seekable);
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
|
||||
riff_codec.SetFile((seekable) ? s : *m_istream);
|
||||
}
|
||||
|
||||
void wxSndWavCodec::SetFile(wxOutputStream& s, bool seekable)
|
||||
{
|
||||
wxMMediaFile::SetFile(s, seekable);
|
||||
if (!seekable)
|
||||
CacheIO();
|
||||
|
||||
riff_codec.SetFile((seekable) ? s : *m_ostream);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndwav.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: February 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_wav_H__
|
||||
#define __SND_wav_H__
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmriff.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
///
|
||||
class wxSndWavCodec : public wxSndFileCodec {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxSndWavCodec)
|
||||
public:
|
||||
///
|
||||
wxSndWavCodec();
|
||||
///
|
||||
wxSndWavCodec(wxInputStream& s, bool preload = FALSE, bool seekable = TRUE);
|
||||
///
|
||||
wxSndWavCodec(wxOutputStream& s, bool seekable = TRUE);
|
||||
///
|
||||
wxSndWavCodec(const wxString& fname);
|
||||
///
|
||||
virtual ~wxSndWavCodec();
|
||||
|
||||
virtual bool OnNeedData(char *buf, wxUint32 size);
|
||||
virtual bool OnWriteData(char *buf, wxUint32 size);
|
||||
|
||||
virtual wxUint32 PrepareToPlay();
|
||||
virtual bool PrepareToRecord(wxUint32 file_size);
|
||||
|
||||
virtual void SetFile(wxInputStream& s, bool preload = FALSE,
|
||||
bool seekable = FALSE);
|
||||
virtual void SetFile(wxOutputStream& s,
|
||||
bool seekable = FALSE);
|
||||
|
||||
protected:
|
||||
wxRiffCodec riff_codec;
|
||||
struct {
|
||||
wxUint16 format;
|
||||
wxUint16 channels;
|
||||
wxUint32 sample_fq;
|
||||
wxUint32 byte_p_sec;
|
||||
wxUint16 byte_p_spl;
|
||||
wxUint16 bits_p_spl;
|
||||
} wav_hdr;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,384 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndwin.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx/wxprec.h"
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include <wx/msw/private.h>
|
||||
|
||||
#define WXMMEDIA_INTERNAL
|
||||
#include "sndwin.h"
|
||||
|
||||
#define MMD_WIN_IO_BSIZE 16384
|
||||
|
||||
#include <mmsystem.h>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
wxSndWinFragment::wxSndWinFragment(wxSound& io_drv)
|
||||
: wxFragmentBuffer(io_drv)
|
||||
{
|
||||
}
|
||||
|
||||
wxSndWinFragment::~wxSndWinFragment(void)
|
||||
{
|
||||
}
|
||||
|
||||
void wxSndWinFragment::AllocIOBuffer(void)
|
||||
{
|
||||
wxWinSound *w_snd = (wxWinSound *) m_iodrv;
|
||||
wxUint8 i;
|
||||
|
||||
m_maxoq = 5;
|
||||
m_maxiq = 5;
|
||||
|
||||
m_lstoptrs = new wxFragBufPtr[m_maxoq];
|
||||
m_lstiptrs = new wxFragBufPtr[m_maxiq];
|
||||
|
||||
for (i=0;i<m_maxoq;i++) {
|
||||
m_lstoptrs[i].buffers = new wxList();
|
||||
m_lstoptrs[i].state = wxBUFFER_FREE;
|
||||
|
||||
w_snd->PrepareHeader(m_lstoptrs[i], wxSND_OUTPUT);
|
||||
}
|
||||
|
||||
for (i=0;i<m_maxiq;i++) {
|
||||
m_lstiptrs[i].size = MMD_WIN_IO_BSIZE;
|
||||
m_lstiptrs[i].ptr = 0;
|
||||
m_lstiptrs[i].buffers = new wxList();
|
||||
m_lstiptrs[i].state = wxBUFFER_FREE;
|
||||
|
||||
w_snd->PrepareHeader(m_lstiptrs[i], wxSND_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void wxSndWinFragment::FreeIOBuffer(void)
|
||||
{
|
||||
wxWinSound *w_snd = (wxWinSound *)m_iodrv;
|
||||
wxUint8 i;
|
||||
|
||||
if (!m_lstoptrs && !m_lstiptrs)
|
||||
return;
|
||||
|
||||
for (i=0;i<m_maxoq;i++) {
|
||||
w_snd->UnprepareHeader(m_lstoptrs[i], wxSND_OUTPUT);
|
||||
delete m_lstoptrs[i].buffers;
|
||||
}
|
||||
|
||||
for (i=0;i<m_maxiq;i++) {
|
||||
w_snd->UnprepareHeader(m_lstiptrs[i], wxSND_INPUT);
|
||||
delete m_lstiptrs[i].buffers;
|
||||
}
|
||||
|
||||
delete[] m_lstoptrs;
|
||||
delete[] m_lstiptrs;
|
||||
|
||||
m_lstoptrs = m_lstiptrs = NULL;
|
||||
m_maxoq = m_maxiq = 0;
|
||||
}
|
||||
|
||||
void wxSndWinFragment::WaitForAll()
|
||||
{
|
||||
bool buf_busy = TRUE;
|
||||
int i;
|
||||
|
||||
m_dontq = TRUE;
|
||||
|
||||
while (buf_busy) {
|
||||
buf_busy = FALSE;
|
||||
|
||||
for (i=0;i<m_maxoq;i++) {
|
||||
if (m_lstoptrs[i].state == wxBUFFER_FFILLED) {
|
||||
buf_busy = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
wxYield();
|
||||
}
|
||||
|
||||
m_dontq = FALSE;
|
||||
FreeBufToFree(TRUE);
|
||||
}
|
||||
|
||||
bool wxSndWinFragment::OnBufferFilled(wxFragBufPtr *ptr, wxSndMode mode)
|
||||
{
|
||||
wxSndWinInfo *info = (wxSndWinInfo *)ptr->user_data;
|
||||
wxWinSound *w_snd = (wxWinSound *)m_iodrv;
|
||||
MMRESULT result;
|
||||
|
||||
switch (mode) {
|
||||
case wxSND_INPUT:
|
||||
result = waveInAddBuffer(w_snd->internal->devin_id, info->hdr,
|
||||
sizeof(WAVEHDR));
|
||||
break;
|
||||
case wxSND_OUTPUT:
|
||||
result = waveOutWrite(w_snd->internal->devout_id, info->hdr,
|
||||
sizeof(WAVEHDR));
|
||||
printf("WINOUT: result=%d\n", result);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxWinSound::wxWinSound(void)
|
||||
: wxSound(),
|
||||
fragments(*this)
|
||||
{
|
||||
internal = new wxWinSoundInternal;
|
||||
internal->devout_id = 0;
|
||||
internal->devin_id = 0;
|
||||
internal->sndWin = 0;
|
||||
|
||||
wout_opened = FALSE;
|
||||
win_opened = FALSE;
|
||||
curr_o_srate = (wxUint32)-1;
|
||||
curr_o_bps = (wxUint8)-1;
|
||||
curr_o_stereo = (bool)-1;
|
||||
curr_i_srate = (wxUint32)-1;
|
||||
curr_i_bps = (wxUint8)-1;
|
||||
curr_i_stereo = (bool)-1;
|
||||
}
|
||||
|
||||
wxWinSound::~wxWinSound(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
fragments.WaitForAll();
|
||||
|
||||
if (wout_opened)
|
||||
waveOutReset(internal->devout_id);
|
||||
if (win_opened)
|
||||
waveInReset(internal->devout_id);
|
||||
|
||||
fragments.FreeIOBuffer();
|
||||
|
||||
if (wout_opened)
|
||||
waveOutClose(internal->devout_id);
|
||||
if (win_opened)
|
||||
waveInClose(internal->devin_id);
|
||||
|
||||
if (internal->sndWin)
|
||||
::DestroyWindow(internal->sndWin);
|
||||
|
||||
delete internal;
|
||||
}
|
||||
|
||||
bool wxWinSound::Wakeup(wxSndBuffer& buf)
|
||||
{
|
||||
if (!Reopen(buf, FALSE)) {
|
||||
buf.Clear(wxSND_BUFLOCKED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fragments.OnBufferFinished(NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxWinSound::PrepareHeader(wxFragmentBuffer::wxFragBufPtr& frag,
|
||||
wxSndMode mode)
|
||||
{
|
||||
wxSndWinInfo *info;
|
||||
WAVEHDR *hdr;
|
||||
|
||||
if ((mode == wxSND_INPUT && !win_opened) ||
|
||||
(mode == wxSND_OUTPUT && !wout_opened))
|
||||
return;
|
||||
|
||||
info = new wxSndWinInfo;
|
||||
|
||||
info->h_data = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, MMD_WIN_IO_BSIZE);
|
||||
info->h_hdr = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, sizeof(WAVEHDR));
|
||||
|
||||
info->data = (char *)GlobalLock(info->h_data);
|
||||
hdr = info->hdr = (WAVEHDR *)GlobalLock(info->h_hdr);
|
||||
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->lpData = info->data;
|
||||
hdr->dwBufferLength = frag.size;
|
||||
hdr->dwUser = (DWORD)&frag;
|
||||
hdr->dwFlags = WHDR_DONE;
|
||||
|
||||
if (mode == wxSND_INPUT) {
|
||||
MMRESULT result = waveInPrepareHeader(internal->devin_id, hdr,
|
||||
sizeof(WAVEHDR));
|
||||
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
wxExit();
|
||||
} else {
|
||||
MMRESULT result = waveOutPrepareHeader(internal->devout_id, hdr,
|
||||
sizeof(WAVEHDR));
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
wxExit();
|
||||
}
|
||||
|
||||
frag.sndbuf = new wxStreamBuffer();
|
||||
frag.sndbuf->SetBufferIO(info->data, info->data + MMD_WIN_IO_BSIZE);
|
||||
frag.user_data = (char *)info;
|
||||
}
|
||||
|
||||
void wxWinSound::UnprepareHeader(wxFragmentBuffer::wxFragBufPtr& frag,
|
||||
wxSndMode mode)
|
||||
{
|
||||
wxSndWinInfo *info = (wxSndWinInfo *)frag.user_data;
|
||||
|
||||
if ((mode == wxSND_INPUT && !win_opened) ||
|
||||
(mode == wxSND_OUTPUT && !wout_opened))
|
||||
return;
|
||||
|
||||
MMRESULT result;
|
||||
|
||||
if (mode == wxSND_INPUT) {
|
||||
result = waveInUnprepareHeader(internal->devin_id, info->hdr, sizeof(*info->hdr));
|
||||
} else {
|
||||
result = waveOutUnprepareHeader(internal->devout_id, info->hdr, sizeof(*info->hdr));
|
||||
}
|
||||
|
||||
delete frag.sndbuf;
|
||||
|
||||
printf("unprepare = %d\n", result);
|
||||
|
||||
GlobalUnlock(info->h_hdr);
|
||||
GlobalUnlock(info->h_data);
|
||||
|
||||
GlobalFree(info->h_hdr);
|
||||
GlobalFree(info->h_data);
|
||||
|
||||
delete info;
|
||||
}
|
||||
|
||||
extern char wxCanvasClassName[];
|
||||
|
||||
LRESULT APIENTRY _EXPORT wxSoundHandlerWndProc(HWND hWnd, UINT message,
|
||||
WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case MM_WOM_DONE: {
|
||||
wxWinSound *snd_drv = (wxWinSound *)GetWindowLong(hWnd, GWL_USERDATA);
|
||||
WAVEHDR *hdr = (WAVEHDR *)lParam;
|
||||
wxFragmentBuffer::wxFragBufPtr *buf =
|
||||
(wxFragmentBuffer::wxFragBufPtr *)hdr->dwUser;
|
||||
|
||||
// To be sure ...
|
||||
hdr->dwFlags |= WHDR_DONE;
|
||||
|
||||
snd_drv->fragments.OnBufferFinished(buf);
|
||||
break;
|
||||
}
|
||||
case MM_WOM_OPEN:
|
||||
printf("wave Open ack\n");
|
||||
break;
|
||||
case MM_WOM_CLOSE:
|
||||
printf("wave Close ack\n");
|
||||
break;
|
||||
default:
|
||||
// TODO: Useful ?
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return (LRESULT)0;
|
||||
}
|
||||
|
||||
void wxWinSound::StopBuffer(wxSndBuffer& buf)
|
||||
{
|
||||
buf.HardLock();
|
||||
buf.Set(wxSND_BUFSTOP);
|
||||
fragments.AbortBuffer(buf);
|
||||
buf.HardUnlock();
|
||||
|
||||
while (buf.IsSet(wxSND_BUFSTOP))
|
||||
wxYield();
|
||||
}
|
||||
|
||||
bool wxWinSound::Reopen(wxSndBuffer& buf, bool force)
|
||||
{
|
||||
WAVEFORMATEX wformat;
|
||||
|
||||
if ((buf.GetSampleRate() != curr_o_srate) ||
|
||||
(buf.GetBps() != curr_o_bps) ||
|
||||
(buf.GetStereo() != curr_o_stereo) ||
|
||||
(buf.GetMode() != curr_mode))
|
||||
force = TRUE;
|
||||
|
||||
if (force) {
|
||||
wxUint32 *curr_srate =
|
||||
(buf.GetMode() == wxSND_OUTPUT) ? &curr_o_srate : &curr_i_srate;
|
||||
wxUint8 *curr_bps =
|
||||
(buf.GetMode() == wxSND_OUTPUT) ? &curr_o_bps : &curr_i_bps;
|
||||
bool *curr_stereo =
|
||||
(buf.GetMode() == wxSND_OUTPUT) ? &curr_o_stereo : &curr_i_stereo;
|
||||
|
||||
fragments.WaitForAll();
|
||||
fragments.FreeIOBuffer();
|
||||
|
||||
if (!internal->sndWin) {
|
||||
FARPROC proc = MakeProcInstance((FARPROC)wxSoundHandlerWndProc, wxGetInstance());
|
||||
|
||||
internal->sndWin = ::CreateWindow(wxCanvasClassName, NULL, 0,
|
||||
0, 0, 0, 0, NULL, (HMENU) NULL,
|
||||
wxGetInstance(), 0);
|
||||
|
||||
::SetWindowLong(internal->sndWin, GWL_WNDPROC,
|
||||
(LONG)proc);
|
||||
::SetWindowLong(internal->sndWin, GWL_USERDATA, (LONG) this);
|
||||
}
|
||||
|
||||
if (wout_opened) {
|
||||
waveOutClose(internal->devout_id);
|
||||
wout_opened = FALSE;
|
||||
}
|
||||
if (win_opened) {
|
||||
waveInClose(internal->devin_id);
|
||||
win_opened = FALSE;
|
||||
}
|
||||
|
||||
*curr_srate = buf.GetSampleRate();
|
||||
*curr_bps = buf.GetBps();
|
||||
*curr_stereo = buf.GetStereo();
|
||||
wformat.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wformat.nChannels = curr_o_stereo+1;
|
||||
|
||||
wformat.nSamplesPerSec = curr_o_srate;
|
||||
wformat.nBlockAlign = curr_o_bps / 8 * wformat.nChannels;
|
||||
wformat.nAvgBytesPerSec =
|
||||
wformat.nSamplesPerSec * wformat.nBlockAlign;
|
||||
wformat.wBitsPerSample = curr_o_bps;
|
||||
wformat.cbSize = 0;
|
||||
|
||||
if (buf.GetMode() == wxSND_OUTPUT) {
|
||||
MMRESULT result = waveOutOpen(&internal->devout_id,
|
||||
WAVE_MAPPER, &wformat,
|
||||
(DWORD)internal->sndWin, (DWORD)this,
|
||||
CALLBACK_WINDOW);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
return FALSE;
|
||||
internal->devin_id = 0;
|
||||
wout_opened = TRUE;
|
||||
curr_mode = wxSND_OUTPUT;
|
||||
|
||||
fragments.AllocIOBuffer();
|
||||
}
|
||||
else {
|
||||
MMRESULT result = waveInOpen(&internal->devin_id,
|
||||
WAVE_MAPPER, &wformat,
|
||||
(DWORD)internal->sndWin, (DWORD)this,
|
||||
CALLBACK_FUNCTION);
|
||||
if (result != MMSYSERR_NOERROR)
|
||||
return FALSE;
|
||||
internal->devout_id = 0;
|
||||
win_opened = TRUE;
|
||||
curr_mode = wxSND_INPUT;
|
||||
|
||||
fragments.AllocIOBuffer();
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Name: sndwin.h
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
/* Real -*- C++ -*- */
|
||||
#ifndef __SND_win_H__
|
||||
#define __SND_win_H__
|
||||
|
||||
#include "sndsnd.h"
|
||||
#include "sndfrag.h"
|
||||
|
||||
#ifdef WXMMEDIA_INTERNAL
|
||||
#include <wx/msw/private.h>
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
typedef struct wxWinSoundInternal {
|
||||
HWAVEOUT devout_id;
|
||||
HWAVEIN devin_id;
|
||||
HWND sndWin;
|
||||
} wxWinSoundInternal;
|
||||
|
||||
typedef struct wxSndWinInfo {
|
||||
HGLOBAL h_data, h_hdr;
|
||||
|
||||
char *data;
|
||||
WAVEHDR *hdr;
|
||||
} wxSndWinInfo;
|
||||
|
||||
#endif
|
||||
|
||||
/** Sound buffer fragmenter: windows specific implementation
|
||||
* @author Guilhem Lavaux
|
||||
*/
|
||||
class wxSndWinFragment : public wxFragmentBuffer {
|
||||
public:
|
||||
wxSndWinFragment(wxSound& io_drv);
|
||||
virtual ~wxSndWinFragment(void);
|
||||
|
||||
virtual void AllocIOBuffer(void);
|
||||
virtual void FreeIOBuffer(void);
|
||||
|
||||
virtual bool OnBufferFilled(wxFragBufPtr *ptr, wxSndMode mode);
|
||||
|
||||
void WaitForAll();
|
||||
};
|
||||
|
||||
///
|
||||
class wxWinSound : public wxSound {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxWinSound)
|
||||
protected:
|
||||
struct wxWinSoundInternal *internal;
|
||||
|
||||
///
|
||||
bool wout_opened, win_opened;
|
||||
///
|
||||
wxUint32 curr_o_srate, curr_i_srate;
|
||||
///
|
||||
wxUint8 curr_o_bps, curr_i_bps;
|
||||
///
|
||||
bool curr_o_stereo, curr_i_stereo;
|
||||
///
|
||||
wxSndMode curr_mode;
|
||||
|
||||
///
|
||||
wxSndWinFragment fragments;
|
||||
|
||||
#ifdef WXMMEDIA_INTERNAL
|
||||
///
|
||||
friend LRESULT APIENTRY _EXPORT wxSoundHandlerWndProc(HWND win,
|
||||
UINT message,
|
||||
WPARAM wParam, LPARAM lParam);
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
///
|
||||
wxWinSound(void);
|
||||
///
|
||||
virtual ~wxWinSound(void);
|
||||
|
||||
///
|
||||
void OnNeedBuffer(wxSndMode mode);
|
||||
///
|
||||
void StopBuffer(wxSndBuffer& buf);
|
||||
protected:
|
||||
///
|
||||
virtual bool Wakeup(wxSndBuffer& buf);
|
||||
|
||||
///
|
||||
bool Reopen(wxSndBuffer& buf, bool force);
|
||||
|
||||
///
|
||||
friend class wxSndWinFragment;
|
||||
|
||||
///
|
||||
void PrepareHeader(wxFragmentBuffer::wxFragBufPtr& frag, wxSndMode mode);
|
||||
///
|
||||
void UnprepareHeader(wxFragmentBuffer::wxFragBufPtr& frag, wxSndMode mode);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,69 +0,0 @@
|
||||
static unsigned char ulaw_dsp[] = {
|
||||
3, 7, 11, 15, 19, 23, 27, 31,
|
||||
35, 39, 43, 47, 51, 55, 59, 63,
|
||||
66, 68, 70, 72, 74, 76, 78, 80,
|
||||
82, 84, 86, 88, 90, 92, 94, 96,
|
||||
98, 99, 100, 101, 102, 103, 104, 105,
|
||||
106, 107, 108, 109, 110, 111, 112, 113,
|
||||
113, 114, 114, 115, 115, 116, 116, 117,
|
||||
117, 118, 118, 119, 119, 120, 120, 121,
|
||||
121, 121, 122, 122, 122, 122, 123, 123,
|
||||
123, 123, 124, 124, 124, 124, 125, 125,
|
||||
125, 125, 125, 125, 126, 126, 126, 126,
|
||||
126, 126, 126, 126, 127, 127, 127, 127,
|
||||
127, 127, 127, 127, 127, 127, 127, 127,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
253, 249, 245, 241, 237, 233, 229, 225,
|
||||
221, 217, 213, 209, 205, 201, 197, 193,
|
||||
190, 188, 186, 184, 182, 180, 178, 176,
|
||||
174, 172, 170, 168, 166, 164, 162, 160,
|
||||
158, 157, 156, 155, 154, 153, 152, 151,
|
||||
150, 149, 148, 147, 146, 145, 144, 143,
|
||||
143, 142, 142, 141, 141, 140, 140, 139,
|
||||
139, 138, 138, 137, 137, 136, 136, 135,
|
||||
135, 135, 134, 134, 134, 134, 133, 133,
|
||||
133, 133, 132, 132, 132, 132, 131, 131,
|
||||
131, 131, 131, 131, 130, 130, 130, 130,
|
||||
130, 130, 130, 130, 129, 129, 129, 129,
|
||||
129, 129, 129, 129, 129, 129, 129, 129,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
};
|
||||
|
||||
static unsigned char dsp_ulaw[] = {
|
||||
0, 0, 0, 0, 0, 1, 1, 1,
|
||||
1, 2, 2, 2, 2, 3, 3, 3,
|
||||
3, 4, 4, 4, 4, 5, 5, 5,
|
||||
5, 6, 6, 6, 6, 7, 7, 7,
|
||||
7, 8, 8, 8, 8, 9, 9, 9,
|
||||
9, 10, 10, 10, 10, 11, 11, 11,
|
||||
11, 12, 12, 12, 12, 13, 13, 13,
|
||||
13, 14, 14, 14, 14, 15, 15, 15,
|
||||
15, 16, 16, 17, 17, 18, 18, 19,
|
||||
19, 20, 20, 21, 21, 22, 22, 23,
|
||||
23, 24, 24, 25, 25, 26, 26, 27,
|
||||
27, 28, 28, 29, 29, 30, 30, 31,
|
||||
31, 32, 33, 34, 35, 36, 37, 38,
|
||||
39, 40, 41, 42, 43, 44, 45, 46,
|
||||
47, 49, 51, 53, 55, 57, 59, 61,
|
||||
63, 66, 70, 74, 78, 84, 92, 104,
|
||||
254, 231, 219, 211, 205, 201, 197, 193,
|
||||
190, 188, 186, 184, 182, 180, 178, 176,
|
||||
175, 174, 173, 172, 171, 170, 169, 168,
|
||||
167, 166, 165, 164, 163, 162, 161, 160,
|
||||
159, 159, 158, 158, 157, 157, 156, 156,
|
||||
155, 155, 154, 154, 153, 153, 152, 152,
|
||||
151, 151, 150, 150, 149, 149, 148, 148,
|
||||
147, 147, 146, 146, 145, 145, 144, 144,
|
||||
143, 143, 143, 143, 142, 142, 142, 142,
|
||||
141, 141, 141, 141, 140, 140, 140, 140,
|
||||
139, 139, 139, 139, 138, 138, 138, 138,
|
||||
137, 137, 137, 137, 136, 136, 136, 136,
|
||||
135, 135, 135, 135, 134, 134, 134, 134,
|
||||
133, 133, 133, 133, 132, 132, 132, 132,
|
||||
131, 131, 131, 131, 130, 130, 130, 130,
|
||||
129, 129, 129, 129, 128, 128, 128, 128,
|
||||
};
|
@ -1,65 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wave.cpp
|
||||
// Purpose: wxWave class
|
||||
// Author: Guilhem Lavaux / API by Julian Smart
|
||||
// Modified by:
|
||||
// Created: 04/23/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "wave.h"
|
||||
#endif
|
||||
|
||||
#include <wx/wfstream.h>
|
||||
#include "wave.h"
|
||||
|
||||
wxWave::wxWave()
|
||||
{
|
||||
m_wave = NULL;
|
||||
m_iowave = NULL;
|
||||
}
|
||||
|
||||
wxWave::wxWave(const wxString& fileName, bool isResource = FALSE)
|
||||
{
|
||||
Create(fileName, isResource);
|
||||
}
|
||||
|
||||
wxWave::~wxWave()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
bool wxWave::Create(const wxString& sFileName, bool isResource = FALSE)
|
||||
{
|
||||
m_iowave = new wxFileInputStream(sFileName);
|
||||
m_wave = new wxSndWavCodec(*m_iowave);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxWave::Play(bool async, bool looped) const
|
||||
{
|
||||
if (!m_wave)
|
||||
return FALSE;
|
||||
|
||||
if (looped)
|
||||
m_wave->Set(wxSND_LOOP);
|
||||
if (!m_wave->StartPlay());
|
||||
return FALSE;
|
||||
if (!async)
|
||||
m_wave->Wait();
|
||||
|
||||
m_wave->Clear(wxSND_LOOP);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxWave::Free()
|
||||
{
|
||||
if (m_wave) {
|
||||
delete m_wave;
|
||||
delete m_iowave;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wave.h
|
||||
// Purpose: wxWave class
|
||||
// Author: Julian Smart
|
||||
// Modified by: Guilhem Lavaux for wxMMedia (02/05/1998)
|
||||
// Created: 01/02/97
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart and Markus Holzem
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __WAVEH__
|
||||
#define __WAVEH__
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <wx/object.h>
|
||||
#include <wx/string.h>
|
||||
#include "sndwav.h"
|
||||
|
||||
class wxWave : public wxObject
|
||||
{
|
||||
public:
|
||||
wxWave();
|
||||
wxWave(const wxString& fileName, bool isResource = FALSE);
|
||||
~wxWave();
|
||||
|
||||
public:
|
||||
bool Create(const wxString& sFileName, bool isResource = FALSE);
|
||||
bool IsOk() const { return (m_wave ? TRUE : FALSE); };
|
||||
bool Play(bool async = TRUE, bool looped = FALSE) const;
|
||||
|
||||
protected:
|
||||
bool Free();
|
||||
|
||||
protected:
|
||||
wxInputStream *m_iowave;
|
||||
wxSndWavCodec *m_wave;
|
||||
};
|
||||
|
||||
#endif
|
3
utils/wxMMedia2/Makefile.in
Normal file
3
utils/wxMMedia2/Makefile.in
Normal file
@ -0,0 +1,3 @@
|
||||
all:
|
||||
cd lib; make
|
||||
cd sample; make
|
8
utils/wxMMedia2/README
Normal file
8
utils/wxMMedia2/README
Normal file
@ -0,0 +1,8 @@
|
||||
To build Makefile with automake:
|
||||
in the top source directory type:
|
||||
automake utils/wxMMedia2/Makefile
|
||||
in the top build directory type:
|
||||
mkdir -p utils/wxMMedia2
|
||||
CONFIG_FILES="utils/wxMMedia2/Makefile utils/wxMMedia2/lib/Makefile utils/wxMMedia2/sample/Makefile" CONFIG_HEADERS= ./config.status
|
||||
|
||||
and then you can run make in utils/wxMMedia2.
|
26
utils/wxMMedia2/lib/Makefile.in
Normal file
26
utils/wxMMedia2/lib/Makefile.in
Normal file
@ -0,0 +1,26 @@
|
||||
#
|
||||
# File: makefile.unx
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) 1998 Julian Smart
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for thread example (UNIX).
|
||||
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = ../../..
|
||||
|
||||
VPATH= $(top_srcdir)/utils/wxMMedia2/lib
|
||||
|
||||
LIBTARGET=libwxmmedia2
|
||||
|
||||
OBJECTS=sndbase.o sndcodec.o sndpcm.o sndcpcm.o sndulaw.o sndfile.o sndoss.o\
|
||||
sndaiff.o sndwav.o \
|
||||
g711.o g721.o g723_24.o g723_40.o g72x.o \
|
||||
cdbase.o cdunix.o \
|
||||
vidbase.o vidxanm.o
|
||||
|
||||
include $(top_builddir)/src/makelib.env
|
||||
|
@ -1,12 +1,12 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ---------------------------------------------------------------------------
|
||||
// Name: sndsnd.cpp
|
||||
// Purpose: wxMMedia
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// Updated: 1999
|
||||
// Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
@ -17,6 +17,10 @@
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxCDAudio, wxObject)
|
||||
#endif
|
||||
|
||||
wxCDtime wxCDAudio::CDtoc::GetTrackTime(wxUint8 track) const
|
||||
{
|
||||
if (track > total_time.track) {
|
@ -20,68 +20,58 @@
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmtype.h"
|
||||
|
||||
typedef struct wxCDtime {
|
||||
wxUint8 track;
|
||||
wxUint8 hour, min, sec;
|
||||
} wxCDtime;
|
||||
|
||||
///
|
||||
class WXDLLEXPORT wxCDAudio : public wxObject {
|
||||
DECLARE_ABSTRACT_CLASS(wxCDAudio)
|
||||
public:
|
||||
///
|
||||
typedef enum { PLAYING, PAUSED, STOPPED } CDstatus;
|
||||
/// Table of contents manager
|
||||
// Table of contents manager
|
||||
class CDtoc {
|
||||
protected:
|
||||
wxCDtime *tracks_time, *tracks_pos;
|
||||
wxCDtime total_time;
|
||||
public:
|
||||
///
|
||||
//
|
||||
CDtoc(wxCDtime& tot_tm, wxCDtime *trks_tm, wxCDtime *trks_pos)
|
||||
{ tracks_time = trks_tm; total_time = tot_tm; tracks_pos = trks_pos; }
|
||||
|
||||
/// Returns the length of the specified track
|
||||
/** @param track track to get length */
|
||||
// Returns the length of the specified track
|
||||
// track: track to get length
|
||||
wxCDtime GetTrackTime(wxUint8 track) const;
|
||||
/** Returns the position of the specified
|
||||
@param track track to get position */
|
||||
// Returns the position of the specified track
|
||||
// track: track to get position
|
||||
wxCDtime GetTrackPos(wxUint8 track) const;
|
||||
/// Returns the total time
|
||||
// Returns the total time
|
||||
inline wxCDtime GetTotalTime() const { return total_time; }
|
||||
};
|
||||
public:
|
||||
///
|
||||
//
|
||||
wxCDAudio() : wxObject() {}
|
||||
///
|
||||
//
|
||||
virtual ~wxCDAudio() {}
|
||||
|
||||
/// Play audio at the specified position
|
||||
/**
|
||||
* @param beg_play start position
|
||||
* @param end_play end position
|
||||
*/
|
||||
// Play audio at the specified position
|
||||
virtual bool Play(const wxCDtime& beg_play, const wxCDtime& end_play) = 0;
|
||||
/// Play audio from the specified to the end of the CD audio
|
||||
/**
|
||||
* @param beg_play start position
|
||||
*/
|
||||
// Play audio from the specified to the end of the CD audio
|
||||
bool Play(const wxCDtime& beg_play);
|
||||
///
|
||||
//
|
||||
bool Play(wxUint8 beg_track, wxUint8 end_track = 0);
|
||||
/// Pause the audio playing
|
||||
// Pause the audio playing
|
||||
virtual bool Pause() = 0;
|
||||
/// Resume a paused audio playing
|
||||
// Resume a paused audio playing
|
||||
virtual bool Resume() = 0;
|
||||
/// Get the current CD status
|
||||
// Get the current CD status
|
||||
virtual CDstatus GetStatus() = 0;
|
||||
/// Get the current playing time
|
||||
// Get the current playing time
|
||||
virtual wxCDtime GetTime() = 0;
|
||||
/// Returns the table of contents
|
||||
// Returns the table of contents
|
||||
virtual const CDtoc& GetToc() = 0;
|
||||
/// CD ok
|
||||
// CD ok
|
||||
virtual bool Ok() const = 0;
|
||||
};
|
||||
|
@ -30,9 +30,13 @@
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmtype.h"
|
||||
#include "cdbase.h"
|
||||
#include "cdunix.h"
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCDAudioLinux, wxCDAudio)
|
||||
#endif
|
||||
|
||||
wxCDAudioLinux::wxCDAudioLinux()
|
||||
: wxCDAudio(), m_fd(-1)
|
||||
{
|
@ -19,7 +19,6 @@
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmtype.h"
|
||||
#include "cdbase.h"
|
||||
|
||||
///
|
@ -20,7 +20,6 @@
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#define WXMMEDIA_INTERNAL
|
||||
#include "mmtype.h"
|
||||
#include "cdbase.h"
|
||||
#include "cdwin.h"
|
||||
|
@ -19,7 +19,6 @@
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
#include "mmtype.h"
|
||||
#include "cdbase.h"
|
||||
|
||||
#ifdef WXMMEDIA_INTERNAL
|
110
utils/wxMMedia2/lib/converter.def
Normal file
110
utils/wxMMedia2/lib/converter.def
Normal file
@ -0,0 +1,110 @@
|
||||
#define DEFINE_CONV_8(name) \
|
||||
static void Convert_##name##_8(const char *buf_in, char *buf_out, size_t len) \
|
||||
{\
|
||||
wxUint16 val; \
|
||||
\
|
||||
while (len > 0) { \
|
||||
val = *buf_in++; \
|
||||
len--;
|
||||
|
||||
#if SWAP_BYTES==0
|
||||
|
||||
#define DEFINE_CONV_16(name) \
|
||||
static void Convert_##name##_16_no(const char *buf_in, char *buf_out, size_t len) \
|
||||
{\
|
||||
wxUint16 val; \
|
||||
\
|
||||
while (len > 0) { \
|
||||
val = *(wxUint16 *)(buf_in); \
|
||||
buf_in += 2; \
|
||||
len -= 2;
|
||||
|
||||
#else
|
||||
|
||||
#define DEFINE_CONV_16(name) \
|
||||
static void Convert_##name##_16_yes(const char *buf_in, char *buf_out, size_t len) \
|
||||
{\
|
||||
wxUint16 val; \
|
||||
\
|
||||
while (len > 0) { \
|
||||
val = *(wxUint16 *)(buf_in); \
|
||||
val = wxUINT16_SWAP_ALWAYS(val); \
|
||||
buf_in += 2; \
|
||||
len -= 2;
|
||||
|
||||
#endif
|
||||
|
||||
#define END_CONV } }
|
||||
|
||||
#define PUT16 *((wxUint16 *)buf_out) = val, buf_out += 2;
|
||||
#define PUT16_SWAP *((wxUint16 *)buf_out) = wxUINT16_SWAP_ALWAYS(val), buf_out += 2;
|
||||
#define PUT8 *buf_out++ = val;
|
||||
#define CHANGE16_SIGN val ^= 0x8000;
|
||||
#define CHANGE8_SIGN val ^= 0x80;
|
||||
#define REDUCE16_TO_8 val /= 256;
|
||||
#define AUGMENT8_TO_16 val *= 256;
|
||||
|
||||
DEFINE_CONV_16(16to8)
|
||||
REDUCE16_TO_8
|
||||
PUT8
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_16(16to8_U2S)
|
||||
CHANGE16_SIGN
|
||||
REDUCE16_TO_8
|
||||
PUT8
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_16(U2S)
|
||||
CHANGE16_SIGN
|
||||
PUT16
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_16(U2S_SWAP)
|
||||
CHANGE16_SIGN
|
||||
PUT16_SWAP
|
||||
END_CONV
|
||||
|
||||
#if SWAP_BYTES == 0
|
||||
|
||||
DEFINE_CONV_16(SWAP)
|
||||
PUT16_SWAP
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_8(U2S)
|
||||
CHANGE8_SIGN
|
||||
PUT8
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_8(8to16)
|
||||
AUGMENT8_TO_16
|
||||
PUT16
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_8(8to16_SWAP)
|
||||
AUGMENT8_TO_16
|
||||
PUT16_SWAP
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_8(8to16_U2S)
|
||||
CHANGE8_SIGN
|
||||
AUGMENT8_TO_16
|
||||
PUT16
|
||||
END_CONV
|
||||
|
||||
DEFINE_CONV_8(8to16_U2S_SWAP)
|
||||
CHANGE8_SIGN
|
||||
AUGMENT8_TO_16
|
||||
PUT16_SWAP
|
||||
END_CONV
|
||||
|
||||
#endif
|
||||
|
||||
#undef DEFINE_CONV_16
|
||||
#undef DEFINE_CONV_8
|
||||
#undef END_CONV
|
||||
#undef CHANGE16_SIGN
|
||||
#undef CHANGE8_SIGN
|
||||
#undef PUT16_SWAP
|
||||
#undef PUT16
|
||||
#undef PUT8
|
134
utils/wxMMedia2/lib/sndaiff.cpp
Normal file
134
utils/wxMMedia2/lib/sndaiff.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndaiff.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndaiff.cpp"
|
||||
#endif
|
||||
|
||||
#include <wx/defs.h>
|
||||
#include <wx/stream.h>
|
||||
#include <wx/datstrm.h>
|
||||
#include <wx/filefn.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndpcm.h"
|
||||
#include "sndaiff.h"
|
||||
|
||||
#define BUILD_SIGNATURE(a,b,c,d) (((wxUint32)a) | (((wxUint32)b) << 8) | (((wxUint32)c) << 16) | (((wxUint32)d) << 24))
|
||||
|
||||
#define FORM_SIGNATURE BUILD_SIGNATURE('F','O','R','M')
|
||||
#define AIFF_SIGNATURE BUILD_SIGNATURE('A','I','F','F')
|
||||
#define AIFC_SIGNATURE BUILD_SIGNATURE('A','I','F','C')
|
||||
#define COMM_SIGNATURE BUILD_SIGNATURE('C','O','M','M')
|
||||
#define SSND_SIGNATURE BUILD_SIGNATURE('S','S','N','D')
|
||||
|
||||
wxSoundAiff::wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundAiff::wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundAiff::~wxSoundAiff()
|
||||
{
|
||||
}
|
||||
|
||||
#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(TRUE);
|
||||
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);
|
||||
end_headers = TRUE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundAiff::PrepareToRecord(unsigned long time)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxSoundAiff::FinishRecording()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size_t wxSoundAiff::GetData(void *buffer, size_t len)
|
||||
{
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
}
|
||||
|
||||
size_t wxSoundAiff::PutData(const void *buffer, size_t len)
|
||||
{
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
}
|
39
utils/wxMMedia2/lib/sndaiff.h
Normal file
39
utils/wxMMedia2/lib/sndaiff.h
Normal file
@ -0,0 +1,39 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndaiff.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDAIFF_H
|
||||
#define _WX_SNDAIFF_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndaiff.h"
|
||||
#endif
|
||||
|
||||
#include <wx/stream.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
//
|
||||
// AIFF codec
|
||||
//
|
||||
|
||||
class wxSoundAiff: public wxSoundFileStream {
|
||||
public:
|
||||
wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundAiff();
|
||||
|
||||
protected:
|
||||
bool PrepareToPlay();
|
||||
bool PrepareToRecord(unsigned long time);
|
||||
bool FinishRecording();
|
||||
|
||||
size_t GetData(void *buffer, size_t len);
|
||||
size_t PutData(const void *buffer, size_t len);
|
||||
};
|
||||
|
||||
#endif
|
109
utils/wxMMedia2/lib/sndbase.cpp
Normal file
109
utils/wxMMedia2/lib/sndbase.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndbase.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndbase.cpp"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxSoundFormatBase
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxSoundFormatBase::wxSoundFormatBase()
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFormatBase::~wxSoundFormatBase()
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFormatBase *wxSoundFormatBase::Clone() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool wxSoundFormatBase::operator!=(const wxSoundFormatBase& frmt2) const
|
||||
{
|
||||
return (GetType() != frmt2.GetType());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxSoundStream
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
wxSoundStream::wxSoundStream()
|
||||
{
|
||||
int i;
|
||||
|
||||
m_sndformat = NULL;
|
||||
m_handler = NULL;
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
m_lastcount = 0;
|
||||
for (i=0;i<2;i++)
|
||||
m_callback[i] = NULL;
|
||||
}
|
||||
|
||||
wxSoundStream::~wxSoundStream()
|
||||
{
|
||||
if (m_sndformat)
|
||||
delete m_sndformat;
|
||||
}
|
||||
|
||||
// SetSoundFormat returns TRUE when the format can be handled.
|
||||
bool wxSoundStream::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
if (m_sndformat)
|
||||
delete m_sndformat;
|
||||
|
||||
m_sndformat = format.Clone();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Register a callback for a specified async event.
|
||||
void wxSoundStream::Register(int evt, wxSoundCallback cbk, char *cdata)
|
||||
{
|
||||
int c;
|
||||
|
||||
switch (evt) {
|
||||
case wxSOUND_INPUT:
|
||||
c = 0;
|
||||
break;
|
||||
case wxSOUND_OUTPUT:
|
||||
c = 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
m_callback[c] = cbk;
|
||||
m_cdata[c] = cdata;
|
||||
}
|
||||
|
||||
void wxSoundStream::OnSoundEvent(int evt)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (m_handler) {
|
||||
m_handler->OnSoundEvent(evt);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt) {
|
||||
case wxSOUND_INPUT:
|
||||
c = 0;
|
||||
break;
|
||||
case wxSOUND_OUTPUT:
|
||||
c = 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (m_callback[c])
|
||||
m_callback[c](this, evt, m_cdata[c]);
|
||||
}
|
125
utils/wxMMedia2/lib/sndbase.h
Normal file
125
utils/wxMMedia2/lib/sndbase.h
Normal file
@ -0,0 +1,125 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndbase.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDBASE_H
|
||||
#define _WX_SNDBASE_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndbase.h"
|
||||
#endif
|
||||
|
||||
#include <wx/defs.h>
|
||||
|
||||
enum {
|
||||
wxSOUND_INPUT = 1,
|
||||
wxSOUND_OUTPUT = 2,
|
||||
wxSOUND_DUPLEX = wxSOUND_INPUT | wxSOUND_OUTPUT,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
wxSOUND_NOFORMAT,
|
||||
wxSOUND_PCM,
|
||||
wxSOUND_ULAW
|
||||
} wxSoundFormatType;
|
||||
|
||||
typedef enum {
|
||||
wxSOUND_NOERR,
|
||||
wxSOUND_IOERR,
|
||||
wxSOUND_INVFRMT,
|
||||
wxSOUND_INVDEV,
|
||||
wxSOUND_NOTEXACT,
|
||||
wxSOUND_INVSTRM,
|
||||
wxSOUND_NOCODEC,
|
||||
wxSOUND_MEMERR
|
||||
} wxSoundError;
|
||||
|
||||
class WXDLLEXPORT wxSoundStream;
|
||||
|
||||
typedef void (*wxSoundCallback)(wxSoundStream *stream, int evt,
|
||||
char *cdata);
|
||||
|
||||
//
|
||||
// Base class for sound format specification
|
||||
//
|
||||
|
||||
class WXDLLEXPORT wxSoundFormatBase {
|
||||
public:
|
||||
wxSoundFormatBase();
|
||||
virtual ~wxSoundFormatBase();
|
||||
|
||||
virtual wxSoundFormatType GetType() const { return wxSOUND_NOFORMAT; }
|
||||
virtual wxSoundFormatBase *Clone() const;
|
||||
|
||||
virtual wxUint32 GetTimeFromByte(wxUint32 bytes) const = 0;
|
||||
virtual wxUint32 GetByteFromTime(wxUint32 time) const = 0;
|
||||
|
||||
virtual bool operator !=(const wxSoundFormatBase& frmt2) const;
|
||||
};
|
||||
|
||||
//
|
||||
// Base class for sound streams
|
||||
//
|
||||
|
||||
class wxSoundStream {
|
||||
public:
|
||||
wxSoundStream();
|
||||
virtual ~wxSoundStream();
|
||||
|
||||
// Reads "len" bytes from the sound stream.
|
||||
virtual wxSoundStream& Read(void *buffer, size_t len) = 0;
|
||||
// Writes "len" byte to the sound stream.
|
||||
virtual wxSoundStream& Write(const void *buffer, size_t len) = 0;
|
||||
// Returns the best size for IO calls
|
||||
virtual wxUint32 GetBestSize() const { return 1024; }
|
||||
|
||||
// SetSoundFormat returns TRUE when the format can be handled.
|
||||
virtual bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
// GetSoundFormat returns the current sound format.
|
||||
wxSoundFormatBase& GetSoundFormat() const { return *m_sndformat; }
|
||||
|
||||
// Register a callback for a specified async event.
|
||||
void Register(int evt, wxSoundCallback cbk, char *cdata);
|
||||
|
||||
// Starts the async notifier.
|
||||
virtual bool StartProduction(int evt) = 0;
|
||||
// Stops the async notifier.
|
||||
virtual bool StopProduction() = 0;
|
||||
// Sets the event handler: if it is non-null, all events are routed to it.
|
||||
void SetEventHandler(wxSoundStream *handler) { m_handler = handler; }
|
||||
|
||||
// Initializes the full duplex mode.
|
||||
virtual void SetDuplexMode(bool duplex) = 0;
|
||||
|
||||
wxSoundError GetError() const { return m_snderror; }
|
||||
size_t GetLastAccess() const { return m_lastcount; }
|
||||
|
||||
protected:
|
||||
// Current sound format
|
||||
wxSoundFormatBase *m_sndformat;
|
||||
|
||||
// Last error
|
||||
wxSoundError m_snderror;
|
||||
|
||||
// Last access
|
||||
size_t m_lastcount;
|
||||
|
||||
// Event handler
|
||||
wxSoundStream *m_handler;
|
||||
|
||||
wxSoundCallback m_callback[2];
|
||||
char *m_cdata[2];
|
||||
|
||||
protected:
|
||||
// Do the async stuff.
|
||||
void DoAsyncStuff(int evt);
|
||||
|
||||
// Handles event
|
||||
virtual void OnSoundEvent(int evt);
|
||||
};
|
||||
|
||||
#endif
|
37
utils/wxMMedia2/lib/sndcodec.cpp
Normal file
37
utils/wxMMedia2/lib/sndcodec.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndcodec.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndcodec.cpp"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
|
||||
wxSoundStreamCodec::wxSoundStreamCodec(wxSoundStream& snd_io)
|
||||
: m_sndio(&snd_io)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundStreamCodec::~wxSoundStreamCodec()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxSoundStreamCodec::StartProduction(int evt)
|
||||
{
|
||||
return m_sndio->StartProduction(evt);
|
||||
}
|
||||
|
||||
bool wxSoundStreamCodec::StopProduction()
|
||||
{
|
||||
return m_sndio->StopProduction();
|
||||
}
|
||||
|
||||
void wxSoundStreamCodec::SetDuplexMode(bool duplex)
|
||||
{
|
||||
m_sndio->SetDuplexMode(duplex);
|
||||
}
|
31
utils/wxMMedia2/lib/sndcodec.h
Normal file
31
utils/wxMMedia2/lib/sndcodec.h
Normal file
@ -0,0 +1,31 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndcodec.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDCODEC_H
|
||||
#define _WX_SNDCODEC_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndcodec.h"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
|
||||
class wxSoundStreamCodec: public wxSoundStream {
|
||||
public:
|
||||
wxSoundStreamCodec(wxSoundStream& snd_io);
|
||||
~wxSoundStreamCodec();
|
||||
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
void SetDuplexMode(bool duplex);
|
||||
|
||||
protected:
|
||||
wxSoundStream *m_sndio;
|
||||
};
|
||||
|
||||
#endif
|
174
utils/wxMMedia2/lib/sndcpcm.cpp
Normal file
174
utils/wxMMedia2/lib/sndcpcm.cpp
Normal file
@ -0,0 +1,174 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndcpcm.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndcpcm.cpp"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
#include "sndpcm.h"
|
||||
#include "sndcpcm.h"
|
||||
|
||||
wxSoundStreamPcm::wxSoundStreamPcm(wxSoundStream& sndio)
|
||||
: wxSoundStreamCodec(sndio)
|
||||
{
|
||||
m_function_in = NULL;
|
||||
m_function_out = NULL;
|
||||
}
|
||||
|
||||
wxSoundStreamPcm::~wxSoundStreamPcm()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#define SWAP_BYTES 0
|
||||
#include "converter.def"
|
||||
#undef SWAP_BYTES
|
||||
|
||||
#define SWAP_BYTES 1
|
||||
#include "converter.def"
|
||||
#undef SWAP_BYTES
|
||||
|
||||
wxSoundStreamPcm::ConverterType s_convert_16_to_8[] = {
|
||||
Convert_16to8_16_no,
|
||||
Convert_16to8_U2S_16_no,
|
||||
NULL,
|
||||
NULL,
|
||||
Convert_16to8_U2S_16_yes,
|
||||
Convert_16to8_16_yes,
|
||||
};
|
||||
|
||||
wxSoundStreamPcm::ConverterType s_convert_16[] = {
|
||||
NULL,
|
||||
Convert_U2S_16_no,
|
||||
Convert_U2S_SWAP_16_no,
|
||||
Convert_U2S_SWAP_16_yes,
|
||||
Convert_U2S_16_yes,
|
||||
Convert_SWAP_16_no
|
||||
};
|
||||
|
||||
wxSoundStreamPcm::ConverterType s_convert_8[] = {
|
||||
NULL,
|
||||
Convert_U2S_8,
|
||||
Convert_U2S_8,
|
||||
Convert_U2S_8,
|
||||
Convert_U2S_8,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define CONVERTER 0
|
||||
#define CONVERTER_SIGN 1
|
||||
#define CONVERTER_SIGN_SWAP 2
|
||||
#define CONVERTER_SWAP_SIGN_SWAP 3
|
||||
#define CONVERTER_SWAP_SIGN 4
|
||||
#define CONVERTER_SWAP 5
|
||||
|
||||
wxSoundStream& wxSoundStreamPcm::Read(void *buffer, size_t len)
|
||||
{
|
||||
if (!m_function_in) {
|
||||
m_sndio->Read(buffer, len);
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
m_snderror = m_sndio->GetError();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO
|
||||
m_sndio->Read(buffer, len);
|
||||
m_lastcount = m_sndio->GetLastAccess();
|
||||
m_snderror = m_sndio->GetError();
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamPcm::Write(const void *buffer, size_t len)
|
||||
{
|
||||
char *tmp_buf;
|
||||
size_t len2;
|
||||
|
||||
if (!m_function_out)
|
||||
return m_sndio->Write(buffer, len);
|
||||
|
||||
len2 = (m_16_to_8) ? len / 2 : len;
|
||||
|
||||
tmp_buf = new char[len2];
|
||||
m_function_out((const char *)buffer, tmp_buf, len);
|
||||
m_sndio->Write(tmp_buf, len);
|
||||
delete[] tmp_buf;
|
||||
|
||||
m_lastcount = (m_16_to_8) ?
|
||||
(m_sndio->GetLastAccess() * 2) : m_sndio->GetLastAccess();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
wxSoundFormatBase *new_format;
|
||||
wxSoundFormatPcm *pcm_format, *pcm_format2;
|
||||
ConverterType *current_table;
|
||||
int index;
|
||||
bool change_sign;
|
||||
|
||||
if (m_sndio->SetSoundFormat(format)) {
|
||||
m_function_out = NULL;
|
||||
m_function_in = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
if (format.GetType() != wxSOUND_PCM) {
|
||||
m_snderror = wxSOUND_INVFRMT;
|
||||
return FALSE;
|
||||
}
|
||||
if (m_sndformat)
|
||||
delete m_sndformat;
|
||||
|
||||
new_format = m_sndio->GetSoundFormat().Clone();
|
||||
pcm_format = (wxSoundFormatPcm *)&format;
|
||||
pcm_format2 = (wxSoundFormatPcm *)new_format;
|
||||
|
||||
m_16_to_8 = FALSE;
|
||||
if (pcm_format->GetBPS() == 16 && pcm_format2->GetBPS() == 8) {
|
||||
m_16_to_8 = TRUE;
|
||||
current_table = s_convert_16_to_8;
|
||||
} else if (pcm_format->GetBPS() == 16)
|
||||
current_table = s_convert_16;
|
||||
else
|
||||
current_table = s_convert_8;
|
||||
|
||||
change_sign = (pcm_format2->Signed() != pcm_format->Signed());
|
||||
|
||||
#define MY_ORDER wxBYTE_ORDER
|
||||
#if wxBYTE_ORDER == wxLITTLE_ENDIAN
|
||||
#define OTHER_ORDER wxBIG_ENDIAN
|
||||
#else
|
||||
#define OTHER_ORDER wxLITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
if (pcm_format->GetOrder() == OTHER_ORDER &&
|
||||
pcm_format2->GetOrder() == OTHER_ORDER && change_sign)
|
||||
index = CONVERTER_SWAP_SIGN_SWAP;
|
||||
|
||||
else if (pcm_format->GetOrder() == OTHER_ORDER &&
|
||||
pcm_format2->GetOrder() == MY_ORDER && change_sign)
|
||||
index = CONVERTER_SWAP_SIGN;
|
||||
|
||||
else if (pcm_format->GetOrder() == MY_ORDER &&
|
||||
pcm_format->GetOrder() == OTHER_ORDER && change_sign)
|
||||
index = CONVERTER_SIGN_SWAP;
|
||||
|
||||
else if (!change_sign &&
|
||||
pcm_format->GetOrder() != pcm_format2->GetOrder())
|
||||
index = CONVERTER_SWAP;
|
||||
|
||||
else
|
||||
index = CONVERTER;
|
||||
|
||||
m_function_out = current_table[index];
|
||||
// m_function_in = current_table[index+1];
|
||||
|
||||
m_sndio->SetSoundFormat(*new_format);
|
||||
m_sndformat = new_format;
|
||||
return TRUE;
|
||||
}
|
40
utils/wxMMedia2/lib/sndcpcm.h
Normal file
40
utils/wxMMedia2/lib/sndcpcm.h
Normal file
@ -0,0 +1,40 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndcpcm.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDCPCM_H
|
||||
#define _WX_SNDCPCM_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndcpcm.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sndcodec.h"
|
||||
|
||||
//
|
||||
// PCM converter class
|
||||
//
|
||||
|
||||
class wxSoundStreamPcm: public wxSoundStreamCodec {
|
||||
public:
|
||||
typedef void (*ConverterType)(const char *buf_in, char *buf_out, size_t len);
|
||||
|
||||
wxSoundStreamPcm(wxSoundStream& sndio);
|
||||
~wxSoundStreamPcm();
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
protected:
|
||||
ConverterType m_function_out, m_function_in;
|
||||
|
||||
bool m_16_to_8;
|
||||
};
|
||||
|
||||
#endif
|
209
utils/wxMMedia2/lib/sndesd.cpp
Normal file
209
utils/wxMMedia2/lib/sndesd.cpp
Normal file
@ -0,0 +1,209 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndesd.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndesd.cpp"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <wx/defs.h>
|
||||
#include <wx/string.h>
|
||||
#include <esd.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndesd.h"
|
||||
#include "sndpcm.h"
|
||||
#ifdef __WXGTK__
|
||||
#include <gdk/gdk.h>
|
||||
#endif
|
||||
|
||||
#define MY_ESD_NAME "wxWindows/wxSoundStreamESD"
|
||||
|
||||
wxSoundStreamESD::wxSoundStreamESD(const wxString& hostname)
|
||||
{
|
||||
wxSoundFormatPcm pcm_default;
|
||||
|
||||
m_fd = esd_monitor_stream(ESD_MONO | ESD_BITS8 | ESD_RECORD, 22050,
|
||||
hostname.mb_str(), MY_ESD_NAME);
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_snderror = wxSOUND_INVDEV;
|
||||
return;
|
||||
}
|
||||
|
||||
esd_close(m_fd);
|
||||
|
||||
m_hostname = hostname;
|
||||
|
||||
SetSoundFormat(pcm_default);
|
||||
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
m_esd_stop = TRUE;
|
||||
}
|
||||
|
||||
wxSoundStreamESD::~wxSoundStreamESD()
|
||||
{
|
||||
if (m_fd > 0)
|
||||
esd_close(m_fd);
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamESD::Read(void *buffer, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
m_lastcount = (size_t)ret = read(m_fd, buffer, len);
|
||||
|
||||
if (ret < 0)
|
||||
m_snderror = wxSOUND_IOERR;
|
||||
else
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamESD::Write(const void *buffer, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
m_lastcount = (size_t)ret = write(m_fd, buffer, len);
|
||||
|
||||
if (ret < 0)
|
||||
m_snderror = wxSOUND_IOERR;
|
||||
else
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxSoundStreamESD::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
wxSoundFormatPcm *pcm_format;
|
||||
|
||||
if (format.GetType() != wxSOUND_PCM) {
|
||||
m_snderror = wxSOUND_INVFRMT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_snderror = wxSOUND_INVDEV;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_sndformat)
|
||||
delete m_sndformat;
|
||||
|
||||
m_sndformat = format.Clone();
|
||||
if (!m_sndformat) {
|
||||
m_snderror = wxSOUND_MEMERR;
|
||||
return FALSE;
|
||||
}
|
||||
pcm_format = (wxSoundFormatPcm *)m_sndformat;
|
||||
|
||||
// Detect the best format
|
||||
DetectBest(pcm_format);
|
||||
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
if (*pcm_format != format) {
|
||||
m_snderror = wxSOUND_NOTEXACT;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef __WXGTK__
|
||||
static void _wxSound_OSS_CBack(gpointer data, int source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
wxSoundStreamESD *esd = (wxSoundStreamESD *)data;
|
||||
|
||||
switch (condition) {
|
||||
case GDK_INPUT_READ:
|
||||
esd->WakeUpEvt(wxSOUND_INPUT);
|
||||
break;
|
||||
case GDK_INPUT_WRITE:
|
||||
esd->WakeUpEvt(wxSOUND_OUTPUT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void wxSoundStreamESD::WakeUpEvt(int evt)
|
||||
{
|
||||
OnSoundEvent(evt);
|
||||
}
|
||||
|
||||
bool wxSoundStreamESD::StartProduction(int evt)
|
||||
{
|
||||
wxSoundFormatPcm *pcm;
|
||||
int flag = 0;
|
||||
|
||||
if (!m_esd_stop)
|
||||
StopProduction();
|
||||
|
||||
pcm = (wxSoundFormatPcm *)m_sndformat;
|
||||
|
||||
flag |= (pcm->GetBPS() == 16) ? ESD_BITS16 : ESD_BITS8;
|
||||
flag |= (pcm->GetChannels() == 2) ? ESD_STEREO : ESD_MONO;
|
||||
|
||||
if (evt == wxSOUND_OUTPUT) {
|
||||
flag |= ESD_PLAY | ESD_STREAM;
|
||||
m_fd = esd_play_stream(flag, pcm->GetSampleRate(), m_hostname.mb_str(),
|
||||
MY_ESD_NAME);
|
||||
} else {
|
||||
flag |= ESD_RECORD | ESD_STREAM;
|
||||
m_fd = esd_record_stream(flag, pcm->GetSampleRate(), m_hostname.mb_str(),
|
||||
MY_ESD_NAME);
|
||||
}
|
||||
|
||||
#ifdef __WXGTK__
|
||||
if (evt == wxSOUND_OUTPUT)
|
||||
m_tag = gdk_input_add(m_fd, GDK_INPUT_WRITE, _wxSound_OSS_CBack, (gpointer)this);
|
||||
else
|
||||
m_tag = gdk_input_add(m_fd, GDK_INPUT_READ, _wxSound_OSS_CBack, (gpointer)this);
|
||||
#endif
|
||||
|
||||
m_esd_stop = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundStreamESD::StopProduction()
|
||||
{
|
||||
if (m_esd_stop)
|
||||
return FALSE;
|
||||
|
||||
gdk_input_remove(m_tag);
|
||||
esd_close(m_fd);
|
||||
m_esd_stop = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect the closest format (The best).
|
||||
//
|
||||
void wxSoundStreamESD::DetectBest(wxSoundFormatPcm *pcm)
|
||||
{
|
||||
wxSoundFormatPcm best_pcm;
|
||||
|
||||
// We change neither the number of channels nor the sample rate
|
||||
|
||||
best_pcm.SetSampleRate(pcm->GetSampleRate());
|
||||
best_pcm.SetChannels(pcm->GetChannels());
|
||||
|
||||
// It supports 16 bits
|
||||
if (pcm->GetBPS() == 16)
|
||||
best_pcm.SetBPS(16);
|
||||
|
||||
best_pcm.SetOrder(wxLITTLE_ENDIAN);
|
||||
best_pcm.Signed(TRUE);
|
||||
|
||||
// Finally recopy the new format
|
||||
*pcm = best_pcm;
|
||||
}
|
50
utils/wxMMedia2/lib/sndesd.h
Normal file
50
utils/wxMMedia2/lib/sndesd.h
Normal file
@ -0,0 +1,50 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndesd.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDESD_H
|
||||
#define _WX_SNDESD_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndesd.h"
|
||||
#endif
|
||||
|
||||
#include <wx/string.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
//
|
||||
// ESD output class
|
||||
//
|
||||
|
||||
class wxSoundStreamESD : public wxSoundStream {
|
||||
public:
|
||||
wxSoundStreamESD(const wxString& hostname = _T("localhost"));
|
||||
~wxSoundStreamESD();
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
void SetDuplexMode(bool duplex) {}
|
||||
|
||||
// You should not call this.
|
||||
void WakeUpEvt(int evt);
|
||||
protected:
|
||||
int m_fd;
|
||||
int m_tag;
|
||||
bool m_esd_stop;
|
||||
wxString m_hostname;
|
||||
|
||||
private:
|
||||
void DetectBest(wxSoundFormatPcm *pcm);
|
||||
};
|
||||
|
||||
#endif
|
293
utils/wxMMedia2/lib/sndfile.cpp
Normal file
293
utils/wxMMedia2/lib/sndfile.cpp
Normal file
@ -0,0 +1,293 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndfile.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#include <wx/stream.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndcpcm.h"
|
||||
#include "sndulaw.h"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Sound codec router
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
wxSoundRouterStream::wxSoundRouterStream(wxSoundStream& sndio)
|
||||
: wxSoundStreamCodec(sndio)
|
||||
{
|
||||
m_router = NULL;
|
||||
}
|
||||
|
||||
wxSoundRouterStream::~wxSoundRouterStream()
|
||||
{
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundRouterStream::Read(void *buffer, size_t 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;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundRouterStream::Write(const void *buffer, size_t 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();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
if (m_router)
|
||||
delete m_router;
|
||||
|
||||
if (m_sndio->SetSoundFormat(format)) {
|
||||
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;
|
||||
}
|
||||
wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_router->StartProduction(evt))
|
||||
return TRUE;
|
||||
|
||||
m_snderror = m_router->GetError();
|
||||
m_lastcount = m_router->GetLastAccess();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxSoundRouterStream::StopProduction()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSoundFileStream: generic reader
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFileStream::wxSoundFileStream(wxOutputStream& stream,
|
||||
wxSoundStream& io_sound)
|
||||
: m_codec(io_sound), m_sndio(&io_sound),
|
||||
m_input(NULL), m_output(&stream), m_state(wxSOUND_FILE_STOPPED)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFileStream::~wxSoundFileStream()
|
||||
{
|
||||
if (m_state != wxSOUND_FILE_STOPPED)
|
||||
Stop();
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Play()
|
||||
{
|
||||
if (m_state != wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
|
||||
if (!PrepareToPlay())
|
||||
return FALSE;
|
||||
|
||||
if (!StartProduction(wxSOUND_OUTPUT))
|
||||
return FALSE;
|
||||
|
||||
m_state = wxSOUND_FILE_PLAYING;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Record(unsigned long time)
|
||||
{
|
||||
if (m_state != wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
|
||||
if (!PrepareToRecord(time))
|
||||
return FALSE;
|
||||
|
||||
m_len = m_sndformat->GetByteFromTime(time);
|
||||
|
||||
if (!StartProduction(wxSOUND_INPUT))
|
||||
return FALSE;
|
||||
|
||||
m_state = wxSOUND_FILE_RECORDING;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Stop()
|
||||
{
|
||||
if (m_state == wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
|
||||
if (!StopProduction())
|
||||
return FALSE;
|
||||
|
||||
if (m_state == wxSOUND_FILE_RECORDING)
|
||||
if (!FinishRecording()) {
|
||||
m_state = wxSOUND_FILE_STOPPED;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// TODO reset counter
|
||||
m_state = wxSOUND_FILE_STOPPED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Pause()
|
||||
{
|
||||
if (m_state == wxSOUND_FILE_PAUSED || m_state == wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
|
||||
if (!StopProduction())
|
||||
return FALSE;
|
||||
|
||||
m_oldstate = m_state;
|
||||
m_state = wxSOUND_FILE_PAUSED;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::Resume()
|
||||
{
|
||||
if (m_state == wxSOUND_FILE_PLAYING || m_state == wxSOUND_FILE_RECORDING ||
|
||||
m_state == wxSOUND_FILE_STOPPED)
|
||||
return FALSE;
|
||||
|
||||
if (!StartProduction( (m_oldstate == wxSOUND_FILE_PLAYING) ?
|
||||
wxSOUND_OUTPUT : wxSOUND_INPUT))
|
||||
return FALSE;
|
||||
|
||||
m_state = m_oldstate;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundFileStream::Read(void *buffer, size_t len)
|
||||
{
|
||||
m_lastcount = GetData(buffer, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundFileStream::Write(const void *buffer, size_t len)
|
||||
{
|
||||
m_lastcount = PutData(buffer, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void wxSoundFileStream::SetDuplexMode(bool duplex)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::StartProduction(int evt)
|
||||
{
|
||||
m_sndio->SetEventHandler(this);
|
||||
|
||||
if (!m_codec.StartProduction(evt))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::StopProduction()
|
||||
{
|
||||
return m_codec.StopProduction();
|
||||
}
|
||||
|
||||
void wxSoundFileStream::OnSoundEvent(int evt)
|
||||
{
|
||||
size_t len = m_sndio->GetBestSize();
|
||||
char buffer[m_sndio->GetBestSize()];
|
||||
|
||||
wxSoundStream::OnSoundEvent(evt);
|
||||
|
||||
switch(evt) {
|
||||
case wxSOUND_INPUT:
|
||||
if (len > m_len)
|
||||
len = m_len;
|
||||
|
||||
len = m_codec.Read(buffer, len).GetLastAccess();
|
||||
PutData(buffer, len);
|
||||
m_len -= len;
|
||||
if (m_len == 0) {
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case wxSOUND_OUTPUT:
|
||||
len = GetData(buffer, len);
|
||||
if (len == 0) {
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
m_codec.Write(buffer, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxSoundFileStream::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
wxSoundStream::SetSoundFormat(format);
|
||||
return m_codec.SetSoundFormat(format);
|
||||
}
|
99
utils/wxMMedia2/lib/sndfile.h
Normal file
99
utils/wxMMedia2/lib/sndfile.h
Normal file
@ -0,0 +1,99 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndfile.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDFILE_H
|
||||
#define _WX_SNDFILE_H
|
||||
|
||||
#include <wx/defs.h>
|
||||
#include <wx/stream.h>
|
||||
#include <stdlib.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
|
||||
#define wxSOUND_INFINITE_TIME ((unsigned long)-1)
|
||||
|
||||
//
|
||||
// Codec router class
|
||||
//
|
||||
|
||||
class WXDLLEXPORT wxSoundRouterStream: public wxSoundStreamCodec {
|
||||
public:
|
||||
wxSoundRouterStream(wxSoundStream& sndio);
|
||||
~wxSoundRouterStream();
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
protected:
|
||||
wxSoundStream *m_router;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
wxSOUND_FILE_STOPPED,
|
||||
wxSOUND_FILE_PAUSED,
|
||||
wxSOUND_FILE_PLAYING,
|
||||
wxSOUND_FILE_RECORDING
|
||||
} wxSoundFileState;
|
||||
|
||||
//
|
||||
// Base class for file coders/decoders
|
||||
//
|
||||
|
||||
class wxSoundFileStream: public wxSoundStream {
|
||||
public:
|
||||
wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundFileStream();
|
||||
|
||||
bool Play();
|
||||
bool Record(unsigned long time);
|
||||
bool Stop();
|
||||
bool Pause();
|
||||
bool Resume();
|
||||
|
||||
bool IsStopped() const { return m_state == wxSOUND_FILE_STOPPED; }
|
||||
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
unsigned long GetLength() const;
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
|
||||
void SetDuplexMode(bool duplex);
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
virtual bool CanRead() { return TRUE; }
|
||||
|
||||
protected:
|
||||
wxSoundRouterStream m_codec;
|
||||
wxSoundStream *m_sndio;
|
||||
wxInputStream *m_input;
|
||||
wxOutputStream *m_output;
|
||||
|
||||
wxSoundFileState m_state, m_oldstate;
|
||||
wxUint32 m_len;
|
||||
|
||||
protected:
|
||||
virtual bool PrepareToPlay() = 0;
|
||||
virtual bool PrepareToRecord(unsigned long time) = 0;
|
||||
virtual bool FinishRecording() = 0;
|
||||
|
||||
virtual size_t GetData(void *buffer, size_t len) = 0;
|
||||
virtual size_t PutData(const void *buffer, size_t len) = 0;
|
||||
|
||||
void OnSoundEvent(int evt);
|
||||
};
|
||||
|
||||
#endif
|
324
utils/wxMMedia2/lib/sndoss.cpp
Normal file
324
utils/wxMMedia2/lib/sndoss.cpp
Normal file
@ -0,0 +1,324 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndoss.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndoss.cpp"
|
||||
#endif
|
||||
|
||||
#include <sys/soundcard.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <wx/defs.h>
|
||||
#include <wx/string.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndoss.h"
|
||||
#include "sndpcm.h"
|
||||
#ifdef __WXGTK__
|
||||
#include <gdk/gdk.h>
|
||||
#endif
|
||||
|
||||
wxSoundStreamOSS::wxSoundStreamOSS(const wxString& dev_name)
|
||||
{
|
||||
wxSoundFormatPcm pcm_default;
|
||||
|
||||
m_fd = open(dev_name.mb_str(), O_RDWR);
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_snderror = wxSOUND_INVDEV;
|
||||
return;
|
||||
}
|
||||
|
||||
m_devname = dev_name;
|
||||
|
||||
wxSoundStreamOSS::SetSoundFormat(pcm_default);
|
||||
|
||||
ioctl(m_fd, SNDCTL_DSP_GETBLKSIZE, &m_bufsize);
|
||||
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
close(m_fd);
|
||||
|
||||
m_oss_stop = TRUE;
|
||||
}
|
||||
|
||||
wxSoundStreamOSS::~wxSoundStreamOSS()
|
||||
{
|
||||
if (m_fd > 0)
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
wxUint32 wxSoundStreamOSS::GetBestSize() const
|
||||
{
|
||||
return m_bufsize;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamOSS::Read(void *buffer, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
m_lastcount = (size_t)ret = read(m_fd, buffer, len);
|
||||
|
||||
if (ret < 0)
|
||||
m_snderror = wxSOUND_IOERR;
|
||||
else
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamOSS::Write(const void *buffer, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
m_lastcount = (size_t)ret = write(m_fd, buffer, len);
|
||||
|
||||
if (ret < 0)
|
||||
m_snderror = wxSOUND_IOERR;
|
||||
else
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool wxSoundStreamOSS::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
int tmp;
|
||||
wxSoundFormatPcm *pcm_format;
|
||||
|
||||
if (format.GetType() != wxSOUND_PCM) {
|
||||
m_snderror = wxSOUND_INVFRMT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_snderror = wxSOUND_INVDEV;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (m_sndformat)
|
||||
delete m_sndformat;
|
||||
|
||||
m_sndformat = format.Clone();
|
||||
if (!m_sndformat) {
|
||||
m_snderror = wxSOUND_MEMERR;
|
||||
return FALSE;
|
||||
}
|
||||
pcm_format = (wxSoundFormatPcm *)m_sndformat;
|
||||
|
||||
// Set the sample rate field.
|
||||
tmp = pcm_format->GetSampleRate();
|
||||
ioctl(m_fd, SNDCTL_DSP_SPEED, &tmp);
|
||||
|
||||
pcm_format->SetSampleRate(tmp);
|
||||
|
||||
// Detect the best format
|
||||
DetectBest(pcm_format);
|
||||
SetupFormat(pcm_format);
|
||||
|
||||
tmp = pcm_format->GetChannels();
|
||||
ioctl(m_fd, SNDCTL_DSP_CHANNELS, &tmp);
|
||||
pcm_format->SetChannels(tmp);
|
||||
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
if (*pcm_format != format) {
|
||||
m_snderror = wxSOUND_NOTEXACT;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundStreamOSS::SetupFormat(wxSoundFormatPcm *pcm_format)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
switch(pcm_format->GetBPS()) {
|
||||
case 8:
|
||||
if (pcm_format->Signed())
|
||||
tmp = AFMT_S8;
|
||||
else
|
||||
tmp = AFMT_U8;
|
||||
break;
|
||||
case 16:
|
||||
switch (pcm_format->GetOrder()) {
|
||||
case wxBIG_ENDIAN:
|
||||
if (pcm_format->Signed())
|
||||
tmp = AFMT_S16_BE;
|
||||
else
|
||||
tmp = AFMT_U16_BE;
|
||||
break;
|
||||
case wxLITTLE_ENDIAN:
|
||||
if (pcm_format->Signed())
|
||||
tmp = AFMT_S16_LE;
|
||||
else
|
||||
tmp = AFMT_U16_LE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ioctl(m_fd, SNDCTL_DSP_SETFMT, &tmp);
|
||||
|
||||
// Demangling.
|
||||
switch (tmp) {
|
||||
case AFMT_U8:
|
||||
pcm_format->SetBPS(8);
|
||||
pcm_format->Signed(FALSE);
|
||||
break;
|
||||
case AFMT_S8:
|
||||
pcm_format->SetBPS(8);
|
||||
pcm_format->Signed(TRUE);
|
||||
break;
|
||||
case AFMT_U16_LE:
|
||||
pcm_format->SetBPS(16);
|
||||
pcm_format->Signed(FALSE);
|
||||
pcm_format->SetOrder(wxLITTLE_ENDIAN);
|
||||
break;
|
||||
case AFMT_U16_BE:
|
||||
pcm_format->SetBPS(16);
|
||||
pcm_format->Signed(FALSE);
|
||||
pcm_format->SetOrder(wxBIG_ENDIAN);
|
||||
break;
|
||||
case AFMT_S16_LE:
|
||||
pcm_format->SetBPS(16);
|
||||
pcm_format->Signed(TRUE);
|
||||
pcm_format->SetOrder(wxLITTLE_ENDIAN);
|
||||
break;
|
||||
case AFMT_S16_BE:
|
||||
pcm_format->SetBPS(16);
|
||||
pcm_format->Signed(TRUE);
|
||||
pcm_format->SetOrder(wxBIG_ENDIAN);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef __WXGTK__
|
||||
static void _wxSound_OSS_CBack(gpointer data, int source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
wxSoundStreamOSS *oss = (wxSoundStreamOSS *)data;
|
||||
|
||||
switch (condition) {
|
||||
case GDK_INPUT_READ:
|
||||
oss->WakeUpEvt(wxSOUND_INPUT);
|
||||
break;
|
||||
case GDK_INPUT_WRITE:
|
||||
oss->WakeUpEvt(wxSOUND_OUTPUT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void wxSoundStreamOSS::WakeUpEvt(int evt)
|
||||
{
|
||||
OnSoundEvent(evt);
|
||||
}
|
||||
|
||||
bool wxSoundStreamOSS::StartProduction(int evt)
|
||||
{
|
||||
wxSoundFormatBase *old_frmt;
|
||||
|
||||
if (!m_oss_stop)
|
||||
StopProduction();
|
||||
|
||||
old_frmt = m_sndformat->Clone();
|
||||
|
||||
if (evt == wxSOUND_OUTPUT)
|
||||
m_fd = open(m_devname.mb_str(), O_WRONLY);
|
||||
else if (evt == wxSOUND_INPUT)
|
||||
m_fd = open(m_devname.mb_str(), O_RDONLY);
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_snderror = wxSOUND_INVDEV;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SetSoundFormat(*old_frmt);
|
||||
delete old_frmt;
|
||||
|
||||
#ifdef __WXGTK__
|
||||
int trig;
|
||||
|
||||
if (evt == wxSOUND_OUTPUT) {
|
||||
m_tag = gdk_input_add(m_fd, GDK_INPUT_WRITE, _wxSound_OSS_CBack, (gpointer)this);
|
||||
trig = PCM_ENABLE_OUTPUT;
|
||||
} else {
|
||||
m_tag = gdk_input_add(m_fd, GDK_INPUT_READ, _wxSound_OSS_CBack, (gpointer)this);
|
||||
trig = PCM_ENABLE_INPUT;
|
||||
}
|
||||
#else
|
||||
while (!m_oss_stop)
|
||||
OnSoundEvent(evt);
|
||||
#endif
|
||||
|
||||
ioctl(m_fd, SNDCTL_DSP_SETTRIGGER, &trig);
|
||||
|
||||
m_oss_stop = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundStreamOSS::StopProduction()
|
||||
{
|
||||
if (m_oss_stop)
|
||||
return FALSE;
|
||||
|
||||
#ifdef __WXGTK__
|
||||
gdk_input_remove(m_tag);
|
||||
#endif
|
||||
|
||||
close(m_fd);
|
||||
m_oss_stop = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect the closest format (The best).
|
||||
//
|
||||
void wxSoundStreamOSS::DetectBest(wxSoundFormatPcm *pcm)
|
||||
{
|
||||
#define MASK_16BITS (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
|
||||
|
||||
int fmt_mask;
|
||||
wxSoundFormatPcm best_pcm;
|
||||
|
||||
// We change neither the number of channels nor the sample rate
|
||||
|
||||
best_pcm.SetSampleRate(pcm->GetSampleRate());
|
||||
best_pcm.SetChannels(pcm->GetChannels());
|
||||
|
||||
// Get the supported format by the sound card
|
||||
ioctl(m_fd, SNDCTL_DSP_GETFMTS, &fmt_mask);
|
||||
|
||||
// It supports 16 bits
|
||||
if (pcm->GetBPS() == 16 && ((fmt_mask & MASK_16BITS) != 0))
|
||||
best_pcm.SetBPS(16);
|
||||
|
||||
// It supports big endianness
|
||||
if (pcm->GetOrder() == wxBIG_ENDIAN && ((fmt_mask & (AFMT_S16_BE | AFMT_U16_BE)) != 0))
|
||||
best_pcm.SetOrder(wxBIG_ENDIAN);
|
||||
|
||||
// It supports little endianness
|
||||
if (pcm->GetOrder() == wxLITTLE_ENDIAN && ((fmt_mask & (AFMT_S16_LE | AFMT_U16_LE)) != 0))
|
||||
best_pcm.SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
// It supports signed samples
|
||||
if (pcm->Signed() && ((fmt_mask & (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)) != 0))
|
||||
best_pcm.Signed(TRUE);
|
||||
|
||||
// It supports unsigned samples
|
||||
if (!pcm->Signed() && ((fmt_mask & (AFMT_U16_LE | AFMT_U16_BE | AFMT_U8)) != 0))
|
||||
best_pcm.Signed(FALSE);
|
||||
|
||||
// Finally recopy the new format
|
||||
*pcm = best_pcm;
|
||||
}
|
53
utils/wxMMedia2/lib/sndoss.h
Normal file
53
utils/wxMMedia2/lib/sndoss.h
Normal file
@ -0,0 +1,53 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndoss.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDOSS_H
|
||||
#define _WX_SNDOSS_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndoss.h"
|
||||
#endif
|
||||
|
||||
#include <wx/string.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
//
|
||||
// OSS output class
|
||||
//
|
||||
|
||||
class wxSoundStreamOSS : public wxSoundStream {
|
||||
public:
|
||||
wxSoundStreamOSS(const wxString& dev_name = _T("/dev/dsp"));
|
||||
~wxSoundStreamOSS();
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
wxUint32 GetBestSize() const;
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
bool StartProduction(int evt);
|
||||
bool StopProduction();
|
||||
|
||||
void SetDuplexMode(bool duplex) {}
|
||||
|
||||
// You should not call this.
|
||||
void WakeUpEvt(int evt);
|
||||
protected:
|
||||
int m_fd;
|
||||
wxUint32 m_bufsize;
|
||||
int m_tag;
|
||||
bool m_oss_stop;
|
||||
wxString m_devname;
|
||||
|
||||
private:
|
||||
bool SetupFormat(wxSoundFormatPcm *pcm);
|
||||
void DetectBest(wxSoundFormatPcm *pcm);
|
||||
};
|
||||
|
||||
#endif
|
89
utils/wxMMedia2/lib/sndpcm.cpp
Normal file
89
utils/wxMMedia2/lib/sndpcm.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndpcm.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndpcm.cpp"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
#include "sndpcm.h"
|
||||
|
||||
|
||||
wxSoundFormatPcm::wxSoundFormatPcm(wxUint32 srate, wxUint8 bps,
|
||||
wxUint16 nchannels, bool sign,
|
||||
int order)
|
||||
: m_srate(srate), m_bps(bps), m_nchan(nchannels), m_order(order),
|
||||
m_signed(sign)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFormatPcm::~wxSoundFormatPcm()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSoundFormatPcm::SetSampleRate(wxUint32 srate)
|
||||
{
|
||||
m_srate = srate;
|
||||
}
|
||||
|
||||
void wxSoundFormatPcm::SetBPS(wxUint8 bps)
|
||||
{
|
||||
m_bps = bps;
|
||||
}
|
||||
|
||||
void wxSoundFormatPcm::SetChannels(wxUint16 nchannels)
|
||||
{
|
||||
m_nchan = nchannels;
|
||||
}
|
||||
|
||||
void wxSoundFormatPcm::SetOrder(int order)
|
||||
{
|
||||
m_order = order;
|
||||
}
|
||||
|
||||
void wxSoundFormatPcm::Signed(bool sign)
|
||||
{
|
||||
m_signed = sign;
|
||||
}
|
||||
|
||||
wxSoundFormatBase *wxSoundFormatPcm::Clone() const
|
||||
{
|
||||
wxSoundFormatPcm *new_pcm;
|
||||
|
||||
new_pcm = new wxSoundFormatPcm();
|
||||
new_pcm->m_srate = m_srate;
|
||||
new_pcm->m_bps = m_bps;
|
||||
new_pcm->m_nchan = m_nchan;
|
||||
new_pcm->m_order = m_order;
|
||||
new_pcm->m_signed= m_signed;
|
||||
|
||||
return new_pcm;
|
||||
}
|
||||
|
||||
wxUint32 wxSoundFormatPcm::GetTimeFromByte(wxUint32 bytes) const
|
||||
{
|
||||
return (bytes / (m_srate * (m_bps / 8) * m_nchan));
|
||||
}
|
||||
|
||||
wxUint32 wxSoundFormatPcm::GetByteFromTime(wxUint32 time) const
|
||||
{
|
||||
return (time * (m_srate * (m_bps / 8) * m_nchan));
|
||||
}
|
||||
|
||||
bool wxSoundFormatPcm::operator!=(const wxSoundFormatBase& format) const
|
||||
{
|
||||
wxSoundFormatPcm *format2 = (wxSoundFormatPcm *)&format;
|
||||
|
||||
if (format.GetType() != wxSOUND_PCM)
|
||||
return TRUE;
|
||||
|
||||
return ( (m_srate != format2->m_srate) ||
|
||||
(m_bps != format2->m_bps) ||
|
||||
(m_nchan != format2->m_nchan) ||
|
||||
(m_order != format2->m_order) ||
|
||||
(m_signed != format2->m_signed) );
|
||||
}
|
57
utils/wxMMedia2/lib/sndpcm.h
Normal file
57
utils/wxMMedia2/lib/sndpcm.h
Normal file
@ -0,0 +1,57 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndpcm.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDPCM_H
|
||||
#define _WX_SNDPCM_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndpcm.h"
|
||||
#endif
|
||||
|
||||
#include <wx/defs.h>
|
||||
#include "sndbase.h"
|
||||
|
||||
//
|
||||
// PCM specification class
|
||||
//
|
||||
|
||||
class wxSoundFormatPcm : public wxSoundFormatBase {
|
||||
public:
|
||||
wxSoundFormatPcm(wxUint32 srate = 22500, wxUint8 bps = 8,
|
||||
wxUint16 channels = 2, bool sign = TRUE,
|
||||
int order = wxLITTLE_ENDIAN);
|
||||
~wxSoundFormatPcm();
|
||||
|
||||
void SetSampleRate(wxUint32 srate);
|
||||
void SetBPS(wxUint8 bps);
|
||||
void SetChannels(wxUint16 nchannels);
|
||||
void SetOrder(int order);
|
||||
void Signed(bool sign);
|
||||
|
||||
wxUint32 GetSampleRate() const { return m_srate; }
|
||||
wxUint8 GetBPS() const { return m_bps; }
|
||||
wxUint16 GetChannels() const { return m_nchan; }
|
||||
int GetOrder() const { return m_order; }
|
||||
bool Signed() const { return m_signed; }
|
||||
|
||||
wxSoundFormatType GetType() const { return wxSOUND_PCM; }
|
||||
wxSoundFormatBase *Clone() const;
|
||||
|
||||
wxUint32 GetTimeFromByte(wxUint32 bytes) const;
|
||||
wxUint32 GetByteFromTime(wxUint32 time) const;
|
||||
|
||||
bool operator!=(const wxSoundFormatBase& frmt2) const;
|
||||
|
||||
protected:
|
||||
wxUint32 m_srate;
|
||||
wxUint8 m_bps;
|
||||
wxUint16 m_nchan;
|
||||
int m_order;
|
||||
bool m_signed;
|
||||
};
|
||||
|
||||
#endif
|
134
utils/wxMMedia2/lib/sndulaw.cpp
Normal file
134
utils/wxMMedia2/lib/sndulaw.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndulaw.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndulaw.cpp"
|
||||
#endif
|
||||
|
||||
#include "sndbase.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndpcm.h"
|
||||
#include "sndulaw.h"
|
||||
#include "g72x.h"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSoundFormatUlaw
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
wxSoundFormatUlaw::wxSoundFormatUlaw()
|
||||
: m_srate(22050)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundFormatUlaw::~wxSoundFormatUlaw()
|
||||
{
|
||||
}
|
||||
|
||||
void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate)
|
||||
{
|
||||
m_srate = srate;
|
||||
}
|
||||
|
||||
wxUint32 wxSoundFormatUlaw::GetSampleRate() const
|
||||
{
|
||||
return m_srate;
|
||||
}
|
||||
|
||||
wxSoundFormatBase *wxSoundFormatUlaw::Clone() const
|
||||
{
|
||||
wxSoundFormatUlaw *ulaw = new wxSoundFormatUlaw();
|
||||
|
||||
ulaw->m_srate = m_srate;
|
||||
return ulaw;
|
||||
}
|
||||
|
||||
wxUint32 wxSoundFormatUlaw::GetTimeFromByte(wxUint32 bytes) const
|
||||
{
|
||||
return (bytes / m_srate);
|
||||
}
|
||||
|
||||
wxUint32 wxSoundFormatUlaw::GetByteFromTime(wxUint32 time) const
|
||||
{
|
||||
return time * m_srate;
|
||||
}
|
||||
|
||||
bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase& frmt2) const
|
||||
{
|
||||
wxSoundFormatUlaw *ulaw = (wxSoundFormatUlaw *)&frmt2;
|
||||
|
||||
if (frmt2.GetType() != wxSOUND_ULAW)
|
||||
return TRUE;
|
||||
|
||||
return (ulaw->m_srate != m_srate);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// wxSoundStreamUlaw
|
||||
// --------------------------------------------------------------------------
|
||||
wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream& sndio)
|
||||
: wxSoundStreamCodec(sndio)
|
||||
{
|
||||
// PCM converter
|
||||
m_router = new wxSoundRouterStream(sndio);
|
||||
}
|
||||
|
||||
wxSoundStreamUlaw::~wxSoundStreamUlaw()
|
||||
{
|
||||
delete m_router;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, size_t len)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, size_t len)
|
||||
{
|
||||
wxUint16 *old_linear;
|
||||
register wxUint16 *linear_buffer;
|
||||
register const wxUint8 *ulaw_buffer;
|
||||
register size_t countdown = len;
|
||||
|
||||
old_linear = linear_buffer = new wxUint16[len*2];
|
||||
ulaw_buffer = (const wxUint8 *)buffer;
|
||||
|
||||
while (countdown != 0) {
|
||||
*linear_buffer++ = ulaw2linear(*ulaw_buffer++);
|
||||
countdown--;
|
||||
}
|
||||
|
||||
m_router->Write(old_linear, len * 2);
|
||||
|
||||
delete[] old_linear;
|
||||
|
||||
return *m_router;
|
||||
}
|
||||
|
||||
bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format)
|
||||
{
|
||||
if (format.GetType() != wxSOUND_ULAW) {
|
||||
m_snderror = wxSOUND_INVFRMT;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxSoundFormatPcm pcm;
|
||||
wxSoundFormatUlaw *ulaw;
|
||||
|
||||
wxSoundStreamCodec::SetSoundFormat(format);
|
||||
|
||||
ulaw = (wxSoundFormatUlaw *)m_sndformat;
|
||||
|
||||
pcm.SetSampleRate(ulaw->GetSampleRate());
|
||||
pcm.SetBPS(16);
|
||||
pcm.SetChannels(1);
|
||||
pcm.Signed(TRUE);
|
||||
pcm.SetOrder(wxBYTE_ORDER);
|
||||
|
||||
m_router->SetSoundFormat(pcm);
|
||||
|
||||
return TRUE;
|
||||
}
|
61
utils/wxMMedia2/lib/sndulaw.h
Normal file
61
utils/wxMMedia2/lib/sndulaw.h
Normal file
@ -0,0 +1,61 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndulaw.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDULAW_H
|
||||
#define _WX_SNDULAW_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndulaw.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sndcodec.h"
|
||||
#include "sndbase.h"
|
||||
|
||||
//
|
||||
// ULAW format
|
||||
//
|
||||
class WXDLLEXPORT wxSoundFormatUlaw: public wxSoundFormatBase {
|
||||
public:
|
||||
wxSoundFormatUlaw();
|
||||
~wxSoundFormatUlaw();
|
||||
|
||||
void SetSampleRate(wxUint32 srate);
|
||||
wxUint32 GetSampleRate() const;
|
||||
|
||||
wxSoundFormatType GetType() const { return wxSOUND_ULAW; }
|
||||
wxSoundFormatBase *Clone() const;
|
||||
|
||||
wxUint32 GetTimeFromByte(wxUint32 bytes) const;
|
||||
wxUint32 GetByteFromTime(wxUint32 time) const;
|
||||
|
||||
bool operator !=(const wxSoundFormatBase& frmt2) const;
|
||||
|
||||
protected:
|
||||
wxUint32 m_srate;
|
||||
};
|
||||
|
||||
//
|
||||
// ULAW converter class
|
||||
//
|
||||
|
||||
class WXDLLEXPORT wxSoundRouterStream;
|
||||
class WXDLLEXPORT wxSoundStreamUlaw: public wxSoundStreamCodec {
|
||||
public:
|
||||
wxSoundStreamUlaw(wxSoundStream& sndio);
|
||||
~wxSoundStreamUlaw();
|
||||
|
||||
wxSoundStream& Read(void *buffer, size_t len);
|
||||
wxSoundStream& Write(const void *buffer, size_t len);
|
||||
|
||||
bool SetSoundFormat(const wxSoundFormatBase& format);
|
||||
|
||||
protected:
|
||||
wxSoundRouterStream *m_router;
|
||||
};
|
||||
|
||||
#endif
|
221
utils/wxMMedia2/lib/sndwav.cpp
Normal file
221
utils/wxMMedia2/lib/sndwav.cpp
Normal file
@ -0,0 +1,221 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndwav.cpp
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "sndwav.cpp"
|
||||
#endif
|
||||
|
||||
#include <wx/defs.h>
|
||||
#include <wx/stream.h>
|
||||
#include <wx/datstrm.h>
|
||||
#include <wx/filefn.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
#include "sndfile.h"
|
||||
#include "sndpcm.h"
|
||||
#include "sndwav.h"
|
||||
|
||||
#define BUILD_SIGNATURE(a,b,c,d) (((wxUint32)a) | (((wxUint32)b) << 8) | (((wxUint32)c) << 16) | (((wxUint32)d) << 24))
|
||||
|
||||
#define RIFF_SIGNATURE BUILD_SIGNATURE('R','I','F','F')
|
||||
#define WAVE_SIGNATURE BUILD_SIGNATURE('W','A','V','E')
|
||||
#define FMT_SIGNATURE BUILD_SIGNATURE('f','m','t',' ')
|
||||
#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
|
||||
|
||||
wxSoundWave::wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundWave::wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound)
|
||||
: wxSoundFileStream(stream, io_sound)
|
||||
{
|
||||
}
|
||||
|
||||
wxSoundWave::~wxSoundWave()
|
||||
{
|
||||
}
|
||||
|
||||
#define FAIL_WITH(condition, err) if (condition) { m_snderror = err; return FALSE; }
|
||||
|
||||
bool wxSoundWave::CanRead()
|
||||
{
|
||||
wxUint32 len, signature;
|
||||
m_snderror = wxSOUND_NOERR;
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
if (wxUINT32_SWAP_ON_BE(signature) != RIFF_SIGNATURE) {
|
||||
m_input->Ungetch(&signature, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Read(&len, 4);
|
||||
FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
|
||||
if (wxUINT32_SWAP_ON_BE(signature) != WAVE_SIGNATURE) {
|
||||
m_input->Ungetch(&signature, 4);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_input->Ungetch("RIFF", 4);
|
||||
m_input->Ungetch(&len, 4);
|
||||
m_input->Ungetch("WAVE", 4);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::PrepareToPlay()
|
||||
{
|
||||
wxUint32 signature, len;
|
||||
bool end_headers;
|
||||
|
||||
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) {
|
||||
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;
|
||||
wxSoundFormatPcm sndformat;
|
||||
|
||||
data >> format >> channels >> sample_fq
|
||||
>> byte_p_sec >> byte_p_spl >> bits_p_spl;
|
||||
FAIL_WITH(format != 1, wxSOUND_NOCODEC);
|
||||
|
||||
sndformat.SetSampleRate(sample_fq);
|
||||
sndformat.SetBPS(bits_p_spl);
|
||||
sndformat.SetChannels(channels);
|
||||
sndformat.Signed(TRUE);
|
||||
sndformat.SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(sndformat))
|
||||
return FALSE;
|
||||
m_input->SeekI(len-16, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
case DATA_SIGNATURE: // "data"
|
||||
end_headers = TRUE;
|
||||
break;
|
||||
default:
|
||||
m_input->SeekI(len, wxFromCurrent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::PrepareToRecord(unsigned long time)
|
||||
{
|
||||
#define WRITE_SIGNATURE(sig) \
|
||||
signature = sig; \
|
||||
signature = wxUINT32_SWAP_ON_BE(signature); \
|
||||
FAIL_WITH(m_output->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
wxUint32 signature, len;
|
||||
|
||||
if (!m_output) {
|
||||
m_snderror = wxSOUND_INVSTRM;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxDataOutputStream data(*m_output);
|
||||
data.BigEndianOrdered(FALSE);
|
||||
|
||||
len = m_sndformat->GetByteFromTime(time);
|
||||
|
||||
len += HEADER_SIZE;
|
||||
|
||||
WRITE_SIGNATURE(RIFF_SIGNATURE);
|
||||
|
||||
data << len;
|
||||
FAIL_WITH(m_output->LastWrite() != 4, wxSOUND_INVSTRM);
|
||||
|
||||
WRITE_SIGNATURE(WAVE_SIGNATURE);
|
||||
|
||||
{
|
||||
wxUint16 format, channels, byte_p_spl, bits_p_spl;
|
||||
wxUint32 sample_fq, byte_p_sec;
|
||||
wxSoundFormatPcm *pcm;
|
||||
|
||||
if (m_sndformat->GetType() != wxSOUND_PCM) {
|
||||
m_snderror = wxSOUND_NOCODEC;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
|
||||
|
||||
WRITE_SIGNATURE(FMT_SIGNATURE);
|
||||
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->GetByteFromTime(1);
|
||||
format = 1;
|
||||
data << format << channels << sample_fq
|
||||
<< byte_p_sec << byte_p_spl << bits_p_spl;
|
||||
|
||||
pcm->Signed(TRUE);
|
||||
pcm->SetOrder(wxLITTLE_ENDIAN);
|
||||
|
||||
if (!SetSoundFormat(*pcm))
|
||||
return FALSE;
|
||||
|
||||
delete pcm;
|
||||
}
|
||||
|
||||
WRITE_SIGNATURE(DATA_SIGNATURE);
|
||||
data.Write32(m_sndformat->GetByteFromTime(time));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxSoundWave::FinishRecording()
|
||||
{
|
||||
// TODO: Update headers when we stop before the specified time (if possible)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
size_t wxSoundWave::GetData(void *buffer, size_t len)
|
||||
{
|
||||
return m_input->Read(buffer, len).LastRead();
|
||||
}
|
||||
|
||||
size_t wxSoundWave::PutData(const void *buffer, size_t len)
|
||||
{
|
||||
return m_output->Write(buffer, len).LastWrite();
|
||||
}
|
41
utils/wxMMedia2/lib/sndwav.h
Normal file
41
utils/wxMMedia2/lib/sndwav.h
Normal file
@ -0,0 +1,41 @@
|
||||
// --------------------------------------------------------------------------
|
||||
// Name: sndwav.h
|
||||
// Purpose:
|
||||
// Date: 08/11/1999
|
||||
// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
|
||||
// CVSID: $Id$
|
||||
// --------------------------------------------------------------------------
|
||||
#ifndef _WX_SNDWAV_H
|
||||
#define _WX_SNDWAV_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "sndwav.h"
|
||||
#endif
|
||||
|
||||
#include <wx/stream.h>
|
||||
#include "sndbase.h"
|
||||
#include "sndcodec.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
//
|
||||
// WAVE codec
|
||||
//
|
||||
|
||||
class wxSoundWave: public wxSoundFileStream {
|
||||
public:
|
||||
wxSoundWave(wxInputStream& stream, wxSoundStream& io_sound);
|
||||
wxSoundWave(wxOutputStream& stream, wxSoundStream& io_sound);
|
||||
~wxSoundWave();
|
||||
|
||||
bool CanRead();
|
||||
|
||||
protected:
|
||||
bool PrepareToPlay();
|
||||
bool PrepareToRecord(unsigned long time);
|
||||
bool FinishRecording();
|
||||
|
||||
size_t GetData(void *buffer, size_t len);
|
||||
size_t PutData(const void *buffer, size_t len);
|
||||
};
|
||||
|
||||
#endif
|
@ -22,10 +22,15 @@
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxVideoBaseDriver, wxObject)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxVideoOutput, wxWindow)
|
||||
#endif
|
||||
|
||||
wxVideoOutput::wxVideoOutput()
|
||||
: wxWindow()
|
||||
{
|
||||
dyn_size = TRUE;
|
||||
m_dyn_size = TRUE;
|
||||
}
|
||||
|
||||
wxVideoOutput::wxVideoOutput(wxWindow *parent, const wxWindowID id, const wxPoint& position,
|
||||
@ -33,7 +38,7 @@ wxVideoOutput::wxVideoOutput(wxWindow *parent, const wxWindowID id, const wxPoin
|
||||
const wxString& name)
|
||||
: wxWindow(parent, id, position, size, style, name)
|
||||
{
|
||||
dyn_size = TRUE;
|
||||
m_dyn_size = TRUE;
|
||||
}
|
||||
|
||||
///
|
||||
@ -42,18 +47,13 @@ wxVideoOutput::~wxVideoOutput()
|
||||
}
|
||||
|
||||
wxVideoBaseDriver::wxVideoBaseDriver()
|
||||
: wxMMediaFile()
|
||||
{
|
||||
m_video_output = NULL;
|
||||
}
|
||||
|
||||
wxVideoBaseDriver::wxVideoBaseDriver(wxInputStream& str, bool seekable)
|
||||
: wxMMediaFile(str, FALSE, seekable)
|
||||
{
|
||||
}
|
||||
|
||||
wxVideoBaseDriver::wxVideoBaseDriver(const wxString& fname)
|
||||
: wxMMediaFile(fname)
|
||||
wxVideoBaseDriver::wxVideoBaseDriver(wxInputStream& str)
|
||||
{
|
||||
m_video_output = NULL;
|
||||
}
|
||||
|
||||
wxVideoBaseDriver::~wxVideoBaseDriver()
|
||||
@ -62,13 +62,13 @@ wxVideoBaseDriver::~wxVideoBaseDriver()
|
||||
|
||||
bool wxVideoBaseDriver::AttachOutput(wxVideoOutput& output)
|
||||
{
|
||||
video_output = &output;
|
||||
m_video_output = &output;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxVideoBaseDriver::DetachOutput()
|
||||
{
|
||||
video_output = NULL;
|
||||
m_video_output = NULL;
|
||||
}
|
||||
|
||||
// Use an external frame for video output
|
||||
@ -76,12 +76,14 @@ void wxVideoBaseDriver::DetachOutput()
|
||||
wxFrame *wxVideoCreateFrame(wxVideoBaseDriver *vid_drv)
|
||||
{
|
||||
wxFrame *frame = new wxFrame(NULL, -1, "Video Output", wxDefaultPosition, wxSize(100, 100));
|
||||
wxVideoOutput *vid_out = new wxVideoOutput(frame, -1);
|
||||
wxVideoOutput *vid_out = new wxVideoOutput(frame, -1, wxPoint(0, 0), wxSize(300, 300));
|
||||
|
||||
vid_out->DynamicSize(TRUE);
|
||||
vid_drv->AttachOutput(*vid_out);
|
||||
frame->Layout();
|
||||
frame->Show(TRUE);
|
||||
wxYield();
|
||||
|
||||
vid_drv->AttachOutput(*vid_out);
|
||||
|
||||
return frame;
|
||||
}
|
@ -16,8 +16,6 @@
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "mmtype.h"
|
||||
#include "mmfile.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/window.h"
|
||||
#include "wx/frame.h"
|
||||
@ -42,7 +40,7 @@ class wxVideoOutput : public wxWindow {
|
||||
///
|
||||
DECLARE_DYNAMIC_CLASS(wxVideoOutput)
|
||||
protected:
|
||||
bool dyn_size;
|
||||
bool m_dyn_size;
|
||||
public:
|
||||
///
|
||||
wxVideoOutput();
|
||||
@ -55,26 +53,24 @@ public:
|
||||
virtual ~wxVideoOutput();
|
||||
|
||||
///
|
||||
bool DynamicSize() { return dyn_size; }
|
||||
bool DynamicSize() { return m_dyn_size; }
|
||||
///
|
||||
void DynamicSize(bool dyn) { dyn_size = dyn; }
|
||||
void DynamicSize(bool dyn) { m_dyn_size = dyn; }
|
||||
};
|
||||
|
||||
///
|
||||
class wxVideoBaseDriver : public wxObject, public wxMMediaFile {
|
||||
class wxVideoBaseDriver : public wxObject {
|
||||
///
|
||||
DECLARE_ABSTRACT_CLASS(wxVideoBaseDriver)
|
||||
protected:
|
||||
wxVideoOutput *video_output;
|
||||
wxVideoOutput *m_video_output;
|
||||
public:
|
||||
friend class wxVideoOutput;
|
||||
|
||||
///
|
||||
wxVideoBaseDriver();
|
||||
///
|
||||
wxVideoBaseDriver(wxInputStream& str, bool seekable = FALSE);
|
||||
///
|
||||
wxVideoBaseDriver(const wxString& fname);
|
||||
wxVideoBaseDriver(wxInputStream& str);
|
||||
///
|
||||
virtual ~wxVideoBaseDriver();
|
||||
|
@ -4,80 +4,88 @@
|
||||
// Author: Guilhem Lavaux
|
||||
// Created: 1997
|
||||
// Updated: 1998
|
||||
// Copyright: (C) 1997, 1998, Guilhem Lavaux
|
||||
// Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
|
||||
// License: wxWindows license
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "vidxanm.h"
|
||||
#endif
|
||||
#define WXMMEDIA_INTERNAL
|
||||
#ifdef __XT__
|
||||
#define Uses_XLib
|
||||
#define Uses_XtIntrinsic
|
||||
#endif
|
||||
#include "vidbase.h"
|
||||
#include "vidxanm.h"
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_prec.h"
|
||||
#include <wx_prec.h>
|
||||
#else
|
||||
#include "wx/wx.h"
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#ifdef __WXGTK__
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkprivate.h>
|
||||
#endif
|
||||
|
||||
#include <wx/filefn.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
#define WXMMEDIA_INTERNAL
|
||||
#include "vidbase.h"
|
||||
#include "vidxanm.h"
|
||||
|
||||
#if !USE_SHARED_LIBRARY
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
|
||||
#endif
|
||||
|
||||
wxVideoXANIM::wxVideoXANIM()
|
||||
: wxVideoBaseDriver()
|
||||
{
|
||||
internal = new wxXANIMinternal;
|
||||
xanim_started = false;
|
||||
paused = false;
|
||||
m_internal = new wxXANIMinternal;
|
||||
m_xanim_started = FALSE;
|
||||
m_paused = FALSE;
|
||||
m_filename = "";
|
||||
}
|
||||
|
||||
wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
|
||||
: wxVideoBaseDriver(str, false)
|
||||
: wxVideoBaseDriver(str)
|
||||
{
|
||||
internal = new wxXANIMinternal;
|
||||
xanim_started = false;
|
||||
paused = false;
|
||||
}
|
||||
m_internal = new wxXANIMinternal;
|
||||
m_xanim_started = FALSE;
|
||||
m_paused = FALSE;
|
||||
|
||||
wxVideoXANIM::wxVideoXANIM(const wxString& fname)
|
||||
: wxVideoBaseDriver(fname)
|
||||
{
|
||||
internal = new wxXANIMinternal;
|
||||
xanim_started = false;
|
||||
m_filename = wxGetTempFileName("vidxa");
|
||||
wxFileOutputStream fout(m_filename);
|
||||
|
||||
fout << str;
|
||||
}
|
||||
|
||||
wxVideoXANIM::~wxVideoXANIM()
|
||||
{
|
||||
if (xanim_started)
|
||||
if (m_xanim_started)
|
||||
StopPlay();
|
||||
delete internal;
|
||||
delete m_internal;
|
||||
|
||||
wxRemoveFile(m_filename);
|
||||
}
|
||||
|
||||
bool wxVideoXANIM::StartPlay()
|
||||
{
|
||||
if (!paused && xanim_started)
|
||||
return true;
|
||||
if (!video_output)
|
||||
if (!m_paused && m_xanim_started)
|
||||
return TRUE;
|
||||
if (!m_video_output) {
|
||||
wxVideoCreateFrame(this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (SendCommand(" ")) {
|
||||
paused = false;
|
||||
return true;
|
||||
m_paused = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxVideoXANIM::Pause()
|
||||
{
|
||||
if (!paused && SendCommand(" ")) {
|
||||
paused = TRUE;
|
||||
if (!m_paused && SendCommand(" ")) {
|
||||
m_paused = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@ -85,8 +93,8 @@ bool wxVideoXANIM::Pause()
|
||||
|
||||
bool wxVideoXANIM::Resume()
|
||||
{
|
||||
if (paused && SendCommand(" ")) {
|
||||
paused = FALSE;
|
||||
if (m_paused && SendCommand(" ")) {
|
||||
m_paused = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@ -94,13 +102,13 @@ bool wxVideoXANIM::Resume()
|
||||
|
||||
void wxVideoXANIM::StopPlay()
|
||||
{
|
||||
if (!xanim_started)
|
||||
if (!m_xanim_started)
|
||||
return;
|
||||
|
||||
SendCommand("q");
|
||||
|
||||
xanim_started = FALSE;
|
||||
paused = FALSE;
|
||||
m_xanim_started = FALSE;
|
||||
m_paused = FALSE;
|
||||
}
|
||||
|
||||
bool wxVideoXANIM::SetVolume(wxUint8 vol)
|
||||
@ -124,15 +132,15 @@ bool wxVideoXANIM::IsCapable(wxVideoType v_type)
|
||||
if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG ||
|
||||
v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV ||
|
||||
v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI)
|
||||
return true;
|
||||
return TRUE;
|
||||
else
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
|
||||
{
|
||||
if (!wxVideoBaseDriver::AttachOutput(out))
|
||||
return false;
|
||||
return FALSE;
|
||||
|
||||
return RestartXANIM();
|
||||
}
|
||||
@ -140,8 +148,8 @@ bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
|
||||
void wxVideoXANIM::DetachOutput()
|
||||
{
|
||||
SendCommand("q");
|
||||
xanim_started = false;
|
||||
paused = false;
|
||||
m_xanim_started = FALSE;
|
||||
m_paused = FALSE;
|
||||
|
||||
wxVideoBaseDriver::DetachOutput();
|
||||
}
|
||||
@ -149,27 +157,27 @@ void wxVideoXANIM::DetachOutput()
|
||||
bool wxVideoXANIM::SendCommand(const char *command, char **ret,
|
||||
wxUint32 *size)
|
||||
{
|
||||
if (!xanim_started)
|
||||
if (!m_xanim_started)
|
||||
if (!RestartXANIM())
|
||||
return false;
|
||||
return FALSE;
|
||||
|
||||
// Send a command to XAnim through X11 Property
|
||||
XChangeProperty(internal->xanim_dpy, internal->xanim_window,
|
||||
internal->xanim_atom,
|
||||
XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
||||
m_internal->xanim_atom,
|
||||
XA_STRING, 8, PropModeReplace, (unsigned char *)command,
|
||||
strlen(command));
|
||||
XFlush(internal->xanim_dpy);
|
||||
XFlush(m_internal->xanim_dpy);
|
||||
if (ret) {
|
||||
int prop_format;
|
||||
Atom prop_type;
|
||||
unsigned long extra;
|
||||
|
||||
XGetWindowProperty(internal->xanim_dpy, internal->xanim_window,
|
||||
internal->xanim_ret, 0, 16, True, AnyPropertyType,
|
||||
XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
||||
m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
|
||||
&prop_type, &prop_format, (unsigned long *)size,
|
||||
&extra, (unsigned char **)ret);
|
||||
}
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxVideoXANIM::RestartXANIM()
|
||||
@ -183,50 +191,46 @@ bool wxVideoXANIM::RestartXANIM()
|
||||
char prop[4];
|
||||
bool xanim_chg_size;
|
||||
|
||||
if (!video_output || xanim_started || !GetCurrentFile())
|
||||
return false;
|
||||
if (!m_video_output || m_xanim_started)
|
||||
return FALSE;
|
||||
|
||||
// Check if we can change the size of the window dynamicly
|
||||
xanim_chg_size = video_output->DynamicSize();
|
||||
xanim_chg_size = m_video_output->DynamicSize();
|
||||
// Get current display
|
||||
#ifdef __XT__
|
||||
internal->xanim_dpy = wxAPP_DISPLAY;
|
||||
#endif
|
||||
#ifdef __WXGTK__
|
||||
internal->xanim_dpy = gdk_display;
|
||||
#endif
|
||||
// Get the window id
|
||||
#ifdef __XT__
|
||||
internal->xanim_window = XtWindow(video_output->FWidget());
|
||||
#else
|
||||
internal->xanim_window =
|
||||
((GdkWindowPrivate *)video_output->m_widget->window)->xwindow;
|
||||
m_internal->xanim_dpy = gdk_display;
|
||||
// We absolutely need the window to be realized.
|
||||
gtk_widget_realize(m_video_output->m_wxwindow);
|
||||
m_internal->xanim_window =
|
||||
((GdkWindowPrivate *)m_video_output->m_wxwindow->window)->xwindow;
|
||||
#endif
|
||||
// Get the XANIM atom
|
||||
internal->xanim_atom = XInternAtom(internal->xanim_dpy,
|
||||
m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
|
||||
"XANIM_PROPERTY", False);
|
||||
|
||||
// Build the command
|
||||
xanim_command.sprintf(__XANIM_COMMAND__ " +W%d +Wp +f +B -Zr +q +Zpe +Ae "
|
||||
"+Av70 %s %s", internal->xanim_window,
|
||||
(xanim_chg_size == true) ? "+Sr" : "",
|
||||
(const char *)GetCurrentFile());
|
||||
xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
|
||||
"+Av70 %s %s"), m_internal->xanim_window,
|
||||
(xanim_chg_size) ? _T("") : _T(""),
|
||||
WXSTRINGCAST m_filename);
|
||||
|
||||
// Execute it
|
||||
if (!wxExecute(xanim_command, false))
|
||||
return false;
|
||||
if (!wxExecute(xanim_command, FALSE))
|
||||
return FALSE;
|
||||
|
||||
// Wait for XAnim to be ready
|
||||
nitems = 0;
|
||||
while (nitems == 0) {
|
||||
ret = XGetWindowProperty(internal->xanim_dpy, internal->xanim_window,
|
||||
internal->xanim_atom,
|
||||
ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
|
||||
m_internal->xanim_atom,
|
||||
0, 4, False, AnyPropertyType, &prop_type,
|
||||
&prop_format, &nitems, &extra,
|
||||
(unsigned char **)&prop);
|
||||
// wxYield();
|
||||
}
|
||||
|
||||
xanim_started = true;
|
||||
// m_paused = TRUE;
|
||||
m_xanim_started = TRUE;
|
||||
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
@ -37,26 +37,26 @@ typedef struct wxXANIMinternal {
|
||||
class wxVideoXANIM : public wxVideoBaseDriver {
|
||||
DECLARE_DYNAMIC_CLASS(wxVideoXANIM)
|
||||
protected:
|
||||
bool xanim_started, paused;
|
||||
struct wxXANIMinternal *internal;
|
||||
bool m_xanim_started, m_paused;
|
||||
struct wxXANIMinternal *m_internal;
|
||||
wxString m_filename;
|
||||
public:
|
||||
wxVideoXANIM();
|
||||
wxVideoXANIM(wxInputStream& str);
|
||||
wxVideoXANIM(const wxString& fname);
|
||||
virtual ~wxVideoXANIM();
|
||||
~wxVideoXANIM();
|
||||
|
||||
virtual bool StartPlay();
|
||||
virtual bool Pause();
|
||||
virtual bool Resume();
|
||||
virtual void StopPlay();
|
||||
bool StartPlay();
|
||||
bool Pause();
|
||||
bool Resume();
|
||||
void StopPlay();
|
||||
|
||||
virtual bool SetVolume(wxUint8 vol);
|
||||
virtual bool Resize(wxUint16 w, wxUint16 h);
|
||||
bool SetVolume(wxUint8 vol);
|
||||
bool Resize(wxUint16 w, wxUint16 h);
|
||||
|
||||
virtual bool IsCapable(wxVideoType v_type);
|
||||
bool IsCapable(wxVideoType v_type);
|
||||
|
||||
virtual bool AttachOutput(wxVideoOutput& output);
|
||||
virtual void DetachOutput();
|
||||
bool AttachOutput(wxVideoOutput& output);
|
||||
void DetachOutput();
|
||||
|
||||
protected:
|
||||
///
|
Loading…
Reference in New Issue
Block a user