Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/util/audio.cpp b/util/audio.cpp
new file mode 100644
index 00000000..87cc6e4d
--- /dev/null
+++ b/util/audio.cpp
@@ -0,0 +1,42 @@
+#include "audio.h"
+
+namespace Util{
+
+AudioConverter::AudioConverter(Encoding inputEncoding, int inputChannels, int inputFrequency,
+ Encoding outputEncoding, int outputChannels, int outputFrequency){
+
+#ifdef USE_SDL
+ SDL_BuildAudioCVT(&conversion, inputEncoding, inputChannels, inputFrequency,
+ outputEncoding, outputChannels, outputFrequency);
+#endif
+
+}
+
+AudioConverter::~AudioConverter(){
+}
+
+int AudioConverter::convertedLength(int length){
+#ifdef USE_SDL
+ return length * conversion.len_mult;
+#else
+ return length;
+#endif
+}
+
+int AudioConverter::convert(void * input, int length){
+#ifdef USE_SDL
+ if (conversion.needed){
+ conversion.buf = (Uint8*) input;
+ conversion.len = length;
+ /* then convert to whatever the real output wants */
+ SDL_ConvertAudio(&conversion);
+ return conversion.len_cvt;
+ } else {
+ return length;
+ }
+#else
+ return length;
+#endif
+}
+
+}
diff --git a/util/audio.h b/util/audio.h
new file mode 100644
index 00000000..226aa1c3
--- /dev/null
+++ b/util/audio.h
@@ -0,0 +1,42 @@
+#ifndef _paintown_audio_h
+#define _paintown_audio_h
+
+#ifdef USE_SDL
+#include <SDL.h>
+#endif
+
+/* Deals with audio conversion between any source format and any destination format.
+ * A format consists of
+ * byte encoding (8/16/32 bit, signed/unsigned, floating point/integer)
+ * number of channels (mono/stereo)
+ * frequency (22050hz, 44100hz, arbitrary hz)
+ */
+
+namespace Util{
+
+typedef int Encoding;
+
+class AudioConverter{
+public:
+ AudioConverter(Encoding inputEncoding, int inputChannels, int inputFrequency,
+ Encoding outputEncoding, int outputChannels, int outputFrequency);
+
+ /* given some input length, return how long the converted output will be */
+ int convertedLength(int length);
+
+ /* convert the audio, put the output in the same buffer passed in -- 'input'
+ * and returns the number of converted samples.
+ */
+ int convert(void * input, int length);
+
+ virtual ~AudioConverter();
+
+protected:
+#ifdef USE_SDL
+ SDL_AudioCVT conversion;
+#endif
+};
+
+}
+
+#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:11 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68311
Default Alt Text
(2 KB)

Event Timeline