From b55c191e04d9569c3b18f31697c7fa3723c46e81 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 28 Jul 2014 21:27:21 -0700 Subject: [PATCH] Initial support for WAV parsing --- lime/audio/Sound.hx | 72 +++++++ lime/system/System.hx | 4 + project/Build.xml | 2 + project/include/audio/Sound.h | 38 ++++ project/include/format/WAV.h | 31 +++ project/include/graphics/Image.h | 9 +- project/src/ExternalInterface.cpp | 47 ++++- project/src/audio/Sound.cpp | 53 +++++ project/src/format/WAV.cpp | 312 +++++++++++++----------------- project/src/graphics/Image.cpp | 55 +++--- 10 files changed, 408 insertions(+), 215 deletions(-) create mode 100644 lime/audio/Sound.hx create mode 100644 project/src/audio/Sound.cpp diff --git a/lime/audio/Sound.hx b/lime/audio/Sound.hx new file mode 100644 index 000000000..706f4e39e --- /dev/null +++ b/lime/audio/Sound.hx @@ -0,0 +1,72 @@ +package lime.audio; + + +import lime.system.System; +import lime.utils.ByteArray; + + +class Sound { + + + public var bitsPerSample:Int; + public var channels:Int; + public var data:ByteArray; + public var sampleRate:Int; + + + public function new () { + + + + } + + + public static function loadFromBytes (bytes:ByteArray):Sound { + + #if (cpp || neko) + + var data = lime_sound_load_bytes (bytes); + var sound = new Sound (); + sound.bitsPerSample = data.bitsPerSample; + sound.channels = data.channels; + sound.data = data.data; + sound.sampleRate = data.sampleRate; + return sound; + + #else + + return null; + + #end + + } + + + public static function loadFromFile (path:String):Sound { + + #if (cpp || neko) + + var data = lime_sound_load (path); + var sound = new Sound (); + sound.bitsPerSample = data.bitsPerSample; + sound.channels = data.channels; + sound.data = data.data; + sound.sampleRate = data.sampleRate; + return sound; + + #else + + return null; + + #end + + } + + + #if (cpp || neko) + private static var lime_sound_load = System.load ("lime", "lime_sound_load", 1); + private static var lime_sound_load_bytes = System.load ("lime", "lime_sound_load_bytes", 1); + #end + + +} \ No newline at end of file diff --git a/lime/system/System.hx b/lime/system/System.hx index 17dcedde1..91df77327 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -31,6 +31,10 @@ class System { element = cast Browser.document.getElementById (elementName); + } else { + + element = cast Browser.document.createElement ("div"); + } var color = null; diff --git a/project/Build.xml b/project/Build.xml index c404de852..90ca8a7cf 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -105,6 +105,8 @@ + + diff --git a/project/include/audio/Sound.h b/project/include/audio/Sound.h index 723805f32..be6a37700 100644 --- a/project/include/audio/Sound.h +++ b/project/include/audio/Sound.h @@ -2,6 +2,30 @@ #define LIME_AUDIO_SOUND_H +#include +#include + +#ifdef ANDROID +#include +#endif + + +#ifdef ANDROID +#define LOG_SOUND(args,...) ELOG(args, ##__VA_ARGS__) +#else +#ifdef IPHONE +//#define LOG_SOUND(args,...) printf(args, ##__VA_ARGS__) +#define LOG_SOUND(args...) { } +#elif defined(TIZEN) +#include +#define LOG_SOUND(args,...) AppLog(args, ##__VA_ARGS__) +#else +#define LOG_SOUND(args,...) printf(args, ##__VA_ARGS__) +#endif +#endif +//#define LOG_SOUND(args...) { } + + namespace lime { @@ -10,6 +34,20 @@ namespace lime { public: + Sound (); + ~Sound (); + + value Value (); + + int bitsPerSample; + int channels; + int sampleRate; + ByteArray *data; + + private: + + value mValue; + }; diff --git a/project/include/format/WAV.h b/project/include/format/WAV.h index 88d5356fa..0b1709b0a 100644 --- a/project/include/format/WAV.h +++ b/project/include/format/WAV.h @@ -9,6 +9,37 @@ namespace lime { + struct RIFF_Header { + + char chunkID[4]; + unsigned int chunkSize; //size not including chunkSize or chunkID + char format[4]; + + }; + + + struct WAVE_Format { + + char subChunkID[4]; + unsigned int subChunkSize; + short audioFormat; + short numChannels; + unsigned int sampleRate; + unsigned int byteRate; + short blockAlign; + short bitsPerSample; + + }; + + + struct WAVE_Data { + + char subChunkID[4]; //should contain the word data + unsigned int subChunkSize; //Stores the size of the data block + + }; + + class WAV { diff --git a/project/include/graphics/Image.h b/project/include/graphics/Image.h index a763b558e..9b184aa8f 100644 --- a/project/include/graphics/Image.h +++ b/project/include/graphics/Image.h @@ -17,15 +17,14 @@ namespace lime { Image (); ~Image (); - void Resize (int width, int height, int bpp = 4); void Blit (const unsigned char *data, int x, int y, int width, int height); + void Resize (int width, int height, int bpp = 4); value Value (); - int width; - int height; - int bpp; // bytes per pixel + int bpp; ByteArray *data; - + int height; + int width; private: diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 68668a195..8ca8b75a3 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -10,11 +10,13 @@ #include #include #include +#include