From: Mart Raudsepp Date: Wed, 28 Oct 1998 13:21:29 +0000 (+0000) Subject: wxWave class for wxGTK (linux) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/cbb8c1d34c68feaeb5861aa91bdbf715b2d963b0 wxWave class for wxGTK (linux) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@928 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/wave.h b/include/wx/gtk/wave.h new file mode 100644 index 0000000000..6b4095c243 --- /dev/null +++ b/include/wx/gtk/wave.h @@ -0,0 +1,63 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wave.h +// Purpose: wxWave class +// Author: Julian Smart +// Modified by: +// Created: 25/10/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WAVE_H_ +#define _WX_WAVE_H_ + +#ifdef __GNUG__ +#pragma interface "wave.h" +#endif + +#ifndef byte +#define byte unsigned char +#endif + +#include "wx/object.h" + +#ifndef AUDIODEV +#define AUDIODEV "/dev/dsp" // Default path for audio device +#endif + +class wxWave : public wxObject +{ +public: + wxWave(); + wxWave(const wxString& fileName, bool isResource = FALSE); + wxWave(int size, const byte* data); + ~wxWave(); + +public: + // Create from resource or file + bool Create(const wxString& fileName, bool isResource = FALSE); + // Create from data + bool Create(int size, const byte* data); + + bool IsOk() const { return (m_waveData ? TRUE : FALSE); }; + bool Play(bool async = TRUE, bool looped = FALSE); + +protected: + bool Free(); + +private: + byte* m_waveData; + int m_waveLength; + bool m_isResource; + + + int OpenDSP(void); + bool InitDSP(int dev, int iDataBits, int iChannel,unsigned long ulSamplingRate); + int m_DSPblkSize; // Size of the DSP buffer + char *m_data; + int m_sizeData; +}; + +#endif + diff --git a/include/wx/gtk1/wave.h b/include/wx/gtk1/wave.h new file mode 100644 index 0000000000..6b4095c243 --- /dev/null +++ b/include/wx/gtk1/wave.h @@ -0,0 +1,63 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wave.h +// Purpose: wxWave class +// Author: Julian Smart +// Modified by: +// Created: 25/10/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_WAVE_H_ +#define _WX_WAVE_H_ + +#ifdef __GNUG__ +#pragma interface "wave.h" +#endif + +#ifndef byte +#define byte unsigned char +#endif + +#include "wx/object.h" + +#ifndef AUDIODEV +#define AUDIODEV "/dev/dsp" // Default path for audio device +#endif + +class wxWave : public wxObject +{ +public: + wxWave(); + wxWave(const wxString& fileName, bool isResource = FALSE); + wxWave(int size, const byte* data); + ~wxWave(); + +public: + // Create from resource or file + bool Create(const wxString& fileName, bool isResource = FALSE); + // Create from data + bool Create(int size, const byte* data); + + bool IsOk() const { return (m_waveData ? TRUE : FALSE); }; + bool Play(bool async = TRUE, bool looped = FALSE); + +protected: + bool Free(); + +private: + byte* m_waveData; + int m_waveLength; + bool m_isResource; + + + int OpenDSP(void); + bool InitDSP(int dev, int iDataBits, int iChannel,unsigned long ulSamplingRate); + int m_DSPblkSize; // Size of the DSP buffer + char *m_data; + int m_sizeData; +}; + +#endif + diff --git a/include/wx/wave.h b/include/wx/wave.h new file mode 100644 index 0000000000..cd61bad818 --- /dev/null +++ b/include/wx/wave.h @@ -0,0 +1,13 @@ +#ifndef _WX_WAVE_H_BASE_ +#define _WX_WAVE_H_BASE_ + +#if defined(__WXMSW__) +#include "wx/msw/wave.h" +#elif defined(__WXGTK__) +#include "wx/gtk/wave.h" +#elif defined(__WXQT__) +#include "wx/qt/wave.h" +#endif + +#endif + // _WX_TREECTRL_H_BASE_ diff --git a/src/gtk/wave.cpp b/src/gtk/wave.cpp new file mode 100644 index 0000000000..a5255b57b9 --- /dev/null +++ b/src/gtk/wave.cpp @@ -0,0 +1,217 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wave.cpp +// Purpose: wxWave +// Author: Marcel Rasche +// Modified by: +// Created: 25/10/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "wave.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) +#pragma hdrstop +#endif + +#include +#include +#include +#include +#include + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include "wx/file.h" +#include "wx/wave.h" + + +wxWave::wxWave() + : m_waveLength(0), m_isResource(FALSE), m_waveData(NULL) +{ +} + +wxWave::wxWave(const wxString& sFileName, bool isResource) + : m_waveLength(0), m_isResource(isResource), m_waveData(NULL) +{ + Create(sFileName, isResource); +} + +wxWave::wxWave(int size, const byte* data) + : m_waveLength(0), m_isResource(FALSE), m_waveData(NULL) +{ + Create(size, data); +} + +wxWave::~wxWave() +{ + Free(); +} + +bool wxWave::Create(const wxString& fileName, bool isResource) +{ + Free(); + + if (isResource) + { + // todo + + return (m_waveData ? TRUE : FALSE); + } + else + { + m_isResource = FALSE; + + wxFile fileWave; + if (!fileWave.Open(fileName, wxFile::read)) + return FALSE; + + m_waveLength = (int) fileWave.Length(); + + m_waveData = new byte[m_waveLength]; + if (!m_waveData) + return FALSE; + + fileWave.Read(m_waveData, m_waveLength); + + return TRUE; + } +} + +bool wxWave::Create(int size, const byte* data) +{ + Free(); + m_isResource = FALSE; + m_waveLength=size; + m_waveData = new byte[size]; + if (!m_waveData) + return FALSE; + + for (int i=0; i 65536) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_SAMPLESIZE,&iDataBits) < 0 ) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_STEREO,&iChannel) < 0 ) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_SPEED,&ulSamplingRate) < 0 ) + return FALSE; + + return TRUE; +} + diff --git a/src/gtk1/wave.cpp b/src/gtk1/wave.cpp new file mode 100644 index 0000000000..a5255b57b9 --- /dev/null +++ b/src/gtk1/wave.cpp @@ -0,0 +1,217 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wave.cpp +// Purpose: wxWave +// Author: Marcel Rasche +// Modified by: +// Created: 25/10/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "wave.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) +#pragma hdrstop +#endif + +#include +#include +#include +#include +#include + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include "wx/file.h" +#include "wx/wave.h" + + +wxWave::wxWave() + : m_waveLength(0), m_isResource(FALSE), m_waveData(NULL) +{ +} + +wxWave::wxWave(const wxString& sFileName, bool isResource) + : m_waveLength(0), m_isResource(isResource), m_waveData(NULL) +{ + Create(sFileName, isResource); +} + +wxWave::wxWave(int size, const byte* data) + : m_waveLength(0), m_isResource(FALSE), m_waveData(NULL) +{ + Create(size, data); +} + +wxWave::~wxWave() +{ + Free(); +} + +bool wxWave::Create(const wxString& fileName, bool isResource) +{ + Free(); + + if (isResource) + { + // todo + + return (m_waveData ? TRUE : FALSE); + } + else + { + m_isResource = FALSE; + + wxFile fileWave; + if (!fileWave.Open(fileName, wxFile::read)) + return FALSE; + + m_waveLength = (int) fileWave.Length(); + + m_waveData = new byte[m_waveLength]; + if (!m_waveData) + return FALSE; + + fileWave.Read(m_waveData, m_waveLength); + + return TRUE; + } +} + +bool wxWave::Create(int size, const byte* data) +{ + Free(); + m_isResource = FALSE; + m_waveLength=size; + m_waveData = new byte[size]; + if (!m_waveData) + return FALSE; + + for (int i=0; i 65536) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_SAMPLESIZE,&iDataBits) < 0 ) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_STEREO,&iChannel) < 0 ) + return FALSE; + if ( ioctl(dev,SNDCTL_DSP_SPEED,&ulSamplingRate) < 0 ) + return FALSE; + + return TRUE; +} +