From ec2056842ea2852a3d883bdcc6682eb266d9fd08 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 6 Jan 2015 15:17:56 -0800 Subject: [PATCH] Expose audio pitch support in Lime legacy (thanks @PaulGene) --- legacy/project/include/Audio.h | 1 + legacy/project/include/Sound.h | 1 + legacy/project/src/ExternalInterface.cpp | 1 + .../project/src/common/ExternalInterface.cpp | 12 ++++++++++ legacy/project/src/iPhone/Sound.mm | 4 ++++ legacy/project/src/openal/OpenALSound.cpp | 22 +++++++++++++++++++ legacy/project/src/openal/OpenALSound.h | 2 ++ 7 files changed, 43 insertions(+) diff --git a/legacy/project/include/Audio.h b/legacy/project/include/Audio.h index 0bc5a882d..2dc9ad535 100644 --- a/legacy/project/include/Audio.h +++ b/legacy/project/include/Audio.h @@ -43,6 +43,7 @@ namespace nme virtual bool update() = 0; virtual void setTransform(const SoundTransform &inTransform) = 0; + virtual void setPitch(const float &inFloat) = 0; virtual double getPosition() = 0; virtual double setPosition(const float &inFloat) = 0; virtual double getLeft() = 0; diff --git a/legacy/project/include/Sound.h b/legacy/project/include/Sound.h index ae03dc159..2de59e248 100644 --- a/legacy/project/include/Sound.h +++ b/legacy/project/include/Sound.h @@ -40,6 +40,7 @@ public: virtual double setPosition(const float &inFloat) = 0; virtual void stop() = 0; virtual void setTransform(const SoundTransform &inTransform) = 0; + virtual void setPitch(const float &inFloat) = 0; virtual double getDataPosition() { return 0.0; } virtual bool needsData() { return false; } diff --git a/legacy/project/src/ExternalInterface.cpp b/legacy/project/src/ExternalInterface.cpp index 3fc30e3fd..7fddc551c 100644 --- a/legacy/project/src/ExternalInterface.cpp +++ b/legacy/project/src/ExternalInterface.cpp @@ -367,6 +367,7 @@ DEFINE_LIME_PRIM_1(sound_channel_get_position); DEFINE_LIME_PRIM_2(sound_channel_set_position); DEFINE_LIME_PRIM_1(sound_channel_stop); DEFINE_LIME_PRIM_2(sound_channel_set_transform); +DEFINE_LIME_PRIM_2(sound_channel_set_pitch); DEFINE_LIME_PRIM_4(sound_channel_create); DEFINE_LIME_PRIM_1(sound_channel_needs_data); DEFINE_LIME_PRIM_2(sound_channel_add_data); diff --git a/legacy/project/src/common/ExternalInterface.cpp b/legacy/project/src/common/ExternalInterface.cpp index 2556720aa..90438cff0 100644 --- a/legacy/project/src/common/ExternalInterface.cpp +++ b/legacy/project/src/common/ExternalInterface.cpp @@ -4456,6 +4456,18 @@ value nme_sound_channel_set_transform(value inChannel, value inTransform) } DEFINE_PRIM(nme_sound_channel_set_transform,2); +value nme_sound_channel_set_pitch(value inChannel, value inFloat) +{ + SoundChannel *channel; + if (AbstractToObject(inChannel,channel)) + { + float pitch = val_number(inFloat); + channel->setPitch(pitch); + } + return alloc_null(); +} +DEFINE_PRIM(nme_sound_channel_set_pitch,2); + value nme_sound_channel_create(value inSound, value inStart, value inLoops, value inTransform) { Sound *sound; diff --git a/legacy/project/src/iPhone/Sound.mm b/legacy/project/src/iPhone/Sound.mm index ffa098fa0..3808f9104 100644 --- a/legacy/project/src/iPhone/Sound.mm +++ b/legacy/project/src/iPhone/Sound.mm @@ -236,6 +236,10 @@ namespace nme } [theActualPlayer setVolume: inTransform.volume]; } + void setPitch(const float &inFloat) { + LOG_SOUND("AVAudioPlayerChannel setPitch()"); + [theActualPlayer setPitch: inFloat]; + } void stop() { LOG_SOUND("AVAudioPlayerChannel stop()"); diff --git a/legacy/project/src/openal/OpenALSound.cpp b/legacy/project/src/openal/OpenALSound.cpp index e3f840a24..d49706649 100644 --- a/legacy/project/src/openal/OpenALSound.cpp +++ b/legacy/project/src/openal/OpenALSound.cpp @@ -410,6 +410,19 @@ namespace nme } + void OpenALChannel::setPitch(const float &inFloat) + { + if (mUseStream) + { + if (mStream) mStream->setPitch(inFloat); + } + else + { + alSourcef(mSourceID, AL_PITCH, inFloat); + } + } + + void OpenALChannel::stop() { if (mUseStream) @@ -1286,6 +1299,15 @@ namespace nme } + void AudioStream_Ogg::setPitch(const float &inFloat) + { + if (!mSuspend) + { + alSourcef(source, AL_PITCH, inFloat); + } + } + + void AudioStream_Ogg::suspend() { mSuspend = true; diff --git a/legacy/project/src/openal/OpenALSound.h b/legacy/project/src/openal/OpenALSound.h index d8048a0f8..90c05e4fd 100644 --- a/legacy/project/src/openal/OpenALSound.h +++ b/legacy/project/src/openal/OpenALSound.h @@ -97,6 +97,7 @@ class OpenALChannel; bool playing(); bool update(); void setTransform(const SoundTransform &inTransform); + void setPitch(const float &inFloat); double getPosition(); double setPosition(const float &inFloat); double getLeft(); @@ -202,6 +203,7 @@ class OpenALChannel; double setPosition(const float &inFloat); double getPosition(); void setTransform(const SoundTransform &inTransform); + void setPitch(const float &inFloat); void stop(); void suspend(); void resume();